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
This commit is contained in:
parent
127b49d45e
commit
ce0765facb
@ -107,7 +107,7 @@ def _get_attrs_network(client_manager, parsed_args):
|
||||
attrs['availability_zone_hints'] = parsed_args.availability_zone_hints
|
||||
|
||||
# set description
|
||||
if parsed_args.description:
|
||||
if parsed_args.description is not None:
|
||||
attrs['description'] = parsed_args.description
|
||||
|
||||
# set mtu
|
||||
@ -139,7 +139,7 @@ def _get_attrs_network(client_manager, parsed_args):
|
||||
if 'no_qos_policy' in parsed_args and parsed_args.no_qos_policy:
|
||||
attrs['qos_policy_id'] = None
|
||||
# Update DNS network options
|
||||
if parsed_args.dns_domain:
|
||||
if parsed_args.dns_domain is not None:
|
||||
attrs['dns_domain'] = parsed_args.dns_domain
|
||||
return attrs
|
||||
|
||||
|
@ -1063,6 +1063,39 @@ class TestSetNetwork(TestNetwork):
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_set_to_empty(self):
|
||||
# Test if empty strings are accepted to clear any of the fields,
|
||||
# so once they are set to a value its possible to clear them again.
|
||||
|
||||
arglist = [
|
||||
self._network.name,
|
||||
'--name',
|
||||
'',
|
||||
'--description',
|
||||
'',
|
||||
'--dns-domain',
|
||||
'',
|
||||
]
|
||||
verifylist = [
|
||||
('network', self._network.name),
|
||||
('description', ''),
|
||||
('name', ''),
|
||||
('dns_domain', ''),
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
attrs = {
|
||||
'name': '',
|
||||
'description': '',
|
||||
'dns_domain': '',
|
||||
}
|
||||
self.network_client.update_network.assert_called_once_with(
|
||||
self._network, **attrs
|
||||
)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_set_nothing(self):
|
||||
arglist = [
|
||||
self._network.name,
|
||||
|
Loading…
Reference in New Issue
Block a user