Skip to content

Commit 03d932e

Browse files
author
reedip
committed
Append existing information during subnet set
Existing values of --dns-nameserver, --allocation-pool and --houst-routes is currently overwritten when a user executes 'port set', but actually that data should be appended. This patch fixes the issue. Closes-Bug: #1564447 Change-Id: I3dba9afa68d869abb3960b55a6880401a10eebf7
1 parent 7ad529e commit 03d932e

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

openstackclient/network/v2/subnet.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,12 @@ def take_action(self, parsed_args):
366366
if not attrs:
367367
msg = "Nothing specified to be set"
368368
raise exceptions.CommandError(msg)
369+
if 'dns_nameservers' in attrs:
370+
attrs['dns_nameservers'] += obj.dns_nameservers
371+
if 'host_routes' in attrs:
372+
attrs['host_routes'] += obj.host_routes
373+
if 'allocation_pools' in attrs:
374+
attrs['allocation_pools'] += obj.allocation_pools
369375
client.update_subnet(obj, **attrs)
370376
return
371377

openstackclient/tests/network/v2/test_subnet.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,26 @@ def test_set_nothing(self):
536536
self.assertRaises(exceptions.CommandError, self.cmd.take_action,
537537
parsed_args)
538538

539+
def test_append_options(self):
540+
_testsubnet = network_fakes.FakeSubnet.create_one_subnet(
541+
{'dns_nameservers': ["10.0.0.1"]})
542+
self.network.find_subnet = mock.Mock(return_value=_testsubnet)
543+
arglist = [
544+
'--dns-nameserver', '10.0.0.2',
545+
_testsubnet.name,
546+
]
547+
verifylist = [
548+
('dns_nameservers', ['10.0.0.2']),
549+
]
550+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
551+
result = self.cmd.take_action(parsed_args)
552+
attrs = {
553+
'dns_nameservers': ['10.0.0.2', '10.0.0.1'],
554+
}
555+
self.network.update_subnet.assert_called_once_with(
556+
_testsubnet, **attrs)
557+
self.assertIsNone(result)
558+
539559

540560
class TestShowSubnet(TestSubnet):
541561
# The subnets to be shown

0 commit comments

Comments
 (0)