mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Centeralize test username lookup
This commit is contained in:
parent
6a6ab69722
commit
a056a293f1
2 changed files with 6 additions and 11 deletions
|
@ -57,6 +57,7 @@ import multiprocessing
|
|||
|
||||
# Import tests support libs
|
||||
import tests.support.paths as paths
|
||||
import tests.support.helpers
|
||||
|
||||
# Import 3rd-party libs
|
||||
import salt.ext.six as six
|
||||
|
@ -103,12 +104,9 @@ try:
|
|||
except ImportError:
|
||||
pass
|
||||
|
||||
if sys.platform.startswith('win'):
|
||||
import win32api # pylint: disable=import-error
|
||||
RUNNING_TESTS_USER = win32api.GetUserName()
|
||||
else:
|
||||
import pwd
|
||||
RUNNING_TESTS_USER = pwd.getpwuid(os.getuid()).pw_name
|
||||
|
||||
RUNNING_TESTS_USER = tests.support.helpers.this_user()
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ from tests.support.mixins import LoaderModuleMockMixin
|
|||
from tests.support.unit import TestCase, skipIf
|
||||
from tests.support.mock import NO_MOCK, NO_MOCK_REASON
|
||||
from tests.support.paths import TMP, FILES
|
||||
from tests.support.helpers import this_user
|
||||
|
||||
# Import salt libs
|
||||
import salt.utils.gitfs
|
||||
|
@ -207,11 +208,7 @@ class GitFSTest(TestCase, LoaderModuleMockMixin):
|
|||
if 'USERNAME' not in os.environ:
|
||||
try:
|
||||
import salt.utils
|
||||
if salt.utils.is_windows():
|
||||
import salt.utils.win_functions
|
||||
os.environ['USERNAME'] = salt.utils.win_functions.get_current_user()
|
||||
else:
|
||||
os.environ['USERNAME'] = pwd.getpwuid(os.geteuid()).pw_name
|
||||
os.environ['USERNAME'] = this_user()
|
||||
except AttributeError:
|
||||
log.error('Unable to get effective username, falling back to '
|
||||
'\'root\'.')
|
||||
|
|
Loading…
Add table
Reference in a new issue