summaryrefslogtreecommitdiff
path: root/openstackclient/tests/functional/compute/v2/common.py
diff options
context:
space:
mode:
authorStephen Finucane <sfinucan@redhat.com>2022-11-08 10:56:26 +0000
committerStephen Finucane <sfinucan@redhat.com>2022-11-29 16:21:29 +0000
commit874519e980b75aa7a659cef7757a154ddd10e3fb (patch)
treef34c9b94d94a2b7037dbd9f472bb4d2a1719f7a2 /openstackclient/tests/functional/compute/v2/common.py
parent6daa6be3926be389cb7cb2faeb921c7230855af3 (diff)
downloadpython-openstackclient-874519e980b75aa7a659cef7757a154ddd10e3fb.tar.gz
tests: Convert compute tests to use 'parse_output'
Change-Id: Ib5b2f46639f14877a9ec295b26cae01a05395d4d Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Diffstat (limited to 'openstackclient/tests/functional/compute/v2/common.py')
-rw-r--r--openstackclient/tests/functional/compute/v2/common.py43
1 files changed, 21 insertions, 22 deletions
diff --git a/openstackclient/tests/functional/compute/v2/common.py b/openstackclient/tests/functional/compute/v2/common.py
index 851664c8..7eca4603 100644
--- a/openstackclient/tests/functional/compute/v2/common.py
+++ b/openstackclient/tests/functional/compute/v2/common.py
@@ -11,7 +11,6 @@
# under the License.
#
-import json
import time
import uuid
@@ -38,9 +37,7 @@ class ComputeTestCase(base.TestCase):
def get_flavor(cls):
# NOTE(rtheis): Get cirros256 or m1.tiny flavors since functional
# tests may create other flavors.
- flavors = json.loads(cls.openstack(
- "flavor list -f json "
- ))
+ flavors = cls.openstack("flavor list", parse_output=True)
server_flavor = None
for flavor in flavors:
if flavor['Name'] in ['m1.tiny', 'cirros256']:
@@ -53,9 +50,7 @@ class ComputeTestCase(base.TestCase):
# NOTE(rtheis): Get first Cirros image since functional tests may
# create other images. Image may be named '-uec' or
# '-disk'.
- images = json.loads(cls.openstack(
- "image list -f json "
- ))
+ images = cls.openstack("image list", parse_output=True)
server_image = None
for image in images:
if (image['Name'].startswith('cirros-') and
@@ -70,9 +65,10 @@ class ComputeTestCase(base.TestCase):
try:
# NOTE(rtheis): Get private network since functional tests may
# create other networks.
- cmd_output = json.loads(cls.openstack(
- 'network show private -f json'
- ))
+ cmd_output = cls.openstack(
+ 'network show private',
+ parse_output=True,
+ )
except exceptions.CommandFailed:
return ''
return '--nic net-id=' + cmd_output['id']
@@ -86,14 +82,15 @@ class ComputeTestCase(base.TestCase):
if not self.network_arg:
self.network_arg = self.get_network()
name = name or uuid.uuid4().hex
- cmd_output = json.loads(self.openstack(
- 'server create -f json ' +
+ cmd_output = self.openstack(
+ 'server create ' +
'--flavor ' + self.flavor_name + ' ' +
'--image ' + self.image_name + ' ' +
self.network_arg + ' ' +
'--wait ' +
- name
- ))
+ name,
+ parse_output=True,
+ )
self.assertIsNotNone(cmd_output["id"])
self.assertEqual(
name,
@@ -120,10 +117,11 @@ class ComputeTestCase(base.TestCase):
failures = ['ERROR']
total_sleep = 0
while total_sleep < wait:
- cmd_output = json.loads(self.openstack(
- 'server show -f json ' +
- name
- ))
+ cmd_output = self.openstack(
+ 'server show ' +
+ name,
+ parse_output=True,
+ )
status = cmd_output['status']
if status == expected_status:
print('Server {} now has status {}'.format(
@@ -135,10 +133,11 @@ class ComputeTestCase(base.TestCase):
time.sleep(interval)
total_sleep += interval
- cmd_output = json.loads(self.openstack(
- 'server show -f json ' +
- name
- ))
+ cmd_output = self.openstack(
+ 'server show ' +
+ name,
+ parse_output=True,
+ )
status = cmd_output['status']
self.assertEqual(status, expected_status)
# give it a little bit more time