Skip to content

Commit 7d93db2

Browse files
jiahui.qiangDean Troyer
authored andcommitted
Fix can not set is_default in network
The value of is_default always be None, can not be set by "network set" command. Allow "--default" and "--no-default" options to be recognized when ``--external`` is not present. Closes-bug:#1665231 Change-Id: I7a05fc7734a15994f72ca4e47997b4952f1f72f8
1 parent 3b562ff commit 7d93db2

3 files changed

Lines changed: 25 additions & 57 deletions

File tree

openstackclient/network/v2/network.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ def _get_attrs(client_manager, parsed_args):
111111
attrs['router:external'] = False
112112
if parsed_args.external:
113113
attrs['router:external'] = True
114-
if parsed_args.no_default:
115-
attrs['is_default'] = False
116-
if parsed_args.default:
117-
attrs['is_default'] = True
114+
if parsed_args.no_default:
115+
attrs['is_default'] = False
116+
if parsed_args.default:
117+
attrs['is_default'] = True
118118
# Update Provider network options
119119
if parsed_args.provider_network_type:
120120
attrs['provider:network_type'] = parsed_args.provider_network_type

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

Lines changed: 15 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ def test_network_list(self):
126126
cmd_output = json.loads(self.openstack(
127127
'network create -f json ' +
128128
'--description aaaa ' +
129+
'--no-default ' +
129130
name1
130131
))
131132
self.addCleanup(self.openstack, 'network delete ' + name1)
@@ -147,17 +148,11 @@ def test_network_list(self):
147148
'Internal',
148149
cmd_output["router:external"],
149150
)
150-
# NOTE(dtroyer): is_default is not present in the create output
151-
# so make sure it stays that way.
152-
# NOTE(stevemar): is_default *is* present in SDK 0.9.11 and newer,
153-
# but the value seems to always be None, regardless
154-
# of the --default or --no-default value.
155-
# self.assertEqual('x', cmd_output)
156-
if ('is_default' in cmd_output):
157-
self.assertEqual(
158-
None,
159-
cmd_output["is_default"],
160-
)
151+
152+
self.assertEqual(
153+
False,
154+
cmd_output["is_default"],
155+
)
161156
self.assertEqual(
162157
True,
163158
cmd_output["port_security_enabled"],
@@ -185,11 +180,10 @@ def test_network_list(self):
185180
True,
186181
cmd_output["shared"],
187182
)
188-
if ('is_default' in cmd_output):
189-
self.assertEqual(
190-
None,
191-
cmd_output["is_default"],
192-
)
183+
self.assertEqual(
184+
None,
185+
cmd_output["is_default"],
186+
)
193187
self.assertEqual(
194188
True,
195189
cmd_output["port_security_enabled"],
@@ -275,16 +269,11 @@ def test_network_set(self):
275269
'Internal',
276270
cmd_output["router:external"],
277271
)
278-
# NOTE(dtroyer): is_default is not present in the create output
279-
# so make sure it stays that way.
280-
# NOTE(stevemar): is_default *is* present in SDK 0.9.11 and newer,
281-
# but the value seems to always be None, regardless
282-
# of the --default or --no-default value.
283-
if ('is_default' in cmd_output):
284-
self.assertEqual(
285-
None,
286-
cmd_output["is_default"],
287-
)
272+
273+
self.assertEqual(
274+
False,
275+
cmd_output["is_default"],
276+
)
288277
self.assertEqual(
289278
True,
290279
cmd_output["port_security_enabled"],
@@ -321,7 +310,6 @@ def test_network_set(self):
321310
'External',
322311
cmd_output["router:external"],
323312
)
324-
# why not 'None' like above??
325313
self.assertEqual(
326314
False,
327315
cmd_output["is_default"],
@@ -330,29 +318,3 @@ def test_network_set(self):
330318
False,
331319
cmd_output["port_security_enabled"],
332320
)
333-
334-
# NOTE(dtroyer): There is ambiguity around is_default in that
335-
# it is not in the API docs and apparently can
336-
# not be set when the network is --external,
337-
# although the option handling code only looks at
338-
# the value of is_default when external is True.
339-
raw_output = self.openstack(
340-
'network set ' +
341-
'--default ' +
342-
name
343-
)
344-
self.assertOutput('', raw_output)
345-
346-
cmd_output = json.loads(self.openstack(
347-
'network show -f json ' + name
348-
))
349-
350-
self.assertEqual(
351-
'cccc',
352-
cmd_output["description"],
353-
)
354-
# NOTE(dtroyer): This should be 'True'
355-
self.assertEqual(
356-
False,
357-
cmd_output["port_security_enabled"],
358-
)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
fixes:
3+
- |
4+
Allow ``--default`` and ``--no-default`` options in ``network create`` command to
5+
be recognized when ``--external`` is not present.
6+
[Bug `1665231 <https://bugs.launchpad.net/python-openstackclient/+bug/1665231>`_]

0 commit comments

Comments
 (0)