From a2cfd9fcd67f392d9ad70868fa358afc7aa1b4c3 Mon Sep 17 00:00:00 2001 From: lzklibj Date: Sun, 27 Dec 2015 14:08:36 +0800 Subject: [PATCH] Unify exceptions for assign router to dvr agent validate_agent_router_combination use two different exceptions for assigning a router to an agent in 'dvr' mode: RouterL3AgentMismatch: assign dvr router to legacy agent. DVRL3CannotAssignToDvrAgent: assign dvr router to (another) dvr agent. This should be unified to one single exception, for routers on agent in 'dvr' mode should be only scheduled, not allowed to be manually assigned. Change-Id: I3673c4c6852105f86b3aac390d0aabc75944de9d Closes-Bug: #1529439 --- neutron/db/l3_agentschedulers_db.py | 27 +++++++------------ neutron/extensions/l3agentscheduler.py | 9 +++---- .../unit/scheduler/test_l3_agent_scheduler.py | 2 +- 3 files changed, 14 insertions(+), 24 deletions(-) diff --git a/neutron/db/l3_agentschedulers_db.py b/neutron/db/l3_agentschedulers_db.py index a12f7840f..ef951ccd9 100644 --- a/neutron/db/l3_agentschedulers_db.py +++ b/neutron/db/l3_agentschedulers_db.py @@ -159,33 +159,24 @@ class L3AgentSchedulerDbMixin(l3agentscheduler.L3AgentSchedulerPluginBase, """Validate if the router can be correctly assigned to the agent. :raises: RouterL3AgentMismatch if attempting to assign DVR router - to legacy agent, or centralized router to compute's L3 agents. + to legacy agent. :raises: InvalidL3Agent if attempting to assign router to an unsuitable agent (disabled, type != L3, incompatible configuration) - :raises: DVRL3CannotAssignToDvrAgent if attempting to assign DVR - router from one DVR Agent to another. + :raises: DVRL3CannotAssignToDvrAgent if attempting to assign a + router to an agent in 'dvr' mode. """ if agent['agent_type'] != constants.AGENT_TYPE_L3: raise l3agentscheduler.InvalidL3Agent(id=agent['id']) - is_distributed = router.get('distributed') agent_mode = self._get_agent_mode(agent) - router_type = ( - 'distributed' if is_distributed else - 'centralized') - is_agent_router_types_incompatible = ( - agent_mode == constants.L3_AGENT_MODE_DVR and not is_distributed - or agent_mode == constants.L3_AGENT_MODE_LEGACY and is_distributed - ) - if is_agent_router_types_incompatible: + if agent_mode == constants.L3_AGENT_MODE_DVR: + raise l3agentscheduler.DVRL3CannotAssignToDvrAgent() + + if (agent_mode == constants.L3_AGENT_MODE_LEGACY and + router.get('distributed')): raise l3agentscheduler.RouterL3AgentMismatch( - router_type=router_type, router_id=router['id'], - agent_mode=agent_mode, agent_id=agent['id']) - if agent_mode == constants.L3_AGENT_MODE_DVR and is_distributed: - raise l3agentscheduler.DVRL3CannotAssignToDvrAgent( - router_type=router_type, router_id=router['id'], - agent_id=agent['id']) + router_id=router['id'], agent_id=agent['id']) is_suitable_agent = ( agentschedulers_db.services_available(agent['admin_state_up']) and diff --git a/neutron/extensions/l3agentscheduler.py b/neutron/extensions/l3agentscheduler.py index 1d0974cec..39b6cd77a 100644 --- a/neutron/extensions/l3agentscheduler.py +++ b/neutron/extensions/l3agentscheduler.py @@ -169,14 +169,13 @@ class RouterReschedulingFailed(exceptions.Conflict): class RouterL3AgentMismatch(exceptions.Conflict): - message = _("Cannot host %(router_type)s router %(router_id)s " - "on %(agent_mode)s L3 agent %(agent_id)s.") + message = _("Cannot host distributed router %(router_id)s " + "on legacy L3 agent %(agent_id)s.") class DVRL3CannotAssignToDvrAgent(exceptions.Conflict): - message = _("Not allowed to manually assign a %(router_type)s " - "router %(router_id)s from an existing DVR node " - "to another L3 agent %(agent_id)s.") + message = _("Not allowed to manually assign a router to an " + "agent in 'dvr' mode.") class L3AgentSchedulerPluginBase(object): diff --git a/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py b/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py index 80a5db52b..7c74fb8ad 100644 --- a/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py +++ b/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py @@ -439,7 +439,7 @@ class L3SchedulerTestBaseMixin(object): self._register_l3_dvr_agents() self._prepare_l3_agent_dvr_move_exceptions( agent_id=self.l3_dvr_agent_id, - expected_exception=l3agent.RouterL3AgentMismatch) + expected_exception=l3agent.DVRL3CannotAssignToDvrAgent) def test_add_router_to_l3_agent_mismatch_error_dvr_to_dvr(self): self._register_l3_dvr_agents() -- 2.45.2