From 139b496ef957364caee6861fd16676cdfb76a38b Mon Sep 17 00:00:00 2001 From: Reedip Date: Mon, 11 Nov 2019 10:54:42 +0900 Subject: [PATCH] Dont schedule Network, respecting network_auto_schedule config Currently, if dhcp mapping from a network is removed, it is reassigned to the network. This is because of the Network Scheduler's schedule function, which considers balancing the networks with the agents, whether enable_dhcp is set on its subnets or not. It does not take into account the network_auto_schedule config option. This is particularly disturbing when considering backends which have their provide their own DHCP. With this patch, if network_auto_schedule is set to False, networks wont be automatically scheduled to DHCP Agents. If DHCP is to be mapped to a network, it can be mapped using the CLI itself. While it may seem that this change is breaking what is already working, but as mentioned earlier, if there are network backends which provide DHCP support themselves, they wont need the automatic mapping, which the term "network_auto_schedule" actually stands for. Closes-Bug: #1647421 Change-Id: If1a6a2a174d0f737415efa2abce518722316a77b --- neutron/db/agentschedulers_db.py | 2 +- .../tests/unit/db/test_agentschedulers_db.py | 29 +++++++++++++++++++ ...etwork-auto-schedule-1ea5e74fd5bb560c.yaml | 14 +++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/modify-dhcp-behavior-based-on-network-auto-schedule-1ea5e74fd5bb560c.yaml 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.