]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fwaas can't run in operating system without namespace feature
authorzhhuabj <zhhuabj@cn.ibm.com>
Mon, 18 Nov 2013 10:09:54 +0000 (18:09 +0800)
committerzhhuabj <zhhuabj@cn.ibm.com>
Mon, 25 Nov 2013 08:45:05 +0000 (16:45 +0800)
Adding the check before generating the local_ns_list
to fix the issue.

Change-Id: If8edb5c0bb0fc0fd9aaf48a3441287f99bcdcf13
Closes-Bug: #1252201

neutron/services/firewall/agents/l3reference/firewall_l3_agent.py
neutron/tests/unit/services/firewall/agents/l3reference/test_firewall_l3_agent.py

index 393b94b5111748c6ea740b91a36e3c804731586e..9b849a5b3994d0328d022978e19a0e8d04af99e7 100644 (file)
@@ -89,7 +89,8 @@ class FWaaSL3AgentRpcCallback(api.FWaaSAgentRpcCallbackMixin):
             router['id']
             for router in routers
             if router['tenant_id'] == tenant_id]
-        local_ns_list = root_ip.get_namespaces(self.root_helper)
+        local_ns_list = root_ip.get_namespaces(
+            self.root_helper) if self.conf.use_namespaces else []
 
         router_info_list = []
         # Pick up namespaces for Tenant Routers
index 0630de07d0443f5605cd756f38c2e751a05139c8..6b76c2ed0bd9a599342e4ea57be5212441d086c4 100644 (file)
 # @author: Dan Florea, dflorea@cisco.com, Cisco Systems, Inc.
 
 import contextlib
+import uuid
+
 import mock
 from oslo.config import cfg
 
 from neutron.agent.common import config as agent_config
+from neutron.agent import l3_agent
+from neutron.agent.linux import ip_lib
 from neutron.common import config as base_config
 from neutron import context
 from neutron.plugins.common import constants
@@ -47,6 +51,7 @@ class TestFwaasL3AgentRpcCallback(base.BaseTestCase):
 
         self.conf = cfg.ConfigOpts()
         self.conf.register_opts(base_config.core_opts)
+        self.conf.register_opts(l3_agent.L3NATAgent.OPTS)
         agent_config.register_root_helper(self.conf)
         self.conf.root_helper = 'sudo'
         self.api = FWaasAgent(self.conf)
@@ -262,3 +267,56 @@ class TestFwaasL3AgentRpcCallback(base.BaseTestCase):
             mock_firewall_deleted.assert_called_once_with(
                 ctx,
                 fake_firewall_list[0]['id'])
+
+    def _prepare_router_data(self, use_namespaces):
+        router = {'id': str(uuid.uuid4()), 'tenant_id': str(uuid.uuid4())}
+        return l3_agent.RouterInfo(router['id'], self.conf.root_helper,
+                                   use_namespaces, router=router)
+
+    def _get_router_info_list_with_namespace_helper(self,
+                                                    router_use_namespaces):
+        self.conf.set_override('use_namespaces', True)
+        ri = self._prepare_router_data(
+            use_namespaces=router_use_namespaces)
+        routers = [ri.router]
+        self.api.router_info = {ri.router_id: ri}
+        with mock.patch.object(ip_lib.IPWrapper,
+                               'get_namespaces') as mock_get_namespaces:
+            mock_get_namespaces.return_value = ri.ns_name()
+            router_info_list = self.api._get_router_info_list_for_tenant(
+                routers,
+                ri.router['tenant_id'])
+            self.assertEqual([ri], router_info_list)
+            mock_get_namespaces.assert_called_once_with(
+                self.conf.root_helper)
+
+    def _get_router_info_list_without_namespace_helper(self,
+                                                       router_use_namespaces):
+        self.conf.set_override('use_namespaces', False)
+        ri = self._prepare_router_data(
+            use_namespaces=router_use_namespaces)
+        routers = [ri.router]
+        self.api.router_info = {ri.router_id: ri}
+        router_info_list = self.api._get_router_info_list_for_tenant(
+            routers,
+            ri.router['tenant_id'])
+        if router_use_namespaces:
+            self.assertFalse(router_info_list)
+        else:
+            self.assertEqual([ri], router_info_list)
+
+    def test_get_router_info_list_for_tenant_for_namespaces_enabled(self):
+        self._get_router_info_list_with_namespace_helper(
+            router_use_namespaces=True)
+
+    def test_get_router_info_list_for_tenant_for_namespaces_disabled(self):
+        self._get_router_info_list_without_namespace_helper(
+            router_use_namespaces=False)
+
+    def test_get_router_info_list_tenant_with_namespace_router_without(self):
+        self._get_router_info_list_with_namespace_helper(
+            router_use_namespaces=False)
+
+    def test_get_router_info_list_tenant_without_namespace_router_with(self):
+        self._get_router_info_list_without_namespace_helper(
+            router_use_namespaces=True)