]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Check whether sudo is enabled in BaseSudoTestCase.setUpClass
authorCedric Brandily <zzelle@gmail.com>
Wed, 25 Feb 2015 17:13:10 +0000 (17:13 +0000)
committerCedric Brandily <zzelle@gmail.com>
Fri, 27 Feb 2015 22:16:00 +0000 (22:16 +0000)
Currently functional test classes requiring invocation of commands via a
root helper inherit from BaseSudoTestCase[1] and should call explicitly
check_sudo_enabled in order to skip the test if sudo is disabled[2].

This change performs such check during BaseSudoTestCase.setUp in order
to ensure the check is done and replaces parent class for functional
test cases not requiring invocation of commands via a root helper.

This change prepares to transform BaseOVSLinuxTestCase[3] methods into
helper methods.

[1] in neutron.tests.functional.base
[2] sudo is enabled if OS_SUDO_TESTING is set to '1' or 'True'
[3] in neutron.tests.functional.agent.linux.base

Change-Id: I91a3506524352211729ac8b3b07cf3082fd8f13a

neutron/tests/functional/agent/linux/base.py
neutron/tests/functional/agent/linux/test_ip_lib.py
neutron/tests/functional/agent/linux/test_keepalived.py
neutron/tests/functional/agent/linux/test_ovsdb_monitor.py
neutron/tests/functional/agent/linux/test_process_monitor.py
neutron/tests/functional/agent/test_l3_agent.py
neutron/tests/functional/base.py
neutron/tests/functional/sanity/test_sanity.py

index 26e7792996eb752fb49fcfe4b46395e36a2c9cb2..e822e1362b9aa7889101bf6eaa175f21839b105c 100644 (file)
@@ -161,10 +161,6 @@ class BaseIPVethTestCase(BaseLinuxTestCase):
     DST_ADDRESS = '192.168.0.2'
     BROADCAST_ADDRESS = '192.168.0.255'
 
-    def setUp(self):
-        super(BaseIPVethTestCase, self).setUp()
-        self.check_sudo_enabled()
-
     @staticmethod
     def _set_ip_up(device, cidr, broadcast, ip_version=4):
         device.addr.add(ip_version=ip_version, cidr=cidr, broadcast=broadcast)
index 6f03f4198df14df53620dbe9ae31d118c7fe731d..bacb51bd7d4543cae9c37a892bf9fe4222b3cec4 100644 (file)
@@ -33,7 +33,6 @@ Device = collections.namedtuple('Device', 'name ip_cidr mac_address namespace')
 class IpLibTestFramework(base.BaseLinuxTestCase):
     def setUp(self):
         super(IpLibTestFramework, self).setUp()
-        self.check_sudo_enabled()
         self._configure()
 
     def _configure(self):
index be8b50bdb7506d009e9938b0fe30239b78163419..656905eea4ab7ed21e7e3d76edd0b1ab51864b9d 100644 (file)
@@ -17,15 +17,12 @@ from oslo_config import cfg
 
 from neutron.agent.linux import external_process
 from neutron.agent.linux import keepalived
-from neutron.tests.functional import base as functional_base
+from neutron.tests import base
 from neutron.tests.unit.agent.linux import test_keepalived
 
 
