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 <yasufum.o@gmail.com>
Change-Id: I1e160500c30c379645bc19a67c429e9b2f12dcda
This commit is contained in:
Yasufumi Ogawa 2022-03-18 18:57:04 +09:00
parent 233a12c378
commit 883cd6bed6
2 changed files with 7 additions and 4 deletions

View File

@ -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,

View File

@ -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