]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Add call to pluggable IPAM from ml2 delete_subnet
authorPavel Bondar <pbondar@infoblox.com>
Wed, 28 Oct 2015 09:22:52 +0000 (12:22 +0300)
committerArmando Migliaccio <armamig@gmail.com>
Tue, 10 Nov 2015 20:05:21 +0000 (20:05 +0000)
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

neutron/plugins/ml2/plugin.py
neutron/tests/unit/plugins/ml2/test_plugin.py

index e7e0b9dc20139d92af0a591e8f17b27d72271808..bec75e6d5225793f6432b720261716bf65a11a93 100644 (file)
@@ -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
 
index 814223135e168b34c1de4957bfa6a3d2a7c7bee6..1db4d7af9f64c3773b93e0c57f10a2cd28e97eaa 100644 (file)
@@ -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()