Browse Source

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.

Conflicts:
	openstack_dashboard/api/neutron.py
(cherry picked from commit 3827a7e73a)

Closes-Bug: #1226224
Change-Id: I47ddf77cd3c5d4c6141a67cb32c22cc917b485e6
Akihiro MOTOKI 5 years ago
parent
commit
3f81d70d4b

+ 9
- 3
openstack_dashboard/api/quantum.py View File

@@ -122,10 +122,15 @@ class FloatingIpManager(network.FloatingIpManager):
122 122
                 in self.client.list_networks(**search_opts).get('networks')]
123 123
 
124 124
     def list(self):
125
-        fips = self.client.list_floatingips().get('floatingips')
125
+        tenant_id = self.request.user.tenant_id
126
+        # In Neutron, list_floatingips returns Floating IPs from all tenants
127
+        # when the API is called with admin role, so we need to filter them
128
+        # with tenant_id.
129
+        fips = self.client.list_floatingips(tenant_id=tenant_id)
130
+        fips = fips.get('floatingips')
126 131
         # Get port list to add instance_id to floating IP list
127 132
         # instance_id is stored in device_id attribute
128
-        ports = port_list(self.request)
133
+        ports = port_list(self.request, tenant_id=tenant_id)
129 134
         device_id_dict = SortedDict([(p['id'], p['device_id']) for p in ports])
130 135
         for fip in fips:
131 136
             if fip['port_id']:
@@ -167,7 +172,8 @@ class FloatingIpManager(network.FloatingIpManager):
167 172
                                       {'floatingip': update_dict})
168 173
 
169 174
     def list_targets(self):
170
-        ports = port_list(self.request)
175
+        tenant_id = self.request.user.tenant_id
176
+        ports = port_list(self.request, tenant_id=tenant_id)
171 177
         servers = nova.server_list(self.request)
172 178
         server_dict = SortedDict([(s.id, s.name) for s in servers])
173 179
         targets = []

+ 7
- 4
openstack_dashboard/test/api_tests/network_tests.py View File

@@ -165,8 +165,11 @@ class NetworkApiQuantumFloatingIpTests(test.APITestCase):
165 165
 
166 166
     def test_floating_ip_list(self):
167 167
         fips = self.api_q_floating_ips.list()
168
-        self.qclient.list_floatingips().AndReturn({'floatingips': fips})
169
-        self.qclient.list_ports().AndReturn({'ports': self.api_ports.list()})
168
+        filters = {'tenant_id': self.request.user.tenant_id}
169
+        self.qclient.list_floatingips(**filters) \
170
+            .AndReturn({'floatingips': fips})
171
+        self.qclient.list_ports(**filters) \
172
+            .AndReturn({'ports': self.api_ports.list()})
170 173
         self.mox.ReplayAll()
171 174
 
172 175
         rets = api.network.tenant_floating_ip_list(self.request)
@@ -265,8 +268,8 @@ class NetworkApiQuantumFloatingIpTests(test.APITestCase):
265 268
         target_ports = [(self._get_target_id(p),
266 269
                          self._get_target_name(p)) for p in ports
267 270
                         if not p['device_owner'].startswith('network:')]
268
-
269
-        self.qclient.list_ports().AndReturn({'ports': ports})
271
+        filters = {'tenant_id': self.request.user.tenant_id}
272
+        self.qclient.list_ports(**filters).AndReturn({'ports': ports})
270 273
         servers = self.servers.list()
271 274
         novaclient = self.stub_novaclient()
272 275
         novaclient.servers = self.mox.CreateMockAnything()

Loading…
Cancel
Save