router list if availability_zone ext not enabled
when calling router list with --long OSC expects the availability_zone field in the response, even if this extension is not loaded: As per the document, http://developer.openstack.org/api-ref/networking/ v2/?expanded=list-routers-detail, The availability zone(s) for the router is available when router_availability_zone extension is enabled. Added testcase to test router list without availability zone Change-Id: Ic9abb06140eb310b797ade8b0463a876d8bea1b8 Closes-bug: #1622565
This commit is contained in:
parent
fb66a5b8f9
commit
e04e389da2
@ -281,13 +281,20 @@ class ListRouter(command.Lister):
|
|||||||
columns = columns + (
|
columns = columns + (
|
||||||
'routes',
|
'routes',
|
||||||
'external_gateway_info',
|
'external_gateway_info',
|
||||||
'availability_zones'
|
|
||||||
)
|
)
|
||||||
column_headers = column_headers + (
|
column_headers = column_headers + (
|
||||||
'Routes',
|
'Routes',
|
||||||
'External gateway info',
|
'External gateway info',
|
||||||
'Availability zones'
|
|
||||||
)
|
)
|
||||||
|
# availability zone will be available only when
|
||||||
|
# router_availability_zone extension is enabled
|
||||||
|
if client.find_extension("router_availability_zone"):
|
||||||
|
columns = columns + (
|
||||||
|
'availability_zones',
|
||||||
|
)
|
||||||
|
column_headers = column_headers + (
|
||||||
|
'Availability zones',
|
||||||
|
)
|
||||||
|
|
||||||
data = client.routers()
|
data = client.routers()
|
||||||
return (column_headers,
|
return (column_headers,
|
||||||
|
@ -285,6 +285,7 @@ class TestListRouter(TestRouter):
|
|||||||
|
|
||||||
# The routers going to be listed up.
|
# The routers going to be listed up.
|
||||||
routers = network_fakes.FakeRouter.create_routers(count=3)
|
routers = network_fakes.FakeRouter.create_routers(count=3)
|
||||||
|
_extensions = network_fakes.FakeExtension.create_one_extension()
|
||||||
|
|
||||||
columns = (
|
columns = (
|
||||||
'ID',
|
'ID',
|
||||||
@ -300,6 +301,10 @@ class TestListRouter(TestRouter):
|
|||||||
'External gateway info',
|
'External gateway info',
|
||||||
'Availability zones'
|
'Availability zones'
|
||||||
)
|
)
|
||||||
|
columns_long_no_az = columns + (
|
||||||
|
'Routes',
|
||||||
|
'External gateway info',
|
||||||
|
)
|
||||||
|
|
||||||
data = []
|
data = []
|
||||||
for r in routers:
|
for r in routers:
|
||||||
@ -322,6 +327,15 @@ class TestListRouter(TestRouter):
|
|||||||
osc_utils.format_list(r.availability_zones),
|
osc_utils.format_list(r.availability_zones),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
data_long_no_az = []
|
||||||
|
for i in range(0, len(routers)):
|
||||||
|
r = routers[i]
|
||||||
|
data_long_no_az.append(
|
||||||
|
data[i] + (
|
||||||
|
router._format_routes(r.routes),
|
||||||
|
router._format_external_gateway_info(r.external_gateway_info),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestListRouter, self).setUp()
|
super(TestListRouter, self).setUp()
|
||||||
@ -330,6 +344,7 @@ class TestListRouter(TestRouter):
|
|||||||
self.cmd = router.ListRouter(self.app, self.namespace)
|
self.cmd = router.ListRouter(self.app, self.namespace)
|
||||||
|
|
||||||
self.network.routers = mock.Mock(return_value=self.routers)
|
self.network.routers = mock.Mock(return_value=self.routers)
|
||||||
|
self.network.find_extension = mock.Mock(return_value=self._extensions)
|
||||||
|
|
||||||
def test_router_list_no_options(self):
|
def test_router_list_no_options(self):
|
||||||
arglist = []
|
arglist = []
|
||||||
@ -365,6 +380,27 @@ class TestListRouter(TestRouter):
|
|||||||
self.assertEqual(self.columns_long, columns)
|
self.assertEqual(self.columns_long, columns)
|
||||||
self.assertEqual(self.data_long, list(data))
|
self.assertEqual(self.data_long, list(data))
|
||||||
|
|
||||||
|
def test_router_list_long_no_az(self):
|
||||||
|
arglist = [
|
||||||
|
'--long',
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('long', True),
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
# to mock, that no availability zone
|
||||||
|
self.network.find_extension = mock.Mock(return_value=None)
|
||||||
|
|
||||||
|
# In base command class Lister in cliff, abstract method take_action()
|
||||||
|
# returns a tuple containing the column names and an iterable
|
||||||
|
# containing the data to be listed.
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
self.network.routers.assert_called_once_with()
|
||||||
|
self.assertEqual(self.columns_long_no_az, columns)
|
||||||
|
self.assertEqual(self.data_long_no_az, list(data))
|
||||||
|
|
||||||
|
|
||||||
class TestRemovePortFromRouter(TestRouter):
|
class TestRemovePortFromRouter(TestRouter):
|
||||||
'''Remove port from a Router '''
|
'''Remove port from a Router '''
|
||||||
|
Loading…
x
Reference in New Issue
Block a user