Change os.getlogin() to getpass.getuser() in test_privsep

For some reasons method os.getlogin() is failing in
Zuul CI in Centos8 job [1].
As recommended in [2], change method to getpass.getuser().

[1] https://review.rdoproject.org/zuul/build/bee7ccaba673409c82cc1f212311fdc2/log/job-output.txt
[2] https://github.com/python/cpython/issues/84998#issuecomment-1093873528

Change-Id: I842dccc196c7611506f2115b4bea42bb406f2c3f
This commit is contained in:
karolinku 2022-05-09 14:55:09 +02:00
parent 59dba1d8ae
commit db94342a86
1 changed files with 3 additions and 3 deletions

View File

@ -43,7 +43,7 @@ class PrivsepTest(base.BaseTestCase):
def setUp(self):
super(PrivsepTest, self).setUp()
@unittest.skipIf(_PWD == _PWD_ZUUL or os.getlogin() != 'stack',
@unittest.skipIf(_PWD == _PWD_ZUUL or getpass.getuser() != 'stack',
"Failed on zuul or non-devstack env for root privilege")
def test_privsep_ls(self):
"""Run ls with root privilege
@ -59,7 +59,7 @@ class PrivsepTest(base.BaseTestCase):
# 'boot' dir must be under '/'.
self.assertIn('boot', res)
@unittest.skipIf(_PWD == _PWD_ZUUL or os.getlogin() != 'stack',
@unittest.skipIf(_PWD == _PWD_ZUUL or getpass.getuser() != 'stack',
"Failed on zuul or non-devstack env for root privilege")
def test_privsep_pwd(self):
"""Run pwd with root privilege
@ -69,7 +69,7 @@ class PrivsepTest(base.BaseTestCase):
res = tacker.privileged.linux_cmd.pwd()[0]
self.assertEqual('/\n', res)
@unittest.skipIf(_PWD == _PWD_ZUUL or os.getlogin() != 'stack',
@unittest.skipIf(_PWD == _PWD_ZUUL or getpass.getuser() != 'stack',
"Failed on zuul or non-devstack env for root privilege")
def test_rootwrap(self):
"""Confirm a command can be run with tacker-rootwrap