]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
allow multiple l3-agents to run, each with one external gateway net
authorDan Wendlandt <dan@nicira.com>
Sun, 9 Sep 2012 14:55:52 +0000 (07:55 -0700)
committerDan Wendlandt <dan@nicira.com>
Sun, 9 Sep 2012 14:55:52 +0000 (07:55 -0700)
bug #1042028

Allows user to invoke L3-agent in a way that limits the agent to
implementing only routers associated with a particular external network.
Thus, it is possible to have a deployment with multiple external networks,
since you can run one agent per external network.

Also makes l3-agent pay attention to router admin_state_up field.

Change-Id: Ia79d29301530718bc381c8e5a9d197de9452bce2

etc/l3_agent.ini
quantum/agent/l3_agent.py
quantum/tests/unit/test_l3_agent.py

index 46cafa3952cdf25f0d083aba6b304857c6a1606c..7ad23531b96b3024d6f07fa177813f90bb9f0638 100644 (file)
@@ -29,3 +29,15 @@ root_helper = sudo
 # If use_namespaces is set as False then the agent can only configure one router.
 # This is done by setting the specific router_id.
 # router_id =
+
+# Each L3 agent can be associated with at most one external network.  This
+# value should be set to the UUID of that external network.  If empty,
+# the agent will enforce that only a single external networks exists and
+# use that external network id
+# gateway_external_net_id =
+
+# Indicates that this L3 agent should also handle routers that do not have
+# an external network gateway configured.  This option should be True only
+# for a single agent in a Quantum deployment, and may be False for all agents
+# if all routers must have an external network gateway
+# handle_internal_only_routers = True
index 9c5a0447bd7905a3153a698f7e53c3268115f0a5..902d60c62f60ffe4daf0dad31cf3cf1fd0a92aa5 100644 (file)
@@ -90,7 +90,13 @@ class L3NATAgent(object):
                     help="Allow overlapping IP."),
         cfg.StrOpt('router_id', default='',
                    help="If namespaces is disabled, the l3 agent can only"
-                        " confgure a router that has the matching router ID.")
+                        " confgure a router that has the matching router ID."),
+        cfg.BoolOpt('handle_internal_only_routers',
+                    default=True,
+                    help="Agent should implement routers with no gateway"),
+        cfg.StrOpt('gateway_external_network_id', default='',
+                   help="UUID of external network for routers implemented "
+                        "by the agents."),
     ]
 
     def __init__(self, conf):
@@ -171,13 +177,37 @@ class L3NATAgent(object):
 
             time.sleep(self.polling_interval)
 
+    def _fetch_external_net_id(self):
+        """Find UUID of single external network for this agent"""
+        if self.conf.gateway_external_network_id:
+            return self.conf.gateway_external_network_id
+
+        params = {'router:external': True}
+        ex_nets = self.qclient.list_networks(**params)['networks']
+        if len(ex_nets) > 1:
+            raise Exception("must configure 'external_network_id' if "
+                            "Quantum has more than one external network.")
+        if len(ex_nets) == 0:
+            return None
+        return ex_nets[0]['id']
+
     def do_single_loop(self):
         prev_router_ids = set(self.router_info)
         cur_router_ids = set()
 
+        target_ex_net_id = self._fetch_external_net_id()
+
         # identify and update new or modified routers
         for r in self.qclient.list_routers()['routers']:
-            #FIXME(danwent): handle admin state
+            if not r['admin_state_up']:
+                continue
+
+            ex_net_id = r['external_gateway_info'].get('network_id', None)
+            if not ex_net_id and not self.conf.handle_internal_only_routers:
+                continue
+
+            if ex_net_id and ex_net_id != target_ex_net_id:
+                continue
 
             # If namespaces are disabled, only process the router associated
             # with the configured agent id.
index 587f611fe9e2d59d4629aa44aa17215ea64539a5..810b6edf066a689efc555baba5fc01a081592361 100644 (file)
@@ -237,8 +237,12 @@ class TestBasicRouterOperations(unittest.TestCase):
 
         self.client_inst.list_ports.return_value = {'ports': []}
 
+        self.client_inst.list_networks.return_value = {'networks': []}
+
         self.client_inst.list_routers.return_value = {'routers': [
-            {'id': _uuid()}]}
+            {'id': _uuid(),
+             'admin_state_up': True,
+             'external_gateway_info': {}}]}
         agent.do_single_loop()
 
         self.client_inst.list_routers.return_value = {'routers': []}