]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Append @randtoken to L3 agent namespaces in full stack tests
authorCarl Baldwin <carl.baldwin@hp.com>
Tue, 21 Apr 2015 21:36:33 +0000 (21:36 +0000)
committerCarl Baldwin <carl.baldwin@hp.com>
Tue, 12 May 2015 20:32:54 +0000 (20:32 +0000)
Change-Id: Ib180a5836f653385ec2877c50fbca6f850eff351
Closes-Bug: #1446261

neutron/tests/common/agents/__init__.py [new file with mode: 0644]
neutron/tests/common/agents/l3_agent.py [new file with mode: 0755]
neutron/tests/fullstack/config_fixtures.py
neutron/tests/fullstack/fullstack_fixtures.py
neutron/tests/fullstack/test_l3_agent.py
neutron/tests/functional/__init__.py

diff --git a/neutron/tests/common/agents/__init__.py b/neutron/tests/common/agents/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/neutron/tests/common/agents/l3_agent.py b/neutron/tests/common/agents/l3_agent.py
new file mode 100755 (executable)
index 0000000..9f87f6b
--- /dev/null
@@ -0,0 +1,78 @@
+#!/usr/bin/env python
+#
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
+#    not use this file except in compliance with the License. You may obtain
+#    a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+#    License for the specific language governing permissions and limitations
+#    under the License.
+
+import mock
+import sys
+
+from oslo_config import cfg
+
+from neutron.agent.l3 import agent
+from neutron.agent.l3 import namespaces
+from neutron.agent import l3_agent
+
+
+class L3NATAgentForTest(agent.L3NATAgentWithStateReport):
+    def __init__(self, host, conf=None):
+        ns_suffix = '@%s' % cfg.CONF.test_namespace_suffix
+
+        # Mock out building of namespace names
+        orig_build_ns_name = namespaces.build_ns_name
+
+        def build_ns_name(prefix, identifier):
+            return "%s%s" % (orig_build_ns_name(prefix, identifier), ns_suffix)
+
+        build_ns = mock.patch.object(namespaces, 'build_ns_name').start()
+        build_ns.side_effect = build_ns_name
+
+        # Mock the parsing prefix from namespace names
+        orig_get_prefix = namespaces.get_prefix_from_ns_name
+
+        def get_prefix_from_ns_name(ns_name):
+            if ns_name.endswith(ns_suffix):
+                return orig_get_prefix(ns_name[:-len(ns_suffix)])
+
+        parse_prefix = mock.patch.object(namespaces,
+                                         'get_prefix_from_ns_name').start()
+        parse_prefix.side_effect = get_prefix_from_ns_name
+
+        # Mock the parsing id from namespace names
+        orig_get_id = namespaces.get_id_from_ns_name
+
+        def get_id_from_ns_name(ns_name):
+            if ns_name.endswith(ns_suffix):
+                return orig_get_id(ns_name[:-len(ns_suffix)])
+
+        parse_id = mock.patch.object(namespaces, 'get_id_from_ns_name').start()
+        parse_id.side_effect = get_id_from_ns_name
+
+        super(L3NATAgentForTest, self).__init__(host, conf)
+
+
+OPTS = [
+    cfg.StrOpt('test_namespace_suffix', default='testprefix',
+               help=_("Suffix to append to all namespace names.")),
+]
+
+
+def register_opts(conf):
+    conf.register_opts(OPTS)
+
+
+def main(manager='neutron.tests.common.agents.l3_agent.L3NATAgentForTest'):
+    register_opts(cfg.CONF)
+    l3_agent.main(manager=manager)
+
+
+if __name__ == "__main__":
+    sys.exit(main())
index 6c25c9655073baf19b1e3aca3fc2ca79497e80b3..4e1e0986176497253a2c8de3ef2f7c1189e76c21 100644 (file)
@@ -207,9 +207,13 @@ class L3ConfigFixture(ConfigFixture):
                 'router_delete_namespaces': 'True',
                 'debug': 'True',
                 'verbose': 'True',
+                'test_namespace_suffix': self._generate_namespace_suffix(),
             }
         })
 
     def _generate_external_bridge(self):
         return base.get_rand_name(prefix='br-ex',
                                   max_length=constants.DEVICE_NAME_MAX_LEN)
+
+    def _generate_namespace_suffix(self):
+        return base.get_rand_name(prefix='test')
index 9d30325860d60f6a5385bb94cbb4d87a226db8f1..526cffaccecd57fcd37f8befe0868eec601f5ecc 100644 (file)
@@ -14,6 +14,7 @@
 
 from distutils import spawn
 import functools
+import os
 
 import fixtures
 from neutronclient.common import exceptions as nc_exc
@@ -24,6 +25,7 @@ from oslo_utils import timeutils
 
 from neutron.agent.linux import async_process
 from neutron.agent.linux import utils
+from neutron.tests import base
 from neutron.tests.common import net_helpers
 from neutron.tests.fullstack import config_fixtures
 
@@ -188,8 +190,13 @@ class L3AgentFixture(fixtures.Fixture):
 
         self.process_fixture = self.useFixture(ProcessFixture(
             name=self.NEUTRON_L3_AGENT,
-            exec_name=self.NEUTRON_L3_AGENT,
+            exec_name=spawn.find_executable(
+                'l3_agent.py',
+                path=os.path.join(base.ROOTDIR, 'common', 'agents')),
             config_filenames=config_filenames))
 
     def _get_br_ex_name(self):
         return self.plugin_config.DEFAULT.external_network_bridge
+
+    def get_namespace_suffix(self):
+        return self.plugin_config.DEFAULT.test_namespace_suffix
index 3c41571f46fcb6310188c833133227c5cfa90572..29ae03f67fd6ed0a29605db92a97f18e075cc302 100644 (file)
@@ -78,7 +78,10 @@ class TestLegacyL3Agent(base.BaseFullStackTestCase):
             body={'subnet_id': subnet['subnet']['id']})
 
         router_id = router['router']['id']
-        self._assert_namespace_exists(self._get_namespace(router_id))
+        namespace = "%s@%s" % (
+            self._get_namespace(router_id),
+            self.environment.l3_agent.get_namespace_suffix(), )
+        self._assert_namespace_exists(namespace)
 
         self.client.remove_interface_router(
             router=router['router']['id'],
index a2a87e23b26e1544d8a0700bd36cb233db17b708..86c037e23ad6dc6e733532c71365e27da825f860 100644 (file)
@@ -27,6 +27,7 @@ def load_tests(loader, tests, pattern):
     target_dirs = [
         this_dir,
         os.path.join(parent_dir, 'retargetable'),
+        os.path.join(parent_dir, 'fullstack'),
     ]
     for start_dir in target_dirs:
         new_tests = loader.discover(start_dir=start_dir, pattern=pattern)