From 509ca3ed36b4ef512a47ff8d39c9df751084015a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89douard=20Thuleau?= Date: Wed, 4 Dec 2019 08:21:50 +0100 Subject: [PATCH] Fix router create/show if extraroute not supported If neutron does not support extraroute l3 extension, the route column formatter fails. Change-Id: I7b89c4f818865073947e0850e86c18d0d2415a51 --- openstackclient/network/v2/router.py | 2 +- .../tests/unit/network/v2/test_router.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/openstackclient/network/v2/router.py b/openstackclient/network/v2/router.py index 02da50c38..5d85e485a 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 079b9746a..500cfbe5a 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):