Fix a bug to unable to retrieve ports when no trunk ext
When neutron trunk extension is not enabled, we cannot retrieve network ports for a new instance. The current version of port_list_with_trunk_types assumes the trunk extension is always available, so if it is not enabled we cannot retrieve network ports. This commit changes the logic to check whether the trunk extension is enabled and if not it does not retrieve trunk information. Change-Id: I2aa476790820f9512fe4728e0a806bd543021b0b Closes-Bug: #1717893
This commit is contained in:
parent
c8189bddcb
commit
61ad9f69bd
@ -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:
|
||||
|
@ -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']
|
||||
|
Loading…
Reference in New Issue
Block a user