From be9f5738d563a8b2444cbdf283c0884bd2f37ab4 Mon Sep 17 00:00:00 2001 From: Kevin Benton Date: Wed, 11 Mar 2015 23:25:52 -0700 Subject: [PATCH] Show ports from shared nets in floating IP assoc Ports from shared networks should be included in the list of 'Ports to be associated' even though a router interface connecting to the external network might not be visible to the tenant. Change-Id: Iba141b51371b955c3cfdcc52c0bf279466131713 Closes-Bug: #1394051 --- openstack_dashboard/api/neutron.py | 6 ++++- .../test/api_tests/network_tests.py | 22 ++++++++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/openstack_dashboard/api/neutron.py b/openstack_dashboard/api/neutron.py index 21dcd2d80d..7035a68dfa 100644 --- a/openstack_dashboard/api/neutron.py +++ b/openstack_dashboard/api/neutron.py @@ -429,7 +429,11 @@ class FloatingIpManager(network_base.FloatingIpManager): if ((p.device_owner in ROUTER_INTERFACE_OWNERS) and (p.device_id in gw_routers))]) - return reachable_subnets + # we have to include any shared subnets as well because we may not + # have permission to see the router interface to infer connectivity + shared = set([s.id for n in network_list(self.request, shared=True) + for s in n.subnets]) + return reachable_subnets | shared def list_targets(self): tenant_id = self.request.user.tenant_id diff --git a/openstack_dashboard/test/api_tests/network_tests.py b/openstack_dashboard/test/api_tests/network_tests.py index 83a595dae7..4a54ce9c9f 100644 --- a/openstack_dashboard/test/api_tests/network_tests.py +++ b/openstack_dashboard/test/api_tests/network_tests.py @@ -688,17 +688,23 @@ class NetworkApiNeutronFloatingIpTests(NetworkApiNeutronTestBase): 'addr': port['fixed_ips'][0]['ip_address']} return 'server_%(svrid)s: %(addr)s' % param + def _subs_from_port(self, port): + return [ip['subnet_id'] for ip in port['fixed_ips']] + @override_settings(OPENSTACK_NEUTRON_NETWORK={'enable_lb': True}) def test_floating_ip_target_list(self): ports = self.api_ports.list() # Port on the first subnet is connected to a router # attached to external network in neutron_data. subnet_id = self.subnets.first().id - target_ports = [(self._get_target_id(p), - self._get_target_name(p)) for p in ports - if (not p['device_owner'].startswith('network:') and - subnet_id in [ip['subnet_id'] - for ip in p['fixed_ips']])] + shared_nets = [n for n in self.api_networks.list() if n['shared']] + shared_subnet_ids = [s for n in shared_nets for s in n['subnets']] + target_ports = [ + (self._get_target_id(p), self._get_target_name(p)) for p in ports + if (not p['device_owner'].startswith('network:') and + (subnet_id in self._subs_from_port(p) or + (set(shared_subnet_ids) & set(self._subs_from_port(p))))) + ] filters = {'tenant_id': self.request.user.tenant_id} self.qclient.list_ports(**filters).AndReturn({'ports': ports}) servers = self.servers.list() @@ -714,7 +720,11 @@ class NetworkApiNeutronFloatingIpTests(NetworkApiNeutronTestBase): .AndReturn({'networks': ext_nets}) self.qclient.list_routers().AndReturn({'routers': self.api_routers.list()}) - + self.qclient.list_networks(shared=True).AndReturn({'networks': + shared_nets}) + shared_subs = [s for s in self.api_subnets.list() + if s['id'] in shared_subnet_ids] + self.qclient.list_subnets().AndReturn({'subnets': shared_subs}) self.qclient.list_vips().AndReturn({'vips': self.vips.list()}) self.mox.ReplayAll()