diff --git a/neutron/db/agentschedulers_db.py b/neutron/db/agentschedulers_db.py index 27676396f40..8e372e62e51 100644 --- a/neutron/db/agentschedulers_db.py +++ b/neutron/db/agentschedulers_db.py @@ -475,7 +475,7 @@ class DhcpAgentSchedulerDbMixin(dhcpagentscheduler return {'agents': []} def schedule_network(self, context, created_network): - if self.network_scheduler: + if self.network_scheduler and cfg.CONF.network_auto_schedule: return self.network_scheduler.schedule( self, context, created_network) diff --git a/neutron/tests/unit/db/test_agentschedulers_db.py b/neutron/tests/unit/db/test_agentschedulers_db.py index 1c2099d05fc..f7707a57dbf 100644 --- a/neutron/tests/unit/db/test_agentschedulers_db.py +++ b/neutron/tests/unit/db/test_agentschedulers_db.py @@ -1354,6 +1354,35 @@ class OvsAgentSchedulerTestCase(OvsAgentSchedulerTestCaseBase): self._list_networks_hosted_by_dhcp_agent(invalid_agentid, exc.HTTPNotFound.code) + def test_network_no_reschedule(self): + cfg.CONF.set_override('allow_overlapping_ips', True) + cfg.CONF.set_override('network_auto_schedule', False) + with self.subnet() as sb1, self.subnet(): + network1_id = sb1['subnet']['network_id'] + dhcp_rpc_cb = dhcp_rpc.DhcpRpcCallback() + self._register_agent_states() + hosta_id = self._get_agent_id(constants.AGENT_TYPE_DHCP, + DHCP_HOSTA) + hostc_id = self._get_agent_id(constants.AGENT_TYPE_DHCP, + DHCP_HOSTC) + dhcp_rpc_cb.get_active_networks_info( + self.adminContext, host=DHCP_HOSTA) + dhcp_rpc_cb.get_active_networks_info( + self.adminContext, host=DHCP_HOSTC) + networks = self._list_networks_hosted_by_dhcp_agent(hostc_id) + num_hostc_nets = len(networks['networks']) + networks = self._list_networks_hosted_by_dhcp_agent(hosta_id) + num_hosta_nets = len(networks['networks']) + self.assertEqual(0, num_hosta_nets) + self.assertEqual(0, num_hostc_nets) + # After this patch, network which requires DHCP + # has to be manually mapped + self._add_network_to_dhcp_agent(hosta_id, + network1_id) + networks = self._list_networks_hosted_by_dhcp_agent(hosta_id) + num_hosta_nets = len(networks['networks']) + self.assertEqual(1, num_hosta_nets) + class OvsDhcpAgentNotifierTestCase(test_agent.AgentDBTestMixIn, AgentSchedulerTestMixIn, diff --git a/releasenotes/notes/modify-dhcp-behavior-based-on-network-auto-schedule-1ea5e74fd5bb560c.yaml b/releasenotes/notes/modify-dhcp-behavior-based-on-network-auto-schedule-1ea5e74fd5bb560c.yaml new file mode 100644 index 00000000000..a4850c70fe6 --- /dev/null +++ b/releasenotes/notes/modify-dhcp-behavior-based-on-network-auto-schedule-1ea5e74fd5bb560c.yaml @@ -0,0 +1,14 @@ +--- +fixes: + - | + Neutron currently does not fully respect the network-auto-schedule + configuration option. If the network-auto-schedule option is set to + False, the network - + a) Is still scheduled on the DHCP agent when it is created + b) Is scheduled on a new DHCP agent if the old DHCP mapping is removed + by the user/admin. + It is especially necessary where the Network Backends provide DHCP + directly. This has been fixed now and if the network-auto-schedule + is set to False in the config file, networks would not be automatically + scheduled to the DHCP Agents. If mapping/scheduling is required, it can + be done manually or by setting the network-auto-schedule to True.