summaryrefslogtreecommitdiffstats
path: root/qa/workunits/mon/pool_ops.sh
blob: b02077691f25b36710265cab00b08daef8e5972b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env bash

set -ex

function expect_false()
{
	set -x
	if "$@"; then return 1; else return 0; fi
}

function get_config_value_or_die()
{
  local pool_name config_opt raw val

  pool_name=$1
  config_opt=$2

  raw="`$SUDO ceph osd pool get $pool_name $config_opt 2>/dev/null`"
  if [[ $? -ne 0 ]]; then
    echo "error obtaining config opt '$config_opt' from '$pool_name': $raw"
    exit 1
  fi

  raw=`echo $raw | sed -e 's/[{} "]//g'`
  val=`echo $raw | cut -f2 -d:`

  echo "$val"
  return 0
}

function expect_config_value()
{
  local pool_name config_opt expected_val val
  pool_name=$1
  config_opt=$2
  expected_val=$3

  val=$(get_config_value_or_die $pool_name $config_opt)

  if [[ "$val" != "$expected_val" ]]; then
    echo "expected '$expected_val', got '$val'"
    exit 1
  fi
}

# note: we need to pass the other args or ceph_argparse.py will take
# 'invalid' that is not replicated|erasure and assume it is the next
# argument, which is a string.
expect_false ceph osd pool create foo 123 123 invalid foo-profile foo-ruleset

ceph osd pool create foo 123 123 replicated
ceph osd pool create fooo 123 123 erasure default
ceph osd pool create foooo 123

ceph osd pool create foo 123 # idempotent

ceph osd pool set foo size 1
expect_config_value "foo" "min_size" 1
ceph osd pool set foo size 4
expect_config_value "foo" "min_size" 2
ceph osd pool set foo size 10
expect_config_value "foo" "min_size" 5
expect_false ceph osd pool set foo size 0
expect_false ceph osd pool set foo size 20

ceph osd pool set foo size 3
ceph osd getcrushmap -o crush
crushtool -d crush -o crush.txt
sed -i 's/max_size 10/max_size 3/' crush.txt
crushtool -c crush.txt -o crush.new
ceph osd setcrushmap -i crush.new
expect_false ceph osd pool set foo size 4
ceph osd setcrushmap -i crush
rm -f crush crush.txt crush.new

# should fail due to safety interlock
expect_false ceph osd pool delete foo
expect_false ceph osd pool delete foo foo
expect_false ceph osd pool delete foo foo --force
expect_false ceph osd pool delete foo fooo --yes-i-really-mean-it
expect_false ceph osd pool delete foo --yes-i-really-mean-it foo

ceph osd pool delete foooo foooo --yes-i-really-really-mean-it
ceph osd pool delete fooo fooo --yes-i-really-really-mean-it
ceph osd pool delete foo foo --yes-i-really-really-mean-it

# idempotent
ceph osd pool delete foo foo --yes-i-really-really-mean-it
ceph osd pool delete fooo fooo --yes-i-really-really-mean-it
ceph osd pool delete fooo fooo --yes-i-really-really-mean-it

# non-existent pool
ceph osd pool delete fuggg fuggg --yes-i-really-really-mean-it

echo OK