From 61ad9f69bde5180af195a254038ca8280a0ffbb9 Mon Sep 17 00:00:00 2001 From: Akihiro Motoki Date: Tue, 19 Sep 2017 18:01:52 +0000 Subject: [PATCH] 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 --- openstack_dashboard/api/neutron.py | 6 ++++++ .../test/api_tests/neutron_tests.py | 21 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/openstack_dashboard/api/neutron.py b/openstack_dashboard/api/neutron.py index 36c53d83c8..fc92069221 100644 --- a/openstack_dashboard/api/neutron.py +++ b/openstack_dashboard/api/neutron.py @@ -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: diff --git a/openstack_dashboard/test/api_tests/neutron_tests.py b/openstack_dashboard/test/api_tests/neutron_tests.py index d02a488757..3082c2b927 100644 --- a/openstack_dashboard/test/api_tests/neutron_tests.py +++ b/openstack_dashboard/test/api_tests/neutron_tests.py @@ -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']