Skip to content

Commit

Permalink
Merge pull request #28508 from twangboy/fix_unit_tests_windows
Browse files Browse the repository at this point in the history
Fixed windows tests
  • Loading branch information
Mike Place committed Nov 3, 2015
2 parents 73c5735 + 0da6ff7 commit ea3bf97
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
24 changes: 18 additions & 6 deletions tests/integration/__init__.py
Expand Up @@ -6,6 +6,7 @@

# Import Python libs
from __future__ import print_function
import platform
import os
import re
import sys
Expand All @@ -28,7 +29,6 @@
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]+)'
Expand Down Expand Up @@ -72,7 +72,11 @@
# 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())
Expand Down Expand Up @@ -430,9 +434,14 @@ def prep_ssh(self):
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):
Expand Down Expand Up @@ -474,7 +483,10 @@ def transplant_configs(cls, transport='zeromq'):
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')
Expand Down
11 changes: 8 additions & 3 deletions tests/runtests.py
Expand Up @@ -8,12 +8,15 @@
# 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
Expand Down Expand Up @@ -253,7 +256,8 @@ def run_integration_suite(self, suite_folder, display_name):
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',
Expand Down Expand Up @@ -358,7 +362,8 @@ def run_integration_tests(self):
# 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(
Expand Down

0 comments on commit ea3bf97

Please sign in to comment.