Merge "Get ports directly instead of via loop"
This commit is contained in:
commit
6a64bdd625
@ -3055,13 +3055,15 @@ 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 = [
|
||||
self.networks.list()[:1],
|
||||
[],
|
||||
]
|
||||
self.mock_port_list_with_trunk_types.return_value = self.ports.list()
|
||||
|
||||
url = reverse('horizon:project:instances:attach_interface',
|
||||
args=[server.id])
|
||||
@ -3074,8 +3076,11 @@ class ConsoleManagerTests(helpers.ResetImageAPIVersionMixin, helpers.TestCase):
|
||||
mock.call(helpers.IsHttpRequest(), self.tenant.id),
|
||||
])
|
||||
self.assertEqual(2, self.mock_network_list_for_tenant.call_count)
|
||||
self.mock_port_list_with_trunk_types.assert_called_once_with(
|
||||
helpers.IsHttpRequest(), tenant_id=self.tenant.id)
|
||||
|
||||
@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'
|
||||
@ -3085,6 +3090,7 @@ class ConsoleManagerTests(helpers.ResetImageAPIVersionMixin, helpers.TestCase):
|
||||
[network],
|
||||
[],
|
||||
]
|
||||
self.mock_port_list_with_trunk_types.return_value = self.ports.list()
|
||||
self.mock_interface_attach.return_value = None
|
||||
|
||||
form_data = {'instance_id': server.id,
|
||||
@ -3104,6 +3110,8 @@ class ConsoleManagerTests(helpers.ResetImageAPIVersionMixin, helpers.TestCase):
|
||||
mock.call(helpers.IsHttpRequest(), self.tenant.id),
|
||||
])
|
||||
self.assertEqual(2, self.mock_network_list_for_tenant.call_count)
|
||||
self.mock_port_list_with_trunk_types.assert_called_once_with(
|
||||
helpers.IsHttpRequest(), tenant_id=self.tenant.id)
|
||||
self.mock_interface_attach.assert_called_once_with(
|
||||
helpers.IsHttpRequest(), server.id,
|
||||
net_id=network.id, fixed_ip=fixed_ip, port_id=None)
|
||||
|
@ -196,7 +196,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
|
||||
|
||||
@ -204,14 +204,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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user