-class KeepalivedManagerTestCase(functional_base.BaseSudoTestCase,
+class KeepalivedManagerTestCase(base.BaseTestCase,
                                 test_keepalived.KeepalivedConfBaseMixin):
-    def setUp(self):
-        super(KeepalivedManagerTestCase, self).setUp()
-        self.check_sudo_enabled()
 
     def test_keepalived_spawn(self):
         expected_config = self._get_config()
index 8b99a6b44ba7b468a578640ab8452a8cec090967..b6f1ab995a4346318a9855c525401bcdfdb3ac42 100644 (file)
@@ -49,7 +49,6 @@ class BaseMonitorTest(linux_base.BaseOVSLinuxTestCase):
         self.bridge = self.create_ovs_bridge()
 
     def _check_test_requirements(self):
-        self.check_sudo_enabled()
         self.check_command(['ovsdb-client', 'list-dbs'],
                            'Exit code: 1',
                            'password-less sudo not granted for ovsdb-client',
index 70492b7baf5da0be76d44bed619f5d3963661b7f..961cf92349b0e90f0c86a04e4c37472ac1c4ce90 100644 (file)
@@ -17,14 +17,14 @@ from oslo_config import cfg
 from six import moves
 
 from neutron.agent.linux import external_process
+from neutron.tests import base
 from neutron.tests.functional.agent.linux import simple_daemon
-from neutron.tests.functional import base
 
 
 UUID_FORMAT = "test-uuid-%d"
 
 
-class BaseTestProcessMonitor(base.BaseSudoTestCase):
+class BaseTestProcessMonitor(base.BaseTestCase):
 
     def setUp(self):
         super(BaseTestProcessMonitor, self).setUp()
index 5217d3c2a385b3b9ab9526730ee0ec7ba31f30a4..fd52296d3a0a76a3362cbfdd5bb60377c823649d 100755 (executable)
@@ -52,7 +52,6 @@ METADATA_REQUEST_TIMEOUT = 60
 class L3AgentTestFramework(base.BaseOVSLinuxTestCase):
     def setUp(self):
         super(L3AgentTestFramework, self).setUp()
-        self.check_sudo_enabled()
         mock.patch('neutron.agent.l3.agent.L3PluginApi').start()
         self.agent = self._configure_agent('agent1')
 
index ac3c90da92d2649523e88b0f89fa271dfa18b2a8..c790f5615838afa8f1585f95db6cbd897ba7634b 100644 (file)
@@ -27,12 +27,10 @@ class BaseSudoTestCase(base.BaseTestCase):
     """
     Base class for tests requiring invocation of commands via a root helper.
 
-    Inheritors of this class should call check_sudo_enabled() in
-    setUp() to ensure that tests requiring sudo are skipped unless
-    OS_SUDO_TESTING is set to '1' or 'True' in the test execution
-    environment.  This is intended to allow developers to run the
-    functional suite (e.g. tox -e functional) without test failures if
-    sudo invocations are not allowed.
+    This class skips (during setUp) its tests unless sudo is enabled, ie:
+    OS_SUDO_TESTING is set to '1' or 'True' in the test execution environment.
+    This is intended to allow developers to run the functional suite (e.g. tox
+    -e functional) without test failures if sudo invocations are not allowed.
 
     Running sudo tests in the upstream gate jobs
     (*-neutron-dsvm-functional) requires the additional step of
@@ -48,14 +46,13 @@ class BaseSudoTestCase(base.BaseTestCase):
 
     def setUp(self):
         super(BaseSudoTestCase, self).setUp()
-        self.sudo_enabled = base.bool_from_env('OS_SUDO_TESTING')
+
+        if not base.bool_from_env('OS_SUDO_TESTING'):
+            self.skipTest('Testing with sudo is not enabled')
+
         self.fail_on_missing_deps = (
             base.bool_from_env('OS_FAIL_ON_MISSING_DEPS'))
 
         config.register_root_helper(cfg.CONF)
         self.config(group='AGENT',
                     root_helper=os.environ.get('OS_ROOTWRAP_CMD', SUDO_CMD))
-
-    def check_sudo_enabled(self):
-        if not self.sudo_enabled:
-            self.skipTest('testing with sudo is not enabled')
index e4e6935f5d9439ba195764529f6715d742402704..027b2bf26c6d1a4cddb5e8786d1e368098152bf9 100644 (file)
@@ -43,9 +43,6 @@ class SanityTestCaseRoot(functional_base.BaseSudoTestCase):
     neutron-sanity-check runs without throwing an exception, as in the case
     where someone modifies the API without updating the check script.
     """
-    def setUp(self):
-        super(SanityTestCaseRoot, self).setUp()
-        self.check_sudo_enabled()
 
     def test_ovs_vxlan_support_runs(self):
         checks.ovs_vxlan_supported()