From 1712e475745f03fbd9365a3042aeafac72e950c6 Mon Sep 17 00:00:00 2001 From: Cedric Brandily Date: Wed, 25 Feb 2015 17:13:10 +0000 Subject: [PATCH] Check whether sudo is enabled in BaseSudoTestCase.setUpClass 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 | 4 ---- .../functional/agent/linux/test_ip_lib.py | 1 - .../functional/agent/linux/test_keepalived.py | 7 ++----- .../agent/linux/test_ovsdb_monitor.py | 1 - .../agent/linux/test_process_monitor.py | 4 ++-- .../tests/functional/agent/test_l3_agent.py | 1 - neutron/tests/functional/base.py | 19 ++++++++----------- .../tests/functional/sanity/test_sanity.py | 3 --- 8 files changed, 12 insertions(+), 28 deletions(-) diff --git a/neutron/tests/functional/agent/linux/base.py b/neutron/tests/functional/agent/linux/base.py index 26e779299..e822e1362 100644 --- a/neutron/tests/functional/agent/linux/base.py +++ b/neutron/tests/functional/agent/linux/base.py @@ -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) diff --git a/neutron/tests/functional/agent/linux/test_ip_lib.py b/neutron/tests/functional/agent/linux/test_ip_lib.py index 6f03f4198..bacb51bd7 100644 --- a/neutron/tests/functional/agent/linux/test_ip_lib.py +++ b/neutron/tests/functional/agent/linux/test_ip_lib.py @@ -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): diff --git a/neutron/tests/functional/agent/linux/test_keepalived.py b/neutron/tests/functional/agent/linux/test_keepalived.py index be8b50bdb..656905eea 100644 --- a/neutron/tests/functional/agent/linux/test_keepalived.py +++ b/neutron/tests/functional/agent/linux/test_keepalived.py @@ -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() diff --git a/neutron/tests/functional/agent/linux/test_ovsdb_monitor.py b/neutron/tests/functional/agent/linux/test_ovsdb_monitor.py index 8b99a6b44..b6f1ab995 100644 --- a/neutron/tests/functional/agent/linux/test_ovsdb_monitor.py +++ b/neutron/tests/functional/agent/linux/test_ovsdb_monitor.py @@ -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', diff --git a/neutron/tests/functional/agent/linux/test_process_monitor.py b/neutron/tests/functional/agent/linux/test_process_monitor.py index 70492b7ba..961cf9234 100644 --- a/neutron/tests/functional/agent/linux/test_process_monitor.py +++ b/neutron/tests/functional/agent/linux/test_process_monitor.py @@ -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() diff --git a/neutron/tests/functional/agent/test_l3_agent.py b/neutron/tests/functional/agent/test_l3_agent.py index 5217d3c2a..fd52296d3 100755 --- a/neutron/tests/functional/agent/test_l3_agent.py +++ b/neutron/tests/functional/agent/test_l3_agent.py @@ -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') diff --git a/neutron/tests/functional/base.py b/neutron/tests/functional/base.py index ac3c90da9..c790f5615 100644 --- a/neutron/tests/functional/base.py +++ b/neutron/tests/functional/base.py @@ -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') diff --git a/neutron/tests/functional/sanity/test_sanity.py b/neutron/tests/functional/sanity/test_sanity.py index e4e6935f5..027b2bf26 100644 --- a/neutron/tests/functional/sanity/test_sanity.py +++ b/neutron/tests/functional/sanity/test_sanity.py @@ -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() -- 2.45.2