summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
authorÉdouard Thuleau <ethuleau@juniper.net>2019-12-04 08:21:50 +0100
committerÉdouard Thuleau <ethuleau@juniper.net>2019-12-04 14:57:20 +0100
commit509ca3ed36b4ef512a47ff8d39c9df751084015a (patch)
tree6a34e2282e08e373bbcb74466225e847ca21d3ec /openstackclient
parent5b3a827a1ff80e4b51c7ede44b84bf640d5b6380 (diff)
downloadpython-openstackclient-509ca3ed36b4ef512a47ff8d39c9df751084015a.tar.gz
Fix router create/show if extraroute not supported
If neutron does not support extraroute l3 extension, the route column formatter fails. Change-Id: I7b89c4f818865073947e0850e86c18d0d2415a51
Diffstat (limited to 'openstackclient')
-rw-r--r--openstackclient/network/v2/router.py2
-rw-r--r--openstackclient/tests/unit/network/v2/test_router.py18
2 files changed, 19 insertions, 1 deletions
diff --git a/openstackclient/network/v2/router.py b/openstackclient/network/v2/router.py
index 02da50c3..5d85e485 100644
--- a/openstackclient/network/v2/router.py
+++ b/openstackclient/network/v2/router.py
@@ -49,7 +49,7 @@ class RouterInfoColumn(cliff_columns.FormattableColumn):
class RoutesColumn(cliff_columns.FormattableColumn):
def human_readable(self):
# Map the route keys to match --route option.
- for route in self._value:
+ for route in self._value or []:
if 'nexthop' in route:
route['gateway'] = route.pop('nexthop')
return utils.format_list_of_dicts(self._value)
diff --git a/openstackclient/tests/unit/network/v2/test_router.py b/openstackclient/tests/unit/network/v2/test_router.py
index 079b9746..500cfbe5 100644
--- a/openstackclient/tests/unit/network/v2/test_router.py
+++ b/openstackclient/tests/unit/network/v2/test_router.py
@@ -1285,6 +1285,24 @@ class TestShowRouter(TestRouter):
self.assertNotIn("is_distributed", columns)
self.assertNotIn("is_ha", columns)
+ def test_show_no_extra_route_extension(self):
+ _router = network_fakes.FakeRouter.create_one_router({'routes': None})
+
+ arglist = [
+ _router.name,
+ ]
+ verifylist = [
+ ('router', _router.name),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ with mock.patch.object(
+ self.network, "find_router", return_value=_router):
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.assertIn("routes", columns)
+ self.assertIsNone(list(data)[columns.index('routes')].human_readable())
+
class TestUnsetRouter(TestRouter):