]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Networks are not scheduled to DHCP agents for Cisco N1KV plugin
authorSourabh Patwardhan <sopatwar@cisco.com>
Thu, 14 Aug 2014 00:31:45 +0000 (17:31 -0700)
committerSourabh Patwardhan <sopatwar@cisco.com>
Tue, 26 Aug 2014 05:25:58 +0000 (22:25 -0700)
With the config option 'network_auto_schedule = False' in
neutron.conf, networks do not get scheduled to available DHCP
agents. The fix is to explicitly schedule the network as part
of the subnet creation flow.

Change-Id: Id1f94a5844111a916f984d6dd7bda2cb4e11e1ee
Closes-Bug: #1356609

neutron/plugins/cisco/n1kv/n1kv_neutron_plugin.py
neutron/tests/unit/cisco/n1kv/test_n1kv_plugin.py

index 7933d5d976030947d3da3a9d0e93f1815b7858a7..b59a5439d62a032632f0f00ebd363a85d888b08d 100644 (file)
@@ -1310,6 +1310,10 @@ class N1kvNeutronPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
                       self).delete_subnet(context, sub['id'])
         else:
             LOG.debug(_("Created subnet: %s"), sub['id'])
+            if not q_conf.CONF.network_auto_schedule:
+                # Schedule network to a DHCP agent
+                net = self.get_network(context, sub['network_id'])
+                self.schedule_network(context, net)
             return sub
 
     def update_subnet(self, context, id, subnet):
index 201016385468f628dffd30a651d343850e527673..c4be3f3a1c9b8027099e85572b7cc2c5a0716235 100644 (file)
@@ -28,6 +28,7 @@ from neutron.extensions import portbindings
 from neutron import manager
 from neutron.plugins.cisco.common import cisco_constants as c_const
 from neutron.plugins.cisco.common import cisco_exceptions as c_exc
+from neutron.plugins.cisco.common import config as c_conf
 from neutron.plugins.cisco.db import n1kv_db_v2
 from neutron.plugins.cisco.db import n1kv_models_v2
 from neutron.plugins.cisco.db import network_db_v2 as cdb
@@ -1073,6 +1074,17 @@ class TestN1kvSubnets(test_plugin.TestSubnetsV2,
             self.assertEqual(req.get_response(self.api).status_int,
                              webob.exc.HTTPNoContent.code)
 
+    def test_schedule_network_with_subnet_create(self):
+        """Test invocation of explicit scheduling for networks."""
+        with mock.patch.object(n1kv_neutron_plugin.N1kvNeutronPluginV2,
+                               'schedule_network') as mock_method:
+            # Test with network auto-scheduling disabled
+            c_conf.CONF.set_override('network_auto_schedule', False)
+            # Subnet creation should trigger scheduling for networks
+            with self.subnet():
+                pass
+        self.assertEqual(1, mock_method.call_count)
+
 
 class TestN1kvL3Test(test_l3_plugin.L3NatExtensionTestCase):