summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
authorHuang Cheng <huang.cheng@h3c.com>2018-02-03 10:48:04 +0800
committerAlexey Stupnikov <aleksey.stupnikov@gmail.com>2020-07-22 19:03:48 +0000
commit333e8abef33eec95330721cd5ae54243680d1612 (patch)
tree8689b9acb9eb6e1635c96002e8b9f4ee3a1cabae /openstackclient
parentfd85a3cde361a8e3eae7bd9e0760150459afe5c2 (diff)
downloadpython-openstackclient-333e8abef33eec95330721cd5ae54243680d1612.tar.gz
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 (cherry picked from commit 5bb5585aa98e17e22963996c02bd7bd688d7871e)
Diffstat (limited to 'openstackclient')
-rw-r--r--openstackclient/network/v2/subnet.py2
-rw-r--r--openstackclient/tests/unit/network/v2/test_subnet.py30
2 files changed, 31 insertions, 1 deletions
diff --git a/openstackclient/network/v2/subnet.py b/openstackclient/network/v2/subnet.py
index 5fd58b5e..b650a7fb 100644
--- a/openstackclient/network/v2/subnet.py
+++ b/openstackclient/network/v2/subnet.py
@@ -581,7 +581,7 @@ class SetSubnet(command.Command):
if not parsed_args.no_host_route:
attrs['host_routes'] += obj.host_routes
elif parsed_args.no_host_route:
- attrs['host_routes'] = ''
+ attrs['host_routes'] = []
if 'allocation_pools' in attrs:
if not parsed_args.no_allocation_pool:
attrs['allocation_pools'] += obj.allocation_pools
diff --git a/openstackclient/tests/unit/network/v2/test_subnet.py b/openstackclient/tests/unit/network/v2/test_subnet.py
index b7f741cd..63eedbe0 100644
--- a/openstackclient/tests/unit/network/v2/test_subnet.py
+++ b/openstackclient/tests/unit/network/v2/test_subnet.py
@@ -1046,6 +1046,36 @@ class TestSetSubnet(TestSubnet):
_testsubnet, **attrs)
self.assertIsNone(result)
+ def test_clear_options(self):
+ _testsubnet = network_fakes.FakeSubnet.create_one_subnet(
+ {'host_routes': [{'destination': '10.20.20.0/24',
+ 'nexthop': '10.20.20.1'}],
+ 'allocation_pools': [{'start': '8.8.8.200',
+ 'end': '8.8.8.250'}],
+ 'dns_nameservers': ['10.0.0.1'], })
+ self.network.find_subnet = mock.Mock(return_value=_testsubnet)
+ arglist = [
+ '--no-host-route',
+ '--no-allocation-pool',
+ '--no-dns-nameservers',
+ _testsubnet.name,
+ ]
+ verifylist = [
+ ('no_dns_nameservers', True),
+ ('no_host_route', True),
+ ('no_allocation_pool', True),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ result = self.cmd.take_action(parsed_args)
+ attrs = {
+ 'host_routes': [],
+ 'allocation_pools': [],
+ 'dns_nameservers': [],
+ }
+ self.network.update_subnet.assert_called_once_with(
+ _testsubnet, **attrs)
+ self.assertIsNone(result)
+
def _test_set_tags(self, with_tags=True):
if with_tags:
arglist = ['--tag', 'red', '--tag', 'blue']