Skip to content

Commit 874519e

Browse files
committed
tests: Convert compute tests to use 'parse_output'
Change-Id: Ib5b2f46639f14877a9ec295b26cae01a05395d4d Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
1 parent 6daa6be commit 874519e

7 files changed

Lines changed: 503 additions & 403 deletions

File tree

openstackclient/tests/functional/compute/v2/common.py

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# under the License.
1212
#
1313

14-
import json
1514
import time
1615
import uuid
1716

@@ -38,9 +37,7 @@ def setUp(self):
3837
def get_flavor(cls):
3938
# NOTE(rtheis): Get cirros256 or m1.tiny flavors since functional
4039
# tests may create other flavors.
41-
flavors = json.loads(cls.openstack(
42-
"flavor list -f json "
43-
))
40+
flavors = cls.openstack("flavor list", parse_output=True)
4441
server_flavor = None
4542
for flavor in flavors:
4643
if flavor['Name'] in ['m1.tiny', 'cirros256']:
@@ -53,9 +50,7 @@ def get_image(cls):
5350
# NOTE(rtheis): Get first Cirros image since functional tests may
5451
# create other images. Image may be named '-uec' or
5552
# '-disk'.
56-
images = json.loads(cls.openstack(
57-
"image list -f json "
58-
))
53+
images = cls.openstack("image list", parse_output=True)
5954
server_image = None
6055
for image in images:
6156
if (image['Name'].startswith('cirros-') and
@@ -70,9 +65,10 @@ def get_network(cls):
7065
try:
7166
# NOTE(rtheis): Get private network since functional tests may
7267
# create other networks.
73-
cmd_output = json.loads(cls.openstack(
74-
'network show private -f json'
75-
))
68+
cmd_output = cls.openstack(
69+
'network show private',
70+
parse_output=True,
71+
)
7672
except exceptions.CommandFailed:
7773
return ''
7874
return '--nic net-id=' + cmd_output['id']
@@ -86,14 +82,15 @@ def server_create(self, name=None, cleanup=True):
8682
if not self.network_arg:
8783
self.network_arg = self.get_network()
8884
name = name or uuid.uuid4().hex
89-
cmd_output = json.loads(self.openstack(
90-
'server create -f json ' +
85+
cmd_output = self.openstack(
86+
'server create ' +
9187
'--flavor ' + self.flavor_name + ' ' +
9288
'--image ' + self.image_name + ' ' +
9389
self.network_arg + ' ' +
9490
'--wait ' +
95-
name
96-
))
91+
name,
92+
parse_output=True,
93+
)
9794
self.assertIsNotNone(cmd_output["id"])
9895
self.assertEqual(
9996
name,
@@ -120,10 +117,11 @@ def wait_for_status(
120117
failures = ['ERROR']
121118
total_sleep = 0
122119
while total_sleep < wait:
123-
cmd_output = json.loads(self.openstack(
124-
'server show -f json ' +
125-
name
126-
))
120+
cmd_output = self.openstack(
121+
'server show ' +
122+
name,
123+
parse_output=True,
124+
)
127125
status = cmd_output['status']
128126
if status == expected_status:
129127
print('Server {} now has status {}'.format(
@@ -135,10 +133,11 @@ def wait_for_status(
135133
time.sleep(interval)
136134
total_sleep += interval
137135

138-
cmd_output = json.loads(self.openstack(
139-
'server show -f json ' +
140-
name
141-
))
136+
cmd_output = self.openstack(
137+
'server show ' +
138+
name,
139+
parse_output=True,
140+
)
142141
status = cmd_output['status']
143142
self.assertEqual(status, expected_status)
144143
# give it a little bit more time

openstackclient/tests/functional/compute/v2/test_aggregate.py

Lines changed: 50 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
# License for the specific language governing permissions and limitations
1111
# under the License.
1212

13-
import json
1413
import uuid
1514

1615
from openstackclient.tests.functional import base
@@ -27,12 +26,13 @@ def test_aggregate_crud(self):
2726
'aggregate delete ' + name1,
2827
fail_ok=True,
2928
)
30-
cmd_output = json.loads(self.openstack(
31-
'aggregate create -f json ' +
29+
cmd_output = self.openstack(
30+
'aggregate create ' +
3231
'--zone nova ' +
3332
'--property a=b ' +
34-
name1
35-
))
33+
name1,
34+
parse_output=True,
35+
)
3636
self.assertEqual(
3737
name1,
3838
cmd_output['name']
@@ -45,8 +45,10 @@ def test_aggregate_crud(self):
4545
'a',
4646
cmd_output['properties']
4747
)
48-
cmd_output = json.loads(self.openstack(
49-
'aggregate show -f json ' + name1))
48+
cmd_output = self.openstack(
49+
'aggregate show ' + name1,
50+
parse_output=True,
51+
)
5052
self.assertEqual(name1, cmd_output['name'])
5153

5254
name2 = uuid.uuid4().hex
@@ -55,11 +57,12 @@ def test_aggregate_crud(self):
5557
'aggregate delete ' + name2,
5658
fail_ok=True,
5759
)
58-
cmd_output = json.loads(self.openstack(
59-
'aggregate create -f json ' +
60+
cmd_output = self.openstack(
61+
'aggregate create ' +
6062
'--zone external ' +
61-
name2
62-
))
63+
name2,
64+
parse_output=True,
65+
)
6366
self.assertEqual(
6467
name2,
6568
cmd_output['name']
@@ -68,8 +71,10 @@ def test_aggregate_crud(self):
6871
'external',
6972
cmd_output['availability_zone']
7073
)
71-
cmd_output = json.loads(self.openstack(
72-
'aggregate show -f json ' + name2))
74+
cmd_output = self.openstack(
75+
'aggregate show ' + name2,
76+
parse_output=True,
77+
)
7378
self.assertEqual(name2, cmd_output['name'])
7479

7580
# Test aggregate set
@@ -89,10 +94,11 @@ def test_aggregate_crud(self):
8994
)
9095
self.assertOutput('', raw_output)
9196

92-
cmd_output = json.loads(self.openstack(
93-
'aggregate show -f json ' +
94-
name3
95-
))
97+
cmd_output = self.openstack(
98+
'aggregate show ' +
99+
name3,
100+
parse_output=True,
101+
)
96102
self.assertEqual(
97103
name3,
98104
cmd_output['name']
@@ -111,9 +117,10 @@ def test_aggregate_crud(self):
111117
)
112118

113119
# Test aggregate list
114-
cmd_output = json.loads(self.openstack(
115-
'aggregate list -f json'
116-
))
120+
cmd_output = self.openstack(
121+
'aggregate list',
122+
parse_output=True,
123+
)
117124
names = [x['Name'] for x in cmd_output]
118125
self.assertIn(name3, names)
119126
self.assertIn(name2, names)
@@ -122,9 +129,10 @@ def test_aggregate_crud(self):
122129
self.assertIn('internal', zones)
123130

124131
# Test aggregate list --long
125-
cmd_output = json.loads(self.openstack(
126-
'aggregate list --long -f json'
127-
))
132+
cmd_output = self.openstack(
133+
'aggregate list --long',
134+
parse_output=True,
135+
)
128136
names = [x['Name'] for x in cmd_output]
129137
self.assertIn(name3, names)
130138
self.assertIn(name2, names)
@@ -143,10 +151,11 @@ def test_aggregate_crud(self):
143151
)
144152
self.assertOutput('', raw_output)
145153

146-
cmd_output = json.loads(self.openstack(
147-
'aggregate show -f json ' +
148-
name3
149-
))
154+
cmd_output = self.openstack(
155+
'aggregate show ' +
156+
name3,
157+
parse_output=True,
158+
)
150159
self.assertNotIn(
151160
"c='d'",
152161
cmd_output['properties']
@@ -163,9 +172,10 @@ def test_aggregate_crud(self):
163172
def test_aggregate_add_and_remove_host(self):
164173
"""Test aggregate add and remove host"""
165174
# Get a host
166-
cmd_output = json.loads(self.openstack(
167-
'host list -f json'
168-
))
175+
cmd_output = self.openstack(
176+
'host list',
177+
parse_output=True,
178+
)
169179
host_name = cmd_output[0]['Host Name']
170180

171181
# NOTE(dtroyer): Cells v1 is not operable with aggregates. Hostnames
@@ -181,22 +191,24 @@ def test_aggregate_add_and_remove_host(self):
181191
)
182192

183193
# Test add host
184-
cmd_output = json.loads(self.openstack(
185-
'aggregate add host -f json ' +
194+
cmd_output = self.openstack(
195+
'aggregate add host ' +
186196
name + ' ' +
187-
host_name
188-
))
197+
host_name,
198+
parse_output=True,
199+
)
189200
self.assertIn(
190201
host_name,
191202
cmd_output['hosts']
192203
)
193204

194205
# Test remove host
195-
cmd_output = json.loads(self.openstack(
196-
'aggregate remove host -f json ' +
206+
cmd_output = self.openstack(
207+
'aggregate remove host ' +
197208
name + ' ' +
198-
host_name
199-
))
209+
host_name,
210+
parse_output=True,
211+
)
200212
self.assertNotIn(
201213
host_name,
202214
cmd_output['hosts']

0 commit comments

Comments
 (0)