|
10 | 10 | # License for the specific language governing permissions and limitations |
11 | 11 | # under the License. |
12 | 12 |
|
| 13 | +import json |
13 | 14 | import time |
14 | 15 | import uuid |
15 | 16 |
|
|
19 | 20 | class VolumeTests(common.BaseVolumeTests): |
20 | 21 | """Functional tests for volume. """ |
21 | 22 |
|
22 | | - NAME = uuid.uuid4().hex |
23 | | - SNAPSHOT_NAME = uuid.uuid4().hex |
24 | | - VOLUME_FROM_SNAPSHOT_NAME = uuid.uuid4().hex |
25 | | - OTHER_NAME = uuid.uuid4().hex |
26 | | - HEADERS = ['"Display Name"'] |
27 | | - FIELDS = ['name'] |
28 | | - |
29 | | - @classmethod |
30 | | - def setUpClass(cls): |
31 | | - super(VolumeTests, cls).setUpClass() |
32 | | - opts = cls.get_opts(cls.FIELDS) |
33 | | - |
34 | | - # Create test volume |
35 | | - raw_output = cls.openstack('volume create --size 1 ' + cls.NAME + opts) |
36 | | - expected = cls.NAME + '\n' |
37 | | - cls.assertOutput(expected, raw_output) |
38 | | - |
39 | | - @classmethod |
40 | | - def tearDownClass(cls): |
41 | | - # Rename test volume |
42 | | - raw_output = cls.openstack( |
43 | | - 'volume set --name ' + cls.OTHER_NAME + ' ' + cls.NAME) |
44 | | - cls.assertOutput('', raw_output) |
45 | | - |
46 | | - # Set volume state |
47 | | - cls.openstack('volume set --state error ' + cls.OTHER_NAME) |
48 | | - opts = cls.get_opts(["status"]) |
49 | | - raw_output_status = cls.openstack( |
50 | | - 'volume show ' + cls.OTHER_NAME + opts) |
51 | | - |
52 | | - # Delete test volume |
53 | | - raw_output = cls.openstack('volume delete ' + cls.OTHER_NAME) |
54 | | - cls.assertOutput('', raw_output) |
55 | | - cls.assertOutput('error\n', raw_output_status) |
| 23 | + def test_volume_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) |
56 | 51 |
|
57 | 52 | def test_volume_list(self): |
58 | | - opts = self.get_opts(self.HEADERS) |
59 | | - raw_output = self.openstack('volume list' + opts) |
60 | | - self.assertIn(self.NAME, raw_output) |
61 | | - |
62 | | - def test_volume_show(self): |
63 | | - opts = self.get_opts(self.FIELDS) |
64 | | - raw_output = self.openstack('volume show ' + self.NAME + opts) |
65 | | - self.assertEqual(self.NAME + "\n", raw_output) |
66 | | - |
67 | | - def test_volume_properties(self): |
| 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") |
68 | 79 | raw_output = self.openstack( |
69 | | - 'volume set --property a=b --property c=d ' + self.NAME) |
70 | | - self.assertEqual("", raw_output) |
71 | | - opts = self.get_opts(["properties"]) |
72 | | - raw_output = self.openstack('volume show ' + self.NAME + opts) |
73 | | - self.assertEqual("a='b', c='d'\n", raw_output) |
| 80 | + 'volume set ' + |
| 81 | + '--state error ' + |
| 82 | + name2 |
| 83 | + ) |
| 84 | + self.assertOutput('', raw_output) |
74 | 85 |
|
75 | | - raw_output = self.openstack('volume unset --property a ' + self.NAME) |
76 | | - self.assertEqual("", raw_output) |
77 | | - raw_output = self.openstack('volume show ' + self.NAME + opts) |
78 | | - self.assertEqual("c='d'\n", raw_output) |
| 86 | + # Test list --long |
| 87 | + cmd_output = json.loads(self.openstack( |
| 88 | + 'volume list -f json ' + |
| 89 | + '--long' |
| 90 | + )) |
| 91 | + names = [x["Display Name"] for x in cmd_output] |
| 92 | + self.assertIn(name1, names) |
| 93 | + self.assertIn(name2, names) |
| 94 | + |
| 95 | + # Test list --status |
| 96 | + cmd_output = json.loads(self.openstack( |
| 97 | + 'volume list -f json ' + |
| 98 | + '--status error' |
| 99 | + )) |
| 100 | + names = [x["Display Name"] for x in cmd_output] |
| 101 | + self.assertNotIn(name1, names) |
| 102 | + self.assertIn(name2, names) |
| 103 | + |
| 104 | + # TODO(qiangjiahui): Add project option to filter tests when we can |
| 105 | + # specify volume with project |
79 | 106 |
|
80 | 107 | def test_volume_set(self): |
81 | | - discription = uuid.uuid4().hex |
82 | | - self.openstack('volume set --description ' + discription + ' ' + |
83 | | - self.NAME) |
84 | | - opts = self.get_opts(["description", "name"]) |
85 | | - raw_output = self.openstack('volume show ' + self.NAME + opts) |
86 | | - self.assertEqual(discription + "\n" + self.NAME + "\n", raw_output) |
87 | | - |
88 | | - def test_volume_set_size(self): |
89 | | - self.openstack('volume set --size 2 ' + self.NAME) |
90 | | - opts = self.get_opts(["name", "size"]) |
91 | | - raw_output = self.openstack('volume show ' + self.NAME + opts) |
92 | | - self.assertEqual(self.NAME + "\n2\n", raw_output) |
93 | | - |
94 | | - def test_volume_set_bootable(self): |
95 | | - self.openstack('volume set --bootable ' + self.NAME) |
96 | | - opts = self.get_opts(["bootable"]) |
97 | | - raw_output = self.openstack('volume show ' + self.NAME + opts) |
98 | | - self.assertEqual("true\n", raw_output) |
99 | | - |
100 | | - self.openstack('volume set --non-bootable ' + self.NAME) |
101 | | - opts = self.get_opts(["bootable"]) |
102 | | - raw_output = self.openstack('volume show ' + self.NAME + opts) |
103 | | - self.assertEqual("false\n", raw_output) |
| 108 | + """Tests create volume, set, unset, show, delete""" |
| 109 | + name = uuid.uuid4().hex |
| 110 | + new_name = name + "_" |
| 111 | + cmd_output = json.loads(self.openstack( |
| 112 | + 'volume create -f json ' + |
| 113 | + '--size 1 ' + |
| 114 | + '--description aaaa ' + |
| 115 | + '--property Alpha=a ' + |
| 116 | + name |
| 117 | + )) |
| 118 | + self.addCleanup(self.openstack, 'volume delete ' + new_name) |
| 119 | + self.assertEqual( |
| 120 | + name, |
| 121 | + cmd_output["name"], |
| 122 | + ) |
| 123 | + self.assertEqual( |
| 124 | + 1, |
| 125 | + cmd_output["size"], |
| 126 | + ) |
| 127 | + self.assertEqual( |
| 128 | + 'aaaa', |
| 129 | + cmd_output["description"], |
| 130 | + ) |
| 131 | + self.assertEqual( |
| 132 | + "Alpha='a'", |
| 133 | + cmd_output["properties"], |
| 134 | + ) |
| 135 | + self.assertEqual( |
| 136 | + 'false', |
| 137 | + cmd_output["bootable"], |
| 138 | + ) |
| 139 | + self.wait_for("volume", name, "available") |
| 140 | + |
| 141 | + # Test volume set |
| 142 | + raw_output = self.openstack( |
| 143 | + 'volume set ' + |
| 144 | + '--name ' + new_name + |
| 145 | + ' --size 2 ' + |
| 146 | + '--description bbbb ' + |
| 147 | + '--property Alpha=c ' + |
| 148 | + '--property Beta=b ' + |
| 149 | + '--bootable ' + |
| 150 | + name, |
| 151 | + ) |
| 152 | + self.assertOutput('', raw_output) |
104 | 153 |
|
105 | | - def test_volume_snapshot(self): |
106 | | - opts = self.get_opts(self.FIELDS) |
107 | | - |
108 | | - # Create snapshot from test volume |
109 | | - raw_output = self.openstack('volume snapshot create ' + |
110 | | - self.SNAPSHOT_NAME + |
111 | | - ' --volume ' + self.NAME + opts) |
112 | | - expected = self.SNAPSHOT_NAME + '\n' |
113 | | - self.assertOutput(expected, raw_output) |
114 | | - self.wait_for("volume snapshot", self.SNAPSHOT_NAME, "available") |
115 | | - |
116 | | - # Create volume from snapshot |
117 | | - raw_output = self.openstack('volume create --size 2 --snapshot ' + |
118 | | - self.SNAPSHOT_NAME + ' ' + |
119 | | - self.VOLUME_FROM_SNAPSHOT_NAME + opts) |
120 | | - expected = self.VOLUME_FROM_SNAPSHOT_NAME + '\n' |
121 | | - self.assertOutput(expected, raw_output) |
122 | | - self.wait_for("volume", self.VOLUME_FROM_SNAPSHOT_NAME, "available") |
123 | | - |
124 | | - # Delete volume that create from snapshot |
125 | | - raw_output = self.openstack('volume delete ' + |
126 | | - self.VOLUME_FROM_SNAPSHOT_NAME) |
| 154 | + cmd_output = json.loads(self.openstack( |
| 155 | + 'volume show -f json ' + |
| 156 | + new_name |
| 157 | + )) |
| 158 | + self.assertEqual( |
| 159 | + new_name, |
| 160 | + cmd_output["name"], |
| 161 | + ) |
| 162 | + self.assertEqual( |
| 163 | + 2, |
| 164 | + cmd_output["size"], |
| 165 | + ) |
| 166 | + self.assertEqual( |
| 167 | + 'bbbb', |
| 168 | + cmd_output["description"], |
| 169 | + ) |
| 170 | + self.assertEqual( |
| 171 | + "Alpha='c', Beta='b'", |
| 172 | + cmd_output["properties"], |
| 173 | + ) |
| 174 | + self.assertEqual( |
| 175 | + 'true', |
| 176 | + cmd_output["bootable"], |
| 177 | + ) |
| 178 | + |
| 179 | + # Test volume unset |
| 180 | + raw_output = self.openstack( |
| 181 | + 'volume unset ' + |
| 182 | + '--property Alpha ' + |
| 183 | + new_name, |
| 184 | + ) |
127 | 185 | self.assertOutput('', raw_output) |
128 | 186 |
|
129 | | - # Delete test snapshot |
| 187 | + cmd_output = json.loads(self.openstack( |
| 188 | + 'volume show -f json ' + |
| 189 | + new_name |
| 190 | + )) |
| 191 | + self.assertEqual( |
| 192 | + "Beta='b'", |
| 193 | + cmd_output["properties"], |
| 194 | + ) |
| 195 | + |
| 196 | + def test_volume_snapshot(self): |
| 197 | + """Tests volume create from snapshot""" |
| 198 | + |
| 199 | + volume_name = uuid.uuid4().hex |
| 200 | + snapshot_name = uuid.uuid4().hex |
| 201 | + # Make a snapshot |
| 202 | + cmd_output = json.loads(self.openstack( |
| 203 | + 'volume create -f json ' + |
| 204 | + '--size 1 ' + |
| 205 | + volume_name |
| 206 | + )) |
| 207 | + self.wait_for("volume", volume_name, "available") |
| 208 | + self.assertEqual( |
| 209 | + volume_name, |
| 210 | + cmd_output["name"], |
| 211 | + ) |
| 212 | + cmd_output = json.loads(self.openstack( |
| 213 | + 'volume snapshot create -f json ' + |
| 214 | + snapshot_name + |
| 215 | + ' --volume ' + volume_name |
| 216 | + )) |
| 217 | + self.wait_for("volume snapshot", snapshot_name, "available") |
| 218 | + |
| 219 | + name = uuid.uuid4().hex |
| 220 | + cmd_output = json.loads(self.openstack( |
| 221 | + 'volume create -f json ' + |
| 222 | + '--snapshot ' + snapshot_name + |
| 223 | + ' ' + name |
| 224 | + )) |
| 225 | + self.addCleanup(self.openstack, 'volume delete ' + name) |
| 226 | + self.addCleanup(self.openstack, 'volume delete ' + volume_name) |
| 227 | + self.assertEqual( |
| 228 | + name, |
| 229 | + cmd_output["name"], |
| 230 | + ) |
| 231 | + self.wait_for("volume", name, "available") |
| 232 | + |
| 233 | + # Delete snapshot |
130 | 234 | raw_output = self.openstack( |
131 | | - 'volume snapshot delete ' + self.SNAPSHOT_NAME) |
| 235 | + 'volume snapshot delete ' + snapshot_name) |
132 | 236 | self.assertOutput('', raw_output) |
133 | | - self.wait_for("volume", self.NAME, "available") |
134 | 237 |
|
135 | 238 | def wait_for(self, check_type, check_name, desired_status, wait=120, |
136 | 239 | interval=5, failures=['ERROR']): |
|
0 commit comments