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
This commit is contained in:
lzklibj 2015-12-27 14:08:36 +08:00 committed by ZongKai LI
parent feced76488
commit a2cfd9fcd6
3 changed files with 14 additions and 24 deletions

View File

@ -159,33 +159,24 @@ class L3AgentSchedulerDbMixin(l3agentscheduler.L3AgentSchedulerPluginBase,
"""Validate if the router can be correctly assigned to the agent. """Validate if the router can be correctly assigned to the agent.
:raises: RouterL3AgentMismatch if attempting to assign DVR router :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 :raises: InvalidL3Agent if attempting to assign router to an
unsuitable agent (disabled, type != L3, incompatible configuration) unsuitable agent (disabled, type != L3, incompatible configuration)
:raises: DVRL3CannotAssignToDvrAgent if attempting to assign DVR :raises: DVRL3CannotAssignToDvrAgent if attempting to assign a
router from one DVR Agent to another. router to an agent in 'dvr' mode.
""" """
if agent['agent_type'] != constants.AGENT_TYPE_L3: if agent['agent_type'] != constants.AGENT_TYPE_L3:
raise l3agentscheduler.InvalidL3Agent(id=agent['id']) raise l3agentscheduler.InvalidL3Agent(id=agent['id'])
is_distributed = router.get('distributed')
agent_mode = self._get_agent_mode(agent) agent_mode = self._get_agent_mode(agent)
router_type = (
'distributed' if is_distributed else
'centralized')
is_agent_router_types_incompatible = ( if agent_mode == constants.L3_AGENT_MODE_DVR:
agent_mode == constants.L3_AGENT_MODE_DVR and not is_distributed raise l3agentscheduler.DVRL3CannotAssignToDvrAgent()
or agent_mode == constants.L3_AGENT_MODE_LEGACY and is_distributed
) if (agent_mode == constants.L3_AGENT_MODE_LEGACY and
if is_agent_router_types_incompatible: router.get('distributed')):
raise l3agentscheduler.RouterL3AgentMismatch( raise l3agentscheduler.RouterL3AgentMismatch(
router_type=router_type, router_id=router['id'], router_id=router['id'], agent_id=agent['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'])
is_suitable_agent = ( is_suitable_agent = (
agentschedulers_db.services_available(agent['admin_state_up']) and agentschedulers_db.services_available(agent['admin_state_up']) and

View File

@ -169,14 +169,13 @@ class RouterReschedulingFailed(exceptions.Conflict):
class RouterL3AgentMismatch(exceptions.Conflict): class RouterL3AgentMismatch(exceptions.Conflict):
message = _("Cannot host %(router_type)s router %(router_id)s " message = _("Cannot host distributed router %(router_id)s "
"on %(agent_mode)s L3 agent %(agent_id)s.") "on legacy L3 agent %(agent_id)s.")
class DVRL3CannotAssignToDvrAgent(exceptions.Conflict): class DVRL3CannotAssignToDvrAgent(exceptions.Conflict):
message = _("Not allowed to manually assign a %(router_type)s " message = _("Not allowed to manually assign a router to an "
"router %(router_id)s from an existing DVR node " "agent in 'dvr' mode.")
"to another L3 agent %(agent_id)s.")
class L3AgentSchedulerPluginBase(object): class L3AgentSchedulerPluginBase(object):

View File

@ -439,7 +439,7 @@ class L3SchedulerTestBaseMixin(object):
self._register_l3_dvr_agents() self._register_l3_dvr_agents()
self._prepare_l3_agent_dvr_move_exceptions( self._prepare_l3_agent_dvr_move_exceptions(
agent_id=self.l3_dvr_agent_id, 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): def test_add_router_to_l3_agent_mismatch_error_dvr_to_dvr(self):
self._register_l3_dvr_agents() self._register_l3_dvr_agents()