Skip to content

Commit 5bb5585

Browse files
Huang Chengjharbott
authored andcommitted
Fix subnet host_routes error
When updating subnet with "no-host-route" option, set host_routes to an empty list as neutron_lib.api.validators expected. Change-Id: I6fe039793d813758429c7a104fd40172b4f8122b Closes-Bug: #1747101
1 parent 9766eb2 commit 5bb5585

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

openstackclient/network/v2/subnet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ def take_action(self, parsed_args):
589589
if not parsed_args.no_host_route:
590590
attrs['host_routes'] += obj.host_routes
591591
elif parsed_args.no_host_route:
592-
attrs['host_routes'] = ''
592+
attrs['host_routes'] = []
593593
if 'allocation_pools' in attrs:
594594
if not parsed_args.no_allocation_pool:
595595
attrs['allocation_pools'] += obj.allocation_pools

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,36 @@ def test_overwrite_options(self):
10461046
_testsubnet, **attrs)
10471047
self.assertIsNone(result)
10481048

1049+
def test_clear_options(self):
1050+
_testsubnet = network_fakes.FakeSubnet.create_one_subnet(
1051+
{'host_routes': [{'destination': '10.20.20.0/24',
1052+
'nexthop': '10.20.20.1'}],
1053+
'allocation_pools': [{'start': '8.8.8.200',
1054+
'end': '8.8.8.250'}],
1055+
'dns_nameservers': ['10.0.0.1'], })
1056+
self.network.find_subnet = mock.Mock(return_value=_testsubnet)
1057+
arglist = [
1058+
'--no-host-route',
1059+
'--no-allocation-pool',
1060+
'--no-dns-nameservers',
1061+
_testsubnet.name,
1062+
]
1063+
verifylist = [
1064+
('no_dns_nameservers', True),
1065+
('no_host_route', True),
1066+
('no_allocation_pool', True),
1067+
]
1068+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1069+
result = self.cmd.take_action(parsed_args)
1070+
attrs = {
1071+
'host_routes': [],
1072+
'allocation_pools': [],
1073+
'dns_nameservers': [],
1074+
}
1075+
self.network.update_subnet.assert_called_once_with(
1076+
_testsubnet, **attrs)
1077+
self.assertIsNone(result)
1078+
10491079
def _test_set_tags(self, with_tags=True):
10501080
if with_tags:
10511081
arglist = ['--tag', 'red', '--tag', 'blue']

0 commit comments

Comments
 (0)