From d5e9f06cf34096cd4c68c168086b6f9cc48072c3 Mon Sep 17 00:00:00 2001 From: Fawad Khaliq Date: Sun, 21 Dec 2014 12:57:27 -0800 Subject: [PATCH] PLUMgrid plugin: Fix for delete subnet with admin context 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 --- .../plumgrid_plugin/plumgrid_plugin.py | 2 +- .../unit/plumgrid/test_plumgrid_plugin.py | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/neutron/plugins/plumgrid/plumgrid_plugin/plumgrid_plugin.py b/neutron/plugins/plumgrid/plumgrid_plugin/plumgrid_plugin.py index a289224a0..d46ae750e 100644 --- a/neutron/plugins/plumgrid/plumgrid_plugin/plumgrid_plugin.py +++ b/neutron/plugins/plumgrid/plumgrid_plugin/plumgrid_plugin.py @@ -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 diff --git a/neutron/tests/unit/plumgrid/test_plumgrid_plugin.py b/neutron/tests/unit/plumgrid/test_plumgrid_plugin.py index 4e04b95b8..27750471a 100644 --- a/neutron/tests/unit/plumgrid/test_plumgrid_plugin.py +++ b/neutron/tests/unit/plumgrid/test_plumgrid_plugin.py @@ -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): -- 2.45.2