|
10 | 10 | # License for the specific language governing permissions and limitations |
11 | 11 | # under the License. |
12 | 12 |
|
| 13 | +import json |
| 14 | +import time |
13 | 15 | import uuid |
14 | 16 |
|
15 | 17 | from openstackclient.tests.functional.volume.v1 import common |
|
18 | 20 | class VolumeTests(common.BaseVolumeTests): |
19 | 21 | """Functional tests for volume. """ |
20 | 22 |
|
21 | | - NAME = uuid.uuid4().hex |
22 | | - OTHER_NAME = uuid.uuid4().hex |
23 | | - HEADERS = ['"Display Name"'] |
24 | | - FIELDS = ['display_name'] |
25 | | - |
26 | | - @classmethod |
27 | | - def setUpClass(cls): |
28 | | - super(VolumeTests, cls).setUpClass() |
29 | | - opts = cls.get_opts(cls.FIELDS) |
30 | | - raw_output = cls.openstack('volume create --size 1 ' + cls.NAME + opts) |
31 | | - expected = cls.NAME + '\n' |
32 | | - cls.assertOutput(expected, raw_output) |
33 | | - |
34 | | - @classmethod |
35 | | - def tearDownClass(cls): |
36 | | - # Rename test |
37 | | - raw_output = cls.openstack( |
38 | | - 'volume set --name ' + cls.OTHER_NAME + ' ' + cls.NAME) |
39 | | - cls.assertOutput('', raw_output) |
40 | | - # Delete test |
41 | | - raw_output = cls.openstack('volume delete ' + cls.OTHER_NAME) |
42 | | - cls.assertOutput('', raw_output) |
| 23 | + def test_volume_create_and_delete(self): |
| 24 | + """Test create, delete multiple""" |
| 25 | + name1 = uuid.uuid4().hex |
| 26 | + cmd_output = json.loads(self.openstack( |
| 27 | + 'volume create -f json ' + |
| 28 | + '--size 1 ' + |
| 29 | + name1 |
| 30 | + )) |
| 31 | + self.assertEqual( |
| 32 | + 1, |
| 33 | + cmd_output["size"], |
| 34 | + ) |
| 35 | + |
| 36 | + name2 = uuid.uuid4().hex |
| 37 | + cmd_output = json.loads(self.openstack( |
| 38 | + 'volume create -f json ' + |
| 39 | + '--size 2 ' + |
| 40 | + name2 |
| 41 | + )) |
| 42 | + self.assertEqual( |
| 43 | + 2, |
| 44 | + cmd_output["size"], |
| 45 | + ) |
| 46 | + |
| 47 | + self.wait_for("volume", name1, "available") |
| 48 | + self.wait_for("volume", name2, "available") |
| 49 | + del_output = self.openstack('volume delete ' + name1 + ' ' + name2) |
| 50 | + self.assertOutput('', del_output) |
43 | 51 |
|
44 | 52 | def test_volume_list(self): |
45 | | - opts = self.get_opts(self.HEADERS) |
46 | | - raw_output = self.openstack('volume list' + opts) |
47 | | - self.assertIn(self.NAME, raw_output) |
| 53 | + """Test create, list filter""" |
| 54 | + name1 = uuid.uuid4().hex |
| 55 | + cmd_output = json.loads(self.openstack( |
| 56 | + 'volume create -f json ' + |
| 57 | + '--size 1 ' + |
| 58 | + name1 |
| 59 | + )) |
| 60 | + self.addCleanup(self.openstack, 'volume delete ' + name1) |
| 61 | + self.assertEqual( |
| 62 | + 1, |
| 63 | + cmd_output["size"], |
| 64 | + ) |
| 65 | + self.wait_for("volume", name1, "available") |
| 66 | + |
| 67 | + name2 = uuid.uuid4().hex |
| 68 | + cmd_output = json.loads(self.openstack( |
| 69 | + 'volume create -f json ' + |
| 70 | + '--size 2 ' + |
| 71 | + name2 |
| 72 | + )) |
| 73 | + self.addCleanup(self.openstack, 'volume delete ' + name2) |
| 74 | + self.assertEqual( |
| 75 | + 2, |
| 76 | + cmd_output["size"], |
| 77 | + ) |
| 78 | + self.wait_for("volume", name2, "available") |
| 79 | + |
| 80 | + # Test list |
| 81 | + cmd_output = json.loads(self.openstack( |
| 82 | + 'volume list -f json ' |
| 83 | + )) |
| 84 | + names = [x["Display Name"] for x in cmd_output] |
| 85 | + self.assertIn(name1, names) |
| 86 | + self.assertIn(name2, names) |
| 87 | + |
| 88 | + # Test list --long |
| 89 | + cmd_output = json.loads(self.openstack( |
| 90 | + 'volume list -f json --long' |
| 91 | + )) |
| 92 | + bootable = [x["Bootable"] for x in cmd_output] |
| 93 | + self.assertIn('false', bootable) |
| 94 | + |
| 95 | + # Test list --name |
| 96 | + cmd_output = json.loads(self.openstack( |
| 97 | + 'volume list -f json ' + |
| 98 | + '--name ' + name1 |
| 99 | + )) |
| 100 | + names = [x["Display Name"] for x in cmd_output] |
| 101 | + self.assertIn(name1, names) |
| 102 | + self.assertNotIn(name2, names) |
48 | 103 |
|
49 | | - def test_volume_show(self): |
50 | | - opts = self.get_opts(self.FIELDS) |
51 | | - raw_output = self.openstack('volume show ' + self.NAME + opts) |
52 | | - self.assertEqual(self.NAME + "\n", raw_output) |
| 104 | + def test_volume_set_and_unset(self): |
| 105 | + """Tests create volume, set, unset, show, delete""" |
| 106 | + name = uuid.uuid4().hex |
| 107 | + cmd_output = json.loads(self.openstack( |
| 108 | + 'volume create -f json ' + |
| 109 | + '--size 1 ' + |
| 110 | + '--description aaaa ' + |
| 111 | + '--property Alpha=a ' + |
| 112 | + name |
| 113 | + )) |
| 114 | + self.assertEqual( |
| 115 | + name, |
| 116 | + cmd_output["display_name"], |
| 117 | + ) |
| 118 | + self.assertEqual( |
| 119 | + 1, |
| 120 | + cmd_output["size"], |
| 121 | + ) |
| 122 | + self.assertEqual( |
| 123 | + 'aaaa', |
| 124 | + cmd_output["display_description"], |
| 125 | + ) |
| 126 | + self.assertEqual( |
| 127 | + "Alpha='a'", |
| 128 | + cmd_output["properties"], |
| 129 | + ) |
| 130 | + self.assertEqual( |
| 131 | + 'false', |
| 132 | + cmd_output["bootable"], |
| 133 | + ) |
| 134 | + self.wait_for("volume", name, "available") |
53 | 135 |
|
54 | | - def test_volume_properties(self): |
| 136 | + # Test volume set |
| 137 | + new_name = uuid.uuid4().hex |
| 138 | + self.addCleanup(self.openstack, 'volume delete ' + new_name) |
55 | 139 | raw_output = self.openstack( |
56 | | - 'volume set --property a=b --property c=d ' + self.NAME) |
57 | | - self.assertEqual("", raw_output) |
58 | | - opts = self.get_opts(["properties"]) |
59 | | - raw_output = self.openstack('volume show ' + self.NAME + opts) |
60 | | - self.assertEqual("a='b', c='d'\n", raw_output) |
61 | | - |
62 | | - raw_output = self.openstack('volume unset --property a ' + self.NAME) |
63 | | - self.assertEqual("", raw_output) |
64 | | - raw_output = self.openstack('volume show ' + self.NAME + opts) |
65 | | - self.assertEqual("c='d'\n", raw_output) |
66 | | - |
67 | | - def test_volume_set(self): |
68 | | - self.openstack('volume set --description RAMAC ' + self.NAME) |
69 | | - opts = self.get_opts(["display_description", "display_name"]) |
70 | | - raw_output = self.openstack('volume show ' + self.NAME + opts) |
71 | | - self.assertEqual("RAMAC\n" + self.NAME + "\n", raw_output) |
72 | | - |
73 | | - def test_volume_set_size(self): |
74 | | - self.openstack('volume set --size 2 ' + self.NAME) |
75 | | - opts = self.get_opts(["display_name", "size"]) |
76 | | - raw_output = self.openstack('volume show ' + self.NAME + opts) |
77 | | - self.assertEqual(self.NAME + "\n2\n", raw_output) |
78 | | - |
79 | | - def test_volume_set_bootable(self): |
80 | | - self.openstack('volume set --bootable ' + self.NAME) |
81 | | - opts = self.get_opts(["bootable"]) |
82 | | - raw_output = self.openstack('volume show ' + self.NAME + opts) |
83 | | - self.assertEqual("true\n", raw_output) |
84 | | - |
85 | | - self.openstack('volume set --non-bootable ' + self.NAME) |
86 | | - opts = self.get_opts(["bootable"]) |
87 | | - raw_output = self.openstack('volume show ' + self.NAME + opts) |
88 | | - self.assertEqual("false\n", raw_output) |
| 140 | + 'volume set ' + |
| 141 | + '--name ' + new_name + |
| 142 | + ' --size 2 ' + |
| 143 | + '--description bbbb ' + |
| 144 | + '--property Alpha=c ' + |
| 145 | + '--property Beta=b ' + |
| 146 | + '--bootable ' + |
| 147 | + name, |
| 148 | + ) |
| 149 | + self.assertOutput('', raw_output) |
| 150 | + |
| 151 | + cmd_output = json.loads(self.openstack( |
| 152 | + 'volume show -f json ' + |
| 153 | + new_name |
| 154 | + )) |
| 155 | + self.assertEqual( |
| 156 | + new_name, |
| 157 | + cmd_output["display_name"], |
| 158 | + ) |
| 159 | + self.assertEqual( |
| 160 | + 2, |
| 161 | + cmd_output["size"], |
| 162 | + ) |
| 163 | + self.assertEqual( |
| 164 | + 'bbbb', |
| 165 | + cmd_output["display_description"], |
| 166 | + ) |
| 167 | + self.assertEqual( |
| 168 | + "Alpha='c', Beta='b'", |
| 169 | + cmd_output["properties"], |
| 170 | + ) |
| 171 | + self.assertEqual( |
| 172 | + 'true', |
| 173 | + cmd_output["bootable"], |
| 174 | + ) |
| 175 | + |
| 176 | + # Test volume unset |
| 177 | + raw_output = self.openstack( |
| 178 | + 'volume unset ' + |
| 179 | + '--property Alpha ' + |
| 180 | + new_name, |
| 181 | + ) |
| 182 | + self.assertOutput('', raw_output) |
| 183 | + |
| 184 | + cmd_output = json.loads(self.openstack( |
| 185 | + 'volume show -f json ' + |
| 186 | + new_name |
| 187 | + )) |
| 188 | + self.assertEqual( |
| 189 | + "Beta='b'", |
| 190 | + cmd_output["properties"], |
| 191 | + ) |
| 192 | + |
| 193 | + def wait_for(self, check_type, check_name, desired_status, wait=120, |
| 194 | + interval=5, failures=['ERROR']): |
| 195 | + status = "notset" |
| 196 | + total_sleep = 0 |
| 197 | + opts = self.get_opts(['status']) |
| 198 | + while total_sleep < wait: |
| 199 | + status = self.openstack(check_type + ' show ' + check_name + opts) |
| 200 | + status = status.rstrip() |
| 201 | + print('Checking {} {} Waiting for {} current status: {}' |
| 202 | + .format(check_type, check_name, desired_status, status)) |
| 203 | + if status == desired_status: |
| 204 | + break |
| 205 | + self.assertNotIn(status, failures) |
| 206 | + time.sleep(interval) |
| 207 | + total_sleep += interval |
| 208 | + self.assertEqual(desired_status, status) |
0 commit comments