Skip to content

Commit 4a12280

Browse files
author
Dean Troyer
committed
Fix address scope list --share
Remove the 'shared' key from the attrs passed in to the SDK with 0.9.13. Also convert the functional tests to the JSON-style (that's how I found this). Closes-bug: 1659993 Change-Id: I614fbce967cdd07fe7360242547dbf52e7677939
1 parent ca76379 commit 4a12280

3 files changed

Lines changed: 79 additions & 62 deletions

File tree

openstackclient/network/v2/address_scope.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,8 @@ def take_action(self, parsed_args):
204204
if parsed_args.ip_version:
205205
attrs['ip_version'] = parsed_args.ip_version
206206
if parsed_args.share:
207-
attrs['shared'] = True
208207
attrs['is_shared'] = True
209208
if parsed_args.no_share:
210-
attrs['shared'] = False
211209
attrs['is_shared'] = False
212210
if 'project' in parsed_args and parsed_args.project is not None:
213211
identity_client = self.app.client_manager.identity

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

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

13-
import re
13+
import json
1414
import uuid
1515

1616
from openstackclient.tests.functional import base
@@ -24,36 +24,31 @@ class AddressScopeTests(base.TestCase):
2424
# has its own needs and there are collisions when running
2525
# tests in parallel.
2626

27-
@classmethod
28-
def setUpClass(cls):
29-
# Set up some regex for matching below
30-
cls.re_name = re.compile("name\s+\|\s+([^|]+?)\s+\|")
31-
cls.re_ip_version = re.compile("ip_version\s+\|\s+(\S+)")
32-
cls.re_shared = re.compile("shared\s+\|\s+(\S+)")
33-
3427
def test_address_scope_delete(self):
3528
"""Test create, delete multiple"""
3629
name1 = uuid.uuid4().hex
37-
raw_output = self.openstack(
38-
'address scope create ' + name1,
39-
)
30+
cmd_output = json.loads(self.openstack(
31+
'address scope create -f json ' +
32+
name1
33+
))
4034
self.assertEqual(
4135
name1,
42-
re.search(self.re_name, raw_output).group(1),
36+
cmd_output['name'],
4337
)
4438
# Check the default values
4539
self.assertEqual(
46-
'False',
47-
re.search(self.re_shared, raw_output).group(1),
40+
False,
41+
cmd_output['shared'],
4842
)
4943

5044
name2 = uuid.uuid4().hex
51-
raw_output = self.openstack(
52-
'address scope create ' + name2,
53-
)
45+
cmd_output = json.loads(self.openstack(
46+
'address scope create -f json ' +
47+
name2
48+
))
5449
self.assertEqual(
5550
name2,
56-
re.search(self.re_name, raw_output).group(1),
51+
cmd_output['name'],
5752
)
5853

5954
raw_output = self.openstack(
@@ -64,72 +59,93 @@ def test_address_scope_delete(self):
6459
def test_address_scope_list(self):
6560
"""Test create defaults, list filters, delete"""
6661
name1 = uuid.uuid4().hex
67-
raw_output = self.openstack(
68-
'address scope create --ip-version 4 --share ' + name1,
69-
)
62+
cmd_output = json.loads(self.openstack(
63+
'address scope create -f json ' +
64+
'--ip-version 4 ' +
65+
'--share ' +
66+
name1
67+
))
7068
self.addCleanup(self.openstack, 'address scope delete ' + name1)
7169
self.assertEqual(
72-
'4',
73-
re.search(self.re_ip_version, raw_output).group(1),
70+
name1,
71+
cmd_output['name'],
72+
)
73+
self.assertEqual(
74+
4,
75+
cmd_output['ip_version'],
7476
)
7577
self.assertEqual(
76-
'True',
77-
re.search(self.re_shared, raw_output).group(1),
78+
True,
79+
cmd_output['shared'],
7880
)
7981

8082
name2 = uuid.uuid4().hex
81-
raw_output = self.openstack(
82-
'address scope create --ip-version 6 --no-share ' + name2,
83-
)
83+
cmd_output = json.loads(self.openstack(
84+
'address scope create -f json ' +
85+
'--ip-version 6 ' +
86+
'--no-share ' +
87+
name2
88+
))
8489
self.addCleanup(self.openstack, 'address scope delete ' + name2)
8590
self.assertEqual(
86-
'6',
87-
re.search(self.re_ip_version, raw_output).group(1),
91+
name2,
92+
cmd_output['name'],
93+
)
94+
self.assertEqual(
95+
6,
96+
cmd_output['ip_version'],
8897
)
8998
self.assertEqual(
90-
'False',
91-
re.search(self.re_shared, raw_output).group(1),
99+
False,
100+
cmd_output['shared'],
92101
)
93102

94103
# Test list
95-
raw_output = self.openstack('address scope list')
96-
self.assertIsNotNone(re.search(name1 + "\s+\|\s+4", raw_output))
97-
self.assertIsNotNone(re.search(name2 + "\s+\|\s+6", raw_output))
104+
cmd_output = json.loads(self.openstack(
105+
'address scope list -f json ',
106+
))
107+
col_data = [x["IP Version"] for x in cmd_output]
108+
self.assertIn(4, col_data)
109+
self.assertIn(6, col_data)
98110

99111
# Test list --share
100-
# TODO(dtroyer): returns 'HttpException: Bad Request'
101-
# raw_output = self.openstack('address scope list --share')
102-
# self.assertIsNotNone(re.search(name1 + "\s+\|\s+4", raw_output))
103-
# self.assertIsNotNone(re.search(name2 + "\s+\|\s+6", raw_output))
112+
cmd_output = json.loads(self.openstack(
113+
'address scope list -f json --share',
114+
))
115+
col_data = [x["Shared"] for x in cmd_output]
116+
self.assertIn(True, col_data)
117+
self.assertNotIn(False, col_data)
104118

105119
# Test list --no-share
106-
# TODO(dtroyer): returns 'HttpException: Bad Request'
107-
# raw_output = self.openstack('address scope list --no-share')
108-
# self.assertIsNotNone(re.search(name1 + "\s+\|\s+4", raw_output))
109-
# self.assertIsNotNone(re.search(name2 + "\s+\|\s+6", raw_output))
120+
cmd_output = json.loads(self.openstack(
121+
'address scope list -f json --no-share',
122+
))
123+
col_data = [x["Shared"] for x in cmd_output]
124+
self.assertIn(False, col_data)
125+
self.assertNotIn(True, col_data)
110126

111127
def test_address_scope_set(self):
112128
"""Tests create options, set, show, delete"""
113129
name = uuid.uuid4().hex
114130
newname = name + "_"
115-
raw_output = self.openstack(
116-
'address scope create ' +
131+
cmd_output = json.loads(self.openstack(
132+
'address scope create -f json ' +
117133
'--ip-version 4 ' +
118134
'--no-share ' +
119-
name,
120-
)
135+
name
136+
))
121137
self.addCleanup(self.openstack, 'address scope delete ' + newname)
122138
self.assertEqual(
123139
name,
124-
re.search(self.re_name, raw_output).group(1),
140+
cmd_output['name'],
125141
)
126142
self.assertEqual(
127-
'4',
128-
re.search(self.re_ip_version, raw_output).group(1),
143+
4,
144+
cmd_output['ip_version'],
129145
)
130146
self.assertEqual(
131-
'False',
132-
re.search(self.re_shared, raw_output).group(1),
147+
False,
148+
cmd_output['shared'],
133149
)
134150

135151
raw_output = self.openstack(
@@ -140,16 +156,19 @@ def test_address_scope_set(self):
140156
)
141157
self.assertOutput('', raw_output)
142158

143-
raw_output = self.openstack('address scope show ' + newname)
159+
cmd_output = json.loads(self.openstack(
160+
'address scope show -f json ' +
161+
newname,
162+
))
144163
self.assertEqual(
145164
newname,
146-
re.search(self.re_name, raw_output).group(1),
165+
cmd_output['name'],
147166
)
148167
self.assertEqual(
149-
'4',
150-
re.search(self.re_ip_version, raw_output).group(1),
168+
4,
169+
cmd_output['ip_version'],
151170
)
152171
self.assertEqual(
153-
'True',
154-
re.search(self.re_shared, raw_output).group(1),
172+
True,
173+
cmd_output['shared'],
155174
)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ def test_address_scope_list_share(self):
352352
columns, data = self.cmd.take_action(parsed_args)
353353

354354
self.network.address_scopes.assert_called_once_with(
355-
**{'shared': True, 'is_shared': True}
355+
**{'is_shared': True}
356356
)
357357
self.assertEqual(self.columns, columns)
358358
self.assertEqual(self.data, list(data))
@@ -368,7 +368,7 @@ def test_address_scope_list_no_share(self):
368368
columns, data = self.cmd.take_action(parsed_args)
369369

370370
self.network.address_scopes.assert_called_once_with(
371-
**{'shared': False, 'is_shared': False}
371+
**{'is_shared': False}
372372
)
373373
self.assertEqual(self.columns, columns)
374374
self.assertEqual(self.data, list(data))

0 commit comments

Comments
 (0)