Skip to content

Commit 50aed3f

Browse files
committed
tests: Convert network tests to use 'parse_output'
Change-Id: I93e2a4e0a4c7ec07da0c78a171f3d787125af053 Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
1 parent 874519e commit 50aed3f

27 files changed

Lines changed: 1130 additions & 892 deletions

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

Lines changed: 17 additions & 11 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
@@ -32,7 +31,10 @@ class NetworkTagTests(NetworkTests):
3231

3332
def test_tag_operation(self):
3433
# Get project IDs
35-
cmd_output = json.loads(self.openstack('token issue -f json '))
34+
cmd_output = self.openstack(
35+
'token issue ',
36+
parse_output=True,
37+
)
3638
auth_project_id = cmd_output['project_id']
3739

3840
# Network create with no options
@@ -63,17 +65,20 @@ def test_tag_operation(self):
6365
self._set_resource_and_tag_check('set', name2, '--no-tag', [])
6466

6567
def _list_tag_check(self, project_id, expected):
66-
cmd_output = json.loads(self.openstack(
67-
'{} list --long --project {} -f json'.format(self.base_command,
68-
project_id)))
68+
cmd_output = self.openstack(
69+
'{} list --long --project {}'.format(self.base_command,
70+
project_id),
71+
parse_output=True,
72+
)
6973
for name, tags in expected:
7074
net = [n for n in cmd_output if n['Name'] == name][0]
7175
self.assertEqual(set(tags), set(net['Tags']))
7276

7377
def _create_resource_for_tag_test(self, name, args):
74-
return json.loads(self.openstack(
75-
'{} create -f json {} {}'.format(self.base_command, args, name)
76-
))
78+
return self.openstack(
79+
'{} create {} {}'.format(self.base_command, args, name),
80+
parse_output=True,
81+
)
7782

7883
def _create_resource_and_tag_check(self, args, expected):
7984
name = uuid.uuid4().hex
@@ -89,7 +94,8 @@ def _set_resource_and_tag_check(self, command, name, args, expected):
8994
'{} {} {} {}'.format(self.base_command, command, args, name)
9095
)
9196
self.assertFalse(cmd_output)
92-
cmd_output = json.loads(self.openstack(
93-
'{} show -f json {}'.format(self.base_command, name)
94-
))
97+
cmd_output = self.openstack(
98+
'{} show {}'.format(self.base_command, name),
99+
parse_output=True,
100+
)
95101
self.assertEqual(set(expected), set(cmd_output['tags']))

openstackclient/tests/functional/network/v2/test_address_group.py

Lines changed: 49 additions & 40 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.network.v2 import common
@@ -30,20 +29,22 @@ def setUp(self):
3029
def test_address_group_create_and_delete(self):
3130
"""Test create, delete multiple"""
3231
name1 = uuid.uuid4().hex
33-
cmd_output = json.loads(self.openstack(
34-
'address group create -f json ' +
35-
name1
36-
))
32+
cmd_output = self.openstack(
33+
'address group create ' +
34+
name1,
35+
parse_output=True,
36+
)
3737
self.assertEqual(
3838
name1,
3939
cmd_output['name'],
4040
)
4141

