Skip to content

Commit 686fabe

Browse files
committed
tests: Convert volume tests to use 'parse_output'
Change-Id: Iec8ca873f6bc3993e0ba557f68895d9aefb6f9c6 Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
1 parent dc03ce9 commit 686fabe

19 files changed

Lines changed: 923 additions & 759 deletions

openstackclient/tests/functional/volume/base.py

Lines changed: 6 additions & 5 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 time
1514

1615
from openstackclient.tests.functional import base
@@ -27,10 +26,12 @@ def wait_for_status(cls, check_type, check_name, desired_status,
2726
failures = ['error']
2827
total_sleep = 0
2928
while total_sleep < wait:
30-
output = json.loads(cls.openstack(
31-
check_type + ' show -f json ' + check_name))
29+
output = cls.openstack(
30+
check_type + ' show ' + check_name,
31+
parse_output=True,
32+
)
3233
current_status = output['status']
33-
if (current_status == desired_status):
34+
if current_status == desired_status:
3435
print('{} {} now has status {}'
3536
.format(check_type, check_name, current_status))
3637
return
@@ -51,7 +52,7 @@ def wait_for_delete(cls, check_type, check_name, wait=120, interval=5,
5152
total_sleep = 0
5253
name_field = name_field or 'Name'
5354
while total_sleep < wait:
54-
result = json.loads(cls.openstack(check_type + ' list -f json'))
55+
result = cls.openstack(check_type + ' list', parse_output=True)
5556
names = [x[name_field] for x in result]
5657
if check_name not in names:
5758
print('{} {} is now deleted'.format(check_type, check_name))

openstackclient/tests/functional/volume/v1/test_qos.py

Lines changed: 29 additions & 24 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.volume.v1 import common
@@ -22,29 +21,32 @@ class QosTests(common.BaseVolumeTests):
2221
def test_volume_qos_create_list(self):
2322
"""Test create, list, delete multiple"""
2423
name1 = uuid.uuid4().hex
25-
cmd_output = json.loads(self.openstack(
26-
'volume qos create -f json ' +
27-
name1
28-
))
24+
cmd_output = self.openstack(
25+
'volume qos create ' +
26+
name1,
27+
parse_output=True,
28+
)
2929
self.assertEqual(
3030
name1,
3131
cmd_output['name']
3232
)
3333

3434
name2 = uuid.uuid4().hex
35-
cmd_output = json.loads(self.openstack(
36-
'volume qos create -f json ' +
37-
name2
38-
))
35+
cmd_output = self.openstack(
36+
'volume qos create ' +
37+
name2,
38+
parse_output=True,
39+
)
3940
self.assertEqual(
4041
name2,
4142
cmd_output['name']
4243
)
4344

4445
# Test list
45-
cmd_output = json.loads(self.openstack(
46-
'volume qos list -f json'
47-
))
46+
cmd_output = self.openstack(
47+
'volume qos list',
48+
parse_output=True,
49+
)
4850
names = [x["Name"] for x in cmd_output]
4951
self.assertIn(name1, names)
5052
self.assertIn(name2, names)
@@ -57,12 +59,13 @@ def test_volume_qos_set_show_unset(self):
5759
"""Tests create volume qos, set, unset, show, delete"""
5860

5961
name = uuid.uuid4().hex
60-
cmd_output = json.loads(self.openstack(
61-
'volume qos create -f json ' +
62+
cmd_output = self.openstack(
63+
'volume qos create ' +
6264
'--consumer front-end '
6365
'--property Alpha=a ' +
64-
name
65-
))
66+
name,
67+
parse_output=True,
68+
)
6669
self.addCleanup(self.openstack, 'volume qos delete ' + name)
6770
self.assertEqual(
6871
name,
@@ -84,10 +87,11 @@ def test_volume_qos_set_show_unset(self):
8487
self.assertOutput('', raw_output)
8588

8689
# Test volume qos show
87-
cmd_output = json.loads(self.openstack(
88-
'volume qos show -f json ' +
89-
name
90-
))
90+
cmd_output = self.openstack(
91+
'volume qos show ' +
92+
name,
93+
parse_output=True,
94+
)
9195
self.assertEqual(
9296
name,
9397
cmd_output['name']
@@ -105,10 +109,11 @@ def test_volume_qos_set_show_unset(self):
105109
)
106110
self.assertOutput('', raw_output)
107111

108-
cmd_output = json.loads(self.openstack(
109-
'volume qos show -f json ' +
110-
name
111-
))
112+
cmd_output = self.openstack(
113+
'volume qos show ' +
114+
name,
115+
parse_output=True,
116+
)
112117
self.assertEqual(
113118
name,
114119
cmd_output['name']

openstackclient/tests/functional/volume/v1/test_service.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,25 @@
1010
# License for the specific language governing permissions and limitations
1111
# under the License.
1212

13-
import json
14-
1513
from openstackclient.tests.functional.volume.v1 import common
1614

1715

1816
class VolumeServiceTests(common.BaseVolumeTests):
1917
"""Functional tests for volume service."""
2018

2119
def test_volume_service_list(self):
22-
cmd_output = json.loads(self.openstack(
23-
'volume service list -f json'))
20+
cmd_output = self.openstack('volume service list', parse_output=True)
2421

2522
# Get the nonredundant services and hosts
2623
services = list(set([x['Binary'] for x in cmd_output]))
2724

2825
# Test volume service list --service
29-
cmd_output = json.loads(self.openstack(
30-
'volume service list -f json ' +
26+
cmd_output = self.openstack(
27+
'volume service list ' +
3128
'--service ' +
32-
services[0]
33-
))
29+
services[0],
30+
parse_output=True,
31+
)
3432
for x in cmd_output:
3533
self.assertEqual(
3634
services[0],
@@ -43,9 +41,10 @@ def test_volume_service_list(self):
4341
def test_volume_service_set(self):
4442

4543
# Get a service and host
46-
cmd_output = json.loads(self.openstack(
47-
'volume service list -f json'
48-
))
44+
cmd_output = self.openstack(
45+
'volume service list',
46+
parse_output=True,
47+
)
4948
service_1 = cmd_output[0]['Binary']
5049
host_1 = cmd_output[0]['Host']
5150

@@ -57,9 +56,10 @@ def test_volume_service_set(self):
5756
)
5857
self.assertOutput('', raw_output)
5958

60-
cmd_output = json.loads(self.openstack(
61-
'volume service list -f json --long'
62-
))
59+
cmd_output = self.openstack(
60+
'volume service list --long',
61+
parse_output=True,
62+
)
6363
self.assertEqual(
6464
'enabled',
6565
cmd_output[0]['Status']
@@ -77,9 +77,10 @@ def test_volume_service_set(self):
7777
)
7878
self.assertOutput('', raw_output)
7979

80-
cmd_output = json.loads(self.openstack(
81-
'volume service list -f json --long'
82-
))
80+
cmd_output = self.openstack(
81+
'volume service list --long',
82+
parse_output=True,
83+
)
8384
self.assertEqual(
8485
'disabled',
8586
cmd_output[0]['Status']

0 commit comments

Comments
 (0)