summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2023-02-01 23:57:08 +0000
committerGerrit Code Review <review@openstack.org>2023-02-01 23:57:08 +0000
commit64ef37fe93f9ad7673de766a97ad8326a0cc262d (patch)
treec5e836917d22448e01c685730b41a1d5170deccc
parent15f9f1777e2205e8fe89c6eb35915c5e14ee6af7 (diff)
parentc5a53bc63b269209285ad623275b3f545e509b8f (diff)
downloadhorizon-64ef37fe93f9ad7673de766a97ad8326a0cc262d.tar.gz
Merge "Get ports directly instead of via loop" into stable/wallaby
-rw-r--r--openstack_dashboard/dashboards/project/instances/tests.py49
-rw-r--r--openstack_dashboard/dashboards/project/instances/utils.py20
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 21d2e62e0..90d250378 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(
@@ -3618,13 +3609,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),
@@ -5095,7 +5082,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 = [
@@ -5115,7 +5103,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