]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Schedule net to a DHCP agt on subnet create
authorKevin Benton <blak111@gmail.com>
Thu, 12 Mar 2015 01:32:52 +0000 (18:32 -0700)
committerKevin Benton <kevinbenton@buttewifi.com>
Tue, 17 Mar 2015 04:22:34 +0000 (04:22 +0000)
Change the DHCP notifier behavior to schedule a network
to a DHCP agent when a subnet is created rather than
waiting for the first port to be created.

This will reduce the possibility to get a VM port created
and have it send a DHCP request before the DHCP agent is
ready. Before, the network would be scheduled to an agent
as a result of the API call to create the VM port, so the
DHCP port wouldn't be created until after the VM port.
After this patch, the network will have been scheduled to
a DHCP agent before the first VM port is created.

There is still a possibility that the DHCP agent could be
responding so slowly that it doesn't create its port and
activate the dnsmasq instance before the VM sends traffic.
A proper fix will ensure that the dnsmasq instance is
truly ready to serve requests for a new port will require
significantly more code for barriers (either on the subnet
creation, port creation, or the nova boot process) are too
complex to add this late in the cycle.

This patch also eliminates the logic in the n1kv plugin that
was already doing the same thing.

Closes-Bug: #1431105
Change-Id: I1c1caed0fdda6b801375a07f9252a9127058a07e

neutron/api/rpc/agentnotifiers/dhcp_rpc_agent_api.py
neutron/plugins/cisco/n1kv/n1kv_neutron_plugin.py
neutron/tests/unit/api/rpc/agentnotifiers/test_dhcp_rpc_agent_api.py
neutron/tests/unit/openvswitch/test_agent_scheduler.py

index 3f2fbc0e2f6134a1851b4c5c61f3cd64b2effd0d..884dde28b90823d709c0c5e380097e05d1178cf2 100644 (file)
@@ -70,8 +70,8 @@ class DhcpAgentNotifyAPI(object):
                     {'network': {'id': network['id']}}, agent['host'])
         elif not existing_agents:
             LOG.warn(_LW('Unable to schedule network %s: no agents available; '
-                         'will retry on subsequent port creation events.'),
-                     network['id'])
+                         'will retry on subsequent port and subnet creation '
+                         'events.'), network['id'])
         return new_agents + existing_agents
 
     def _get_enabled_agents(self, context, network, agents, method, payload):
@@ -126,6 +126,7 @@ class DhcpAgentNotifyAPI(object):
 
             # schedule the network first, if needed
             schedule_required = (
+                method == 'subnet_create_end' or
                 method == 'port_create_end' and
                 not self._is_reserved_dhcp_port(payload['port']))
             if schedule_required:
index cb4b9b907cffc220d0d0f029000717c69f4e1fca..274b56143c5127a7ed3933cd049f408e007ed5a5 100644 (file)
@@ -1297,10 +1297,6 @@ 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 0f0ff8c0349c7f6fb592d7ff0233f107f828d178..89b41f13620383686fe4f672c007087021283ad3 100644 (file)
@@ -139,9 +139,9 @@ class TestDhcpAgentNotifyAPI(base.BaseTestCase):
         self._test__notify_agents('port_update_end',
                                   expected_scheduling=0, expected_casts=1)
 
-    def test__notify_agents_cast_required_wo_scheduling_on_subnet_create(self):
+    def test__notify_agents_cast_required_with_scheduling_subnet_create(self):
         self._test__notify_agents('subnet_create_end',
-                                  expected_scheduling=0, expected_casts=1)
+                                  expected_scheduling=1, expected_casts=1)
 
     def test__notify_agents_no_action(self):
         self._test__notify_agents('network_create_end',
index b9dc54338a2e2e1f281dec9eb77a47b4a4c30aad..a76a66d5721c7caf7106ee69afc22f53dc2aa056 100644 (file)
@@ -1285,6 +1285,11 @@ class OvsDhcpAgentNotifierTestCase(test_l3_plugin.L3NatTestCaseMixin,
                     'network_create_end',
                     {'network': {'id': net['network']['id']}},
                     host),
+                mock.call(
+                    mock.ANY,
+                    'subnet_create_end',
+                    subnet,
+                    host, 'dhcp_agent'),
                 mock.call(
                     mock.ANY,
                     'port_create_end',