diff options
author | Zuul <zuul@review.opendev.org> | 2022-11-29 12:00:48 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2022-11-29 12:00:48 +0000 |
commit | eece3fc803a972ec0593acc34ce8fdf3ba4ba971 (patch) | |
tree | 4f56b1c6cb58b1db01c6608f6e0e5c91d7b3bb54 | |
parent | 0ad2f14e9c026eb23cb87a930c0d82342fff847a (diff) | |
parent | 1561fcce55371c6b2d93a31b83ca533dea82f746 (diff) | |
download | horizon-eece3fc803a972ec0593acc34ce8fdf3ba4ba971.tar.gz |
Merge "Get ports directly instead of via loop" into stable/xena
-rw-r--r-- | openstack_dashboard/dashboards/project/instances/tests.py | 49 | ||||
-rw-r--r-- | openstack_dashboard/dashboards/project/instances/utils.py | 20 |
2 files changed, 30 insertions, 39 deletions
diff --git a/openstack_dashboard/dashboards/project/instances/tests.py b/openstack_dashboard/dashboards/project/instances/tests.py index 57cf18325..29ae1789f 100644 --- a/openstack_dashboard/dashboards/project/instances/tests.py +++ b/openstack_dashboard/dashboards/project/instances/tests.py @@ -131,13 +131,9 @@ class InstanceTableTestMixin(object): shared=False), mock.call(helpers.IsHttpRequest(), shared=True), ]) - self.assertEqual(len(self.networks.list()), - self.mock_port_list_with_trunk_types.call_count) - self.mock_port_list_with_trunk_types( - [mock.call(helpers.IsHttpRequest(), - network_id=net.id, - tenant_id=self.tenant.id) - for net in self.networks.list()]) + self.mock_port_list_with_trunk_types.assert_called_once_with( + helpers.IsHttpRequest(), + tenant_id=self.tenant.id) def _mock_nova_lists(self): self.mock_flavor_list.return_value = self.flavors.list() @@ -2215,12 +2211,9 @@ class InstanceLaunchInstanceTests(InstanceTestBase, mock.call(helpers.IsHttpRequest(), shared=True), ]) self.assertEqual(4, self.mock_network_list.call_count) - self.mock_port_list_with_trunk_types.assert_has_calls( - [mock.call(helpers.IsHttpRequest(), - network_id=net.id, tenant_id=self.tenant.id) - for net in self.networks.list()]) - self.assertEqual(len(self.networks.list()), - self.mock_port_list_with_trunk_types.call_count) + self.mock_port_list_with_trunk_types.assert_called_once_with( + helpers.IsHttpRequest(), + tenant_id=self.tenant.id) self.mock_server_group_list.assert_called_once_with( helpers.IsHttpRequest()) self.mock_tenant_quota_usages.assert_called_once_with( @@ -2366,10 +2359,9 @@ class InstanceLaunchInstanceTests(InstanceTestBase, mock.call(helpers.IsHttpRequest(), shared=True), ]) self.assertEqual(4, self.mock_network_list.call_count) - self.mock_port_list_with_trunk_types.assert_has_calls( - [mock.call(helpers.IsHttpRequest(), - network_id=net.id, tenant_id=self.tenant.id) - for net in self.networks.list()]) + self.mock_port_list_with_trunk_types.assert_called_once_with( + helpers.IsHttpRequest(), + tenant_id=self.tenant.id) self.mock_server_group_list.assert_called_once_with( helpers.IsHttpRequest()) self.mock_tenant_quota_usages.assert_called_once_with( @@ -2449,10 +2441,9 @@ class InstanceLaunchInstanceTests(InstanceTestBase, mock.call(helpers.IsHttpRequest(), shared=True), ]) self.assertEqual(4, self.mock_network_list.call_count) - self.mock_port_list_with_trunk_types.assert_has_calls( - [mock.call(helpers.IsHttpRequest(), - network_id=net.id, tenant_id=self.tenant.id) - for net in self.networks.list()]) + self.mock_port_list_with_trunk_types.assert_called_once_with( + helpers.IsHttpRequest(), + tenant_id=self.tenant.id) self.mock_server_group_list.assert_called_once_with( helpers.IsHttpRequest()) self.mock_tenant_quota_usages.assert_called_once_with( @@ -3624,13 +3615,9 @@ class InstanceLaunchInstanceTests(InstanceTestBase, helpers.IsHttpRequest(), shared=True), ]) - self.assertEqual(len(self.networks.list()), - self.mock_port_list_with_trunk_types.call_count) - self.mock_port_list_with_trunk_types.assert_has_calls( - [mock.call(helpers.IsHttpRequest(), - network_id=net.id, - tenant_id=self.tenant.id) - for net in self.networks.list()]) + self.mock_port_list_with_trunk_types.assert_called_once_with( + helpers.IsHttpRequest(), + tenant_id=self.tenant.id) self.mock_volume_list.assert_has_calls([ mock.call(helpers.IsHttpRequest(), search_opts=VOLUME_SEARCH_OPTS), @@ -5103,7 +5090,8 @@ class ConsoleManagerTests(helpers.ResetImageAPIVersionMixin, helpers.TestCase): self.assertRaises(exceptions.NotAvailable, console.get_console, None, 'FAKE', None) - @helpers.create_mocks({api.neutron: ('network_list_for_tenant',)}) + @helpers.create_mocks({api.neutron: ('network_list_for_tenant', + 'port_list_with_trunk_types',)}) def test_interface_attach_get(self): server = self.servers.first() self.mock_network_list_for_tenant.side_effect = [ @@ -5123,7 +5111,8 @@ class ConsoleManagerTests(helpers.ResetImageAPIVersionMixin, helpers.TestCase): ]) self.assertEqual(2, self.mock_network_list_for_tenant.call_count) - @helpers.create_mocks({api.neutron: ('network_list_for_tenant',), + @helpers.create_mocks({api.neutron: ('network_list_for_tenant', + 'port_list_with_trunk_types',), api.nova: ('interface_attach',)}) def test_interface_attach_post(self): fixed_ip = '10.0.0.10' diff --git a/openstack_dashboard/dashboards/project/instances/utils.py b/openstack_dashboard/dashboards/project/instances/utils.py index 0639690db..005ce12b2 100644 --- a/openstack_dashboard/dashboards/project/instances/utils.py +++ b/openstack_dashboard/dashboards/project/instances/utils.py @@ -197,7 +197,7 @@ def port_field_data(request, with_network=False): port_name = "{} ({})".format( port.name_or_id, ",".join( [ip['ip_address'] for ip in port['fixed_ips']])) - if with_network and network: + if with_network: port_name += " - {}".format(network.name_or_id) return port_name @@ -205,14 +205,16 @@ def port_field_data(request, with_network=False): if api.base.is_service_enabled(request, 'network'): network_list = api.neutron.network_list_for_tenant( request, request.user.tenant_id) - for network in network_list: - ports.extend( - [(port.id, add_more_info_port_name(port, network)) - for port in api.neutron.port_list_with_trunk_types( - request, network_id=network.id, - tenant_id=request.user.tenant_id) - if (not port.device_owner and - not isinstance(port, api.neutron.PortTrunkSubport))]) + network_dict = dict((n.id, n) for n in network_list) + ports = [ + (port.id, + add_more_info_port_name(port, network_dict[port.network_id])) + for port + in api.neutron.port_list_with_trunk_types( + request, tenant_id=request.user.tenant_id) + if (not port.device_owner and + not isinstance(port, api.neutron.PortTrunkSubport)) + ] ports.sort(key=lambda obj: obj[1]) return ports |