]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix static strings with labels for DVR
authorSwaminathan Vasudevan <swaminathan.vasudevan@hp.com>
Sat, 20 Dec 2014 00:58:17 +0000 (16:58 -0800)
committerSwaminathan Vasudevan <swaminathan.vasudevan@hp.com>
Wed, 18 Feb 2015 18:55:51 +0000 (10:55 -0800)
There are couple of static strings introduced for
DVR configuration such as the L3 agent mode.

This patch would clean up the static strings with
the labels.

Closes-Bug: #1411351
Change-Id: I143262e62ee994e6c01d63e4ea7d5f6292de8286

neutron/agent/l3/agent.py
neutron/common/constants.py
neutron/db/l3_agentschedulers_db.py
neutron/db/l3_hamode_db.py

index c39e52ad95c5673b15dbb05ac502ce778d6c221d..0b07c090c8b08f6746d56a88c42499ef1aba64be 100644 (file)
@@ -815,7 +815,7 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback,
                     self._snat_redirect_add(ri, gateway['fixed_ips'][0]
                                             ['ip_address'], p, id_name)
 
-            if (self.conf.agent_mode == 'dvr_snat' and
+            if (self.conf.agent_mode == l3_constants.L3_AGENT_MODE_DVR_SNAT and
                 self.get_gw_port_host(ri.router) == self.host):
                 self._create_dvr_gateway(ri, ex_gw_port, interface_name,
                                          snat_ports)
@@ -843,7 +843,7 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback,
     def external_gateway_updated(self, ri, ex_gw_port, interface_name):
         preserve_ips = []
         if ri.router['distributed']:
-            if (self.conf.agent_mode == 'dvr_snat' and
+            if (self.conf.agent_mode == l3_constants.L3_AGENT_MODE_DVR_SNAT and
                 self.get_gw_port_host(ri.router) == self.host):
                 ns_name = self.get_snat_ns_name(ri.router['id'])
             else:
@@ -898,8 +898,8 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback,
                 internal_interface = self.get_internal_device_name(p['id'])
                 self._snat_redirect_remove(ri, p, internal_interface)
 
-            if self.conf.agent_mode == 'dvr_snat' and (
-                self.get_gw_port_host(ri.router) == self.host):
+            if (self.conf.agent_mode == l3_constants.L3_AGENT_MODE_DVR_SNAT
+                and self.get_gw_port_host(ri.router) == self.host):
                 ns_name = self.get_snat_ns_name(ri.router['id'])
             else:
                 # not hosting agent - no work to do
@@ -971,8 +971,8 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback,
             if sn_port:
                 self._snat_redirect_add(ri, sn_port['fixed_ips'][0]
                                         ['ip_address'], port, interface_name)
-                if (self.conf.agent_mode == 'dvr_snat' and
-                    self.get_gw_port_host(ri.router) == self.host):
+                if (self.conf.agent_mode == l3_constants.L3_AGENT_MODE_DVR_SNAT
+                    and self.get_gw_port_host(ri.router) == self.host):
                     ns_name = self.get_snat_ns_name(ri.router['id'])
                     self._set_subnet_info(sn_port)
                     interface_name = (
@@ -991,8 +991,8 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback,
         if ri.router['distributed'] and ri.ex_gw_port:
             # DVR handling code for SNAT
             self._snat_redirect_remove(ri, port, interface_name)
-            if self.conf.agent_mode == 'dvr_snat' and (
-                ri.ex_gw_port['binding:host_id'] == self.host):
+            if (self.conf.agent_mode == l3_constants.L3_AGENT_MODE_DVR_SNAT
+                and ri.ex_gw_port['binding:host_id'] == self.host):
                 snat_port = self._map_internal_interfaces(ri, port,
                                                           ri.snat_ports)
                 if snat_port:
index 4b16165a07436ea8e8fcc8a0e581993886229954..b30458a6e68bb8c014c77ac9bfaf94ea3e4b21b1 100644 (file)
@@ -43,6 +43,10 @@ DEVICE_OWNER_LOADBALANCER = "neutron:LOADBALANCER"
 # DEVICE_OWNER_ROUTER_HA_INTF is a special case and so is not included.
 ROUTER_INTERFACE_OWNERS = (DEVICE_OWNER_ROUTER_INTF,
                            DEVICE_OWNER_DVR_INTERFACE)
+L3_AGENT_MODE_DVR = 'dvr'
+L3_AGENT_MODE_DVR_SNAT = 'dvr_snat'
+L3_AGENT_MODE_LEGACY = 'legacy'
+L3_AGENT_MODE = 'agent_mode'
 
 DEVICE_ID_RESERVED_DHCP_PORT = "reserved_dhcp_port"
 
index 691869ca5a4b0bd92edd2117a106431c6eceb791..8bb3b19a228bb22a4db076de46f46dd7e2327deb 100644 (file)
@@ -134,17 +134,21 @@ class L3AgentSchedulerDbMixin(l3agentscheduler.L3AgentSchedulerPluginBase,
         """
         is_distributed = router.get('distributed')
         agent_conf = self.get_configuration_dict(agent)
-        agent_mode = agent_conf.get('agent_mode', 'legacy')
-        router_type = ('distributed' if is_distributed else 'centralized')
+        agent_mode = agent_conf.get(constants.L3_AGENT_MODE,
+                                    constants.L3_AGENT_MODE_LEGACY)
+        router_type = (
+            'distributed' if is_distributed else
+            'centralized')
+
         is_agent_router_types_incompatible = (
-            agent_mode == 'dvr' and not is_distributed
-            or agent_mode == 'legacy' and is_distributed
+            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:
             raise l3agentscheduler.RouterL3AgentMismatch(
                 router_type=router_type, router_id=router['id'],
                 agent_mode=agent_mode, agent_id=agent['id'])
-        if agent_mode == 'dvr' and is_distributed:
+        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'])
@@ -400,8 +404,9 @@ class L3AgentSchedulerDbMixin(l3agentscheduler.L3AgentSchedulerPluginBase,
                 continue
 
             agent_conf = self.get_configuration_dict(l3_agent)
-            agent_mode = agent_conf.get('agent_mode', 'legacy')
-            if agent_mode != 'dvr_snat':
+            agent_mode = agent_conf.get(constants.L3_AGENT_MODE,
+                                        constants.L3_AGENT_MODE_LEGACY)
+            if agent_mode != constants.L3_AGENT_MODE_DVR_SNAT:
                 continue
 
             router_id = agent_conf.get('router_id', None)
@@ -436,7 +441,8 @@ class L3AgentSchedulerDbMixin(l3agentscheduler.L3AgentSchedulerPluginBase,
                 'handle_internal_only_routers', True)
             gateway_external_network_id = agent_conf.get(
                 'gateway_external_network_id', None)
-            agent_mode = agent_conf.get('agent_mode', 'legacy')
+            agent_mode = agent_conf.get(constants.L3_AGENT_MODE,
+                                        constants.L3_AGENT_MODE_LEGACY)
             if not use_namespaces and router_id != sync_router['id']:
                 continue
             ex_net_id = (sync_router['external_gateway_info'] or {}).get(
@@ -446,10 +452,13 @@ class L3AgentSchedulerDbMixin(l3agentscheduler.L3AgentSchedulerPluginBase,
                  ex_net_id != gateway_external_network_id)):
                 continue
             is_router_distributed = sync_router.get('distributed', False)
-            if agent_mode in ('legacy', 'dvr_snat') and (
+            if agent_mode in (
+                constants.L3_AGENT_MODE_LEGACY,
+                constants.L3_AGENT_MODE_DVR_SNAT) and (
                 not is_router_distributed):
                 candidates.append(l3_agent)
-            elif is_router_distributed and agent_mode.startswith('dvr') and (
+            elif is_router_distributed and agent_mode.startswith(
+                constants.L3_AGENT_MODE_DVR) and (
                 self.check_ports_exist_on_l3agent(
                     context, l3_agent, sync_router['id'])):
                 candidates.append(l3_agent)
index 570d00c3272171931965e2c2bb5a597cd1e88634..54c7a59b607ecd41bfbd0fd67f040005becd6ab4 100644 (file)
@@ -262,7 +262,8 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin):
 
         min_agents = cfg.CONF.min_l3_agents_per_router
         num_agents = len(self.get_l3_agents(context,
-            filters={'agent_modes': ['legacy', 'dvr_snat']}))
+            filters={'agent_modes': [constants.L3_AGENT_MODE_LEGACY,
+                                     constants.L3_AGENT_MODE_DVR_SNAT]}))
         max_agents = cfg.CONF.max_l3_agents_per_router
         if max_agents:
             if max_agents > num_agents: