]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
PLUMgrid plugin: Fix for delete subnet with admin context
authorFawad Khaliq <fawad@plumgrid.com>
Sun, 21 Dec 2014 20:57:27 +0000 (12:57 -0800)
committerFawad Khaliq <fawad@plumgrid.com>
Mon, 22 Dec 2014 09:30:48 +0000 (01:30 -0800)
When delete call using admin for a subnet created from a
non-admin project is made, the tenant_id passed to backend
happened to be of admin project. This commit fixes the issues
by getting the correct tenant_id.

Closes-Bug: 1404688
Change-Id: Id21c38610ed73defb937d971a7aade57713541c0

neutron/plugins/plumgrid/plumgrid_plugin/plumgrid_plugin.py
neutron/tests/unit/plumgrid/test_plumgrid_plugin.py

index a289224a00c22748a45e655f44f355090b2ae3a4..d46ae750e3ba0050150267357447fad43c32f3a5 100644 (file)
@@ -356,9 +356,9 @@ class NeutronPluginPLUMgridV2(db_base_plugin_v2.NeutronDbPluginV2,
         LOG.debug("Neutron PLUMgrid Director: delete_subnet() called")
         # Collecting subnet info
         sub_db = self._get_subnet(context, subnet_id)
-        tenant_id = self._get_tenant_id_for_create(context, subnet_id)
         net_id = sub_db["network_id"]
         net_db = self.get_network(context, net_id)
+        tenant_id = net_db["tenant_id"]
 
         with context.session.begin(subtransactions=True):
             # Plugin DB - Subnet Delete
index 4e04b95b834446c6b944b7895fb854acbe1904b8..27750471ac1f757b6e87b71331b310a0c73be92f 100644 (file)
@@ -19,6 +19,7 @@ Test cases for  Neutron PLUMgrid Plug-in
 import mock
 from oslo.utils import importutils
 
+from neutron import context
 from neutron.extensions import portbindings
 from neutron.extensions import providernet as provider
 from neutron import manager
@@ -91,6 +92,43 @@ class TestPlumgridPluginSubnetsV2(test_plugin.TestSubnetsV2,
             self.skipTest("Plugin does not support Neutron allocation process")
         super(TestPlumgridPluginSubnetsV2, self).setUp()
 
+    def test_subnet_admin_delete(self):
+        plugin = manager.NeutronManager.get_plugin()
+        admin_context = context.get_admin_context()
+        tenant_context = context.Context('', 'not_admin')
+
+        network1 = self._fake_network('network1')
+        network1_ret = plugin.create_network(tenant_context, network1)
+
+        subnet1 = self._fake_subnet(network1_ret['id'])
+        plugin.create_subnet(tenant_context, subnet1)
+        net_db = plugin.get_network(admin_context, network1_ret['id'])
+
+        self.assertEqual(network1_ret['tenant_id'], net_db["tenant_id"])
+
+    def _fake_network(self, name):
+        data = {'network': {'name': name,
+                            'admin_state_up': False,
+                            'shared': False,
+                            'router:external': [],
+                            'provider:network_type': None,
+                            'provider:segmentation_id': None,
+                            'provider:physical_network': None}}
+        return data
+
+    def _fake_subnet(self, net_id):
+        allocation_pools = [{'start': '10.0.0.2',
+                             'end': '10.0.0.254'}]
+        return {'subnet': {'name': net_id,
+                           'network_id': net_id,
+                           'gateway_ip': '10.0.0.1',
+                           'dns_nameservers': ['10.0.0.2'],
+                           'host_routes': [],
+                           'cidr': '10.0.0.0/24',
+                           'allocation_pools': allocation_pools,
+                           'enable_dhcp': True,
+                           'ip_version': 4}}
+
 
 class TestPlumgridPluginPortBinding(PLUMgridPluginV2TestCase,
                                     test_bindings.PortBindingsTestCase):