|
10 | 10 | # License for the specific language governing permissions and limitations |
11 | 11 | # under the License. |
12 | 12 |
|
13 | | -from openstackclient.tests.functional.volume.v2 import test_qos as v2 |
| 13 | +import json |
| 14 | +import uuid |
| 15 | + |
14 | 16 | from openstackclient.tests.functional.volume.v3 import common |
15 | 17 |
|
16 | 18 |
|
17 | | -class QosTests(common.BaseVolumeTests, v2.QosTests): |
| 19 | +class QosTests(common.BaseVolumeTests): |
18 | 20 | """Functional tests for volume qos. """ |
| 21 | + |
| 22 | + def test_volume_qos_create_delete_list(self): |
| 23 | + """Test create, list, delete multiple""" |
| 24 | + name1 = uuid.uuid4().hex |
| 25 | + cmd_output = json.loads(self.openstack( |
| 26 | + 'volume qos create -f json ' + |
| 27 | + name1 |
| 28 | + )) |
| 29 | + self.assertEqual( |
| 30 | + name1, |
| 31 | + cmd_output['name'] |
| 32 | + ) |
| 33 | + |
| 34 | + name2 = uuid.uuid4().hex |
| 35 | + cmd_output = json.loads(self.openstack( |
| 36 | + 'volume qos create -f json ' + |
| 37 | + name2 |
| 38 | + )) |
| 39 | + self.assertEqual( |
| 40 | + name2, |
| 41 | + cmd_output['name'] |
| 42 | + ) |
| 43 | + |
| 44 | + # Test list |
| 45 | + cmd_output = json.loads(self.openstack( |
| 46 | + 'volume qos list -f json' |
| 47 | + )) |
| 48 | + names = [x["Name"] for x in cmd_output] |
| 49 | + self.assertIn(name1, names) |
| 50 | + self.assertIn(name2, names) |
| 51 | + |
| 52 | + # Test delete multiple |
| 53 | + del_output = self.openstack('volume qos delete ' + name1 + ' ' + name2) |
| 54 | + self.assertOutput('', del_output) |
| 55 | + |
| 56 | + def test_volume_qos_set_show_unset(self): |
| 57 | + """Tests create volume qos, set, unset, show, delete""" |
| 58 | + |
| 59 | + name = uuid.uuid4().hex |
| 60 | + cmd_output = json.loads(self.openstack( |
| 61 | + 'volume qos create -f json ' + |
| 62 | + '--consumer front-end ' |
| 63 | + '--property Alpha=a ' + |
| 64 | + name |
| 65 | + )) |
| 66 | + self.addCleanup(self.openstack, 'volume qos delete ' + name) |
| 67 | + self.assertEqual( |
| 68 | + name, |
| 69 | + cmd_output['name'] |
| 70 | + ) |
| 71 | + |
| 72 | + self.assertEqual( |
| 73 | + "front-end", |
| 74 | + cmd_output['consumer'] |
| 75 | + ) |
| 76 | + self.assertEqual( |
| 77 | + {'Alpha': 'a'}, |
| 78 | + cmd_output['properties'] |
| 79 | + ) |
| 80 | + |
| 81 | + # Test volume qos set |
| 82 | + raw_output = self.openstack( |
| 83 | + 'volume qos set ' + |
| 84 | + '--property Alpha=c ' + |
| 85 | + '--property Beta=b ' + |
| 86 | + name, |
| 87 | + ) |
| 88 | + self.assertOutput('', raw_output) |
| 89 | + |
| 90 | + # Test volume qos show |
| 91 | + cmd_output = json.loads(self.openstack( |
| 92 | + 'volume qos show -f json ' + |
| 93 | + name |
| 94 | + )) |
| 95 | + self.assertEqual( |
| 96 | + name, |
| 97 | + cmd_output['name'] |
| 98 | + ) |
| 99 | + self.assertEqual( |
| 100 | + {'Alpha': 'c', 'Beta': 'b'}, |
| 101 | + cmd_output['properties'] |
| 102 | + ) |
| 103 | + |
| 104 | + # Test volume qos unset |
| 105 | + raw_output = self.openstack( |
| 106 | + 'volume qos unset ' + |
| 107 | + '--property Alpha ' + |
| 108 | + name, |
| 109 | + ) |
| 110 | + self.assertOutput('', raw_output) |
| 111 | + |
| 112 | + cmd_output = json.loads(self.openstack( |
| 113 | + 'volume qos show -f json ' + |
| 114 | + name |
| 115 | + )) |
| 116 | + self.assertEqual( |
| 117 | + name, |
| 118 | + cmd_output['name'] |
| 119 | + ) |
| 120 | + self.assertEqual( |
| 121 | + {'Beta': 'b'}, |
| 122 | + cmd_output['properties'] |
| 123 | + ) |
| 124 | + |
| 125 | + def test_volume_qos_asso_disasso(self): |
| 126 | + """Tests associate and disassociate qos with volume type""" |
| 127 | + vol_type1 = uuid.uuid4().hex |
| 128 | + cmd_output = json.loads(self.openstack( |
| 129 | + 'volume type create -f json ' + |
| 130 | + vol_type1 |
| 131 | + )) |
| 132 | + self.assertEqual( |
| 133 | + vol_type1, |
| 134 | + cmd_output['name'] |
| 135 | + ) |
| 136 | + self.addCleanup(self.openstack, 'volume type delete ' + vol_type1) |
| 137 | + |
| 138 | + vol_type2 = uuid.uuid4().hex |
| 139 | + cmd_output = json.loads(self.openstack( |
| 140 | + 'volume type create -f json ' + |
| 141 | + vol_type2 |
| 142 | + )) |
| 143 | + self.assertEqual( |
| 144 | + vol_type2, |
| 145 | + cmd_output['name'] |
| 146 | + ) |
| 147 | + self.addCleanup(self.openstack, 'volume type delete ' + vol_type2) |
| 148 | + |
| 149 | + name = uuid.uuid4().hex |
| 150 | + cmd_output = json.loads(self.openstack( |
| 151 | + 'volume qos create -f json ' + |
| 152 | + name |
| 153 | + )) |
| 154 | + self.assertEqual( |
| 155 | + name, |
| 156 | + cmd_output['name'] |
| 157 | + ) |
| 158 | + self.addCleanup(self.openstack, 'volume qos delete ' + name) |
| 159 | + |
| 160 | + # Test associate |
| 161 | + raw_output = self.openstack( |
| 162 | + 'volume qos associate ' + |
| 163 | + name + ' ' + vol_type1 |
| 164 | + ) |
| 165 | + self.assertOutput('', raw_output) |
| 166 | + raw_output = self.openstack( |
| 167 | + 'volume qos associate ' + |
| 168 | + name + ' ' + vol_type2 |
| 169 | + ) |
| 170 | + self.assertOutput('', raw_output) |
| 171 | + |
| 172 | + cmd_output = json.loads(self.openstack( |
| 173 | + 'volume qos show -f json ' + |
| 174 | + name |
| 175 | + )) |
| 176 | + types = cmd_output["associations"] |
| 177 | + self.assertIn(vol_type1, types) |
| 178 | + self.assertIn(vol_type2, types) |
| 179 | + |
| 180 | + # Test disassociate |
| 181 | + raw_output = self.openstack( |
| 182 | + 'volume qos disassociate ' + |
| 183 | + '--volume-type ' + vol_type1 + |
| 184 | + ' ' + name |
| 185 | + ) |
| 186 | + self.assertOutput('', raw_output) |
| 187 | + cmd_output = json.loads(self.openstack( |
| 188 | + 'volume qos show -f json ' + |
| 189 | + name |
| 190 | + )) |
| 191 | + types = cmd_output["associations"] |
| 192 | + self.assertNotIn(vol_type1, types) |
| 193 | + self.assertIn(vol_type2, types) |
| 194 | + |
| 195 | + # Test disassociate --all |
| 196 | + raw_output = self.openstack( |
| 197 | + 'volume qos associate ' + |
| 198 | + name + ' ' + vol_type1 |
| 199 | + ) |
| 200 | + self.assertOutput('', raw_output) |
| 201 | + cmd_output = json.loads(self.openstack( |
| 202 | + 'volume qos show -f json ' + |
| 203 | + name |
| 204 | + )) |
| 205 | + types = cmd_output["associations"] |
| 206 | + self.assertIn(vol_type1, types) |
| 207 | + self.assertIn(vol_type2, types) |
| 208 | + |
| 209 | + raw_output = self.openstack( |
| 210 | + 'volume qos disassociate ' + |
| 211 | + '--all ' + name |
| 212 | + ) |
| 213 | + self.assertOutput('', raw_output) |
| 214 | + cmd_output = json.loads(self.openstack( |
| 215 | + 'volume qos show -f json ' + |
| 216 | + name |
| 217 | + )) |
| 218 | + self.assertNotIn("associations", cmd_output.keys()) |
0 commit comments