4242
name2 = uuid.uuid4().hex
43-
cmd_output = json.loads(self.openstack(
44-
'address group create -f json ' +
45-
name2
46-
))
43+
cmd_output = self.openstack(
44+
'address group create ' +
45+
name2,
46+
parse_output=True,
47+
)
4748
self.assertEqual(
4849
name2,
4950
cmd_output['name'],
@@ -57,10 +58,10 @@ def test_address_group_create_and_delete(self):
5758
def test_address_group_list(self):
5859
"""Test create, list filters, delete"""
5960
# Get project IDs
60-
cmd_output = json.loads(self.openstack('token issue -f json '))
61+
cmd_output = self.openstack('token issue ', parse_output=True)
6162
auth_project_id = cmd_output['project_id']
6263

63-
cmd_output = json.loads(self.openstack('project list -f json '))
64+
cmd_output = self.openstack('project list ', parse_output=True)
6465
admin_project_id = None
6566
demo_project_id = None
6667
for p in cmd_output:
@@ -79,50 +80,55 @@ def test_address_group_list(self):
7980
self.assertEqual(admin_project_id, auth_project_id)
8081

8182
name1 = uuid.uuid4().hex
82-
cmd_output = json.loads(self.openstack(
83-
'address group create -f json ' +
84-
name1
85-
))
83+
cmd_output = self.openstack(
84+
'address group create ' +
85+
name1,
86+
parse_output=True,
87+
)
8688
self.addCleanup(self.openstack, 'address group delete ' + name1)
8789
self.assertEqual(
8890
admin_project_id,
8991
cmd_output["project_id"],
9092
)
9193

9294
name2 = uuid.uuid4().hex
93-
cmd_output = json.loads(self.openstack(
94-
'address group create -f json ' +
95+
cmd_output = self.openstack(
96+
'address group create ' +
9597
'--project ' + demo_project_id +
96-
' ' + name2
97-
))
98+
' ' + name2,
99+
parse_output=True,
100+
)
98101
self.addCleanup(self.openstack, 'address group delete ' + name2)
99102
self.assertEqual(
100103
demo_project_id,
101104
cmd_output["project_id"],
102105
)
103106

104107
# Test list
105-
cmd_output = json.loads(self.openstack(
106-
'address group list -f json ',
107-
))
108+
cmd_output = self.openstack(
109+
'address group list ',
110+
parse_output=True,
111+
)
108112
names = [x["Name"] for x in cmd_output]
109113
self.assertIn(name1, names)
110114
self.assertIn(name2, names)
111115

112116
# Test list --project
113-
cmd_output = json.loads(self.openstack(
114-
'address group list -f json ' +
115-
'--project ' + demo_project_id
116-
))
117+
cmd_output = self.openstack(
118+
'address group list ' +
119+
'--project ' + demo_project_id,
120+
parse_output=True,
121+
)
117122
names = [x["Name"] for x in cmd_output]
118123
self.assertNotIn(name1, names)
119124
self.assertIn(name2, names)
120125

121126
# Test list --name
122-
cmd_output = json.loads(self.openstack(
123-
'address group list -f json ' +
124-
'--name ' + name1
125-
))
127+
cmd_output = self.openstack(
128+
'address group list ' +
129+
'--name ' + name1,
130+
parse_output=True,
131+
)
126132
names = [x["Name"] for x in cmd_output]
127133
self.assertIn(name1, names)
128134
self.assertNotIn(name2, names)
@@ -131,12 +137,13 @@ def test_address_group_set_unset_and_show(self):
131137
"""Tests create options, set, unset, and show"""
132138
name = uuid.uuid4().hex
133139
newname = name + "_"
134-
cmd_output = json.loads(self.openstack(
135-
'address group create -f json ' +
140+
cmd_output = self.openstack(
141+
'address group create ' +
136142
'--description aaaa ' +
137143
'--address 10.0.0.1 --address 2001::/16 ' +
138-
name
139-
))
144+
name,
145+
parse_output=True,
146+
)
140147
self.addCleanup(self.openstack, 'address group delete ' + newname)
141148
self.assertEqual(name, cmd_output['name'])
142149
self.assertEqual('aaaa', cmd_output['description'])
@@ -153,10 +160,11 @@ def test_address_group_set_unset_and_show(self):
153160
self.assertOutput('', raw_output)
154161

155162
# Show the updated address group
156-
cmd_output = json.loads(self.openstack(
157-
'address group show -f json ' +
163+
cmd_output = self.openstack(
164+
'address group show ' +
158165
newname,
159-
))
166+
parse_output=True,
167+
)
160168
self.assertEqual(newname, cmd_output['name'])
161169
self.assertEqual('bbbb', cmd_output['description'])
162170
self.assertEqual(4, len(cmd_output['addresses']))
@@ -170,8 +178,9 @@ def test_address_group_set_unset_and_show(self):
170178
)
171179
self.assertEqual('', raw_output)
172180

173-
cmd_output = json.loads(self.openstack(
174-
'address group show -f json ' +
181+
cmd_output = self.openstack(
182+
'address group show ' +
175183
newname,
176-
))
184+
parse_output=True,
185+
)
177186
self.assertEqual(0, len(cmd_output['addresses']))

openstackclient/tests/functional/network/v2/test_address_scope.py

