From cf1e059be5beaf6c261ebbf2686588471ba74b75 Mon Sep 17 00:00:00 2001 From: twangboy Date: Mon, 2 Nov 2015 16:15:02 -0700 Subject: [PATCH 1/2] Fixed windows tests --- tests/integration/__init__.py | 24 ++++++++++++++++++------ tests/runtests.py | 11 ++++++++--- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/tests/integration/__init__.py b/tests/integration/__init__.py index 358485c54d..e75736803d 100644 --- a/tests/integration/__init__.py +++ b/tests/integration/__init__.py @@ -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.*)(?:"|') is running as PID ''' r'(?P[\d]+) and was started at (?P.*) with jid (?P[\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') diff --git a/tests/runtests.py b/tests/runtests.py index 115b906b7a..af1459e6c2 100755 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -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 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.` 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( From 0da6ff7c5084e7c7f7e18e4b0888d1ac410cae02 Mon Sep 17 00:00:00 2001 From: twangboy Date: Tue, 3 Nov 2015 10:09:49 -0700 Subject: [PATCH 2/2] Fixed some logic --- tests/runtests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/runtests.py b/tests/runtests.py index af1459e6c2..7b58f1a9c3 100755 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -256,7 +256,7 @@ class SaltTestsuiteParser(SaltCoverageTestingParser): return self.run_suite(path, display_name) def start_daemons_only(self): - if salt.utils.is_windows(): + if not salt.utils.is_windows(): self.prep_filehandles() try: print_header(