]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Unify exceptions for assign router to dvr agent
authorlzklibj <lzklibj@cn.ibm.com>
Sun, 27 Dec 2015 06:08:36 +0000 (14:08 +0800)
committerZongKai LI <lzklibj@cn.ibm.com>
Thu, 14 Jan 2016 16:10:23 +0000 (16:10 +0000)
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
neutron/extensions/l3agentscheduler.py
neutron/tests/unit/scheduler/test_l3_agent_scheduler.py

index a12f7840f1c686751bee8ce02222a49283ec0af3..ef951ccd9c9511c8899315250d4b854ec18650c8 100644 (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
index 1d0974cec3f32b63b5d83712cc7573a89e0b9f64..39b6cd77a962daa66f6e88929d377a29a4948b16 100644 (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):
index 80a5db52b256ab92c8724a7ad82e92accdc581c7..7c74fb8ad8fb2708d9c56f7b07ec678bae5bf860 100644 (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()