Lines changed: 41 additions & 33 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.network.v2 import common
@@ -33,10 +32,11 @@ def setUp(self):
3332
def test_address_scope_delete(self):
3433
"""Test create, delete multiple"""
3534
name1 = uuid.uuid4().hex
36-
cmd_output = json.loads(self.openstack(
37-
'address scope create -f json ' +
38-
name1
39-
))
35+
cmd_output = self.openstack(
36+
'address scope create ' +
37+
name1,
38+
parse_output=True,
39+
)
4040
self.assertEqual(
4141
name1,
4242
cmd_output['name'],
@@ -45,10 +45,11 @@ def test_address_scope_delete(self):
4545
self.assertFalse(cmd_output['shared'])
4646

4747
name2 = uuid.uuid4().hex
48-
cmd_output = json.loads(self.openstack(
49-
'address scope create -f json ' +
50-
name2
51-
))
48+
cmd_output = self.openstack(
49+
'address scope create ' +
50+
name2,
51+
parse_output=True,
52+
)
5253
self.assertEqual(
5354
name2,
5455
cmd_output['name'],
@@ -62,12 +63,13 @@ def test_address_scope_delete(self):
6263
def test_address_scope_list(self):
6364
"""Test create defaults, list filters, delete"""
6465
name1 = uuid.uuid4().hex
65-
cmd_output = json.loads(self.openstack(
66-
'address scope create -f json ' +
66+
cmd_output = self.openstack(
67+
'address scope create ' +
6768
'--ip-version 4 ' +
6869
'--share ' +
69-
name1
70-
))
70+
name1,
71+
parse_output=True,
72+
)
7173
self.addCleanup(self.openstack, 'address scope delete ' + name1)
7274
self.assertEqual(
7375
name1,
@@ -80,12 +82,13 @@ def test_address_scope_list(self):
8082
self.assertTrue(cmd_output['shared'])
8183

8284
name2 = uuid.uuid4().hex
83-
cmd_output = json.loads(self.openstack(
84-
'address scope create -f json ' +
85+
cmd_output = self.openstack(
86+
'address scope create ' +
8587
'--ip-version 6 ' +
8688
'--no-share ' +
87-
name2
88-
))
89+
name2,
90+
parse_output=True,
91+
)
8992
self.addCleanup(self.openstack, 'address scope delete ' + name2)
9093
self.assertEqual(
9194
name2,
@@ -98,25 +101,28 @@ def test_address_scope_list(self):
98101
self.assertFalse(cmd_output['shared'])
99102

100103
# Test list
101-
cmd_output = json.loads(self.openstack(
102-
'address scope list -f json ',
103-
))
104+
cmd_output = self.openstack(
105+
'address scope list ',
106+
parse_output=True,
107+
)
104108
col_data = [x["IP Version"] for x in cmd_output]
105109
self.assertIn(4, col_data)
106110
self.assertIn(6, col_data)
107111

108112
# Test list --share
109-
cmd_output = json.loads(self.openstack(
110-
'address scope list -f json --share',
111-
))
113+
cmd_output = self.openstack(
114+
'address scope list --share',
115+
parse_output=True,
116+
)
112117
col_data = [x["Shared"] for x in cmd_output]
113118
self.assertIn(True, col_data)
114119
self.assertNotIn(False, col_data)
115120

116121
# Test list --no-share
117-
cmd_output = json.loads(self.openstack(
118-
'address scope list -f json --no-share',
119-
))
122+
cmd_output = self.openstack(
123+
'address scope list --no-share',
124+
parse_output=True,
125+
)
120126
col_data = [x["Shared"] for x in cmd_output]
121127
self.assertIn(False, col_data)
122128
self.assertNotIn(True, col_data)
@@ -125,12 +131,13 @@ def test_address_scope_set(self):
125131
"""Tests create options, set, show, delete"""
126132
name = uuid.uuid4().hex
127133
newname = name + "_"
128-
cmd_output = json.loads(self.openstack(
129-
'address scope create -f json ' +
134+
cmd_output = self.openstack(
135+
'address scope create ' +
130136
'--ip-version 4 ' +
131137
'--no-share ' +
132-
name
133-
))
138+
name,
139+
parse_output=True,
140+
)
134141
self.addCleanup(self.openstack, 'address scope delete ' + newname)
135142
self.assertEqual(
136143
name,
@@ -150,10 +157,11 @@ def test_address_scope_set(self):
150157
)
151158
self.assertOutput('', raw_output)
152159

153-
cmd_output = json.loads(self.openstack(
154-
'address scope show -f json ' +
160+
cmd_output = self.openstack(
161+
'address scope show ' +
155162
newname,
156-
))
163+
parse_output=True,
164+
)
157165
self.assertEqual(
158166
newname,
159167
cmd_output['name'],

0 commit comments

Comments
 (0)