|
10 | 10 | # License for the specific language governing permissions and limitations |
11 | 11 | # under the License. |
12 | 12 |
|
| 13 | +import json |
13 | 14 | import uuid |
14 | 15 |
|
15 | 16 | from openstackclient.tests.functional import base |
|
18 | 19 | class FlavorTests(base.TestCase): |
19 | 20 | """Functional tests for flavor.""" |
20 | 21 |
|
21 | | - NAME = uuid.uuid4().hex |
22 | | - HEADERS = ['Name'] |
23 | | - FIELDS = ['name'] |
| 22 | + PROJECT_NAME = uuid.uuid4().hex |
24 | 23 |
|
25 | 24 | @classmethod |
26 | 25 | def setUpClass(cls): |
27 | | - opts = cls.get_opts(cls.FIELDS) |
28 | | - raw_output = cls.openstack( |
29 | | - 'flavor create --property a=b --property c=d ' + cls.NAME + opts) |
30 | | - expected = cls.NAME + '\n' |
31 | | - cls.assertOutput(expected, raw_output) |
| 26 | + # Make a project |
| 27 | + cmd_output = json.loads(cls.openstack( |
| 28 | + "project create -f json --enable " + cls.PROJECT_NAME |
| 29 | + )) |
| 30 | + cls.project_id = cmd_output["id"] |
32 | 31 |
|
33 | 32 | @classmethod |
34 | 33 | def tearDownClass(cls): |
35 | | - raw_output = cls.openstack('flavor delete ' + cls.NAME) |
| 34 | + raw_output = cls.openstack("project delete " + cls.PROJECT_NAME) |
36 | 35 | cls.assertOutput('', raw_output) |
37 | 36 |
|
| 37 | + def test_flavor_delete(self): |
| 38 | + """Test create w/project, delete multiple""" |
| 39 | + name1 = uuid.uuid4().hex |
| 40 | + cmd_output = json.loads(self.openstack( |
| 41 | + "flavor create -f json " + |
| 42 | + "--project " + self.PROJECT_NAME + " " + |
| 43 | + "--private " + |
| 44 | + name1 |
| 45 | + )) |
| 46 | + self.assertIsNotNone(cmd_output["id"]) |
| 47 | + |
| 48 | + name2 = uuid.uuid4().hex |
| 49 | + cmd_output = json.loads(self.openstack( |
| 50 | + "flavor create -f json " + |
| 51 | + "--id qaz " + |
| 52 | + "--project " + self.PROJECT_NAME + " " + |
| 53 | + "--private " + |
| 54 | + name2 |
| 55 | + )) |
| 56 | + self.assertIsNotNone(cmd_output["id"]) |
| 57 | + self.assertEqual( |
| 58 | + "qaz", |
| 59 | + cmd_output["id"], |
| 60 | + ) |
| 61 | + |
| 62 | + raw_output = self.openstack( |
| 63 | + "flavor delete " + name1 + " " + name2, |
| 64 | + ) |
| 65 | + self.assertOutput('', raw_output) |
| 66 | + |
38 | 67 | def test_flavor_list(self): |
39 | | - opts = self.get_opts(self.HEADERS) |
40 | | - raw_output = self.openstack('flavor list' + opts) |
41 | | - self.assertIn("small", raw_output) |
42 | | - self.assertIn(self.NAME, raw_output) |
| 68 | + """Test create defaults, list filters, delete""" |
| 69 | + name1 = uuid.uuid4().hex |
| 70 | + cmd_output = json.loads(self.openstack( |
| 71 | + "flavor create -f json " + |
| 72 | + "--property a=b " + |
| 73 | + "--property c=d " + |
| 74 | + name1 |
| 75 | + )) |
| 76 | + self.addCleanup(self.openstack, "flavor delete " + name1) |
| 77 | + self.assertIsNotNone(cmd_output["id"]) |
| 78 | + self.assertEqual( |
| 79 | + name1, |
| 80 | + cmd_output["name"], |
| 81 | + ) |
| 82 | + |
| 83 | + name2 = uuid.uuid4().hex |
| 84 | + cmd_output = json.loads(self.openstack( |
| 85 | + "flavor create -f json " + |
| 86 | + "--id qaz " + |
| 87 | + "--ram 123 " + |
| 88 | + "--private " + |
| 89 | + "--property a=b2 " + |
| 90 | + "--property b=d2 " + |
| 91 | + name2 |
| 92 | + )) |
| 93 | + self.addCleanup(self.openstack, "flavor delete " + name2) |
| 94 | + self.assertIsNotNone(cmd_output["id"]) |
| 95 | + self.assertEqual( |
| 96 | + "qaz", |
| 97 | + cmd_output["id"], |
| 98 | + ) |
| 99 | + self.assertEqual( |
| 100 | + name2, |
| 101 | + cmd_output["name"], |
| 102 | + ) |
| 103 | + self.assertEqual( |
| 104 | + 123, |
| 105 | + cmd_output["ram"], |
| 106 | + ) |
| 107 | + self.assertEqual( |
| 108 | + 0, |
| 109 | + cmd_output["disk"], |
| 110 | + ) |
| 111 | + self.assertEqual( |
| 112 | + False, |
| 113 | + cmd_output["os-flavor-access:is_public"], |
| 114 | + ) |
| 115 | + self.assertEqual( |
| 116 | + "a='b2', b='d2'", |
| 117 | + cmd_output["properties"], |
| 118 | + ) |
43 | 119 |
|
44 | | - def test_flavor_show(self): |
45 | | - opts = self.get_opts(self.FIELDS) |
46 | | - raw_output = self.openstack('flavor show ' + self.NAME + opts) |
47 | | - self.assertEqual(self.NAME + "\n", raw_output) |
| 120 | + # Test list |
| 121 | + cmd_output = json.loads(self.openstack( |
| 122 | + "flavor list -f json" |
| 123 | + )) |
| 124 | + col_name = [x["Name"] for x in cmd_output] |
| 125 | + self.assertIn(name1, col_name) |
| 126 | + self.assertNotIn(name2, col_name) |
| 127 | + |
| 128 | + # Test list --long |
| 129 | + cmd_output = json.loads(self.openstack( |
| 130 | + "flavor list -f json " + |
| 131 | + "--long" |
| 132 | + )) |
| 133 | + col_name = [x["Name"] for x in cmd_output] |
| 134 | + col_properties = [x['Properties'] for x in cmd_output] |
| 135 | + self.assertIn(name1, col_name) |
| 136 | + self.assertIn("a='b', c='d'", col_properties) |
| 137 | + self.assertNotIn(name2, col_name) |
| 138 | + self.assertNotIn("b2', b='d2'", col_properties) |
| 139 | + |
| 140 | + # Test list --public |
| 141 | + cmd_output = json.loads(self.openstack( |
| 142 | + "flavor list -f json " + |
| 143 | + "--public" |
| 144 | + )) |
| 145 | + col_name = [x["Name"] for x in cmd_output] |
| 146 | + self.assertIn(name1, col_name) |
| 147 | + self.assertNotIn(name2, col_name) |
| 148 | + |
| 149 | + # Test list --private |
| 150 | + cmd_output = json.loads(self.openstack( |
| 151 | + "flavor list -f json " + |
| 152 | + "--private" |
| 153 | + )) |
| 154 | + col_name = [x["Name"] for x in cmd_output] |
| 155 | + self.assertNotIn(name1, col_name) |
| 156 | + self.assertIn(name2, col_name) |
| 157 | + |
| 158 | + # Test list --all |
| 159 | + cmd_output = json.loads(self.openstack( |
| 160 | + "flavor list -f json " + |
| 161 | + "--all" |
| 162 | + )) |
| 163 | + col_name = [x["Name"] for x in cmd_output] |
| 164 | + self.assertIn(name1, col_name) |
| 165 | + self.assertIn(name2, col_name) |
48 | 166 |
|
49 | 167 | def test_flavor_properties(self): |
50 | | - opts = self.get_opts(['properties']) |
51 | | - # check the properties we added in create command. |
52 | | - raw_output = self.openstack('flavor show ' + self.NAME + opts) |
53 | | - self.assertEqual("a='b', c='d'\n", raw_output) |
| 168 | + """Test create defaults, list filters, delete""" |
| 169 | + name1 = uuid.uuid4().hex |
| 170 | + cmd_output = json.loads(self.openstack( |
| 171 | + "flavor create -f json " + |
| 172 | + "--id qaz " + |
| 173 | + "--ram 123 " + |
| 174 | + "--disk 20 " + |
| 175 | + "--private " + |
| 176 | + "--property a=first " + |
| 177 | + "--property b=second " + |
| 178 | + name1 |
| 179 | + )) |
| 180 | + self.addCleanup(self.openstack, "flavor delete " + name1) |
| 181 | + self.assertIsNotNone(cmd_output["id"]) |
| 182 | + self.assertEqual( |
| 183 | + "qaz", |
| 184 | + cmd_output["id"], |
| 185 | + ) |
| 186 | + self.assertEqual( |
| 187 | + name1, |
| 188 | + cmd_output["name"], |
| 189 | + ) |
| 190 | + self.assertEqual( |
| 191 | + 123, |
| 192 | + cmd_output["ram"], |
| 193 | + ) |
| 194 | + self.assertEqual( |
| 195 | + 20, |
| 196 | + cmd_output["disk"], |
| 197 | + ) |
| 198 | + self.assertEqual( |
| 199 | + False, |
| 200 | + cmd_output["os-flavor-access:is_public"], |
| 201 | + ) |
| 202 | + self.assertEqual( |
| 203 | + "a='first', b='second'", |
| 204 | + cmd_output["properties"], |
| 205 | + ) |
54 | 206 |
|
55 | 207 | raw_output = self.openstack( |
56 | | - 'flavor set --property e=f --property g=h ' + self.NAME |
| 208 | + "flavor set " + |
| 209 | + "--property a='third and 10' " + |
| 210 | + "--property g=fourth " + |
| 211 | + name1 |
57 | 212 | ) |
58 | 213 | self.assertEqual('', raw_output) |
59 | 214 |
|
60 | | - raw_output = self.openstack('flavor show ' + self.NAME + opts) |
61 | | - self.assertEqual("a='b', c='d', e='f', g='h'\n", raw_output) |
| 215 | + cmd_output = json.loads(self.openstack( |
| 216 | + "flavor show -f json " + |
| 217 | + name1 |
| 218 | + )) |
| 219 | + self.assertEqual( |
| 220 | + "qaz", |
| 221 | + cmd_output["id"], |
| 222 | + ) |
| 223 | + self.assertEqual( |
| 224 | + "a='third and 10', b='second', g='fourth'", |
| 225 | + cmd_output['properties'], |
| 226 | + ) |
62 | 227 |
|
63 | 228 | raw_output = self.openstack( |
64 | | - 'flavor unset --property a --property c ' + self.NAME |
| 229 | + "flavor unset " + |
| 230 | + "--property b " + |
| 231 | + name1 |
65 | 232 | ) |
66 | 233 | self.assertEqual('', raw_output) |
67 | 234 |
|
68 | | - raw_output = self.openstack('flavor show ' + self.NAME + opts) |
69 | | - self.assertEqual("e='f', g='h'\n", raw_output) |
| 235 | + cmd_output = json.loads(self.openstack( |
| 236 | + "flavor show -f json " + |
| 237 | + name1 |
| 238 | + )) |
| 239 | + self.assertEqual( |
| 240 | + "a='third and 10', g='fourth'", |
| 241 | + cmd_output["properties"], |
| 242 | + ) |
0 commit comments