mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Merge pull request #28508 from twangboy/fix_unit_tests_windows
Fixed windows tests
This commit is contained in:
commit
ea3bf972c4
@ -6,6 +6,7 @@ Set up the Salt integration test suite
|
||||
|
||||
# Import Python libs
|
||||
from __future__ import print_function
|
||||
import platform
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
@ -28,7 +29,6 @@ try:
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
STATE_FUNCTION_RUNNING_RE = re.compile(
|
||||
r'''The function (?:"|')(?P<state_func>.*)(?:"|') is running as PID '''
|
||||
r'(?P<pid>[\d]+) and was started at (?P<date>.*) with jid (?P<jid>[\d]+)'
|
||||
@ -72,7 +72,11 @@ except ImportError:
|
||||
# Import 3rd-party libs
|
||||
import yaml
|
||||
|
||||
if os.uname()[0] == 'Darwin':
|
||||
if salt.utils.is_windows():
|
||||
import win32api
|
||||
|
||||
|
||||
if platform.uname()[0] == 'Darwin':
|
||||
SYS_TMP_DIR = '/tmp'
|
||||
else:
|
||||
SYS_TMP_DIR = os.environ.get('TMPDIR', tempfile.gettempdir())
|
||||
@ -430,9 +434,14 @@ class TestDaemon(object):
|
||||
os.environ['SSH_DAEMON_RUNNING'] = 'True'
|
||||
roster_path = os.path.join(FILES, 'conf/_ssh/roster')
|
||||
shutil.copy(roster_path, TMP_CONF_DIR)
|
||||
with salt.utils.fopen(os.path.join(TMP_CONF_DIR, 'roster'), 'a') as roster:
|
||||
roster.write(' user: {0}\n'.format(pwd.getpwuid(os.getuid()).pw_name))
|
||||
roster.write(' priv: {0}/{1}'.format(TMP_CONF_DIR, 'key_test'))
|
||||
if salt.utils.is_windows():
|
||||
with salt.utils.fopen(os.path.join(TMP_CONF_DIR, 'roster'), 'a') as roster:
|
||||
roster.write(' user: {0}\n'.format(win32api.GetUserName()))
|
||||
roster.write(' priv: {0}/{1}'.format(TMP_CONF_DIR, 'key_test'))
|
||||
else:
|
||||
with salt.utils.fopen(os.path.join(TMP_CONF_DIR, 'roster'), 'a') as roster:
|
||||
roster.write(' user: {0}\n'.format(pwd.getpwuid(os.getuid()).pw_name))
|
||||
roster.write(' priv: {0}/{1}'.format(TMP_CONF_DIR, 'key_test'))
|
||||
|
||||
@classmethod
|
||||
def config(cls, role):
|
||||
@ -474,7 +483,10 @@ class TestDaemon(object):
|
||||
shutil.rmtree(TMP_CONF_DIR)
|
||||
os.makedirs(TMP_CONF_DIR)
|
||||
print(' * Transplanting configuration files to {0!r}'.format(TMP_CONF_DIR))
|
||||
running_tests_user = pwd.getpwuid(os.getuid()).pw_name
|
||||
if salt.utils.is_windows():
|
||||
running_tests_user = win32api.GetUserName()
|
||||
else:
|
||||
running_tests_user = pwd.getpwuid(os.getuid()).pw_name
|
||||
master_opts = salt.config._read_conf_file(os.path.join(CONF_DIR, 'master'))
|
||||
master_opts['user'] = running_tests_user
|
||||
tests_know_hosts_file = os.path.join(TMP_CONF_DIR, 'salt_ssh_known_hosts')
|
||||
|
@ -8,12 +8,15 @@ Discover all instances of unittest.TestCase in this directory.
|
||||
# Import python libs
|
||||
from __future__ import print_function
|
||||
import os
|
||||
import resource
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
# Import salt libs
|
||||
from integration import TestDaemon, TMP # pylint: disable=W0403
|
||||
import salt.utils
|
||||
|
||||
if not salt.utils.is_windows():
|
||||
import resource
|
||||
|
||||
# Import Salt Testing libs
|
||||
from salttesting.parser import PNUM, print_header
|
||||
@ -253,7 +256,8 @@ class SaltTestsuiteParser(SaltCoverageTestingParser):
|
||||
return self.run_suite(path, display_name)
|
||||
|
||||
def start_daemons_only(self):
|
||||
self.prep_filehandles()
|
||||
if not salt.utils.is_windows():
|
||||
self.prep_filehandles()
|
||||
try:
|
||||
print_header(
|
||||
' * Setting up Salt daemons for interactive use',
|
||||
@ -358,7 +362,8 @@ class SaltTestsuiteParser(SaltCoverageTestingParser):
|
||||
# passing only `unit.<whatever>` to --name.
|
||||
# We don't need the tests daemon running
|
||||
return [True]
|
||||
self.prep_filehandles()
|
||||
if not salt.utils.is_windows():
|
||||
self.prep_filehandles()
|
||||
|
||||
try:
|
||||
print_header(
|
||||
|
Loading…
Reference in New Issue
Block a user