Skip to content

Commit ce0765f

Browse files
committed
Fix clearing of dns_domain and description on a network by setting to empty strings
After setting a default dns_domain on a network openstack net set --dns-domain 'example.com.' <NETWORKID> the setting could not be reverted back to an empty string using openstack net set --dns-domain '' <NETWORKID> and the call also does not emit any error. The same is true for the description of a network. Reason was using the parsed argument directly as a condition instead of comparing against None -- dropping the empty string as valid value. The name parameter already accepted an empty string. This change also adds a testcase for dns_domain, description and the network name parameter, checking if the empty string is forwarded. Change-Id: Ia7b9738205002b028c19e4f397411c86469cba1a
1 parent 127b49d commit ce0765f

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

openstackclient/network/v2/network.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def _get_attrs_network(client_manager, parsed_args):
107107
attrs['availability_zone_hints'] = parsed_args.availability_zone_hints
108108

109109
# set description
110-
if parsed_args.description:
110+
if parsed_args.description is not None:
111111
attrs['description'] = parsed_args.description
112112

113113
# set mtu
@@ -139,7 +139,7 @@ def _get_attrs_network(client_manager, parsed_args):
139139
if 'no_qos_policy' in parsed_args and parsed_args.no_qos_policy:
140140
attrs['qos_policy_id'] = None
141141
# Update DNS network options
142-
if parsed_args.dns_domain:
142+
if parsed_args.dns_domain is not None:
143143
attrs['dns_domain'] = parsed_args.dns_domain
144144
return attrs
145145

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,39 @@ def test_set_that(self):
10631063
)
10641064
self.assertIsNone(result)
10651065

1066+
def test_set_to_empty(self):
1067+
# Test if empty strings are accepted to clear any of the fields,
1068+
# so once they are set to a value its possible to clear them again.
1069+
1070+
arglist = [
1071+
self._network.name,
1072+
'--name',
1073+
'',
1074+
'--description',
1075+
'',
1076+
'--dns-domain',
1077+
'',
1078+
]
1079+
verifylist = [
1080+
('network', self._network.name),
1081+
('description', ''),
1082+
('name', ''),
1083+
('dns_domain', ''),
1084+
]
1085+
1086+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1087+
result = self.cmd.take_action(parsed_args)
1088+
1089+
attrs = {
1090+
'name': '',
1091+
'description': '',
1092+
'dns_domain': '',
1093+
}
1094+
self.network_client.update_network.assert_called_once_with(
1095+
self._network, **attrs
1096+
)
1097+
self.assertIsNone(result)
1098+
10661099
def test_set_nothing(self):
10671100
arglist = [
10681101
self._network.name,

0 commit comments

Comments
 (0)