Browse Source

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
tags/8.0.0.0b2
lzklibj 4 years ago
parent
commit
a2cfd9fcd6
3 changed files with 14 additions and 24 deletions
  1. +9
    -18
      neutron/db/l3_agentschedulers_db.py
  2. +4
    -5
      neutron/extensions/l3agentscheduler.py
  3. +1
    -1
      neutron/tests/unit/scheduler/test_l3_agent_scheduler.py

+ 9
- 18
neutron/db/l3_agentschedulers_db.py View File

@@ -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

+ 4
- 5
neutron/extensions/l3agentscheduler.py View File

@@ -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):

+ 1
- 1
neutron/tests/unit/scheduler/test_l3_agent_scheduler.py View File

@@ -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()

Loading…
Cancel
Save