Merge "Fix a bug to unable to retrieve ports when no trunk ext"

This commit is contained in:
Jenkins 2017-09-19 19:32:16 +00:00 committed by Gerrit Code Review
commit 40b76ff9fc
2 changed files with 27 additions and 0 deletions

View File

@ -1108,6 +1108,12 @@ def port_list_with_trunk_types(request, **params):
gracefully.
"""
LOG.debug("port_list_with_trunk_types(): params=%s", params)
# When trunk feature is disabled in neutron, we have no need to fetch
# trunk information and port_list() is enough.
if not is_extension_supported(request, 'trunk'):
return port_list(request, **params)
ports = neutronclient(request).list_ports(**params)['ports']
trunk_filters = {}
if 'tenant_id' in params:

View File

@ -394,6 +394,8 @@ class NeutronApiTests(test.APITestCase):
trunks = self.api_tp_trunks.list()
neutronclient = self.stub_neutronclient()
neutronclient.list_extensions() \
.AndReturn({'extensions': self.api_extensions.list()})
neutronclient.list_ports().AndReturn({'ports': ports})
neutronclient.list_trunks().AndReturn({'trunks': trunks})
self.mox.ReplayAll()
@ -422,6 +424,25 @@ class NeutronApiTests(test.APITestCase):
self.assertEqual(expected_subport_ids, subport_ids)
self.assertEqual(expected_normal_port_ids, normal_port_ids)
def test_port_list_with_trunk_types_without_trunk_extension(self):
extensions = [ext for ext in self.api_extensions.list()
if ext['alias'] != 'trunk']
ports = self.api_tp_ports.list()
neutronclient = self.stub_neutronclient()
neutronclient.list_extensions().AndReturn({'extensions': extensions})
neutronclient.list_ports().AndReturn({'ports': ports})
self.mox.ReplayAll()
ret_val = api.neutron.port_list_with_trunk_types(self.request)
self.assertEqual(len(ports), len(ret_val))
self.assertEqual(set(p['id'] for p in ports),
set(p.id for p in ret_val))
# When trunk extension is disabled, all returned values should be
# instances of Port class.
self.assertTrue(all(isinstance(p, api.neutron.Port) for p in ret_val))
def test_port_get(self):
port = {'port': self.api_ports.first()}
port_id = self.api_ports.first()['id']