Don't display non-tenant Floating IP in Floating IP project tab
Previously Floating IPs from all tenants are displayed when logged in as a user with admin role and Neutron is enabled. Neutron API returns resources from all tenants when the API is called with admin role, so we need to call the API with additional filter parameter to limit the results to a given tenant. Closes-Bug: #1226224 Change-Id: I47ddf77cd3c5d4c6141a67cb32c22cc917b485e6
This commit is contained in:
parent
5a27e303c7
commit
3827a7e73a
@ -319,10 +319,15 @@ class FloatingIpManager(network_base.FloatingIpManager):
|
||||
in self.client.list_networks(**search_opts).get('networks')]
|
||||
|
||||
def list(self):
|
||||
fips = self.client.list_floatingips().get('floatingips')
|
||||
tenant_id = self.request.user.tenant_id
|
||||
# In Neutron, list_floatingips returns Floating IPs from all tenants
|
||||
# when the API is called with admin role, so we need to filter them
|
||||
# with tenant_id.
|
||||
fips = self.client.list_floatingips(tenant_id=tenant_id)
|
||||
fips = fips.get('floatingips')
|
||||
# Get port list to add instance_id to floating IP list
|
||||
# instance_id is stored in device_id attribute
|
||||
ports = port_list(self.request)
|
||||
ports = port_list(self.request, tenant_id=tenant_id)
|
||||
device_id_dict = SortedDict([(p['id'], p['device_id']) for p in ports])
|
||||
for fip in fips:
|
||||
if fip['port_id']:
|
||||
@ -364,7 +369,8 @@ class FloatingIpManager(network_base.FloatingIpManager):
|
||||
{'floatingip': update_dict})
|
||||
|
||||
def list_targets(self):
|
||||
ports = port_list(self.request)
|
||||
tenant_id = self.request.user.tenant_id
|
||||
ports = port_list(self.request, tenant_id=tenant_id)
|
||||
servers, has_more = nova.server_list(self.request)
|
||||
server_dict = SortedDict([(s.id, s.name) for s in servers])
|
||||
targets = []
|
||||
|
@ -349,8 +349,11 @@ class NetworkApiNeutronFloatingIpTests(NetworkApiNeutronTestBase):
|
||||
|
||||
def test_floating_ip_list(self):
|
||||
fips = self.api_q_floating_ips.list()
|
||||
self.qclient.list_floatingips().AndReturn({'floatingips': fips})
|
||||
self.qclient.list_ports().AndReturn({'ports': self.api_ports.list()})
|
||||
filters = {'tenant_id': self.request.user.tenant_id}
|
||||
self.qclient.list_floatingips(**filters) \
|
||||
.AndReturn({'floatingips': fips})
|
||||
self.qclient.list_ports(**filters) \
|
||||
.AndReturn({'ports': self.api_ports.list()})
|
||||
self.mox.ReplayAll()
|
||||
|
||||
rets = api.network.tenant_floating_ip_list(self.request)
|
||||
@ -449,8 +452,8 @@ class NetworkApiNeutronFloatingIpTests(NetworkApiNeutronTestBase):
|
||||
target_ports = [(self._get_target_id(p),
|
||||
self._get_target_name(p)) for p in ports
|
||||
if not p['device_owner'].startswith('network:')]
|
||||
|
||||
self.qclient.list_ports().AndReturn({'ports': ports})
|
||||
filters = {'tenant_id': self.request.user.tenant_id}
|
||||
self.qclient.list_ports(**filters).AndReturn({'ports': ports})
|
||||
servers = self.servers.list()
|
||||
novaclient = self.stub_novaclient()
|
||||
novaclient.servers = self.mox.CreateMockAnything()
|
||||
|
Loading…
x
Reference in New Issue
Block a user