From 883cd6bed6e96cc8daed367124a9dc71b43637dc Mon Sep 17 00:00:00 2001 From: Yasufumi Ogawa Date: Fri, 18 Mar 2022 18:57:04 +0900 Subject: [PATCH] Fix failure of testing privsep Unittests for privsep and rootwrap fail if it runs on non-linux env such as MacOS, or other than devstack environment. It's because `oslo.privsep` and its tool are not installed properly in tox env. So, skip the tests on other than devstack env to avoid such a failure. This patch also modifies `pypath` in initialization of Privcontext because its fstring cannot be expanded correctly in some environment and tests are failed. Signed-off-by: Yasufumi Ogawa Change-Id: I1e160500c30c379645bc19a67c429e9b2f12dcda --- tacker/privileged/__init__.py | 2 +- tacker/tests/unit/test_privsep.py | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tacker/privileged/__init__.py b/tacker/privileged/__init__.py index 6dc64b1a8..db3958554 100644 --- a/tacker/privileged/__init__.py +++ b/tacker/privileged/__init__.py @@ -22,7 +22,7 @@ from oslo_privsep import priv_context default = priv_context.PrivContext( __name__, cfg_section='privsep', - pypath="f{__name__}.default", + pypath=__name__ + '.default', capabilities=[caps.CAP_SYS_ADMIN, caps.CAP_NET_ADMIN, caps.CAP_DAC_OVERRIDE, diff --git a/tacker/tests/unit/test_privsep.py b/tacker/tests/unit/test_privsep.py index f169ff6a8..f2906fb1f 100644 --- a/tacker/tests/unit/test_privsep.py +++ b/tacker/tests/unit/test_privsep.py @@ -43,7 +43,8 @@ class PrivsepTest(base.BaseTestCase): def setUp(self): super(PrivsepTest, self).setUp() - @unittest.skipIf(_PWD == _PWD_ZUUL, "Failed on zuul for root priv") + @unittest.skipIf(_PWD == _PWD_ZUUL or os.getlogin() != 'stack', + "Failed on zuul or non-devstack env for root privilege") def test_privsep_ls(self): """Run ls with root privilege @@ -58,7 +59,8 @@ class PrivsepTest(base.BaseTestCase): # 'boot' dir must be under '/'. self.assertIn('boot', res) - @unittest.skipIf(_PWD == _PWD_ZUUL, "Failed on zuul for root priv") + @unittest.skipIf(_PWD == _PWD_ZUUL or os.getlogin() != 'stack', + "Failed on zuul or non-devstack env for root privilege") def test_privsep_pwd(self): """Run pwd with root privilege @@ -67,7 +69,8 @@ class PrivsepTest(base.BaseTestCase): res = tacker.privileged.linux_cmd.pwd()[0] self.assertEqual('/\n', res) - @unittest.skipIf(_PWD == _PWD_ZUUL, "Failed on zuul for root priv") + @unittest.skipIf(_PWD == _PWD_ZUUL or os.getlogin() != 'stack', + "Failed on zuul or non-devstack env for root privilege") def test_rootwrap(self): """Confirm a command can be run with tacker-rootwrap