From: Pavel Bondar Date: Wed, 28 Oct 2015 09:22:52 +0000 (+0300) Subject: Add call to pluggable IPAM from ml2 delete_subnet X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=99573f62d1fc79a4308784ab2c799d836b7a3d74;p=openstack-build%2Fneutron-build.git Add call to pluggable IPAM from ml2 delete_subnet ml2 plugin overrides delete_subnet and do not call super(), so pluggable IPAM action defined in db_base_plugin_v2 are not called. As a result subnets can not be deleted from IPAM driver if ml2 plugin is used. Added ipam.delete_subnet call into ml2 delete_subnet. Patch includes UT to verify IPAM driver is called on subnet allocation and deallocation. Test class is inherited from TestMl2SubnetsV2, so all SubnetV2 tests are additionally executed for ml2 plugin with reference IPAM driver. Closes-Bug: #1510653 Change-Id: I2b7ddfe70a1275a141af38e18151e1fc000e2682 --- diff --git a/neutron/plugins/ml2/plugin.py b/neutron/plugins/ml2/plugin.py index e7e0b9dc2..bec75e6d5 100644 --- a/neutron/plugins/ml2/plugin.py +++ b/neutron/plugins/ml2/plugin.py @@ -951,6 +951,10 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, LOG.debug("Deleting subnet record") session.delete(record) + # The super(Ml2Plugin, self).delete_subnet() is not called, + # so need to manually call delete_subnet for pluggable ipam + self.ipam.delete_subnet(context, id) + LOG.debug("Committing transaction") break diff --git a/neutron/tests/unit/plugins/ml2/test_plugin.py b/neutron/tests/unit/plugins/ml2/test_plugin.py index 814223135..1db4d7af9 100644 --- a/neutron/tests/unit/plugins/ml2/test_plugin.py +++ b/neutron/tests/unit/plugins/ml2/test_plugin.py @@ -55,6 +55,7 @@ from neutron.tests.unit import _test_extension_portbindings as test_bindings from neutron.tests.unit.agent import test_securitygroups_rpc as test_sg_rpc from neutron.tests.unit.db import test_allowedaddresspairs_db as test_pair from neutron.tests.unit.db import test_db_base_plugin_v2 as test_plugin +from neutron.tests.unit.db import test_ipam_pluggable_backend as test_ipam from neutron.tests.unit.extensions import test_extra_dhcp_opt as test_dhcpopts from neutron.tests.unit.plugins.ml2.drivers import mechanism_logger as \ mech_logger @@ -1621,6 +1622,29 @@ class TestFaultyMechansimDriver(Ml2PluginV2FaultyDriverTestCase): self.assertEqual(new_name, port['port']['name']) +class TestML2PluggableIPAM(test_ipam.UseIpamMixin, TestMl2SubnetsV2): + def test_create_subnet_delete_subnet_call_ipam_driver(self): + driver = 'neutron.ipam.drivers.neutrondb_ipam.driver.NeutronDbPool' + gateway_ip = '10.0.0.1' + cidr = '10.0.0.0/24' + with mock.patch(driver) as driver_mock: + request = mock.Mock() + request.subnet_id = uuidutils.generate_uuid() + request.subnet_cidr = cidr + request.allocation_pools = [] + request.gateway_ip = gateway_ip + request.tenant_id = uuidutils.generate_uuid() + + ipam_subnet = mock.Mock() + ipam_subnet.get_details.return_value = request + driver_mock().allocate_subnet.return_value = ipam_subnet + + self._test_create_subnet(gateway_ip=gateway_ip, cidr=cidr) + + driver_mock().allocate_subnet.assert_called_with(mock.ANY) + driver_mock().remove_subnet.assert_called_with(request.subnet_id) + + class TestMl2PluginCreateUpdateDeletePort(base.BaseTestCase): def setUp(self): super(TestMl2PluginCreateUpdateDeletePort, self).setUp()