From: Kevin Benton Date: Thu, 12 Mar 2015 01:32:52 +0000 (-0700) Subject: Schedule net to a DHCP agt on subnet create X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=05f234481474aa05f59c4af459b4343d21397afc;p=openstack-build%2Fneutron-build.git Schedule net to a DHCP agt on subnet create 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 --- diff --git a/neutron/api/rpc/agentnotifiers/dhcp_rpc_agent_api.py b/neutron/api/rpc/agentnotifiers/dhcp_rpc_agent_api.py index 3f2fbc0e2..884dde28b 100644 --- a/neutron/api/rpc/agentnotifiers/dhcp_rpc_agent_api.py +++ b/neutron/api/rpc/agentnotifiers/dhcp_rpc_agent_api.py @@ -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: diff --git a/neutron/plugins/cisco/n1kv/n1kv_neutron_plugin.py b/neutron/plugins/cisco/n1kv/n1kv_neutron_plugin.py index cb4b9b907..274b56143 100644 --- a/neutron/plugins/cisco/n1kv/n1kv_neutron_plugin.py +++ b/neutron/plugins/cisco/n1kv/n1kv_neutron_plugin.py @@ -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): diff --git a/neutron/tests/unit/api/rpc/agentnotifiers/test_dhcp_rpc_agent_api.py b/neutron/tests/unit/api/rpc/agentnotifiers/test_dhcp_rpc_agent_api.py index 0f0ff8c03..89b41f136 100644 --- a/neutron/tests/unit/api/rpc/agentnotifiers/test_dhcp_rpc_agent_api.py +++ b/neutron/tests/unit/api/rpc/agentnotifiers/test_dhcp_rpc_agent_api.py @@ -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', diff --git a/neutron/tests/unit/openvswitch/test_agent_scheduler.py b/neutron/tests/unit/openvswitch/test_agent_scheduler.py index b9dc54338..a76a66d57 100644 --- a/neutron/tests/unit/openvswitch/test_agent_scheduler.py +++ b/neutron/tests/unit/openvswitch/test_agent_scheduler.py @@ -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',