Skip to content

Commit

Permalink
Don't display non-tenant Floating IP in Floating IP project tab
Browse files Browse the repository at this point in the history
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
  • Loading branch information
amotoki committed Sep 16, 2013
1 parent 5a27e30 commit 3827a7e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
12 changes: 9 additions & 3 deletions openstack_dashboard/api/neutron.py
Expand Up @@ -319,10 +319,15 @@ def list_pools(self):
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']:
Expand Down Expand Up @@ -364,7 +369,8 @@ def disassociate(self, floating_ip_id, port_id):
{'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 = []
Expand Down
11 changes: 7 additions & 4 deletions openstack_dashboard/test/api_tests/network_tests.py
Expand Up @@ -349,8 +349,11 @@ def test_floating_ip_pools_list(self):

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)
Expand Down Expand Up @@ -449,8 +452,8 @@ def test_floating_ip_target_list(self):
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()
Expand Down

0 comments on commit 3827a7e

Please sign in to comment.