From ac0db895abf144832e792f9f83c9562cdc306acb Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Fri, 7 Dec 2018 17:52:49 +0000 Subject: [PATCH 1/5] Prefer `RUNTIME_VARS` usage --- tests/integration/cloud/clouds/test_ec2.py | 8 +- tests/integration/cloud/helpers/virtualbox.py | 4 +- tests/integration/daemons/test_masterapi.py | 37 +++-- tests/integration/doc/test_man.py | 133 +++++++++-------- .../files/file/base/_modules/mantest.py | 4 +- .../file/base/_modules/runtests_decorators.py | 6 +- .../file/base/_modules/runtests_helpers.py | 17 +-- tests/integration/loader/test_ext_grains.py | 4 +- tests/integration/loader/test_ext_modules.py | 4 +- tests/integration/minion/test_pillar.py | 12 +- tests/integration/modules/test_archive.py | 4 +- tests/integration/modules/test_cmdmod.py | 10 +- tests/integration/modules/test_cp.py | 40 ++--- tests/integration/modules/test_file.py | 14 +- tests/integration/modules/test_git.py | 20 +-- tests/integration/modules/test_hosts.py | 5 +- tests/integration/modules/test_linux_acl.py | 10 +- .../integration/modules/test_mac_keychain.py | 4 +- tests/integration/modules/test_mac_pkgutil.py | 11 +- tests/integration/modules/test_mac_xattr.py | 82 +++++----- tests/integration/modules/test_pillar.py | 6 +- tests/integration/modules/test_pip.py | 4 +- tests/integration/modules/test_saltutil.py | 10 +- tests/integration/modules/test_ssh.py | 67 +++++---- tests/integration/modules/test_state.py | 73 ++++----- tests/integration/modules/test_supervisord.py | 4 +- .../modules/test_virtualenv_mod.py | 4 +- tests/integration/modules/test_win_pkg.py | 22 +-- tests/integration/netapi/test_client.py | 4 +- tests/integration/runners/test_state.py | 6 +- tests/integration/sdb/test_env.py | 6 +- tests/integration/sdb/test_vault.py | 4 +- tests/integration/shell/test_call.py | 16 +- tests/integration/shell/test_cp.py | 8 +- tests/integration/shell/test_enabled.py | 9 +- tests/integration/shell/test_key.py | 6 +- tests/integration/shell/test_minion.py | 4 +- tests/integration/ssh/test_state.py | 4 +- tests/integration/states/test_archive.py | 36 ++--- tests/integration/states/test_cmd.py | 6 +- .../states/test_docker_container.py | 6 +- .../integration/states/test_docker_network.py | 7 +- tests/integration/states/test_file.py | 140 +++++++++--------- tests/integration/states/test_git.py | 10 +- tests/integration/states/test_host.py | 17 +-- tests/integration/states/test_match.py | 6 +- .../states/test_ssh_known_hosts.py | 25 ++-- tests/integration/states/test_supervisord.py | 4 +- tests/integration/states/test_svn.py | 4 +- tests/integration/states/test_x509.py | 20 +-- tests/integration/utils/test_win_runas.py | 9 +- tests/integration/utils/testprogram.py | 8 +- tests/support/cherrypy_testclasses.py | 6 +- tests/support/helpers.py | 10 +- tests/support/runtests.py | 7 +- tests/unit/cache/test_localfs.py | 14 +- tests/unit/client/test_ssh.py | 6 +- tests/unit/cloud/clouds/test_ec2.py | 4 +- tests/unit/daemons/test_masterapi.py | 4 +- tests/unit/fileserver/test_gitfs.py | 17 +-- tests/unit/fileserver/test_roots.py | 20 +-- tests/unit/modules/test_beacons.py | 23 +-- tests/unit/modules/test_boto_elb.py | 6 +- tests/unit/modules/test_boto_route53.py | 4 +- tests/unit/modules/test_boto_secgroup.py | 4 +- tests/unit/modules/test_boto_vpc.py | 4 +- tests/unit/modules/test_cmdmod.py | 4 +- tests/unit/modules/test_event.py | 4 +- tests/unit/modules/test_file.py | 4 +- tests/unit/modules/test_grains.py | 6 +- tests/unit/modules/test_portage_config.py | 4 +- tests/unit/modules/test_schedule.py | 31 ++-- tests/unit/modules/test_state.py | 8 +- tests/unit/modules/test_win_file.py | 6 +- tests/unit/modules/test_zcbuildout.py | 16 +- tests/unit/pillar/test_file_tree.py | 4 +- tests/unit/pillar/test_hg_pillar.py | 4 +- tests/unit/returners/test_local_cache.py | 34 +++-- tests/unit/roster/test_ansible.py | 3 +- tests/unit/runners/test_cache.py | 4 +- tests/unit/runners/test_queue.py | 4 +- tests/unit/runners/test_winrepo.py | 6 +- tests/unit/states/test_beacon.py | 4 +- tests/unit/states/test_boto_vpc.py | 4 +- tests/unit/states/test_grains.py | 10 +- tests/unit/states/test_saltmod.py | 6 +- tests/unit/states/test_virt.py | 4 +- tests/unit/states/test_zcbuildout.py | 3 - tests/unit/test_config.py | 6 +- tests/unit/test_doc.py | 4 +- tests/unit/test_fileclient.py | 65 ++++---- tests/unit/test_loader.py | 40 ++--- tests/unit/test_module_names.py | 9 +- tests/unit/test_pillar.py | 6 +- tests/unit/test_state.py | 3 +- tests/unit/test_virtualname.py | 6 +- tests/unit/transport/test_ipc.py | 6 +- tests/unit/transport/test_zeromq.py | 4 +- tests/unit/utils/test_botomod.py | 4 +- tests/unit/utils/test_cloud.py | 8 +- tests/unit/utils/test_configparser.py | 6 +- tests/unit/utils/test_extend.py | 8 +- tests/unit/utils/test_find.py | 8 +- tests/unit/utils/test_jinja.py | 21 ++- tests/unit/utils/test_pydsl.py | 4 +- tests/unit/utils/test_sdb.py | 31 ++-- tests/unit/utils/test_verify.py | 4 +- tests/unit/utils/test_vmware.py | 21 ++- 108 files changed, 792 insertions(+), 758 deletions(-) diff --git a/tests/integration/cloud/clouds/test_ec2.py b/tests/integration/cloud/clouds/test_ec2.py index 35196d1f7d53..a0eb37a58a64 100644 --- a/tests/integration/cloud/clouds/test_ec2.py +++ b/tests/integration/cloud/clouds/test_ec2.py @@ -14,7 +14,7 @@ import salt.utils.yaml # Import Salt Testing Libs -from tests.support.paths import FILES +from tests.support.runtests import RUNTIME_VARS from tests.support.helpers import expensiveTest from tests.support.unit import skipIf from tests.support import win_installer @@ -38,14 +38,14 @@ class EC2Test(CloudTest): def __fetch_installer(): # Determine the downloaded installer name by searching the files # directory for the first file that looks like an installer. - for path, dirs, files in os.walk(FILES): + for path, dirs, files in os.walk(RUNTIME_VARS.FILES): for file in files: if file.startswith(win_installer.PREFIX): return file # If the installer wasn't found in the previous steps, download the latest Windows installer executable name = win_installer.latest_installer_name() - path = os.path.join(FILES, name) + path = os.path.join(RUNTIME_VARS.FILES, name) with salt.utils.files.fopen(path, 'wb') as fp: win_installer.download_and_verify(fp, name) return name @@ -87,7 +87,7 @@ def copy_file(self, name): configuration directory. The path to the file which is created will be returned. ''' - src = os.path.join(FILES, name) + src = os.path.join(RUNTIME_VARS.FILES, name) dst = os.path.join(self.config_dir, name) with salt.utils.files.fopen(src, 'rb') as sfp: with salt.utils.files.fopen(dst, 'wb') as dfp: diff --git a/tests/integration/cloud/helpers/virtualbox.py b/tests/integration/cloud/helpers/virtualbox.py index a4a6694408ea..e7900e0a9509 100644 --- a/tests/integration/cloud/helpers/virtualbox.py +++ b/tests/integration/cloud/helpers/virtualbox.py @@ -9,7 +9,7 @@ import tests.integration.cloud.helpers from tests.support.case import ShellCase from tests.support.unit import TestCase, skipIf -from tests.support.paths import FILES +from tests.support.runtests import RUNTIME_VARS # Import Salt libs from salt.ext import six @@ -57,7 +57,7 @@ def run_cloud(self, arg_str, catch_stderr=False, timeout=None): @return: @rtype: dict """ - config_path = os.path.join(FILES, 'conf') + config_path = os.path.join(RUNTIME_VARS.FILES, 'conf') arg_str = '--out=json -c {0} {1}'.format(config_path, arg_str) # arg_str = "{0} --log-level=error".format(arg_str) log.debug("running salt-cloud with %s", arg_str) diff --git a/tests/integration/daemons/test_masterapi.py b/tests/integration/daemons/test_masterapi.py index a2a0ff84a69a..ca1638ab80fc 100644 --- a/tests/integration/daemons/test_masterapi.py +++ b/tests/integration/daemons/test_masterapi.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# -tests/integration/daemons/test_masterapi.py:71*- coding: utf-8 -*- # Import Python libs from __future__ import absolute_import, print_function, unicode_literals @@ -7,8 +7,8 @@ import stat # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.case import ShellCase -from tests.support.paths import TMP, INTEGRATION_TEST_DIR # Import 3rd-party libs @@ -16,10 +16,6 @@ import salt.utils.files import salt.utils.stringutils -# all read, only owner write -autosign_file_permissions = stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH | stat.S_IWUSR -autosign_file_path = os.path.join(TMP, 'rootdir', 'autosign_file') - class AutosignGrainsTest(ShellCase): ''' @@ -27,11 +23,17 @@ class AutosignGrainsTest(ShellCase): ''' def setUp(self): + # all read, only owner write + self.autosign_file_permissions = stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH | stat.S_IWUSR + if RUNTIME_VARS.PYTEST_SESSION: + self.autosign_file_path = os.path.join(RUNTIME_VARS.TMP, 'autosign_file') + else: + self.autosign_file_path = os.path.join(RUNTIME_VARS.TMP, 'rootdir', 'autosign_file') shutil.copyfile( - os.path.join(INTEGRATION_TEST_DIR, 'files', 'autosign_grains', 'autosign_file'), - autosign_file_path + os.path.join(RUNTIME_VARS.FILES, 'autosign_grains', 'autosign_file'), + self.autosign_file_path ) - os.chmod(autosign_file_path, autosign_file_permissions) + os.chmod(self.autosign_file_path, self.autosign_file_permissions) self.run_key('-d minion -y') self.run_call('test.ping -l quiet') # get minon to try to authenticate itself again @@ -49,21 +51,24 @@ def setUp(self): def tearDown(self): shutil.copyfile( - os.path.join(INTEGRATION_TEST_DIR, 'files', 'autosign_file'), - autosign_file_path + os.path.join(RUNTIME_VARS.FILES, 'autosign_file'), + self.autosign_file_path ) - os.chmod(autosign_file_path, autosign_file_permissions) + os.chmod(self.autosign_file_path, self.autosign_file_permissions) self.run_call('test.ping -l quiet') # get minon to authenticate itself again - if os.path.isdir(self.autosign_grains_dir): - shutil.rmtree(self.autosign_grains_dir) + try: + if os.path.isdir(self.autosign_grains_dir): + shutil.rmtree(self.autosign_grains_dir) + except AttributeError: + pass def test_autosign_grains_accept(self): grain_file_path = os.path.join(self.autosign_grains_dir, 'test_grain') with salt.utils.files.fopen(grain_file_path, 'w') as f: f.write(salt.utils.stringutils.to_str('#invalid_value\ncheese')) - os.chmod(grain_file_path, autosign_file_permissions) + os.chmod(grain_file_path, self.autosign_file_permissions) self.run_call('test.ping -l quiet') # get minon to try to authenticate itself again self.assertIn('minion', self.run_key('-l acc')) @@ -72,7 +77,7 @@ def test_autosign_grains_fail(self): grain_file_path = os.path.join(self.autosign_grains_dir, 'test_grain') with salt.utils.files.fopen(grain_file_path, 'w') as f: f.write(salt.utils.stringutils.to_str('#cheese\ninvalid_value')) - os.chmod(grain_file_path, autosign_file_permissions) + os.chmod(grain_file_path, self.autosign_file_permissions) self.run_call('test.ping -l quiet') # get minon to try to authenticate itself again self.assertNotIn('minion', self.run_key('-l acc')) diff --git a/tests/integration/doc/test_man.py b/tests/integration/doc/test_man.py index 15ee43124d9a..8e3262feb74f 100644 --- a/tests/integration/doc/test_man.py +++ b/tests/integration/doc/test_man.py @@ -12,77 +12,84 @@ import salt.utils.platform # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.case import ModuleCase -from tests.support.paths import TMP from tests.support.unit import skipIf @skipIf(salt.utils.platform.is_windows(), 'minion is windows') class ManTest(ModuleCase): - # Map filenames to search strings which should be in the manpage - manpages = { - 'salt-cp.1': [ - 'salt-cp Documentation', - 'copies files from the master', - ], - 'salt-cloud.1': [ - 'Salt Cloud Command', - 'Provision virtual machines in the cloud', - ], - 'salt-call.1': [ - 'salt-call Documentation', - 'run module functions locally', - ], - 'salt-api.1': [ - 'salt-api Command', - 'Start interfaces used to remotely connect', - ], - 'salt-unity.1': [ - 'salt-unity Command', - 'unified invocation wrapper', - ], - 'salt-syndic.1': [ - 'salt-syndic Documentation', - 'Salt syndic daemon', - ], - 'salt-ssh.1': [ - 'salt-ssh Documentation', - 'executed using only SSH', - ], - 'salt-run.1': [ - 'salt-run Documentation', - 'frontend command for executing', - ], - 'salt-proxy.1': [ - 'salt-proxy Documentation', - 'proxies these commands', - ], - 'salt-minion.1': [ - 'salt-minion Documentation', - 'Salt minion daemon', - ], - 'salt-master.1': [ - 'salt-master Documentation', - 'Salt master daemon', - ], - 'salt-key.1': [ - 'salt-key Documentation', - 'management of Salt server public keys', - ], - 'salt.1': [ - 'allows for commands to be executed', - ], - 'salt.7': [ - 'Salt Documentation', - ], - 'spm.1': [ - 'Salt Package Manager Command', - 'command for managing Salt packages', - ], - } + + @classmethod + def setUpClass(cls): + cls.rootdir = os.path.join(RUNTIME_VARS.TMP, 'mantest') + # Map filenames to search strings which should be in the manpage + cls.manpages = { + 'salt-cp.1': [ + 'salt-cp Documentation', + 'copies files from the master', + ], + 'salt-cloud.1': [ + 'Salt Cloud Command', + 'Provision virtual machines in the cloud', + ], + 'salt-call.1': [ + 'salt-call Documentation', + 'run module functions locally', + ], + 'salt-api.1': [ + 'salt-api Command', + 'Start interfaces used to remotely connect', + ], + 'salt-unity.1': [ + 'salt-unity Command', + 'unified invocation wrapper', + ], + 'salt-syndic.1': [ + 'salt-syndic Documentation', + 'Salt syndic daemon', + ], + 'salt-ssh.1': [ + 'salt-ssh Documentation', + 'executed using only SSH', + ], + 'salt-run.1': [ + 'salt-run Documentation', + 'frontend command for executing', + ], + 'salt-proxy.1': [ + 'salt-proxy Documentation', + 'proxies these commands', + ], + 'salt-minion.1': [ + 'salt-minion Documentation', + 'Salt minion daemon', + ], + 'salt-master.1': [ + 'salt-master Documentation', + 'Salt master daemon', + ], + 'salt-key.1': [ + 'salt-key Documentation', + 'management of Salt server public keys', + ], + 'salt.1': [ + 'allows for commands to be executed', + ], + 'salt.7': [ + 'Salt Documentation', + ], + 'spm.1': [ + 'Salt Package Manager Command', + 'command for managing Salt packages', + ], + } + + @classmethod + def tearDownClass(cls): + cls.manpages = None def setUp(self): - self.rootdir = os.path.join(TMP, 'mantest') self.addCleanup(shutil.rmtree, self.rootdir, ignore_errors=True) if not os.path.exists(self.rootdir): ret = self.run_function('mantest.install', [self.rootdir]) diff --git a/tests/integration/files/file/base/_modules/mantest.py b/tests/integration/files/file/base/_modules/mantest.py index ee0acb9fcc3b..16a9d5e5d2ab 100644 --- a/tests/integration/files/file/base/_modules/mantest.py +++ b/tests/integration/files/file/base/_modules/mantest.py @@ -15,7 +15,7 @@ from salt.exceptions import CommandExecutionError # Import Salt Tesing libs -from tests.support.paths import CODE_DIR +from tests.support.runtests import RUNTIME_VARS log = logging.getLogger(__name__) @@ -26,7 +26,7 @@ def install(rootdir): return __salt__['cmd.run_all']( [ sys.executable, - os.path.join(CODE_DIR, 'setup.py'), + os.path.join(RUNTIME_VARS.CODE_DIR, 'setup.py'), 'install', '--root={0}'.format(rootdir) ], redirect_stderr=True diff --git a/tests/integration/files/file/base/_modules/runtests_decorators.py b/tests/integration/files/file/base/_modules/runtests_decorators.py index ff316bf8a195..c0cd4106c629 100644 --- a/tests/integration/files/file/base/_modules/runtests_decorators.py +++ b/tests/integration/files/file/base/_modules/runtests_decorators.py @@ -7,10 +7,10 @@ # Import Salt libs import salt.utils.decorators -from tests.support.paths import BASE_FILES +from tests.support.runtests import RUNTIME_VARS -EXIT_CODE_SH = os.path.join(BASE_FILES, 'exit_code.sh') -EXIT_CODE_CMD = os.path.join(BASE_FILES, 'exit_code.cmd') +EXIT_CODE_SH = os.path.join(RUNTIME_VARS.BASE_FILES, 'exit_code.sh') +EXIT_CODE_CMD = os.path.join(RUNTIME_VARS.BASE_FILES, 'exit_code.cmd') def _exit_code(code): diff --git a/tests/integration/files/file/base/_modules/runtests_helpers.py b/tests/integration/files/file/base/_modules/runtests_helpers.py index de252a68e438..436fb85939e1 100644 --- a/tests/integration/files/file/base/_modules/runtests_helpers.py +++ b/tests/integration/files/file/base/_modules/runtests_helpers.py @@ -14,7 +14,6 @@ import re import sys import fnmatch -import tempfile # Import salt libs import salt.utils.platform @@ -22,26 +21,20 @@ # Import 3rd-party libs from salt.ext import six -SYS_TMP_DIR = os.path.realpath( - # Avoid ${TMPDIR} and gettempdir() on MacOS as they yield a base path too long - # for unix sockets: ``error: AF_UNIX path too long`` - # Gentoo Portage prefers ebuild tests are rooted in ${TMPDIR} - os.environ.get('TMPDIR', tempfile.gettempdir()) if not salt.utils.platform.is_darwin() else '/tmp' -) -# This tempdir path is defined on tests.integration.__init__ -TMP = os.path.join(SYS_TMP_DIR, 'salt-tests-tmpdir') +# Import tests libs +from tests.support.runtests import RUNTIME_VARS def get_salt_temp_dir(): - return TMP + return RUNTIME_VARS.TMP def get_salt_temp_dir_for_path(*path): - return os.path.join(TMP, *path) + return os.path.join(RUNTIME_VARS.TMP, *path) def get_sys_temp_dir_for_path(*path): - return os.path.join(SYS_TMP_DIR, *path) + return os.path.join(RUNTIME_VARS.SYS_TMP_DIR, *path) def get_invalid_docs(): diff --git a/tests/integration/loader/test_ext_grains.py b/tests/integration/loader/test_ext_grains.py index 758b575aad3d..405013042fee 100644 --- a/tests/integration/loader/test_ext_grains.py +++ b/tests/integration/loader/test_ext_grains.py @@ -12,8 +12,8 @@ import time # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.case import ModuleCase -from tests.support.paths import TMP from tests.support.unit import skipIf # Import salt libs @@ -38,7 +38,7 @@ def test_grains_overwrite(self): # `test_custom_grain2.py` file is present in the _grains directory # before trying to get the grains. This test may execute before the # minion has finished syncing down the files it needs. - module = os.path.join(TMP, 'rootdir', 'cache', 'files', + module = os.path.join(RUNTIME_VARS.TMP, 'rootdir', 'cache', 'files', 'base', '_grains', 'test_custom_grain2.py') tries = 0 while not os.path.exists(module): diff --git a/tests/integration/loader/test_ext_modules.py b/tests/integration/loader/test_ext_modules.py index bad67f8c0dd5..053666bc2e22 100644 --- a/tests/integration/loader/test_ext_modules.py +++ b/tests/integration/loader/test_ext_modules.py @@ -15,8 +15,8 @@ import time # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.case import ModuleCase -from tests.support.paths import TMP class LoaderOverridesTest(ModuleCase): @@ -29,7 +29,7 @@ def test_overridden_internal(self): # `override_test.py` file is present in the _modules directory before # trying to list all functions. This test may execute before the # minion has finished syncing down the files it needs. - module = os.path.join(TMP, 'rootdir', 'cache', 'files', + module = os.path.join(RUNTIME_VARS.TMP, 'rootdir', 'cache', 'files', 'base', '_modules', 'override_test.py') tries = 0 while not os.path.exists(module): diff --git a/tests/integration/minion/test_pillar.py b/tests/integration/minion/test_pillar.py index eaa201466727..68b36f27a0b5 100644 --- a/tests/integration/minion/test_pillar.py +++ b/tests/integration/minion/test_pillar.py @@ -14,8 +14,8 @@ import subprocess # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.case import ModuleCase -from tests.support.paths import TMP, TMP_CONF_DIR from tests.support.unit import skipIf from tests.support.helpers import requires_system_grains, dedent from tests.support.runtests import RUNTIME_VARS @@ -30,15 +30,15 @@ log = logging.getLogger(__name__) -GPG_HOMEDIR = os.path.join(TMP_CONF_DIR, 'gpgkeys') -PILLAR_BASE = os.path.join(TMP, 'test-decrypt-pillar', 'pillar') +GPG_HOMEDIR = os.path.join(RUNTIME_VARS.TMP_CONF_DIR, 'gpgkeys') +PILLAR_BASE = os.path.join(RUNTIME_VARS.TMP, 'test-decrypt-pillar', 'pillar') TOP_SLS = os.path.join(PILLAR_BASE, 'top.sls') GPG_SLS = os.path.join(PILLAR_BASE, 'gpg.sls') DEFAULT_OPTS = { - 'cachedir': os.path.join(TMP, 'rootdir', 'cache'), - 'config_dir': TMP_CONF_DIR, + 'cachedir': os.path.join(RUNTIME_VARS.TMP, 'rootdir', 'cache'), + 'config_dir': RUNTIME_VARS.TMP_CONF_DIR, 'optimization_order': [0, 1, 2], - 'extension_modules': os.path.join(TMP, + 'extension_modules': os.path.join(RUNTIME_VARS.TMP, 'test-decrypt-pillar', 'extmods'), 'pillar_roots': {'base': [PILLAR_BASE]}, diff --git a/tests/integration/modules/test_archive.py b/tests/integration/modules/test_archive.py index ca77c6d42f2f..56f603ea4321 100644 --- a/tests/integration/modules/test_archive.py +++ b/tests/integration/modules/test_archive.py @@ -9,9 +9,9 @@ import textwrap # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.case import ModuleCase from tests.support.unit import skipIf -from tests.support.paths import TMP from tests.support.helpers import destructiveTest # Import salt libs @@ -35,7 +35,7 @@ class ArchiveTest(ModuleCase): Validate the archive module ''' # Base path used for test artifacts - base_path = os.path.join(TMP, 'modules', 'archive') + base_path = os.path.join(RUNTIME_VARS.TMP, 'modules', 'archive') def _set_artifact_paths(self, arch_fmt): ''' diff --git a/tests/integration/modules/test_cmdmod.py b/tests/integration/modules/test_cmdmod.py index 0f3a9f8c0d95..0631f95d802b 100644 --- a/tests/integration/modules/test_cmdmod.py +++ b/tests/integration/modules/test_cmdmod.py @@ -16,7 +16,7 @@ skip_if_not_root, this_user, ) -from tests.support.paths import TMP +from tests.support.runtests import RUNTIME_VARS from tests.support.unit import skipIf # Import salt libs @@ -189,7 +189,7 @@ def test_script_cwd(self): ''' cmd.script with cwd ''' - tmp_cwd = tempfile.mkdtemp(dir=TMP) + tmp_cwd = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) args = 'saltines crackers biscuits=yes' script = 'salt://script.py' ret = self.run_function('cmd.script', [script, args], cwd=tmp_cwd) @@ -199,7 +199,7 @@ def test_script_cwd_with_space(self): ''' cmd.script with cwd ''' - tmp_cwd = "{0}{1}test 2".format(tempfile.mkdtemp(dir=TMP), os.path.sep) + tmp_cwd = "{0}{1}test 2".format(tempfile.mkdtemp(dir=RUNTIME_VARS.TMP), os.path.sep) os.mkdir(tmp_cwd) args = 'saltines crackers biscuits=yes' @@ -338,7 +338,7 @@ def test_cwd_runas(self): or not runas is in use. ''' cmd = 'pwd' - tmp_cwd = tempfile.mkdtemp(dir=TMP) + tmp_cwd = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) os.chmod(tmp_cwd, 0o711) cwd_normal = self.run_function('cmd.run_stdout', [cmd], cwd=tmp_cwd).rstrip('\n') @@ -377,7 +377,7 @@ def test_runas_complex_command_bad_cwd(self): buggy behaviour, but its purpose is to ensure that the greater bug of running commands after failing to cd does not occur. ''' - tmp_cwd = tempfile.mkdtemp(dir=TMP) + tmp_cwd = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) os.chmod(tmp_cwd, 0o700) with self._ensure_user_exists(self.runas_usr): diff --git a/tests/integration/modules/test_cp.py b/tests/integration/modules/test_cp.py index e59686a14a48..cf64ab946578 100644 --- a/tests/integration/modules/test_cp.py +++ b/tests/integration/modules/test_cp.py @@ -20,7 +20,7 @@ skip_if_not_root, with_tempfile) from tests.support.unit import skipIf -import tests.support.paths as paths +from tests.support.runtests import RUNTIME_VARS # Import 3rd party libs import salt.ext.six as six @@ -71,7 +71,7 @@ def test_get_file_to_dir(self): ''' cp.get_file ''' - tgt = os.path.join(paths.TMP, '') + tgt = os.path.join(RUNTIME_VARS.TMP, '') self.run_function( 'cp.get_file', [ @@ -107,7 +107,7 @@ def test_get_file_gzipped(self, tgt): ''' cp.get_file ''' - src = os.path.join(paths.FILES, 'file', 'base', 'file.big') + src = os.path.join(RUNTIME_VARS.FILES, 'file', 'base', 'file.big') with salt.utils.files.fopen(src, 'rb') as fp_: hash_str = hashlib.md5(fp_.read()).hexdigest() @@ -130,7 +130,7 @@ def test_get_file_makedirs(self): ''' cp.get_file ''' - tgt = os.path.join(paths.TMP, 'make', 'dirs', 'scene33') + tgt = os.path.join(RUNTIME_VARS.TMP, 'make', 'dirs', 'scene33') self.run_function( 'cp.get_file', [ @@ -139,7 +139,7 @@ def test_get_file_makedirs(self): ], makedirs=True ) - self.addCleanup(shutil.rmtree, os.path.join(paths.TMP, 'make'), ignore_errors=True) + self.addCleanup(shutil.rmtree, os.path.join(RUNTIME_VARS.TMP, 'make'), ignore_errors=True) with salt.utils.files.fopen(tgt, 'r') as scene: data = salt.utils.stringutils.to_unicode(scene.read()) self.assertIn('KNIGHT: They\'re nervous, sire.', data) @@ -163,7 +163,7 @@ def test_get_dir(self): ''' cp.get_dir ''' - tgt = os.path.join(paths.TMP, 'many') + tgt = os.path.join(RUNTIME_VARS.TMP, 'many') self.run_function( 'cp.get_dir', [ @@ -179,7 +179,7 @@ def test_get_dir_templated_paths(self): ''' cp.get_dir ''' - tgt = os.path.join(paths.TMP, 'many') + tgt = os.path.join(RUNTIME_VARS.TMP, 'many') self.run_function( 'cp.get_dir', [ @@ -214,7 +214,7 @@ def test_get_url_makedirs(self): ''' cp.get_url ''' - tgt = os.path.join(paths.TMP, 'make', 'dirs', 'scene33') + tgt = os.path.join(RUNTIME_VARS.TMP, 'make', 'dirs', 'scene33') self.run_function( 'cp.get_url', [ @@ -223,7 +223,7 @@ def test_get_url_makedirs(self): ], makedirs=True ) - self.addCleanup(shutil.rmtree, os.path.join(paths.TMP, 'make'), ignore_errors=True) + self.addCleanup(shutil.rmtree, os.path.join(RUNTIME_VARS.TMP, 'make'), ignore_errors=True) with salt.utils.files.fopen(tgt, 'r') as scene: data = salt.utils.stringutils.to_unicode(scene.read()) self.assertIn('KNIGHT: They\'re nervous, sire.', data) @@ -273,7 +273,7 @@ def test_get_url_to_dir(self): ''' cp.get_url with salt:// source ''' - tgt = os.path.join(paths.TMP, '') + tgt = os.path.join(RUNTIME_VARS.TMP, '') self.run_function( 'cp.get_url', [ @@ -346,7 +346,7 @@ def test_get_url_file(self): cp.get_url with file:// source given ''' tgt = '' - src = os.path.join('file://', paths.FILES, 'file', 'base', 'file.big') + src = os.path.join('file://', RUNTIME_VARS.FILES, 'file', 'base', 'file.big') ret = self.run_function( 'cp.get_url', [ @@ -363,7 +363,7 @@ def test_get_url_file_no_dest(self): cp.get_url with file:// source given and destination set as None ''' tgt = None - src = os.path.join('file://', paths.FILES, 'file', 'base', 'file.big') + src = os.path.join('file://', RUNTIME_VARS.FILES, 'file', 'base', 'file.big') ret = self.run_function( 'cp.get_url', [ @@ -420,7 +420,7 @@ def test_get_file_str_local(self): ''' cp.get_file_str with file:// source given ''' - src = os.path.join('file://', paths.FILES, 'file', 'base', 'file.big') + src = os.path.join('file://', RUNTIME_VARS.FILES, 'file', 'base', 'file.big') ret = self.run_function( 'cp.get_file_str', [ @@ -476,7 +476,7 @@ def test_cache_local_file(self): ''' cp.cache_local_file ''' - src = os.path.join(paths.TMP, 'random') + src = os.path.join(RUNTIME_VARS.TMP, 'random') with salt.utils.files.fopen(src, 'w+') as fn_: fn_.write(salt.utils.stringutils.to_str('foo')) ret = self.run_function( @@ -496,7 +496,7 @@ def test_cache_remote_file(self): ''' nginx_port = get_unused_localhost_port() url_prefix = 'http://localhost:{0}/'.format(nginx_port) - temp_dir = tempfile.mkdtemp(dir=paths.TMP) + temp_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) self.addCleanup(shutil.rmtree, temp_dir, ignore_errors=True) nginx_root_dir = os.path.join(temp_dir, 'root') nginx_conf_dir = os.path.join(temp_dir, 'conf') @@ -642,7 +642,7 @@ def test_get_file_from_env_predefined(self, tgt): ''' cp.get_file ''' - tgt = os.path.join(paths.TMP, 'cheese') + tgt = os.path.join(RUNTIME_VARS.TMP, 'cheese') try: self.run_function('cp.get_file', ['salt://cheese', tgt]) with salt.utils.files.fopen(tgt, 'r') as cheese: @@ -654,7 +654,7 @@ def test_get_file_from_env_predefined(self, tgt): @with_tempfile() def test_get_file_from_env_in_url(self, tgt): - tgt = os.path.join(paths.TMP, 'cheese') + tgt = os.path.join(RUNTIME_VARS.TMP, 'cheese') try: self.run_function('cp.get_file', ['salt://cheese?saltenv=prod', tgt]) with salt.utils.files.fopen(tgt, 'r') as cheese: @@ -665,18 +665,18 @@ def test_get_file_from_env_in_url(self, tgt): os.unlink(tgt) def test_push(self): - log_to_xfer = os.path.join(paths.TMP, uuid.uuid4().hex) + log_to_xfer = os.path.join(RUNTIME_VARS.TMP, uuid.uuid4().hex) open(log_to_xfer, 'w').close() # pylint: disable=resource-leakage try: self.run_function('cp.push', [log_to_xfer]) tgt_cache_file = os.path.join( - paths.TMP, + RUNTIME_VARS.TMP, 'master-minion-root', 'cache', 'minions', 'minion', 'files', - paths.TMP, + RUNTIME_VARS.TMP, log_to_xfer) self.assertTrue(os.path.isfile(tgt_cache_file), 'File was not cached on the master') finally: diff --git a/tests/integration/modules/test_file.py b/tests/integration/modules/test_file.py index 234f5404fdfb..aac9272c8c27 100644 --- a/tests/integration/modules/test_file.py +++ b/tests/integration/modules/test_file.py @@ -21,9 +21,9 @@ pass # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.case import ModuleCase from tests.support.unit import skipIf -from tests.support.paths import FILES, TMP # Import salt libs import salt.utils.files @@ -45,18 +45,18 @@ class FileModuleTest(ModuleCase): Validate the file module ''' def setUp(self): - self.myfile = os.path.join(TMP, 'myfile') + self.myfile = os.path.join(RUNTIME_VARS.TMP, 'myfile') with salt.utils.files.fopen(self.myfile, 'w+') as fp: fp.write(salt.utils.stringutils.to_str('Hello' + os.linesep)) - self.mydir = os.path.join(TMP, 'mydir/isawesome') + self.mydir = os.path.join(RUNTIME_VARS.TMP, 'mydir/isawesome') if not os.path.isdir(self.mydir): # left behind... Don't fail because of this! os.makedirs(self.mydir) - self.mysymlink = os.path.join(TMP, 'mysymlink') + self.mysymlink = os.path.join(RUNTIME_VARS.TMP, 'mysymlink') if os.path.islink(self.mysymlink) or os.path.isfile(self.mysymlink): os.remove(self.mysymlink) symlink(self.myfile, self.mysymlink) - self.mybadsymlink = os.path.join(TMP, 'mybadsymlink') + self.mybadsymlink = os.path.join(RUNTIME_VARS.TMP, 'mybadsymlink') if os.path.islink(self.mybadsymlink) or os.path.isfile(self.mybadsymlink): os.remove(self.mybadsymlink) symlink('/nonexistentpath', self.mybadsymlink) @@ -143,8 +143,8 @@ def test_patch(self): self.skipTest('patch is not installed') src_patch = os.path.join( - FILES, 'file', 'base', 'hello.patch') - src_file = os.path.join(TMP, 'src.txt') + RUNTIME_VARS.FILES, 'file', 'base', 'hello.patch') + src_file = os.path.join(RUNTIME_VARS.TMP, 'src.txt') with salt.utils.files.fopen(src_file, 'w+') as fp: fp.write(salt.utils.stringutils.to_str('Hello\n')) diff --git a/tests/integration/modules/test_git.py b/tests/integration/modules/test_git.py index f0341871a32c..671d1f18cc6e 100644 --- a/tests/integration/modules/test_git.py +++ b/tests/integration/modules/test_git.py @@ -20,9 +20,9 @@ import tempfile # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.case import ModuleCase from tests.support.unit import skipIf -from tests.support.paths import TMP from tests.support.helpers import skip_if_binaries_missing # Import salt libs @@ -83,7 +83,7 @@ def setUp(self): super(GitModuleTest, self).setUp() self.orig_cwd = os.getcwd() self.addCleanup(os.chdir, self.orig_cwd) - self.repo = tempfile.mkdtemp(dir=TMP) + self.repo = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) self.addCleanup(shutil.rmtree, self.repo, ignore_errors=True) self.files = ('foo', 'bar', 'baz', 'питон') self.dirs = ('', 'qux') @@ -193,7 +193,7 @@ def test_archive(self): ''' Test git.archive ''' - tar_archive = os.path.join(TMP, 'test_archive.tar.gz') + tar_archive = os.path.join(RUNTIME_VARS.TMP, 'test_archive.tar.gz') try: self.assertTrue( self.run_function( @@ -224,7 +224,7 @@ def test_archive_subdir(self): Test git.archive on a subdir, giving only a partial copy of the repo in the resulting archive ''' - tar_archive = os.path.join(TMP, 'test_archive.tar.gz') + tar_archive = os.path.join(RUNTIME_VARS.TMP, 'test_archive.tar.gz') try: self.assertTrue( self.run_function( @@ -306,7 +306,7 @@ def test_clone(self): ''' Test cloning an existing repo ''' - clone_parent_dir = tempfile.mkdtemp(dir=TMP) + clone_parent_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) self.assertTrue( self.run_function('git.clone', [clone_parent_dir, self.repo]) ) @@ -317,7 +317,7 @@ def test_clone_with_alternate_name(self): ''' Test cloning an existing repo with an alternate name for the repo dir ''' - clone_parent_dir = tempfile.mkdtemp(dir=TMP) + clone_parent_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) clone_name = os.path.basename(self.repo) # Change to newly-created temp dir self.assertTrue( @@ -617,7 +617,7 @@ def test_init(self): ''' Use git.init to init a new repo ''' - new_repo = tempfile.mkdtemp(dir=TMP) + new_repo = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) # `tempfile.mkdtemp` gets the path to the Temp directory using # environment variables. As a result, folder names longer than 8 @@ -971,9 +971,9 @@ def test_worktree_add_rm(self): else: worktree_add_prefix = 'Enter ' - worktree_path = tempfile.mkdtemp(dir=TMP) + worktree_path = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) worktree_basename = os.path.basename(worktree_path) - worktree_path2 = tempfile.mkdtemp(dir=TMP) + worktree_path2 = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) worktree_basename2 = os.path.basename(worktree_path2) # Even though this is Windows, git commands return a unix style path @@ -997,7 +997,7 @@ def test_worktree_add_rm(self): # Check if the main repo is a worktree self.assertFalse(self.run_function('git.is_worktree', [self.repo])) # Check if a non-repo directory is a worktree - empty_dir = tempfile.mkdtemp(dir=TMP) + empty_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) self.assertFalse(self.run_function('git.is_worktree', [empty_dir])) shutil.rmtree(empty_dir) # Remove the first worktree diff --git a/tests/integration/modules/test_hosts.py b/tests/integration/modules/test_hosts.py index 2c601af890b1..2f2c80127c99 100644 --- a/tests/integration/modules/test_hosts.py +++ b/tests/integration/modules/test_hosts.py @@ -8,14 +8,15 @@ import shutil # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.case import ModuleCase -from tests.support.paths import FILES, TMP +from tests.support.paths import FILES # Import Salt libs import salt.utils.files import salt.utils.stringutils -HFN = os.path.join(TMP, 'hosts') +HFN = os.path.join(RUNTIME_VARS.TMP, 'hosts') class HostsModuleTest(ModuleCase): diff --git a/tests/integration/modules/test_linux_acl.py b/tests/integration/modules/test_linux_acl.py index c6139c33f6e9..bb7f2af16036 100644 --- a/tests/integration/modules/test_linux_acl.py +++ b/tests/integration/modules/test_linux_acl.py @@ -6,8 +6,8 @@ import shutil # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.case import ModuleCase -from tests.support.paths import TMP from tests.support.mixins import AdaptedConfigurationTestCaseMixin from tests.support.helpers import skip_if_binaries_missing @@ -27,18 +27,18 @@ class LinuxAclModuleTest(ModuleCase, AdaptedConfigurationTestCaseMixin): ''' def setUp(self): # Blindly copied from tests.integration.modules.file; Refactoring? - self.myfile = os.path.join(TMP, 'myfile') + self.myfile = os.path.join(RUNTIME_VARS.TMP, 'myfile') with salt.utils.files.fopen(self.myfile, 'w+') as fp: fp.write('Hello\n') - self.mydir = os.path.join(TMP, 'mydir/isawesome') + self.mydir = os.path.join(RUNTIME_VARS.TMP, 'mydir/isawesome') if not os.path.isdir(self.mydir): # left behind... Don't fail because of this! os.makedirs(self.mydir) - self.mysymlink = os.path.join(TMP, 'mysymlink') + self.mysymlink = os.path.join(RUNTIME_VARS.TMP, 'mysymlink') if os.path.islink(self.mysymlink): os.remove(self.mysymlink) os.symlink(self.myfile, self.mysymlink) - self.mybadsymlink = os.path.join(TMP, 'mybadsymlink') + self.mybadsymlink = os.path.join(RUNTIME_VARS.TMP, 'mybadsymlink') if os.path.islink(self.mybadsymlink): os.remove(self.mybadsymlink) os.symlink('/nonexistentpath', self.mybadsymlink) diff --git a/tests/integration/modules/test_mac_keychain.py b/tests/integration/modules/test_mac_keychain.py index 763191f812b8..58fe75ff1b92 100644 --- a/tests/integration/modules/test_mac_keychain.py +++ b/tests/integration/modules/test_mac_keychain.py @@ -9,7 +9,7 @@ # Import Salt Testing Libs from tests.support.case import ModuleCase -from tests.support.paths import FILES +from tests.support.runtests import RUNTIME_VARS from tests.support.helpers import destructiveTest, skip_if_not_root # Import Salt Libs @@ -19,7 +19,7 @@ from salt.ext import six CERT = os.path.join( - FILES, + RUNTIME_VARS.FILES, 'file', 'base', 'certs', diff --git a/tests/integration/modules/test_mac_pkgutil.py b/tests/integration/modules/test_mac_pkgutil.py index b02e65388a7c..d5502c30e690 100644 --- a/tests/integration/modules/test_mac_pkgutil.py +++ b/tests/integration/modules/test_mac_pkgutil.py @@ -8,8 +8,8 @@ import os # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.case import ModuleCase -from tests.support.paths import TMP from tests.support.helpers import destructiveTest, skip_if_not_root # Import Salt libs @@ -18,7 +18,6 @@ TEST_PKG_URL = 'https://distfiles.macports.org/MacPorts/MacPorts-2.3.4-10.11-ElCapitan.pkg' TEST_PKG_NAME = 'org.macports.MacPorts' -TEST_PKG = os.path.join(TMP, 'MacPorts-2.3.4-10.11-ElCapitan.pkg') @skip_if_not_root @@ -27,6 +26,10 @@ class MacPkgutilModuleTest(ModuleCase): Validate the mac_pkgutil module ''' + @classmethod + def setUpClass(cls): + cls.test_pkg = os.path.join(RUNTIME_VARS.TMP, 'MacPorts-2.3.4-10.11-ElCapitan.pkg') + def setUp(self): ''' Get current settings @@ -81,11 +84,11 @@ def test_install_forget(self): self.run_function('pkgutil.is_installed', [TEST_PKG_NAME])) # Download the package - self.run_function('cp.get_url', [TEST_PKG_URL, TEST_PKG]) + self.run_function('cp.get_url', [TEST_PKG_URL, self.test_pkg]) # Test install self.assertTrue( - self.run_function('pkgutil.install', [TEST_PKG, TEST_PKG_NAME])) + self.run_function('pkgutil.install', [self.test_pkg, TEST_PKG_NAME])) self.assertIn( 'Unsupported scheme', self.run_function('pkgutil.install', ['ftp://test', 'spongebob'])) diff --git a/tests/integration/modules/test_mac_xattr.py b/tests/integration/modules/test_mac_xattr.py index 5fc98878045e..22d2771f1cd7 100644 --- a/tests/integration/modules/test_mac_xattr.py +++ b/tests/integration/modules/test_mac_xattr.py @@ -8,22 +8,24 @@ import os # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.case import ModuleCase -from tests.support.paths import TMP # Import Salt libs import salt.utils.path import salt.utils.platform -TEST_FILE = os.path.join(TMP, 'xattr_test_file.txt') -NO_FILE = os.path.join(TMP, 'xattr_no_file.txt') - class MacXattrModuleTest(ModuleCase): ''' Validate the mac_xattr module ''' + @classmethod + def setUpClass(cls): + cls.test_file = os.path.join(RUNTIME_VARS.TMP, 'xattr_test_file.txt') + cls.no_file = os.path.join(RUNTIME_VARS.TMP, 'xattr_no_file.txt') + def setUp(self): ''' Create test file for testing extended attributes @@ -34,84 +36,84 @@ def setUp(self): if not salt.utils.path.which('xattr'): self.skipTest('Test requires xattr binary') - self.run_function('file.touch', [TEST_FILE]) + self.run_function('file.touch', [self.test_file]) def tearDown(self): ''' Clean up test file ''' - if os.path.exists(TEST_FILE): - os.remove(TEST_FILE) + if os.path.exists(self.test_file): + os.remove(self.test_file) def test_list_no_xattr(self): ''' Make sure there are no attributes ''' # Clear existing attributes - self.assertTrue(self.run_function('xattr.clear', [TEST_FILE])) + self.assertTrue(self.run_function('xattr.clear', [self.test_file])) # Test no attributes - self.assertEqual(self.run_function('xattr.list', [TEST_FILE]), {}) + self.assertEqual(self.run_function('xattr.list', [self.test_file]), {}) # Test file not found - self.assertEqual(self.run_function('xattr.list', [NO_FILE]), - 'ERROR: File not found: {0}'.format(NO_FILE)) + self.assertEqual(self.run_function('xattr.list', [self.no_file]), + 'ERROR: File not found: {0}'.format(self.no_file)) def test_write(self): ''' Write an attribute ''' # Clear existing attributes - self.assertTrue(self.run_function('xattr.clear', [TEST_FILE])) + self.assertTrue(self.run_function('xattr.clear', [self.test_file])) # Write some attributes self.assertTrue( self.run_function('xattr.write', - [TEST_FILE, 'spongebob', 'squarepants'])) + [self.test_file, 'spongebob', 'squarepants'])) self.assertTrue( self.run_function('xattr.write', - [TEST_FILE, 'squidward', 'plankton'])) + [self.test_file, 'squidward', 'plankton'])) self.assertTrue( self.run_function('xattr.write', - [TEST_FILE, 'crabby', 'patty'])) + [self.test_file, 'crabby', 'patty'])) # Test that they were actually added self.assertEqual( - self.run_function('xattr.list', [TEST_FILE]), + self.run_function('xattr.list', [self.test_file]), {'spongebob': 'squarepants', 'squidward': 'plankton', 'crabby': 'patty'}) # Test file not found self.assertEqual( - self.run_function('xattr.write', [NO_FILE, 'patrick', 'jellyfish']), - 'ERROR: File not found: {0}'.format(NO_FILE)) + self.run_function('xattr.write', [self.no_file, 'patrick', 'jellyfish']), + 'ERROR: File not found: {0}'.format(self.no_file)) def test_read(self): ''' Test xattr.read ''' # Clear existing attributes - self.assertTrue(self.run_function('xattr.clear', [TEST_FILE])) + self.assertTrue(self.run_function('xattr.clear', [self.test_file])) # Write an attribute self.assertTrue( self.run_function('xattr.write', - [TEST_FILE, 'spongebob', 'squarepants'])) + [self.test_file, 'spongebob', 'squarepants'])) # Read the attribute self.assertEqual( - self.run_function('xattr.read', [TEST_FILE, 'spongebob']), + self.run_function('xattr.read', [self.test_file, 'spongebob']), 'squarepants') # Test file not found self.assertEqual( - self.run_function('xattr.read', [NO_FILE, 'spongebob']), - 'ERROR: File not found: {0}'.format(NO_FILE)) + self.run_function('xattr.read', [self.no_file, 'spongebob']), + 'ERROR: File not found: {0}'.format(self.no_file)) # Test attribute not found self.assertEqual( - self.run_function('xattr.read', [TEST_FILE, 'patrick']), + self.run_function('xattr.read', [self.test_file, 'patrick']), 'ERROR: Attribute not found: patrick') def test_delete(self): @@ -119,36 +121,36 @@ def test_delete(self): Test xattr.delete ''' # Clear existing attributes - self.assertTrue(self.run_function('xattr.clear', [TEST_FILE])) + self.assertTrue(self.run_function('xattr.clear', [self.test_file])) # Write some attributes self.assertTrue( self.run_function('xattr.write', - [TEST_FILE, 'spongebob', 'squarepants'])) + [self.test_file, 'spongebob', 'squarepants'])) self.assertTrue( self.run_function('xattr.write', - [TEST_FILE, 'squidward', 'plankton'])) + [self.test_file, 'squidward', 'plankton'])) self.assertTrue( self.run_function('xattr.write', - [TEST_FILE, 'crabby', 'patty'])) + [self.test_file, 'crabby', 'patty'])) # Delete an attribute self.assertTrue( - self.run_function('xattr.delete', [TEST_FILE, 'squidward'])) + self.run_function('xattr.delete', [self.test_file, 'squidward'])) # Make sure it was actually deleted self.assertEqual( - self.run_function('xattr.list', [TEST_FILE]), + self.run_function('xattr.list', [self.test_file]), {'spongebob': 'squarepants', 'crabby': 'patty'}) # Test file not found self.assertEqual( - self.run_function('xattr.delete', [NO_FILE, 'spongebob']), - 'ERROR: File not found: {0}'.format(NO_FILE)) + self.run_function('xattr.delete', [self.no_file, 'spongebob']), + 'ERROR: File not found: {0}'.format(self.no_file)) # Test attribute not found self.assertEqual( - self.run_function('xattr.delete', [TEST_FILE, 'patrick']), + self.run_function('xattr.delete', [self.test_file, 'patrick']), 'ERROR: Attribute not found: patrick') def test_clear(self): @@ -156,22 +158,22 @@ def test_clear(self): Test xattr.clear ''' # Clear existing attributes - self.assertTrue(self.run_function('xattr.clear', [TEST_FILE])) + self.assertTrue(self.run_function('xattr.clear', [self.test_file])) # Write some attributes self.assertTrue( self.run_function('xattr.write', - [TEST_FILE, 'spongebob', 'squarepants'])) + [self.test_file, 'spongebob', 'squarepants'])) self.assertTrue( self.run_function('xattr.write', - [TEST_FILE, 'squidward', 'plankton'])) + [self.test_file, 'squidward', 'plankton'])) self.assertTrue( self.run_function('xattr.write', - [TEST_FILE, 'crabby', 'patty'])) + [self.test_file, 'crabby', 'patty'])) # Test Clear - self.assertTrue(self.run_function('xattr.clear', [TEST_FILE])) + self.assertTrue(self.run_function('xattr.clear', [self.test_file])) # Test file not found - self.assertEqual(self.run_function('xattr.clear', [NO_FILE]), - 'ERROR: File not found: {0}'.format(NO_FILE)) + self.assertEqual(self.run_function('xattr.clear', [self.no_file]), + 'ERROR: File not found: {0}'.format(self.no_file)) diff --git a/tests/integration/modules/test_pillar.py b/tests/integration/modules/test_pillar.py index 1591a6db0840..f23d3d519b38 100644 --- a/tests/integration/modules/test_pillar.py +++ b/tests/integration/modules/test_pillar.py @@ -4,8 +4,8 @@ from __future__ import absolute_import, print_function, unicode_literals # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.case import ModuleCase -from tests.support.paths import TMP_STATE_TREE class PillarModuleTest(ModuleCase): @@ -33,7 +33,7 @@ def test_issue_5449_report_actual_file_roots_in_pillar(self): the pillar back to the minion. ''' self.assertIn( - TMP_STATE_TREE, + RUNTIME_VARS.TMP_STATE_TREE, self.run_function('pillar.data')['master']['file_roots']['base'] ) @@ -47,7 +47,7 @@ def test_ext_cmd_yaml(self): def test_issue_5951_actual_file_roots_in_opts(self): self.assertIn( - TMP_STATE_TREE, + RUNTIME_VARS.TMP_STATE_TREE, self.run_function('pillar.data')['ext_pillar_opts']['file_roots']['base'] ) diff --git a/tests/integration/modules/test_pip.py b/tests/integration/modules/test_pip.py index c98d8b923ccf..4c73c3aeb1f4 100644 --- a/tests/integration/modules/test_pip.py +++ b/tests/integration/modules/test_pip.py @@ -14,9 +14,9 @@ import tempfile # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.case import ModuleCase from tests.support.unit import skipIf -from tests.support.paths import TMP # Import salt libs import salt.utils.files @@ -38,7 +38,7 @@ def cleanup_environ(environ): self.addCleanup(cleanup_environ, os.environ.copy()) - self.venv_test_dir = tempfile.mkdtemp(dir=TMP) + self.venv_test_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) # Remove the venv test directory self.addCleanup(shutil.rmtree, self.venv_test_dir, ignore_errors=True) self.venv_dir = os.path.join(self.venv_test_dir, 'venv') diff --git a/tests/integration/modules/test_saltutil.py b/tests/integration/modules/test_saltutil.py index 4a4515c7f2df..b0af7948f9e0 100644 --- a/tests/integration/modules/test_saltutil.py +++ b/tests/integration/modules/test_saltutil.py @@ -10,9 +10,9 @@ import textwrap # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.case import ModuleCase from tests.support.helpers import flaky -from tests.support.paths import TMP_PILLAR_TREE from tests.support.unit import skipIf # Import Salt Libs @@ -198,12 +198,12 @@ def test_pillar_refresh(self): pre_pillar = self.run_function('pillar.raw') self.assertNotIn(pillar_key, pre_pillar.get(pillar_key, 'didnotwork')) - with salt.utils.files.fopen(os.path.join(TMP_PILLAR_TREE, 'add_pillar.sls'), 'w') as fp: + with salt.utils.files.fopen(os.path.join(RUNTIME_VARS.TMP_PILLAR_TREE, 'add_pillar.sls'), 'w') as fp: fp.write(salt.utils.stringutils.to_str( '{0}: itworked'.format(pillar_key) )) - with salt.utils.files.fopen(os.path.join(TMP_PILLAR_TREE, 'top.sls'), 'w') as fp: + with salt.utils.files.fopen(os.path.join(RUNTIME_VARS.TMP_PILLAR_TREE, 'top.sls'), 'w') as fp: fp.write(textwrap.dedent('''\ base: '*': @@ -228,5 +228,5 @@ def test_pillar_refresh(self): self.assertIn(pillar_key, post_pillar.get(pillar_key, 'didnotwork')) def tearDown(self): - for filename in os.listdir(TMP_PILLAR_TREE): - os.remove(os.path.join(TMP_PILLAR_TREE, filename)) + for filename in os.listdir(RUNTIME_VARS.TMP_PILLAR_TREE): + os.remove(os.path.join(RUNTIME_VARS.TMP_PILLAR_TREE, filename)) diff --git a/tests/integration/modules/test_ssh.py b/tests/integration/modules/test_ssh.py index 34bbcb966a90..b3af96cda036 100644 --- a/tests/integration/modules/test_ssh.py +++ b/tests/integration/modules/test_ssh.py @@ -9,8 +9,8 @@ import shutil # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.case import ModuleCase -from tests.support.paths import FILES, TMP from tests.support.helpers import skip_if_binaries_missing # Import salt libs @@ -20,9 +20,6 @@ # Import 3rd-party libs from tornado.httpclient import HTTPClient -SUBSALT_DIR = os.path.join(TMP, 'subsalt') -AUTHORIZED_KEYS = os.path.join(SUBSALT_DIR, 'authorized_keys') -KNOWN_HOSTS = os.path.join(SUBSALT_DIR, 'known_hosts') GITHUB_FINGERPRINT = '9d:38:5b:83:a9:17:52:92:56:1a:5e:c4:d4:81:8e:0a:ca:51:a2:64:f1:74:20:11:2e:f8:8a:c3:a1:39:49:8f' @@ -41,6 +38,12 @@ class SSHModuleTest(ModuleCase): ''' Test the ssh module ''' + @classmethod + def setUpClass(cls): + cls.subsalt_dir = os.path.join(RUNTIME_VARS.TMP, 'subsalt') + cls.authorized_keys = os.path.join(cls.subsalt_dir, 'authorized_keys') + cls.known_hosts = os.path.join(cls.subsalt_dir, 'known_hosts') + def setUp(self): ''' Set up the ssh module tests @@ -48,10 +51,10 @@ def setUp(self): if not check_status(): self.skipTest('External source, github.com is down') super(SSHModuleTest, self).setUp() - if not os.path.isdir(SUBSALT_DIR): - os.makedirs(SUBSALT_DIR) + if not os.path.isdir(self.subsalt_dir): + os.makedirs(self.subsalt_dir) - ssh_raw_path = os.path.join(FILES, 'ssh', 'raw') + ssh_raw_path = os.path.join(RUNTIME_VARS.FILES, 'ssh', 'raw') with salt.utils.files.fopen(ssh_raw_path) as fd: self.key = fd.read().strip() @@ -59,8 +62,8 @@ def tearDown(self): ''' Tear down the ssh module tests ''' - if os.path.isdir(SUBSALT_DIR): - shutil.rmtree(SUBSALT_DIR) + if os.path.isdir(self.subsalt_dir): + shutil.rmtree(self.subsalt_dir) super(SSHModuleTest, self).tearDown() del self.key @@ -69,12 +72,12 @@ def test_auth_keys(self): test ssh.auth_keys ''' shutil.copyfile( - os.path.join(FILES, 'ssh', 'authorized_keys'), - AUTHORIZED_KEYS) + os.path.join(RUNTIME_VARS.FILES, 'ssh', 'authorized_keys'), + self.authorized_keys) user = 'root' if salt.utils.platform.is_windows(): user = 'Administrator' - ret = self.run_function('ssh.auth_keys', [user, AUTHORIZED_KEYS]) + ret = self.run_function('ssh.auth_keys', [user, self.authorized_keys]) self.assertEqual(len(list(ret.items())), 1) # exactly one key is found key_data = list(ret.items())[0][1] try: @@ -97,9 +100,9 @@ def test_bad_enctype(self): invalid key entry in authorized_keys ''' shutil.copyfile( - os.path.join(FILES, 'ssh', 'authorized_badkeys'), - AUTHORIZED_KEYS) - ret = self.run_function('ssh.auth_keys', ['root', AUTHORIZED_KEYS]) + os.path.join(RUNTIME_VARS.FILES, 'ssh', 'authorized_badkeys'), + self.authorized_keys) + ret = self.run_function('ssh.auth_keys', ['root', self.authorized_keys]) # The authorized_badkeys file contains a key with an invalid ssh key # encoding (dsa-sha2-nistp256 instead of ecdsa-sha2-nistp256) @@ -113,10 +116,10 @@ def test_get_known_host_entries(self): Check that known host information is returned from ~/.ssh/config ''' shutil.copyfile( - os.path.join(FILES, 'ssh', 'known_hosts'), - KNOWN_HOSTS) + os.path.join(RUNTIME_VARS.FILES, 'ssh', 'known_hosts'), + self.known_hosts) arg = ['root', 'github.com'] - kwargs = {'config': KNOWN_HOSTS} + kwargs = {'config': self.known_hosts} ret = self.run_function('ssh.get_known_host_entries', arg, **kwargs)[0] try: self.assertEqual(ret['enc'], 'ssh-rsa') @@ -151,7 +154,7 @@ def test_check_known_host_add(self): Check known hosts by its fingerprint. File needs to be updated ''' arg = ['root', 'github.com'] - kwargs = {'fingerprint': GITHUB_FINGERPRINT, 'config': KNOWN_HOSTS} + kwargs = {'fingerprint': GITHUB_FINGERPRINT, 'config': self.known_hosts} ret = self.run_function('ssh.check_known_host', arg, **kwargs) self.assertEqual(ret, 'add') @@ -160,10 +163,10 @@ def test_check_known_host_update(self): ssh.check_known_host update verification ''' shutil.copyfile( - os.path.join(FILES, 'ssh', 'known_hosts'), - KNOWN_HOSTS) + os.path.join(RUNTIME_VARS.FILES, 'ssh', 'known_hosts'), + self.known_hosts) arg = ['root', 'github.com'] - kwargs = {'config': KNOWN_HOSTS} + kwargs = {'config': self.known_hosts} # wrong fingerprint ret = self.run_function('ssh.check_known_host', arg, **dict(kwargs, fingerprint='aa:bb:cc:dd')) @@ -178,10 +181,10 @@ def test_check_known_host_exists(self): Verify check_known_host_exists ''' shutil.copyfile( - os.path.join(FILES, 'ssh', 'known_hosts'), - KNOWN_HOSTS) + os.path.join(RUNTIME_VARS.FILES, 'ssh', 'known_hosts'), + self.known_hosts) arg = ['root', 'github.com'] - kwargs = {'config': KNOWN_HOSTS} + kwargs = {'config': self.known_hosts} # wrong fingerprint ret = self.run_function('ssh.check_known_host', arg, **dict(kwargs, fingerprint=GITHUB_FINGERPRINT)) @@ -196,15 +199,15 @@ def test_rm_known_host(self): ssh.rm_known_host ''' shutil.copyfile( - os.path.join(FILES, 'ssh', 'known_hosts'), - KNOWN_HOSTS) + os.path.join(RUNTIME_VARS.FILES, 'ssh', 'known_hosts'), + self.known_hosts) arg = ['root', 'github.com'] - kwargs = {'config': KNOWN_HOSTS, 'key': self.key} + kwargs = {'config': self.known_hosts, 'key': self.key} # before removal ret = self.run_function('ssh.check_known_host', arg, **kwargs) self.assertEqual(ret, 'exists') # remove - self.run_function('ssh.rm_known_host', arg, config=KNOWN_HOSTS) + self.run_function('ssh.rm_known_host', arg, config=self.known_hosts) # after removal ret = self.run_function('ssh.check_known_host', arg, **kwargs) self.assertEqual(ret, 'add') @@ -215,7 +218,7 @@ def test_set_known_host(self): ''' # add item ret = self.run_function('ssh.set_known_host', ['root', 'github.com'], - config=KNOWN_HOSTS) + config=self.known_hosts) try: self.assertEqual(ret['status'], 'updated') self.assertEqual(ret['old'], None) @@ -228,7 +231,7 @@ def test_set_known_host(self): ) # check that item does exist ret = self.run_function('ssh.get_known_host_entries', ['root', 'github.com'], - config=KNOWN_HOSTS)[0] + config=self.known_hosts)[0] try: self.assertEqual(ret['fingerprint'], GITHUB_FINGERPRINT) except AssertionError as exc: @@ -239,7 +242,7 @@ def test_set_known_host(self): ) # add the same item once again ret = self.run_function('ssh.set_known_host', ['root', 'github.com'], - config=KNOWN_HOSTS) + config=self.known_hosts) try: self.assertEqual(ret['status'], 'exists') except AssertionError as exc: diff --git a/tests/integration/modules/test_state.py b/tests/integration/modules/test_state.py index ee32b1f1d999..d5f20652fb44 100644 --- a/tests/integration/modules/test_state.py +++ b/tests/integration/modules/test_state.py @@ -12,10 +12,10 @@ import time # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.case import ModuleCase from tests.support.helpers import with_tempdir from tests.support.unit import skipIf -from tests.support.paths import BASE_FILES, TMP, TMP_PILLAR_TREE, TMP_STATE_TREE from tests.support.mixins import SaltReturnAssertsMixin # Import Salt libs @@ -82,9 +82,9 @@ def _reline(path, ending=DEFAULT_ENDING): for line in lines: fhw.write(line + ending) - destpath = os.path.join(BASE_FILES, 'testappend', 'firstif') + destpath = os.path.join(RUNTIME_VARS.BASE_FILES, 'testappend', 'firstif') _reline(destpath) - destpath = os.path.join(BASE_FILES, 'testappend', 'secondif') + destpath = os.path.join(RUNTIME_VARS.BASE_FILES, 'testappend', 'secondif') _reline(destpath) cls.TIMEOUT = 600 if salt.utils.platform.is_windows() else 10 @@ -93,7 +93,7 @@ def test_show_highstate(self): state.show_highstate ''' high = self.run_function('state.show_highstate') - destpath = os.path.join(TMP, 'testfile') + destpath = os.path.join(RUNTIME_VARS.TMP, 'testfile') self.assertTrue(isinstance(high, dict)) self.assertTrue(destpath in high) self.assertEqual(high[destpath]['__env__'], 'base') @@ -123,7 +123,8 @@ def test_show_states_missing_sls(self): Test state.show_states with a sls file defined in a top file is missing ''' - with salt.utils.files.fopen(os.path.join(TMP_STATE_TREE, 'top.sls'), 'w') as top_file: + topfile = os.path.join(RUNTIME_VARS.TMP_STATE_TREE, 'top.sls') + with salt.utils.files.fopen(topfile, 'w') as top_file: top_file.write(textwrap.dedent('''\ base: '*': @@ -338,7 +339,7 @@ def test_issue_1876_syntax_error(self): - text: foo ''' - testfile = os.path.join(TMP, 'issue-1876') + testfile = os.path.join(RUNTIME_VARS.TMP, 'issue-1876') sls = self.run_function('state.sls', mods='issue-1876') self.assertIn( @@ -364,7 +365,7 @@ def test_issue_1879_too_simple_contains_check(self): expected = os.linesep.join(new_contents) expected += os.linesep - testfile = os.path.join(TMP, 'issue-1879') + testfile = os.path.join(RUNTIME_VARS.TMP, 'issue-1879') # Delete if exiting if os.path.isfile(testfile): os.unlink(testfile) @@ -413,7 +414,7 @@ def test_issue_1879_too_simple_contains_check(self): os.unlink(testfile) def test_include(self): - tempdir = tempfile.mkdtemp(dir=TMP) + tempdir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) self.addCleanup(shutil.rmtree, tempdir, ignore_errors=True) pillar = {} for path in ('include-test', 'to-include-test', 'exclude-test'): @@ -425,7 +426,7 @@ def test_include(self): self.assertFalse(os.path.isfile(pillar['exclude-test'])) def test_exclude(self): - tempdir = tempfile.mkdtemp(dir=TMP) + tempdir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) self.addCleanup(shutil.rmtree, tempdir, ignore_errors=True) pillar = {} for path in ('include-test', 'exclude-test', 'to-include-test'): @@ -439,7 +440,7 @@ def test_exclude(self): @skipIf(salt.utils.path.which_bin(KNOWN_BINARY_NAMES) is None, 'virtualenv not installed') def test_issue_2068_template_str(self): venv_dir = os.path.join( - TMP, 'issue-2068-template-str' + RUNTIME_VARS.TMP, 'issue-2068-template-str' ) try: @@ -1366,7 +1367,7 @@ def test_requisites_use_no_state_module(self): self.assertEqual(descr['comment'], 'onlyif condition is false') def test_get_file_from_env_in_top_match(self): - tgt = os.path.join(TMP, 'prod-cheese-file') + tgt = os.path.join(RUNTIME_VARS.TMP, 'prod-cheese-file') try: ret = self.run_function( 'state.highstate', minion_tgt='sub_minion' @@ -1764,7 +1765,7 @@ def test_retry_option_success(self): ''' test a state with the retry option that should return True immedietly (i.e. no retries) ''' - testfile = os.path.join(TMP, 'retry_file_option_success') + testfile = os.path.join(RUNTIME_VARS.TMP, 'retry_file_option_success') state_run = self.run_function( 'state.sls', mods='retry.retry_success' @@ -1792,7 +1793,7 @@ def test_retry_option_eventual_success(self): test a state with the retry option that should return True after at least 4 retry attmempt but never run 15 attempts ''' - testfile = os.path.join(TMP, 'retry_file_eventual_success') + testfile = os.path.join(RUNTIME_VARS.TMP, 'retry_file_eventual_success') assert not os.path.exists(testfile + '_a') assert not os.path.exists(testfile) create_thread = threading.Thread(target=self.run_create, args=(testfile,)) @@ -1867,7 +1868,7 @@ def test_state_nonbase_environment(self): test state.sls with saltenv using a nonbase environment with a salt source ''' - filename = os.path.join(TMP, 'nonbase_env') + filename = os.path.join(RUNTIME_VARS.TMP, 'nonbase_env') try: ret = self.run_function( 'state.sls', @@ -1918,11 +1919,11 @@ def _add_runtime_pillar(self, pillar): helper class to add pillar data at runtime ''' import salt.utils.yaml - with salt.utils.files.fopen(os.path.join(TMP_PILLAR_TREE, + with salt.utils.files.fopen(os.path.join(RUNTIME_VARS.TMP_PILLAR_TREE, 'pillar.sls'), 'w') as fp: salt.utils.yaml.safe_dump(pillar, fp) - with salt.utils.files.fopen(os.path.join(TMP_PILLAR_TREE, 'top.sls'), 'w') as fp: + with salt.utils.files.fopen(os.path.join(RUNTIME_VARS.TMP_PILLAR_TREE, 'top.sls'), 'w') as fp: fp.write(textwrap.dedent('''\ base: '*': @@ -1938,7 +1939,7 @@ def test_state_sls_id_test(self): to true in pillar data ''' self._add_runtime_pillar(pillar={'test': True}) - testfile = os.path.join(TMP, 'testfile') + testfile = os.path.join(RUNTIME_VARS.TMP, 'testfile') comment = 'The file {0} is set to be changed\nNote: No changes made, actual changes may\nbe different due to other states.'.format(testfile) ret = self.run_function('state.sls', ['core']) @@ -1951,7 +1952,7 @@ def test_state_sls_id_test_state_test_post_run(self): test state.sls_id when test is set to true post the state already being run previously ''' - file_name = os.path.join(TMP, 'testfile') + file_name = os.path.join(RUNTIME_VARS.TMP, 'testfile') ret = self.run_function('state.sls', ['core']) for key, val in ret.items(): self.assertEqual(val['comment'], @@ -1971,7 +1972,7 @@ def test_state_sls_id_test_true(self): ''' test state.sls_id when test=True is passed as arg ''' - file_name = os.path.join(TMP, 'testfile') + file_name = os.path.join(RUNTIME_VARS.TMP, 'testfile') ret = self.run_function('state.sls', ['core'], test=True) for key, val in ret.items(): self.assertEqual( @@ -1984,7 +1985,7 @@ def test_state_sls_id_test_true_post_run(self): test state.sls_id when test is set to true as an arg post the state already being run previously ''' - file_name = os.path.join(TMP, 'testfile') + file_name = os.path.join(RUNTIME_VARS.TMP, 'testfile') ret = self.run_function('state.sls', ['core']) for key, val in ret.items(): self.assertEqual(val['comment'], @@ -2005,7 +2006,7 @@ def test_state_sls_id_test_false_pillar_true(self): arg and minion_state_test is set to True. Should return test=False. ''' - file_name = os.path.join(TMP, 'testfile') + file_name = os.path.join(RUNTIME_VARS.TMP, 'testfile') self._add_runtime_pillar(pillar={'test': True}) ret = self.run_function('state.sls', ['core'], test=False) @@ -2028,29 +2029,29 @@ def test_issue_30161_unless_and_onlyif_together(self): # command in the state. If the comment reads "unless condition is true", or similar, # then the unless state run bailed out after the first unless command succeeded, # which is the bug we're regression testing for. - _expected = {'file_|-unless_false_onlyif_false_|-{0}{1}test.txt_|-managed'.format(TMP, os.path.sep): + _expected = {'file_|-unless_false_onlyif_false_|-{0}{1}test.txt_|-managed'.format(RUNTIME_VARS.TMP, os.path.sep): {'comment': 'onlyif condition is false\nunless condition is false', - 'name': '{0}{1}test.txt'.format(TMP, os.path.sep), + 'name': '{0}{1}test.txt'.format(RUNTIME_VARS.TMP, os.path.sep), 'skip_watch': True, 'changes': {}, 'result': True}, - 'file_|-unless_false_onlyif_true_|-{0}{1}test.txt_|-managed'.format(TMP, os.path.sep): + 'file_|-unless_false_onlyif_true_|-{0}{1}test.txt_|-managed'.format(RUNTIME_VARS.TMP, os.path.sep): {'comment': 'Empty file', 'pchanges': {}, - 'name': '{0}{1}test.txt'.format(TMP, os.path.sep), + 'name': '{0}{1}test.txt'.format(RUNTIME_VARS.TMP, os.path.sep), 'start_time': '18:10:20.341753', 'result': True, - 'changes': {'new': 'file {0}{1}test.txt created'.format(TMP, os.path.sep)}}, - 'file_|-unless_true_onlyif_false_|-{0}{1}test.txt_|-managed'.format(TMP, os.path.sep): + 'changes': {'new': 'file {0}{1}test.txt created'.format(RUNTIME_VARS.TMP, os.path.sep)}}, + 'file_|-unless_true_onlyif_false_|-{0}{1}test.txt_|-managed'.format(RUNTIME_VARS.TMP, os.path.sep): {'comment': 'onlyif condition is false\nunless condition is true', - 'name': '{0}{1}test.txt'.format(TMP, os.path.sep), + 'name': '{0}{1}test.txt'.format(RUNTIME_VARS.TMP, os.path.sep), 'start_time': '18:10:22.936446', 'skip_watch': True, 'changes': {}, 'result': True}, - 'file_|-unless_true_onlyif_true_|-{0}{1}test.txt_|-managed'.format(TMP, os.path.sep): + 'file_|-unless_true_onlyif_true_|-{0}{1}test.txt_|-managed'.format(RUNTIME_VARS.TMP, os.path.sep): {'comment': 'onlyif condition is true\nunless condition is true', - 'name': '{0}{1}test.txt'.format(TMP, os.path.sep), + 'name': '{0}{1}test.txt'.format(RUNTIME_VARS.TMP, os.path.sep), 'skip_watch': True, 'changes': {}, 'result': True}} @@ -2087,18 +2088,18 @@ def test_state_sls_unicode_characters_cmd_output(self): self.assertEqual(_expected, ret[key]['changes']['stdout']) def tearDown(self): - rm_files = [os.path.join(TMP, 'nonbase_env'), - os.path.join(TMP, 'testfile'), - os.path.join(TMP, 'test.txt'), - os.path.join(TMP_STATE_TREE, 'top.sls')] + rm_files = [os.path.join(RUNTIME_VARS.TMP, 'nonbase_env'), + os.path.join(RUNTIME_VARS.TMP, 'testfile'), + os.path.join(RUNTIME_VARS.TMP, 'test.txt'), + os.path.join(RUNTIME_VARS.TMP_STATE_TREE, 'top.sls')] for file_ in rm_files: if os.path.isfile(file_): os.remove(file_) # remove old pillar data - for filename in os.listdir(TMP_PILLAR_TREE): - os.remove(os.path.join(TMP_PILLAR_TREE, filename)) + for filename in os.listdir(RUNTIME_VARS.TMP_PILLAR_TREE): + os.remove(os.path.join(RUNTIME_VARS.TMP_PILLAR_TREE, filename)) self.run_function('saltutil.refresh_pillar') self.run_function('test.sleep', [5]) diff --git a/tests/integration/modules/test_supervisord.py b/tests/integration/modules/test_supervisord.py index 6a508f8d0877..0c215469f30b 100644 --- a/tests/integration/modules/test_supervisord.py +++ b/tests/integration/modules/test_supervisord.py @@ -7,9 +7,9 @@ import subprocess # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.case import ModuleCase from tests.support.unit import skipIf -from tests.support.paths import TMP # Import salt libs import salt.utils.path @@ -29,7 +29,7 @@ class SupervisordModuleTest(ModuleCase): def setUp(self): super(SupervisordModuleTest, self).setUp() - self.venv_test_dir = os.path.join(TMP, 'supervisortests') + self.venv_test_dir = os.path.join(RUNTIME_VARS.TMP, 'supervisortests') self.venv_dir = os.path.join(self.venv_test_dir, 'venv') self.supervisor_sock = os.path.join(self.venv_dir, 'supervisor.sock') diff --git a/tests/integration/modules/test_virtualenv_mod.py b/tests/integration/modules/test_virtualenv_mod.py index 23e9d98fbf8d..52bd3fc3f8b8 100644 --- a/tests/integration/modules/test_virtualenv_mod.py +++ b/tests/integration/modules/test_virtualenv_mod.py @@ -6,9 +6,9 @@ import tempfile # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.case import ModuleCase from tests.support.unit import skipIf -from tests.support.paths import TMP # Import salt libs import salt.utils.path @@ -22,7 +22,7 @@ class VirtualenvModuleTest(ModuleCase): ''' def setUp(self): super(VirtualenvModuleTest, self).setUp() - self.venv_test_dir = tempfile.mkdtemp(dir=TMP) + self.venv_test_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) self.venv_dir = os.path.join(self.venv_test_dir, 'venv') def test_create_defaults(self): diff --git a/tests/integration/modules/test_win_pkg.py b/tests/integration/modules/test_win_pkg.py index 8e20bfba3f00..00924684b0b5 100644 --- a/tests/integration/modules/test_win_pkg.py +++ b/tests/integration/modules/test_win_pkg.py @@ -15,9 +15,6 @@ import salt.utils.files import salt.utils.platform -REPO_DIR = os.path.join(RUNTIME_VARS.FILES, 'file', 'base', 'win', 'repo-ng') -CURL = os.path.join(REPO_DIR, 'curl.sls') - @skipIf(not salt.utils.platform.is_windows(), 'windows test only') class WinPKGTest(ModuleCase): @@ -28,6 +25,15 @@ class WinPKGTest(ModuleCase): specific windows software respository tests while using the win_pkg module. ''' + @classmethod + def setUpClass(cls): + cls.repo_dir = os.path.join(RUNTIME_VARS.FILES, 'file', 'base', 'win', 'repo-ng') + cls.curl_sls_path = os.path.join(cls.repo_dir, 'curl.sls') + + def tearDown(self): + if os.path.isfile(self.curl_sls_path): + os.remove(self.curl_sls_path) + @destructiveTest def test_adding_removing_pkg_sls(self): ''' @@ -57,7 +63,7 @@ def _check_pkg(pkgs, check_refresh, exists=True): _check_pkg(pkgs, 2) # now add new sls - with salt.utils.files.fopen(CURL, 'w') as fp_: + with salt.utils.files.fopen(self.curl_sls_path, 'w') as fp_: fp_.write(textwrap.dedent(''' curl: '7.46.0': @@ -78,13 +84,9 @@ def _check_pkg(pkgs, check_refresh, exists=True): # now check if curl is also in cache and repo query pkgs.append('curl') for pkg in pkgs: - self.assertIn(pkg + '.sls', os.listdir(REPO_DIR)) + self.assertIn(pkg + '.sls', os.listdir(self.repo_dir)) _check_pkg(pkgs, 3) # remove curl sls and check its not in cache and repo query - os.remove(CURL) + os.remove(self.curl_sls_path) _check_pkg(['curl'], 2, exists=False) - - def tearDown(self): - if os.path.isfile(CURL): - os.remove(CURL) diff --git a/tests/integration/netapi/test_client.py b/tests/integration/netapi/test_client.py index 998454d15166..98408b4656c0 100644 --- a/tests/integration/netapi/test_client.py +++ b/tests/integration/netapi/test_client.py @@ -6,7 +6,7 @@ import time # Import Salt Testing libs -from tests.support.paths import TMP_CONF_DIR +from tests.support.runtests import RUNTIME_VARS from tests.support.unit import TestCase, skipIf # Import Salt libs @@ -25,7 +25,7 @@ def setUp(self): ''' Set up a NetapiClient instance ''' - opts = salt.config.client_config(os.path.join(TMP_CONF_DIR, 'master')) + opts = salt.config.client_config(os.path.join(RUNTIME_VARS.TMP_CONF_DIR, 'master')) self.netapi = salt.netapi.NetapiClient(opts) def tearDown(self): diff --git a/tests/integration/runners/test_state.py b/tests/integration/runners/test_state.py index a2cd81555ad9..4cdfac9d1f82 100644 --- a/tests/integration/runners/test_state.py +++ b/tests/integration/runners/test_state.py @@ -16,10 +16,10 @@ import threading # Import Salt Testing Libs +from tests.support.runtests import RUNTIME_VARS from tests.support.case import ShellCase from tests.support.helpers import flaky, expensiveTest from tests.support.mock import MagicMock, patch -from tests.support.paths import TMP from tests.support.unit import skipIf # Import Salt Libs @@ -347,7 +347,7 @@ def setUp(self): dir=self.master_d_dir, delete=True, ) - self.base_env = tempfile.mkdtemp(dir=TMP) + self.base_env = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) self.addCleanup(shutil.rmtree, self.base_env) self.addCleanup(self.conf.close) for attr in ('timeout', 'master_d_dir', 'conf', 'base_env'): @@ -734,7 +734,7 @@ def test_orchestration_onchanges_and_prereq(self): __reload_config=True).get('jid') finally: try: - os.remove(os.path.join(TMP, 'orch.req_test')) + os.remove(os.path.join(RUNTIME_VARS.TMP, 'orch.req_test')) except OSError: pass diff --git a/tests/integration/sdb/test_env.py b/tests/integration/sdb/test_env.py index ac26de5a5502..9d03dc0763cd 100644 --- a/tests/integration/sdb/test_env.py +++ b/tests/integration/sdb/test_env.py @@ -8,21 +8,19 @@ # Import Salt Testing libs from tests.support.case import ModuleCase -from tests.support.paths import FILES +from tests.support.runtests import RUNTIME_VARS from tests.support.mixins import SaltReturnAssertsMixin # Import salt libs import salt.utils.files -STATE_DIR = os.path.join(FILES, 'file', 'base') - class EnvTestCase(ModuleCase, SaltReturnAssertsMixin): def setUp(self): self.state_name = 'test_sdb_env' self.state_file_name = self.state_name + '.sls' - self.state_file_set_var = os.path.join(STATE_DIR, self.state_file_name) + self.state_file_set_var = os.path.join(RUNTIME_VARS.BASE_FILES, self.state_file_name) with salt.utils.files.fopen(self.state_file_set_var, 'w') as wfh: wfh.write(textwrap.dedent('''\ set some env var: diff --git a/tests/integration/sdb/test_vault.py b/tests/integration/sdb/test_vault.py index 6f0ee8c4bc5c..1a950b9a6256 100644 --- a/tests/integration/sdb/test_vault.py +++ b/tests/integration/sdb/test_vault.py @@ -12,7 +12,7 @@ from tests.support.unit import skipIf from tests.support.case import ModuleCase, ShellCase from tests.support.helpers import destructiveTest, flaky -from tests.support.paths import FILES +from tests.support.runtests import RUNTIME_VARS # Import Salt Libs import salt.utils.path @@ -78,7 +78,7 @@ def setUp(self): self.skipTest('unable to login to vault') ret = self.run_function( 'cmd.retcode', - cmd='/usr/local/bin/vault policy write testpolicy {0}/vault.hcl'.format(FILES), + cmd='/usr/local/bin/vault policy write testpolicy {0}/vault.hcl'.format(RUNTIME_VARS.FILES), env={'VAULT_ADDR': 'http://127.0.0.1:8200'}, ) if ret != 0: diff --git a/tests/integration/shell/test_call.py b/tests/integration/shell/test_call.py index 1632e215a17c..b65e974014f9 100644 --- a/tests/integration/shell/test_call.py +++ b/tests/integration/shell/test_call.py @@ -16,9 +16,9 @@ import sys # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.case import ShellCase from tests.support.unit import skipIf -from tests.support.paths import FILES, TMP from tests.support.mixins import ShellCaseCommonTestsMixin from tests.support.helpers import flaky, with_tempfile from tests.integration.utils import testprogram @@ -64,7 +64,7 @@ def test_json_out_indent(self): self.assertIn('"local": true', ''.join(out)) def test_local_sls_call(self): - fileroot = os.path.join(FILES, 'file', 'base') + fileroot = os.path.join(RUNTIME_VARS.FILES, 'file', 'base') out = self.run_call('--file-root {0} state.sls saltcalllocal'.format(fileroot), local=True) self.assertIn('Name: test.echo', ''.join(out)) self.assertIn('Result: True', ''.join(out)) @@ -110,8 +110,8 @@ def test_issue_6973_state_highstate_exit_code(self): for this minion, salt-call should exit non-zero if invoked with option --retcode-passthrough ''' - src = os.path.join(FILES, 'file/base/top.sls') - dst = os.path.join(FILES, 'file/base/top.sls.bak') + src = os.path.join(RUNTIME_VARS.BASE_FILES, 'top.sls') + dst = os.path.join(RUNTIME_VARS.BASE_FILES, 'top.sls.bak') shutil.move(src, dst) expected_comment = 'No states found for this minion' try: @@ -155,7 +155,7 @@ def test_syslog_file_not_found(self): test when log_file is set to a syslog file that does not exist ''' old_cwd = os.getcwd() - config_dir = os.path.join(TMP, 'log_file_incorrect') + config_dir = os.path.join(RUNTIME_VARS.TMP, 'log_file_incorrect') if not os.path.isdir(config_dir): os.makedirs(config_dir) @@ -195,7 +195,7 @@ def test_syslog_file_not_found(self): @skipIf(True, 'This test is unreliable. Need to investigate why more deeply.') @flaky def test_issue_15074_output_file_append(self): - output_file_append = os.path.join(TMP, 'issue-15074') + output_file_append = os.path.join(RUNTIME_VARS.TMP, 'issue-15074') try: # Let's create an initial output file with some data _ = self.run_script( @@ -229,7 +229,7 @@ def test_issue_15074_output_file_append(self): @skipIf(True, 'This test is unreliable. Need to investigate why more deeply.') @flaky def test_issue_14979_output_file_permissions(self): - output_file = os.path.join(TMP, 'issue-14979') + output_file = os.path.join(RUNTIME_VARS.TMP, 'issue-14979') with salt.utils.files.set_umask(0o077): try: # Let's create an initial output file with some data @@ -355,7 +355,7 @@ def test_masterless_highstate(self): ''' ret = self.run_call('state.highstate', local=True) - destpath = os.path.join(TMP, 'testfile') + destpath = os.path.join(RUNTIME_VARS.TMP, 'testfile') exp_out = [' Function: file.managed', ' Result: True', ' ID: {0}'.format(destpath)] diff --git a/tests/integration/shell/test_cp.py b/tests/integration/shell/test_cp.py index 80875e643b20..7964aa794c5b 100644 --- a/tests/integration/shell/test_cp.py +++ b/tests/integration/shell/test_cp.py @@ -14,8 +14,8 @@ import logging # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.case import ShellCase -from tests.support.paths import TMP from tests.support.mixins import ShellCaseCommonTestsMixin # Import salt libs @@ -64,7 +64,7 @@ def quote(arg): continue ret = self.run_salt( '--out yaml {0} file.directory_exists {1}'.format( - quote(minion), TMP + quote(minion), RUNTIME_VARS.TMP ) ) data = salt.utils.yaml.safe_load('\n'.join(ret)) @@ -72,7 +72,7 @@ def quote(arg): ret = self.run_salt( '--out yaml {0} file.makedirs {1}'.format( quote(minion), - TMP + RUNTIME_VARS.TMP ) ) @@ -80,7 +80,7 @@ def quote(arg): self.assertTrue(data[minion]) minion_testfile = os.path.join( - TMP, 'cp_{0}_testfile'.format(idx) + RUNTIME_VARS.TMP, 'cp_{0}_testfile'.format(idx) ) ret = self.run_cp('--out pprint {0} {1} {2}'.format( diff --git a/tests/integration/shell/test_enabled.py b/tests/integration/shell/test_enabled.py index f7a44b38adbe..40ff02404120 100644 --- a/tests/integration/shell/test_enabled.py +++ b/tests/integration/shell/test_enabled.py @@ -7,17 +7,14 @@ # Import Salt Testing libs from tests.support.case import ModuleCase -from tests.support.paths import FILES from tests.support.unit import skipIf +from tests.support.runtests import RUNTIME_VARS # Import Salt Libs import salt.utils.platform import salt.utils.files -STATE_DIR = os.path.join(FILES, 'file', 'base') - - class EnabledTest(ModuleCase): ''' validate the use of shell processing for cmd.run on the salt command line @@ -57,7 +54,7 @@ def test_template_shell(self): ''' state_name = 'template_shell_enabled' state_filename = state_name + '.sls' - state_file = os.path.join(STATE_DIR, state_filename) + state_file = os.path.join(RUNTIME_VARS.BASE_FILES, state_filename) enabled_ret = '3 saltines' # the result of running self.cmd in a shell ret_key = 'test_|-shell_enabled_|-{0}_|-configurable_test_state'.format(enabled_ret) @@ -85,7 +82,7 @@ def test_template_default_disabled(self): ''' state_name = 'template_shell_disabled' state_filename = state_name + '.sls' - state_file = os.path.join(STATE_DIR, state_filename) + state_file = os.path.join(RUNTIME_VARS.BASE_FILES, state_filename) # the result of running self.cmd not in a shell disabled_ret = ('first second third | wc -l ; export SALTY_VARIABLE=saltines ' diff --git a/tests/integration/shell/test_key.py b/tests/integration/shell/test_key.py index 7a989a490447..990633514585 100644 --- a/tests/integration/shell/test_key.py +++ b/tests/integration/shell/test_key.py @@ -8,8 +8,8 @@ import textwrap # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.case import ShellCase -from tests.support.paths import TMP from tests.support.mixins import ShellCaseCommonTestsMixin from tests.support.helpers import skip_if_not_root, destructiveTest @@ -229,7 +229,7 @@ def test_list_un(self): self.assertEqual(data, expect) def test_keys_generation(self): - tempdir = tempfile.mkdtemp(dir=TMP) + tempdir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) arg_str = '--gen-keys minibar --gen-keys-dir {0}'.format(tempdir) self.run_key(arg_str) try: @@ -245,7 +245,7 @@ def test_keys_generation(self): shutil.rmtree(tempdir) def test_keys_generation_keysize_minmax(self): - tempdir = tempfile.mkdtemp(dir=TMP) + tempdir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) arg_str = '--gen-keys minion --gen-keys-dir {0}'.format(tempdir) try: data, error = self.run_key( diff --git a/tests/integration/shell/test_minion.py b/tests/integration/shell/test_minion.py index 5cf73b1ea3bb..18aca4a86b14 100644 --- a/tests/integration/shell/test_minion.py +++ b/tests/integration/shell/test_minion.py @@ -19,9 +19,9 @@ import tests.integration.utils from tests.support.case import ShellCase from tests.support.unit import skipIf -from tests.support.paths import CODE_DIR from tests.support.mixins import ShellCaseCommonTestsMixin from tests.integration.utils import testprogram +from tests.support.runtests import RUNTIME_VARS # Import 3rd-party libs from salt.ext import six @@ -165,7 +165,7 @@ def _initscript_setup(self, minions): init_script = testprogram.TestProgram( name='init:salt-minion', - program=os.path.join(CODE_DIR, 'pkg', 'rpm', 'salt-minion'), + program=os.path.join(RUNTIME_VARS.CODE_DIR, 'pkg', 'rpm', 'salt-minion'), env=cmd_env, ) diff --git a/tests/integration/ssh/test_state.py b/tests/integration/ssh/test_state.py index 263ec7347a06..e96343a7fffa 100644 --- a/tests/integration/ssh/test_state.py +++ b/tests/integration/ssh/test_state.py @@ -9,9 +9,9 @@ import logging # Import Salt Testing Libs +from tests.support.runtests import RUNTIME_VARS from tests.support.case import SSHCase from tests.support.helpers import flaky -from tests.support.paths import TMP # Import Salt Libs from salt.ext import six @@ -123,7 +123,7 @@ def test_show_highstate(self): state.show_highstate with salt-ssh ''' high = self.run_function('state.show_highstate') - destpath = os.path.join(TMP, 'testfile') + destpath = os.path.join(RUNTIME_VARS.TMP, 'testfile') self.assertIsInstance(high, dict) self.assertIn(destpath, high) self.assertEqual(high[destpath]['__env__'], 'base') diff --git a/tests/integration/states/test_archive.py b/tests/integration/states/test_archive.py index 66fbf76d78b4..9ecd414bef7b 100644 --- a/tests/integration/states/test_archive.py +++ b/tests/integration/states/test_archive.py @@ -12,7 +12,7 @@ from tests.support.case import ModuleCase from tests.support.helpers import skip_if_not_root, Webserver from tests.support.mixins import SaltReturnAssertsMixin -from tests.support.paths import FILES +from tests.support.runtests import RUNTIME_VARS # Import Salt libs import salt.utils.files @@ -27,8 +27,6 @@ ARCHIVE_NAME = 'custom.tar.gz' ARCHIVE_TAR_SOURCE = 'http://localhost:{0}/{1}'.format(9999, ARCHIVE_NAME) -ARCHIVE_LOCAL_TAR_SOURCE = 'file://{0}'.format(os.path.join(FILES, 'file', 'base', ARCHIVE_NAME)) -UNTAR_FILE = os.path.join(ARCHIVE_DIR, 'custom/README') ARCHIVE_TAR_HASH = 'md5=7643861ac07c30fe7d2310e9f25ca514' ARCHIVE_TAR_BAD_HASH = 'md5=d41d8cd98f00b204e9800998ecf8427e' ARCHIVE_TAR_HASH_UPPER = 'md5=7643861AC07C30FE7D2310E9F25CA514' @@ -43,6 +41,8 @@ def setUpClass(cls): cls.webserver = Webserver() cls.webserver.start() cls.archive_tar_source = cls.webserver.url('custom.tar.gz') + cls.archive_local_tar_source = 'file://{0}'.format(os.path.join(RUNTIME_VARS.BASE_FILES, ARCHIVE_NAME)) + cls.untar_file = os.path.join(ARCHIVE_DIR, 'custom/README') @classmethod def tearDownClass(cls): @@ -90,7 +90,7 @@ def test_archive_extracted_skip_verify(self): self.skipTest('Timeout talking to local tornado server.') self.assertSaltTrueReturn(ret) - self._check_extracted(UNTAR_FILE) + self._check_extracted(self.untar_file) def test_archive_extracted_with_source_hash(self): ''' @@ -106,7 +106,7 @@ def test_archive_extracted_with_source_hash(self): self.assertSaltTrueReturn(ret) - self._check_extracted(UNTAR_FILE) + self._check_extracted(self.untar_file) @skip_if_not_root def test_archive_extracted_with_root_user_and_group(self): @@ -125,7 +125,7 @@ def test_archive_extracted_with_root_user_and_group(self): self.assertSaltTrueReturn(ret) - self._check_extracted(UNTAR_FILE) + self._check_extracted(self.untar_file) def test_archive_extracted_with_strip_in_options(self): ''' @@ -170,7 +170,7 @@ def test_archive_extracted_without_archive_format(self): self.skipTest('Timeout talking to local tornado server.') self.assertSaltTrueReturn(ret) - self._check_extracted(UNTAR_FILE) + self._check_extracted(self.untar_file) def test_archive_extracted_with_cmd_unzip_false(self): ''' @@ -186,49 +186,49 @@ def test_archive_extracted_with_cmd_unzip_false(self): self.skipTest('Timeout talking to local tornado server.') self.assertSaltTrueReturn(ret) - self._check_extracted(UNTAR_FILE) + self._check_extracted(self.untar_file) def test_local_archive_extracted(self): ''' test archive.extracted with local file ''' ret = self.run_state('archive.extracted', name=ARCHIVE_DIR, - source=ARCHIVE_LOCAL_TAR_SOURCE, archive_format='tar') + source=self.archive_local_tar_source, archive_format='tar') self.assertSaltTrueReturn(ret) - self._check_extracted(UNTAR_FILE) + self._check_extracted(self.untar_file) def test_local_archive_extracted_skip_verify(self): ''' test archive.extracted with local file, bad hash and skip_verify ''' ret = self.run_state('archive.extracted', name=ARCHIVE_DIR, - source=ARCHIVE_LOCAL_TAR_SOURCE, archive_format='tar', + source=self.archive_local_tar_source, archive_format='tar', source_hash=ARCHIVE_TAR_BAD_HASH, skip_verify=True) self.assertSaltTrueReturn(ret) - self._check_extracted(UNTAR_FILE) + self._check_extracted(self.untar_file) def test_local_archive_extracted_with_source_hash(self): ''' test archive.extracted with local file and valid hash ''' ret = self.run_state('archive.extracted', name=ARCHIVE_DIR, - source=ARCHIVE_LOCAL_TAR_SOURCE, archive_format='tar', + source=self.archive_local_tar_source, archive_format='tar', source_hash=ARCHIVE_TAR_HASH) self.assertSaltTrueReturn(ret) - self._check_extracted(UNTAR_FILE) + self._check_extracted(self.untar_file) def test_local_archive_extracted_with_bad_source_hash(self): ''' test archive.extracted with local file and bad hash ''' ret = self.run_state('archive.extracted', name=ARCHIVE_DIR, - source=ARCHIVE_LOCAL_TAR_SOURCE, archive_format='tar', + source=self.archive_local_tar_source, archive_format='tar', source_hash=ARCHIVE_TAR_BAD_HASH) self.assertSaltFalseReturn(ret) @@ -238,12 +238,12 @@ def test_local_archive_extracted_with_uppercase_source_hash(self): test archive.extracted with local file and bad hash ''' ret = self.run_state('archive.extracted', name=ARCHIVE_DIR, - source=ARCHIVE_LOCAL_TAR_SOURCE, archive_format='tar', + source=self.archive_local_tar_source, archive_format='tar', source_hash=ARCHIVE_TAR_HASH_UPPER) self.assertSaltTrueReturn(ret) - self._check_extracted(UNTAR_FILE) + self._check_extracted(self.untar_file) def test_archive_extracted_with_non_base_saltenv(self): ''' @@ -255,4 +255,4 @@ def test_archive_extracted_with_non_base_saltenv(self): pillar={'issue45893.name': ARCHIVE_DIR}, saltenv='prod') self.assertSaltTrueReturn(ret) - self._check_extracted(os.path.join(ARCHIVE_DIR, UNTAR_FILE)) + self._check_extracted(os.path.join(ARCHIVE_DIR, self.untar_file)) diff --git a/tests/integration/states/test_cmd.py b/tests/integration/states/test_cmd.py index f109fb071b9b..5e41e10f6fed 100644 --- a/tests/integration/states/test_cmd.py +++ b/tests/integration/states/test_cmd.py @@ -11,8 +11,8 @@ import time # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.case import ModuleCase -from tests.support.paths import TMP_STATE_TREE from tests.support.mixins import SaltReturnAssertsMixin # Import Salt libs @@ -65,7 +65,7 @@ class CMDRunRedirectTest(ModuleCase, SaltReturnAssertsMixin): def setUp(self): self.state_name = 'run_redirect' state_filename = self.state_name + '.sls' - self.state_file = os.path.join(TMP_STATE_TREE, state_filename) + self.state_file = os.path.join(RUNTIME_VARS.TMP_STATE_TREE, state_filename) # Create the testfile and release the handle fd, self.test_file = tempfile.mkstemp() @@ -183,7 +183,7 @@ class CMDRunWatchTest(ModuleCase, SaltReturnAssertsMixin): def setUp(self): self.state_name = 'run_watch' state_filename = self.state_name + '.sls' - self.state_file = os.path.join(TMP_STATE_TREE, state_filename) + self.state_file = os.path.join(RUNTIME_VARS.TMP_STATE_TREE, state_filename) super(CMDRunWatchTest, self).setUp() def tearDown(self): diff --git a/tests/integration/states/test_docker_container.py b/tests/integration/states/test_docker_container.py index bd49cf4ea09d..c133c6af2400 100644 --- a/tests/integration/states/test_docker_container.py +++ b/tests/integration/states/test_docker_container.py @@ -12,10 +12,10 @@ import tempfile # Import Salt Testing Libs +from tests.support.runtests import RUNTIME_VARS from tests.support.unit import skipIf from tests.support.case import ModuleCase from tests.support.docker import with_network, random_name -from tests.support.paths import FILES, TMP from tests.support.helpers import destructiveTest, with_tempdir from tests.support.mixins import SaltReturnAssertsMixin @@ -63,11 +63,11 @@ def setUpClass(cls): ''' ''' # Create temp dir - cls.image_build_rootdir = tempfile.mkdtemp(dir=TMP) + cls.image_build_rootdir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) # Generate image name cls.image = random_name(prefix='salt_busybox_') - script_path = os.path.join(FILES, 'file/base/mkimage-busybox-static') + script_path = os.path.join(RUNTIME_VARS.BASE_FILES, 'mkimage-busybox-static') cmd = [script_path, cls.image_build_rootdir, cls.image] log.debug('Running \'%s\' to build busybox image', ' '.join(cmd)) process = subprocess.Popen( diff --git a/tests/integration/states/test_docker_network.py b/tests/integration/states/test_docker_network.py index 8613085ae2cf..8600bbda98a0 100644 --- a/tests/integration/states/test_docker_network.py +++ b/tests/integration/states/test_docker_network.py @@ -12,10 +12,10 @@ import tempfile # Import Salt Testing Libs +from tests.support.runtests import RUNTIME_VARS from tests.support.unit import skipIf from tests.support.case import ModuleCase from tests.support.docker import with_network, random_name -from tests.support.paths import FILES, TMP from tests.support.helpers import destructiveTest, requires_system_grains from tests.support.mixins import SaltReturnAssertsMixin @@ -58,9 +58,8 @@ def container_name(func): ''' def build_image(): # Create temp dir - image_build_rootdir = tempfile.mkdtemp(dir=TMP) - script_path = \ - os.path.join(FILES, 'file/base/mkimage-busybox-static') + image_build_rootdir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) + script_path = os.path.join(RUNTIME_VARS.BASE_FILES, 'mkimage-busybox-static') cmd = [script_path, image_build_rootdir, IMAGE_NAME] log.debug('Running \'%s\' to build busybox image', ' '.join(cmd)) process = subprocess.Popen( diff --git a/tests/integration/states/test_file.py b/tests/integration/states/test_file.py index 521fd52b176e..ef7e3075902f 100644 --- a/tests/integration/states/test_file.py +++ b/tests/integration/states/test_file.py @@ -20,9 +20,9 @@ log = logging.getLogger(__name__) # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.case import ModuleCase from tests.support.unit import skipIf -from tests.support.paths import BASE_FILES, FILES, TMP, TMP_STATE_TREE from tests.support.helpers import ( destructiveTest, skip_if_not_root, @@ -82,8 +82,8 @@ def _test_managed_file_mode_keep_helper(testcase, local=False): ''' DRY helper function to run the same test with a local or remote path ''' - name = os.path.join(TMP, 'scene33') - grail_fs_path = os.path.join(BASE_FILES, 'grail', 'scene33') + name = os.path.join(RUNTIME_VARS.TMP, 'scene33') + grail_fs_path = os.path.join(RUNTIME_VARS.BASE_FILES, 'grail', 'scene33') grail = 'salt://grail/scene33' if not local else grail_fs_path # Get the current mode so that we can put the file back the way we @@ -166,8 +166,8 @@ def test_symlink(self): ''' file.symlink ''' - name = os.path.join(TMP, 'symlink') - tgt = os.path.join(TMP, 'target') + name = os.path.join(RUNTIME_VARS.TMP, 'symlink') + tgt = os.path.join(RUNTIME_VARS.TMP, 'target') # Windows must have a source directory to link to if IS_WINDOWS and not os.path.isdir(tgt): @@ -184,8 +184,8 @@ def test_test_symlink(self): ''' file.symlink test interface ''' - name = os.path.join(TMP, 'symlink2') - tgt = os.path.join(TMP, 'target') + name = os.path.join(RUNTIME_VARS.TMP, 'symlink2') + tgt = os.path.join(RUNTIME_VARS.TMP, 'target') ret = self.run_state('file.symlink', test=True, name=name, target=tgt) self.assertSaltNoneReturn(ret) @@ -193,7 +193,7 @@ def test_absent_file(self): ''' file.absent ''' - name = os.path.join(TMP, 'file_to_kill') + name = os.path.join(RUNTIME_VARS.TMP, 'file_to_kill') with salt.utils.files.fopen(name, 'w+') as fp_: fp_.write('killme') ret = self.run_state('file.absent', name=name) @@ -204,7 +204,7 @@ def test_absent_dir(self): ''' file.absent ''' - name = os.path.join(TMP, 'dir_to_kill') + name = os.path.join(RUNTIME_VARS.TMP, 'dir_to_kill') if not os.path.isdir(name): # left behind... Don't fail because of this! os.makedirs(name) @@ -216,7 +216,7 @@ def test_absent_link(self): ''' file.absent ''' - name = os.path.join(TMP, 'link_to_kill') + name = os.path.join(RUNTIME_VARS.TMP, 'link_to_kill') tgt = '{0}.tgt'.format(name) # Windows must have a source directory to link to @@ -250,11 +250,11 @@ def test_managed(self): ''' file.managed ''' - name = os.path.join(TMP, 'grail_scene33') + name = os.path.join(RUNTIME_VARS.TMP, 'grail_scene33') ret = self.run_state( 'file.managed', name=name, source='salt://grail/scene33' ) - src = os.path.join(BASE_FILES, 'grail', 'scene33') + src = os.path.join(RUNTIME_VARS.BASE_FILES, 'grail', 'scene33') with salt.utils.files.fopen(src, 'r') as fp_: master_data = fp_.read() with salt.utils.files.fopen(name, 'r') as fp_: @@ -267,7 +267,7 @@ def test_managed_file_mode(self): file.managed, correct file permissions ''' desired_mode = 504 # 0770 octal - name = os.path.join(TMP, 'grail_scene33') + name = os.path.join(RUNTIME_VARS.TMP, 'grail_scene33') ret = self.run_state( 'file.managed', name=name, mode='0770', source='salt://grail/scene33' ) @@ -305,7 +305,7 @@ def test_managed_file_mode_file_exists_replace(self): ''' initial_mode = 504 # 0770 octal desired_mode = 384 # 0600 octal - name = os.path.join(TMP, 'grail_scene33') + name = os.path.join(RUNTIME_VARS.TMP, 'grail_scene33') ret = self.run_state( 'file.managed', name=name, mode=oct(initial_mode), source='salt://grail/scene33' ) @@ -321,7 +321,7 @@ def test_managed_file_mode_file_exists_replace(self): ) self.assertEqual(oct(initial_mode), oct(resulting_mode)) - name = os.path.join(TMP, 'grail_scene33') + name = os.path.join(RUNTIME_VARS.TMP, 'grail_scene33') ret = self.run_state( 'file.managed', name=name, replace=True, mode=oct(desired_mode), source='salt://grail/scene33' ) @@ -337,7 +337,7 @@ def test_managed_file_mode_file_exists_noreplace(self): ''' initial_mode = 504 # 0770 octal desired_mode = 384 # 0600 octal - name = os.path.join(TMP, 'grail_scene33') + name = os.path.join(RUNTIME_VARS.TMP, 'grail_scene33') ret = self.run_state( 'file.managed', name=name, replace=True, mode=oct(initial_mode), source='salt://grail/scene33' ) @@ -362,7 +362,7 @@ def test_managed_file_with_grains_data(self): Test to ensure we can render grains data into a managed file. ''' - grain_path = os.path.join(TMP, 'file-grain-test') + grain_path = os.path.join(RUNTIME_VARS.TMP, 'file-grain-test') state_file = 'file-grainget' self.run_function('state.sls', [state_file], pillar={'grain_path': grain_path}) @@ -413,7 +413,7 @@ def test_managed_dir_mode(self): permissions requested with the dir_mode argument ''' desired_mode = 511 # 0777 in octal - name = os.path.join(TMP, 'a', 'managed_dir_mode_test_file') + name = os.path.join(RUNTIME_VARS.TMP, 'a', 'managed_dir_mode_test_file') desired_owner = 'nobody' ret = self.run_state( 'file.managed', @@ -431,9 +431,9 @@ def test_managed_dir_mode(self): return resulting_mode = stat.S_IMODE( - os.stat(os.path.join(TMP, 'a')).st_mode + os.stat(os.path.join(RUNTIME_VARS.TMP, 'a')).st_mode ) - resulting_owner = pwd.getpwuid(os.stat(os.path.join(TMP, 'a')).st_uid).pw_name + resulting_owner = pwd.getpwuid(os.stat(os.path.join(RUNTIME_VARS.TMP, 'a')).st_uid).pw_name self.assertEqual(oct(desired_mode), oct(resulting_mode)) self.assertSaltTrueReturn(ret) self.assertEqual(desired_owner, resulting_owner) @@ -442,7 +442,7 @@ def test_test_managed(self): ''' file.managed test interface ''' - name = os.path.join(TMP, 'grail_not_not_scene33') + name = os.path.join(RUNTIME_VARS.TMP, 'grail_not_not_scene33') ret = self.run_state( 'file.managed', test=True, name=name, source='salt://grail/scene33' ) @@ -453,7 +453,7 @@ def test_managed_show_changes_false(self): ''' file.managed test interface ''' - name = os.path.join(TMP, 'grail_not_scene33') + name = os.path.join(RUNTIME_VARS.TMP, 'grail_not_scene33') with salt.utils.files.fopen(name, 'wb') as fp_: fp_.write(b'test_managed_show_changes_false\n') @@ -469,7 +469,7 @@ def test_managed_show_changes_true(self): ''' file.managed test interface ''' - name = os.path.join(TMP, 'grail_not_scene33') + name = os.path.join(RUNTIME_VARS.TMP, 'grail_not_scene33') with salt.utils.files.fopen(name, 'wb') as fp_: fp_.write(b'test_managed_show_changes_false\n') @@ -488,11 +488,11 @@ def test_managed_escaped_file_path(self): funny_file = salt.utils.files.mkstemp(prefix='?f!le? n@=3&', suffix='.file type') funny_file_name = os.path.split(funny_file)[1] funny_url = 'salt://|' + funny_file_name - funny_url_path = os.path.join(BASE_FILES, funny_file_name) + funny_url_path = os.path.join(RUNTIME_VARS.BASE_FILES, funny_file_name) state_name = 'funny_file' state_file_name = state_name + '.sls' - state_file = os.path.join(BASE_FILES, state_file_name) + state_file = os.path.join(RUNTIME_VARS.BASE_FILES, state_file_name) state_key = 'file_|-{0}_|-{0}_|-managed'.format(funny_file) self.addCleanup(os.remove, state_file) @@ -519,7 +519,7 @@ def test_managed_contents(self): ''' state_name = 'file-FileTest-test_managed_contents' state_filename = state_name + '.sls' - state_file = os.path.join(BASE_FILES, state_filename) + state_file = os.path.join(RUNTIME_VARS.BASE_FILES, state_filename) managed_files = {} state_keys = {} @@ -607,8 +607,8 @@ def test_managed_local_source_with_source_hash(self): ''' Make sure that we enforce the source_hash even with local files ''' - name = os.path.join(TMP, 'local_source_with_source_hash') - local_path = os.path.join(BASE_FILES, 'grail', 'scene33') + name = os.path.join(RUNTIME_VARS.TMP, 'local_source_with_source_hash') + local_path = os.path.join(RUNTIME_VARS.BASE_FILES, 'grail', 'scene33') actual_hash = '567fd840bf1548edc35c48eb66cdd78bfdfcccff' if IS_WINDOWS: # CRLF vs LF causes a different hash on windows @@ -666,8 +666,8 @@ def test_managed_local_source_does_not_exist(self): ''' Make sure that we exit gracefully when a local source doesn't exist ''' - name = os.path.join(TMP, 'local_source_does_not_exist') - local_path = os.path.join(BASE_FILES, 'grail', 'scene99') + name = os.path.join(RUNTIME_VARS.TMP, 'local_source_does_not_exist') + local_path = os.path.join(RUNTIME_VARS.BASE_FILES, 'grail', 'scene99') for proto in ('file://', ''): source = proto + local_path @@ -710,7 +710,7 @@ def test_managed_unicode_jinja_with_tojson_filter(self): should produce an inline data structure which is valid YAML and will be loaded properly by our YAML loader. ''' - test_file = os.path.join(TMP, 'test-tojson.txt') + test_file = os.path.join(RUNTIME_VARS.TMP, 'test-tojson.txt') ret = self.run_function( 'state.apply', mods='tojson', @@ -732,10 +732,10 @@ def test_managed_source_hash_indifferent_case(self): This is a regression test for Issue #38914 and Issue #48230 (test=true use). ''' - name = os.path.join(TMP, 'source_hash_indifferent_case') + name = os.path.join(RUNTIME_VARS.TMP, 'source_hash_indifferent_case') state_name = 'file_|-{0}_|' \ '-{0}_|-managed'.format(name) - local_path = os.path.join(BASE_FILES, 'hello_world.txt') + local_path = os.path.join(RUNTIME_VARS.BASE_FILES, 'hello_world.txt') actual_hash = 'c98c24b677eff44860afea6f493bbaec5bb1c4cbb209c6fc2bbb47f66ff2ad31' if IS_WINDOWS: # CRLF vs LF causes a differnt hash on windows @@ -909,7 +909,7 @@ def test_directory(self): ''' file.directory ''' - name = os.path.join(TMP, 'a_new_dir') + name = os.path.join(RUNTIME_VARS.TMP, 'a_new_dir') ret = self.run_state('file.directory', name=name) self.assertSaltTrueReturn(ret) self.assertTrue(os.path.isdir(name)) @@ -920,8 +920,8 @@ def test_directory_symlink_dry_run(self): test=True ''' try: - tmp_dir = os.path.join(TMP, 'pgdata') - sym_dir = os.path.join(TMP, 'pg_data') + tmp_dir = os.path.join(RUNTIME_VARS.TMP, 'pgdata') + sym_dir = os.path.join(RUNTIME_VARS.TMP, 'pg_data') os.mkdir(tmp_dir, 0o700) @@ -957,7 +957,7 @@ def _get_oct_mode(name): ''' return salt.utils.files.normalize_mode(oct(os.stat(name).st_mode & 0o777)) - top = os.path.join(TMP, 'top_dir') + top = os.path.join(RUNTIME_VARS.TMP, 'top_dir') sub = os.path.join(top, 'sub_dir') subsub = os.path.join(sub, 'sub_sub_dir') dirs = [top, sub, subsub] @@ -1004,7 +1004,7 @@ def test_test_directory(self): ''' file.directory ''' - name = os.path.join(TMP, 'a_not_dir') + name = os.path.join(RUNTIME_VARS.TMP, 'a_not_dir') ret = self.run_state('file.directory', test=True, name=name) self.assertSaltNoneReturn(ret) self.assertFalse(os.path.isdir(name)) @@ -1038,7 +1038,7 @@ def test_directory_is_idempotent(self): ''' Ensure the file.directory state produces no changes when rerun. ''' - name = os.path.join(TMP, 'a_dir_twice') + name = os.path.join(RUNTIME_VARS.TMP, 'a_dir_twice') if IS_WINDOWS: username = os.environ.get('USERNAME', 'Administrators') @@ -1154,7 +1154,7 @@ def test_directory_clean_require_in(self, name): ''' state_name = 'file-FileTest-test_directory_clean_require_in' state_filename = state_name + '.sls' - state_file = os.path.join(BASE_FILES, state_filename) + state_file = os.path.join(RUNTIME_VARS.BASE_FILES, state_filename) wrong_file = os.path.join(name, "wrong") with salt.utils.files.fopen(wrong_file, "w") as fp: @@ -1187,7 +1187,7 @@ def test_directory_clean_require_in_with_id(self, name): ''' state_name = 'file-FileTest-test_directory_clean_require_in_with_id' state_filename = state_name + '.sls' - state_file = os.path.join(BASE_FILES, state_filename) + state_file = os.path.join(RUNTIME_VARS.BASE_FILES, state_filename) wrong_file = os.path.join(name, "wrong") with salt.utils.files.fopen(wrong_file, "w") as fp: @@ -1222,7 +1222,7 @@ def test_directory_clean_require_with_name(self, name): ''' state_name = 'file-FileTest-test_directory_clean_require_in_with_id' state_filename = state_name + '.sls' - state_file = os.path.join(BASE_FILES, state_filename) + state_file = os.path.join(RUNTIME_VARS.BASE_FILES, state_filename) wrong_file = os.path.join(name, "wrong") with salt.utils.files.fopen(wrong_file, "w") as fp: @@ -1256,7 +1256,7 @@ def test_directory_broken_symlink(self): contains broken symbolic link ''' try: - tmp_dir = os.path.join(TMP, 'foo') + tmp_dir = os.path.join(RUNTIME_VARS.TMP, 'foo') null_file = '{0}/null'.format(tmp_dir) broken_link = '{0}/broken'.format(tmp_dir) @@ -1543,10 +1543,10 @@ def test_replace_issue_18612_prepend(self, base_dir): ''' test_name = 'test_replace_issue_18612_prepend' path_in = os.path.join( - FILES, 'file.replace', '{0}.in'.format(test_name) + RUNTIME_VARS.FILES, 'file.replace', '{0}.in'.format(test_name) ) path_out = os.path.join( - FILES, 'file.replace', '{0}.out'.format(test_name) + RUNTIME_VARS.FILES, 'file.replace', '{0}.out'.format(test_name) ) path_test = os.path.join(base_dir, test_name) @@ -1584,10 +1584,10 @@ def test_replace_issue_18612_append(self, base_dir): ''' test_name = 'test_replace_issue_18612_append' path_in = os.path.join( - FILES, 'file.replace', '{0}.in'.format(test_name) + RUNTIME_VARS.FILES, 'file.replace', '{0}.in'.format(test_name) ) path_out = os.path.join( - FILES, 'file.replace', '{0}.out'.format(test_name) + RUNTIME_VARS.FILES, 'file.replace', '{0}.out'.format(test_name) ) path_test = os.path.join(base_dir, test_name) @@ -1625,10 +1625,10 @@ def test_replace_issue_18612_append_not_found_content(self, base_dir): ''' test_name = 'test_replace_issue_18612_append_not_found_content' path_in = os.path.join( - FILES, 'file.replace', '{0}.in'.format(test_name) + RUNTIME_VARS.FILES, 'file.replace', '{0}.in'.format(test_name) ) path_out = os.path.join( - FILES, 'file.replace', '{0}.out'.format(test_name) + RUNTIME_VARS.FILES, 'file.replace', '{0}.out'.format(test_name) ) path_test = os.path.join(base_dir, test_name) @@ -1673,10 +1673,10 @@ def test_replace_issue_18612_change_mid_line_with_comment(self, base_dir): ''' test_name = 'test_replace_issue_18612_change_mid_line_with_comment' path_in = os.path.join( - FILES, 'file.replace', '{0}.in'.format(test_name) + RUNTIME_VARS.FILES, 'file.replace', '{0}.in'.format(test_name) ) path_out = os.path.join( - FILES, 'file.replace', '{0}.out'.format(test_name) + RUNTIME_VARS.FILES, 'file.replace', '{0}.out'.format(test_name) ) path_test = os.path.join(base_dir, test_name) @@ -1716,7 +1716,7 @@ def test_replace_issue_18841_no_changes(self, base_dir): ''' test_name = 'test_replace_issue_18841_no_changes' path_in = os.path.join( - FILES, 'file.replace', '{0}.in'.format(test_name) + RUNTIME_VARS.FILES, 'file.replace', '{0}.in'.format(test_name) ) path_test = os.path.join(base_dir, test_name) @@ -1761,7 +1761,7 @@ def test_serialize(self): Test to ensure that file.serialize returns a data structure that's both serialized and formatted properly ''' - path_test = os.path.join(TMP, 'test_serialize') + path_test = os.path.join(RUNTIME_VARS.TMP, 'test_serialize') ret = self.run_state('file.serialize', name=path_test, dataset={'name': 'naive', @@ -1854,7 +1854,7 @@ def test_replace_issue_18841_omit_backup(self, base_dir): ''' test_name = 'test_replace_issue_18841_omit_backup' path_in = os.path.join( - FILES, 'file.replace', '{0}.in'.format(test_name) + RUNTIME_VARS.FILES, 'file.replace', '{0}.in'.format(test_name) ) path_test = os.path.join(base_dir, test_name) @@ -2235,7 +2235,7 @@ def test_issue_2726_mode_kwarg(self, dir1, dir2): @with_tempdir() def test_issue_8343_accumulated_require_in(self, base_dir): - template_path = os.path.join(TMP_STATE_TREE, 'issue-8343.sls') + template_path = os.path.join(RUNTIME_VARS.TMP_STATE_TREE, 'issue-8343.sls') testcase_filedest = os.path.join(base_dir, 'issue-8343.txt') if os.path.exists(template_path): os.remove(template_path) @@ -2309,7 +2309,7 @@ def test_issue_8343_accumulated_require_in(self, base_dir): @skipIf(salt.utils.platform.is_darwin() and six.PY2, 'This test hangs on OS X on Py2') def test_issue_11003_immutable_lazy_proxy_sum(self, base_dir): # causes the Import-Module ServerManager error on Windows - template_path = os.path.join(TMP_STATE_TREE, 'issue-11003.sls') + template_path = os.path.join(RUNTIME_VARS.TMP_STATE_TREE, 'issue-11003.sls') testcase_filedest = os.path.join(base_dir, 'issue-11003.txt') sls_template = [ 'a{0}:', @@ -2377,7 +2377,7 @@ def test_issue_8947_utf8_sls(self, base_dir): korean_3 = '마지막 행' test_file = os.path.join(base_dir, '{0}.txt'.format(korean_1)) test_file_encoded = test_file - template_path = os.path.join(TMP_STATE_TREE, 'issue-8947.sls') + template_path = os.path.join(RUNTIME_VARS.TMP_STATE_TREE, 'issue-8947.sls') # create the sls template template = textwrap.dedent('''\ some-utf8-file-create: @@ -2598,8 +2598,8 @@ def test_issue_25250_force_copy_deletes(self, source, dest): ''' ensure force option in copy state does not delete target file ''' - shutil.copyfile(os.path.join(FILES, 'hosts'), source) - shutil.copyfile(os.path.join(FILES, 'file/base/cheese'), dest) + shutil.copyfile(os.path.join(RUNTIME_VARS.FILES, 'hosts'), source) + shutil.copyfile(os.path.join(RUNTIME_VARS.FILES, 'file/base/cheese'), dest) self.run_state('file.copy', name=dest, source=source, force=True) self.assertTrue(os.path.exists(dest)) @@ -2615,17 +2615,17 @@ def test_file_copy_make_dirs(self, source): ''' ensure make_dirs creates correct user perms ''' - shutil.copyfile(os.path.join(FILES, 'hosts'), source) - dest = os.path.join(TMP, 'dir1', 'dir2', 'copied_file.txt') + shutil.copyfile(os.path.join(RUNTIME_VARS.FILES, 'hosts'), source) + dest = os.path.join(RUNTIME_VARS.TMP, 'dir1', 'dir2', 'copied_file.txt') user = 'salt' mode = '0644' ret = self.run_function('user.add', [user]) self.assertTrue(ret, 'Failed to add user. Are you running as sudo?') ret = self.run_state('file.copy', name=dest, source=source, user=user, - makedirs=True, mode=mode) + makedirs=True, mode=mode) self.assertSaltTrueReturn(ret) - file_checks = [dest, os.path.join(TMP, 'dir1'), os.path.join(TMP, 'dir1', 'dir2')] + file_checks = [dest, os.path.join(RUNTIME_VARS.TMP, 'dir1'), os.path.join(RUNTIME_VARS.TMP, 'dir1', 'dir2')] for check in file_checks: user_check = self.run_function('file.get_user', [check]) mode_check = self.run_function('file.get_mode', [check]) @@ -2657,7 +2657,7 @@ def test_owner_after_setuid(self, user, group): # Desired configuration. desired = { - 'file': os.path.join(TMP, 'file_with_setuid'), + 'file': os.path.join(RUNTIME_VARS.TMP, 'file_with_setuid'), 'user': user, 'group': group, 'mode': '4750' @@ -2686,7 +2686,7 @@ def test_binary_contents(self): ''' This tests to ensure that binary contents do not cause a traceback. ''' - name = os.path.join(TMP, '1px.gif') + name = os.path.join(RUNTIME_VARS.TMP, '1px.gif') try: ret = self.run_state( 'file.managed', @@ -2705,7 +2705,7 @@ def test_binary_contents_twice(self): that the file is in the correct state. ''' # Create a binary file - name = os.path.join(TMP, '1px.gif') + name = os.path.join(RUNTIME_VARS.TMP, '1px.gif') # First run state ensures file is created ret = self.run_state('file.managed', name=name, contents=BINARY_FILE) @@ -2801,11 +2801,11 @@ def test_managed_file_issue_51208(self): ''' Test to ensure we can handle a file with escaped double-quotes ''' - name = os.path.join(TMP, 'issue_51208.txt') + name = os.path.join(RUNTIME_VARS.TMP, 'issue_51208.txt') ret = self.run_state( 'file.managed', name=name, source='salt://issue-51208/vimrc.stub' ) - src = os.path.join(BASE_FILES, 'issue-51208', 'vimrc.stub') + src = os.path.join(RUNTIME_VARS.BASE_FILES, 'issue-51208', 'vimrc.stub') with salt.utils.files.fopen(src, 'r') as fp_: master_data = fp_.read() with salt.utils.files.fopen(name, 'r') as fp_: @@ -4174,7 +4174,7 @@ def setUpClass(cls): cls.all_patch_template_http = \ cls.webserver.url(cls.all_patch_template_path) - patches_dir = os.path.join(FILES, 'file', 'base', 'patches') + patches_dir = os.path.join(RUNTIME_VARS.FILES, 'file', 'base', 'patches') cls.numbers_patch_hash = salt.utils.hashutils.get_hash( os.path.join(patches_dir, cls.numbers_patch_name) ) @@ -4204,7 +4204,7 @@ def setUp(self): ''' Create a new unpatched set of files ''' - self.base_dir = tempfile.mkdtemp(dir=TMP) + self.base_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) os.makedirs(os.path.join(self.base_dir, 'foo', 'bar')) self.numbers_file = os.path.join(self.base_dir, 'foo', 'numbers.txt') self.math_file = os.path.join(self.base_dir, 'foo', 'bar', 'math.txt') diff --git a/tests/integration/states/test_git.py b/tests/integration/states/test_git.py index bcab361df17f..ebc4799a4b52 100644 --- a/tests/integration/states/test_git.py +++ b/tests/integration/states/test_git.py @@ -14,10 +14,10 @@ import tempfile # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.case import ModuleCase from tests.support.helpers import with_tempdir from tests.support.mixins import SaltReturnAssertsMixin -from tests.support.paths import TMP # Import salt libs import salt.utils.files @@ -90,7 +90,7 @@ class WithGitMirror(object): def __init__(self, repo_url, **kwargs): self.repo_url = repo_url if 'dir' not in kwargs: - kwargs['dir'] = TMP + kwargs['dir'] = RUNTIME_VARS.TMP self.kwargs = kwargs def __call__(self, func): @@ -835,9 +835,9 @@ class LocalRepoGitTest(ModuleCase, SaltReturnAssertsMixin): Tests which do no require connectivity to github.com ''' def setUp(self): - self.repo = tempfile.mkdtemp(dir=TMP) - self.admin = tempfile.mkdtemp(dir=TMP) - self.target = tempfile.mkdtemp(dir=TMP) + self.repo = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) + self.admin = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) + self.target = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) for dirname in (self.repo, self.admin, self.target): self.addCleanup(shutil.rmtree, dirname, ignore_errors=True) diff --git a/tests/integration/states/test_host.py b/tests/integration/states/test_host.py index 1eac631d19c1..4217ae60dbf3 100644 --- a/tests/integration/states/test_host.py +++ b/tests/integration/states/test_host.py @@ -9,16 +9,14 @@ import shutil # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.case import ModuleCase -from tests.support.paths import FILES, TMP from tests.support.mixins import SaltReturnAssertsMixin # Import salt libs import salt.utils.files import salt.utils.stringutils -HFILE = os.path.join(TMP, 'hosts') - class HostTest(ModuleCase, SaltReturnAssertsMixin): ''' @@ -26,13 +24,14 @@ class HostTest(ModuleCase, SaltReturnAssertsMixin): ''' def setUp(self): - shutil.copyfile(os.path.join(FILES, 'hosts'), HFILE) + self.hfpath = os.path.join(RUNTIME_VARS.TMP, 'hosts') + shutil.copyfile(os.path.join(RUNTIME_VARS.FILES, 'hosts'), self.hfpath) + self.addCleanup(self._delete_hosts_file) super(HostTest, self).setUp() - def tearDown(self): - if os.path.exists(HFILE): - os.remove(HFILE) - super(HostTest, self).tearDown() + def _delete_hosts_file(self): + if os.path.exists(self.hfpath): + os.remove(self.hfpath) def test_present(self): ''' @@ -42,6 +41,6 @@ def test_present(self): ip = '10.10.10.10' ret = self.run_state('host.present', name=name, ip=ip) self.assertSaltTrueReturn(ret) - with salt.utils.files.fopen(HFILE) as fp_: + with salt.utils.files.fopen(self.hfpath) as fp_: output = salt.utils.stringutils.to_unicode(fp_.read()) self.assertIn('{0}\t\t{1}'.format(ip, name), output) diff --git a/tests/integration/states/test_match.py b/tests/integration/states/test_match.py index e4abc174a66f..6a7f41168ad1 100644 --- a/tests/integration/states/test_match.py +++ b/tests/integration/states/test_match.py @@ -13,15 +13,13 @@ # Import Salt Testing libs from tests.support.case import ModuleCase -from tests.support.paths import FILES from tests.support.helpers import skip_if_not_root +from tests.support.runtests import RUNTIME_VARS # Import salt libs import salt.utils.files import salt.utils.stringutils -STATE_DIR = os.path.join(FILES, 'file', 'base') - class StateMatchTest(ModuleCase): ''' @@ -33,7 +31,7 @@ def test_issue_2167_ipcidr_no_AttributeError(self): subnets = self.run_function('network.subnets') self.assertTrue(len(subnets) > 0) top_filename = 'issue-2167-ipcidr-match.sls' - top_file = os.path.join(STATE_DIR, top_filename) + top_file = os.path.join(RUNTIME_VARS.BASE_FILES, top_filename) try: with salt.utils.files.fopen(top_file, 'w') as fp_: fp_.write( diff --git a/tests/integration/states/test_ssh_known_hosts.py b/tests/integration/states/test_ssh_known_hosts.py index 339f4bb05a48..18ce9077165e 100644 --- a/tests/integration/states/test_ssh_known_hosts.py +++ b/tests/integration/states/test_ssh_known_hosts.py @@ -14,7 +14,6 @@ from tests.support.runtests import RUNTIME_VARS from tests.support.helpers import skip_if_binaries_missing -KNOWN_HOSTS = os.path.join(RUNTIME_VARS.TMP, 'known_hosts') GITHUB_FINGERPRINT = '9d:38:5b:83:a9:17:52:92:56:1a:5e:c4:d4:81:8e:0a:ca:51:a2:64:f1:74:20:11:2e:f8:8a:c3:a1:39:49:8f' GITHUB_IP = '192.30.253.113' @@ -24,9 +23,13 @@ class SSHKnownHostsStateTest(ModuleCase, SaltReturnAssertsMixin): ''' Validate the ssh state ''' + @classmethod + def setUpClass(cls): + cls.known_hosts = os.path.join(RUNTIME_VARS.TMP, 'known_hosts') + def tearDown(self): - if os.path.isfile(KNOWN_HOSTS): - os.remove(KNOWN_HOSTS) + if os.path.isfile(self.known_hosts): + os.remove(self.known_hosts) super(SSHKnownHostsStateTest, self).tearDown() def test_present(self): @@ -37,7 +40,7 @@ def test_present(self): 'name': 'github.com', 'user': 'root', 'fingerprint': GITHUB_FINGERPRINT, - 'config': KNOWN_HOSTS + 'config': self.known_hosts } # test first ret = self.run_state('ssh_known_hosts.present', test=True, **kwargs) @@ -86,7 +89,7 @@ def test_present(self): # record for every host must be available ret = self.run_function( - 'ssh.get_known_host_entries', ['root', 'github.com'], config=KNOWN_HOSTS + 'ssh.get_known_host_entries', ['root', 'github.com'], config=self.known_hosts )[0] try: self.assertNotIn(ret, ('', None)) @@ -95,7 +98,7 @@ def test_present(self): 'Salt return \'{0}\' is in (\'\', None).'.format(ret) ) ret = self.run_function( - 'ssh.get_known_host_entries', ['root', GITHUB_IP], config=KNOWN_HOSTS + 'ssh.get_known_host_entries', ['root', GITHUB_IP], config=self.known_hosts )[0] try: self.assertNotIn(ret, ('', None, {})) @@ -111,7 +114,7 @@ def test_present_fail(self): name='github.com', user='root', fingerprint='aa:bb:cc:dd', - config=KNOWN_HOSTS + config=self.known_hosts ) self.assertSaltFalseReturn(ret) @@ -120,15 +123,15 @@ def test_absent(self): ssh_known_hosts.absent ''' known_hosts = os.path.join(RUNTIME_VARS.FILES, 'ssh', 'known_hosts') - shutil.copyfile(known_hosts, KNOWN_HOSTS) - if not os.path.isfile(KNOWN_HOSTS): + shutil.copyfile(known_hosts, self.known_hosts) + if not os.path.isfile(self.known_hosts): self.skipTest( 'Unable to copy {0} to {1}'.format( - known_hosts, KNOWN_HOSTS + known_hosts, self.known_hosts ) ) - kwargs = {'name': 'github.com', 'user': 'root', 'config': KNOWN_HOSTS} + kwargs = {'name': 'github.com', 'user': 'root', 'config': self.known_hosts} # test first ret = self.run_state('ssh_known_hosts.absent', test=True, **kwargs) self.assertSaltNoneReturn(ret) diff --git a/tests/integration/states/test_supervisord.py b/tests/integration/states/test_supervisord.py index 5c24924a8737..9fb46167f5a9 100644 --- a/tests/integration/states/test_supervisord.py +++ b/tests/integration/states/test_supervisord.py @@ -11,9 +11,9 @@ import subprocess # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.case import ModuleCase from tests.support.unit import skipIf -from tests.support.paths import TMP from tests.support.mixins import SaltReturnAssertsMixin # Import salt libs @@ -34,7 +34,7 @@ class SupervisordTest(ModuleCase, SaltReturnAssertsMixin): def setUp(self): super(SupervisordTest, self).setUp() - self.venv_test_dir = os.path.join(TMP, 'supervisortests') + self.venv_test_dir = os.path.join(RUNTIME_VARS.TMP, 'supervisortests') self.venv_dir = os.path.join(self.venv_test_dir, 'venv') self.supervisor_sock = os.path.join(self.venv_dir, 'supervisor.sock') diff --git a/tests/integration/states/test_svn.py b/tests/integration/states/test_svn.py index 53a2df3adf6e..115c7133b9c9 100644 --- a/tests/integration/states/test_svn.py +++ b/tests/integration/states/test_svn.py @@ -11,8 +11,8 @@ import socket # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.case import ModuleCase -from tests.support.paths import TMP from tests.support.mixins import SaltReturnAssertsMixin @@ -37,7 +37,7 @@ def setUp(self): msg = 'error resolving {0}, possible network issue?' self.skipTest(msg.format(self.__domain)) - self.target = os.path.join(TMP, 'apache_http_test_repo') + self.target = os.path.join(RUNTIME_VARS.TMP, 'apache_http_test_repo') self.name = 'http://{0}/repos/asf/httpd/httpd/trunk/test/'.format( self.__domain ) diff --git a/tests/integration/states/test_x509.py b/tests/integration/states/test_x509.py index 1808d3c19ef2..bbb59bb49812 100644 --- a/tests/integration/states/test_x509.py +++ b/tests/integration/states/test_x509.py @@ -8,10 +8,10 @@ import textwrap from tests.support.helpers import with_tempfile -from tests.support.paths import BASE_FILES, TMP, TMP_PILLAR_TREE from tests.support.case import ModuleCase from tests.support.unit import skipIf from tests.support.mixins import SaltReturnAssertsMixin +from tests.support.runtests import RUNTIME_VARS try: import M2Crypto # pylint: disable=W0611 @@ -28,12 +28,12 @@ class x509Test(ModuleCase, SaltReturnAssertsMixin): @classmethod def setUpClass(cls): - cert_path = os.path.join(BASE_FILES, 'x509_test.crt') + cert_path = os.path.join(RUNTIME_VARS.BASE_FILES, 'x509_test.crt') with salt.utils.files.fopen(cert_path) as fp: cls.x509_cert_text = fp.read() def setUp(self): - with salt.utils.files.fopen(os.path.join(TMP_PILLAR_TREE, 'signing_policies.sls'), 'w') as fp: + with salt.utils.files.fopen(os.path.join(RUNTIME_VARS.TMP_PILLAR_TREE, 'signing_policies.sls'), 'w') as fp: fp.write(textwrap.dedent('''\ x509_signing_policies: ca_policy: @@ -48,8 +48,8 @@ def setUp(self): - authorityKeyIdentifier: keyid - days_valid: 730 - copypath: {0}/pki - '''.format(TMP))) - with salt.utils.files.fopen(os.path.join(TMP_PILLAR_TREE, 'top.sls'), 'w') as fp: + '''.format(RUNTIME_VARS.TMP))) + with salt.utils.files.fopen(os.path.join(RUNTIME_VARS.TMP_PILLAR_TREE, 'top.sls'), 'w') as fp: fp.write(textwrap.dedent('''\ base: '*': @@ -58,9 +58,9 @@ def setUp(self): self.run_function('saltutil.refresh_pillar') def tearDown(self): - os.remove(os.path.join(TMP_PILLAR_TREE, 'signing_policies.sls')) - os.remove(os.path.join(TMP_PILLAR_TREE, 'top.sls')) - certs_path = os.path.join(TMP, 'pki') + os.remove(os.path.join(RUNTIME_VARS.TMP_PILLAR_TREE, 'signing_policies.sls')) + os.remove(os.path.join(RUNTIME_VARS.TMP_PILLAR_TREE, 'top.sls')) + certs_path = os.path.join(RUNTIME_VARS.TMP, 'pki') if os.path.exists(certs_path): salt.utils.files.rm_rf(certs_path) self.run_function('saltutil.refresh_pillar') @@ -97,8 +97,8 @@ def test_issue_49008(self, keyfile, crtfile): assert os.path.exists(crtfile) def test_cert_signing(self): - ret = self.run_function('state.apply', ['test_cert'], pillar={'tmp_dir': TMP}) - key = 'x509_|-test_crt_|-{}/pki/test.crt_|-certificate_managed'.format(TMP) + ret = self.run_function('state.apply', ['test_cert'], pillar={'tmp_dir': RUNTIME_VARS.TMP}) + key = 'x509_|-test_crt_|-{}/pki/test.crt_|-certificate_managed'.format(RUNTIME_VARS.TMP) assert key in ret assert 'changes' in ret[key] assert 'Certificate' in ret[key]['changes'] diff --git a/tests/integration/utils/test_win_runas.py b/tests/integration/utils/test_win_runas.py index 3042a77991da..b0cd2157968f 100644 --- a/tests/integration/utils/test_win_runas.py +++ b/tests/integration/utils/test_win_runas.py @@ -17,8 +17,8 @@ import yaml from tests.support.case import ModuleCase from tests.support.mock import Mock -from tests.support.paths import CODE_DIR from tests.support.unit import skipIf +from tests.support.runtests import RUNTIME_VARS from tests.support.helpers import ( with_system_user, @@ -33,7 +33,7 @@ import win32event import servicemanager import win32api - CODE_DIR = win32api.GetLongPathName(CODE_DIR) + CODE_DIR = win32api.GetLongPathName(RUNTIME_VARS.CODE_DIR) HAS_WIN32 = True except ImportError: # Mock win32serviceutil object to avoid @@ -52,8 +52,9 @@ 'points:\n---------------------------------------------\n\n' 'INFO: No shared open files found.\n' ) -RUNAS_PATH = os.path.abspath(os.path.join(CODE_DIR, 'runas.py')) -RUNAS_OUT = os.path.abspath(os.path.join(CODE_DIR, 'runas.out')) +if HAS_WIN32: + RUNAS_PATH = os.path.abspath(os.path.join(CODE_DIR, 'runas.py')) + RUNAS_OUT = os.path.abspath(os.path.join(CODE_DIR, 'runas.out')) def default_target(service, *args, **kwargs): diff --git a/tests/integration/utils/testprogram.py b/tests/integration/utils/testprogram.py index 7f80af4aec62..985325479e20 100644 --- a/tests/integration/utils/testprogram.py +++ b/tests/integration/utils/testprogram.py @@ -31,7 +31,7 @@ from tests.support.unit import TestCase from tests.support.helpers import win32_kill_process_tree -from tests.support.paths import CODE_DIR +from tests.support.runtests import RUNTIME_VARS from tests.support.processes import terminate_process, terminate_process_list log = logging.getLogger(__name__) @@ -389,8 +389,8 @@ def run( if path not in env_pypath: env_pypath.append(path) # Always ensure that the test tree is searched first for python modules - if CODE_DIR != env_pypath[0]: - env_pypath.insert(0, CODE_DIR) + if RUNTIME_VARS.CODE_DIR != env_pypath[0]: + env_pypath.insert(0, RUNTIME_VARS.CODE_DIR) if salt.utils.platform.is_windows(): env_delta['PYTHONPATH'] = ';'.join(env_pypath) else: @@ -694,7 +694,7 @@ def setup(self, *args, **kwargs): def install_script(self): '''Generate the script file that calls python objects and libraries.''' lines = [] - script_source = os.path.join(CODE_DIR, 'scripts', self.script) + script_source = os.path.join(RUNTIME_VARS.CODE_DIR, 'scripts', self.script) with salt.utils.files.fopen(script_source, 'r') as sso: lines.extend(sso.readlines()) if lines[0].startswith('#!'): diff --git a/tests/support/cherrypy_testclasses.py b/tests/support/cherrypy_testclasses.py index 3686a3597e6f..37d72ad5d6ca 100644 --- a/tests/support/cherrypy_testclasses.py +++ b/tests/support/cherrypy_testclasses.py @@ -11,7 +11,7 @@ import salt.config from tests.support.mock import patch -from tests.support.paths import TMP_CONF_DIR +from tests.support.runtests import RUNTIME_VARS if HAS_CHERRYPY: from tests.support.cptestcase import BaseCherryPyTestCase @@ -39,7 +39,7 @@ def __get_opts__(self): @classmethod def setUpClass(cls): - master_conf = os.path.join(TMP_CONF_DIR, 'master') + master_conf = os.path.join(RUNTIME_VARS.TMP_CONF_DIR, 'master') cls.config = salt.config.client_config(master_conf) cls.base_opts = {} cls.base_opts.update(cls.config) @@ -54,7 +54,7 @@ def setUp(self): self.app = app self.addCleanup(delattr, self, 'app') - master_conf = os.path.join(TMP_CONF_DIR, 'master') + master_conf = os.path.join(RUNTIME_VARS.TMP_CONF_DIR, 'master') client_config = salt.config.client_config(master_conf) base_opts = {} base_opts.update(client_config) diff --git a/tests/support/helpers.py b/tests/support/helpers.py index 7eda1de151a4..67b7c927bd6d 100644 --- a/tests/support/helpers.py +++ b/tests/support/helpers.py @@ -44,7 +44,7 @@ # Import Salt Tests Support libs from tests.support.unit import skip, _id, SkipTest from tests.support.mock import patch -from tests.support.paths import FILES, TMP +from tests.support.runtests import RUNTIME_VARS # Import Salt libs import salt.utils.files @@ -72,7 +72,7 @@ def no_symlinks(): try: output = subprocess.Popen( ['git', 'config', '--get', 'core.symlinks'], - cwd=TMP, + cwd=RUNTIME_VARS.TMP, stdout=subprocess.PIPE).communicate()[0] except OSError as exc: if exc.errno != errno.ENOENT: @@ -1013,7 +1013,7 @@ class WithTempfile(object): def __init__(self, **kwargs): self.create = kwargs.pop('create', True) if 'dir' not in kwargs: - kwargs['dir'] = TMP + kwargs['dir'] = RUNTIME_VARS.TMP if 'prefix' not in kwargs: kwargs['prefix'] = '__salt.test.' self.kwargs = kwargs @@ -1044,7 +1044,7 @@ class WithTempdir(object): def __init__(self, **kwargs): self.create = kwargs.pop('create', True) if 'dir' not in kwargs: - kwargs['dir'] = TMP + kwargs['dir'] = RUNTIME_VARS.TMP self.kwargs = kwargs def __call__(self, func): @@ -1517,7 +1517,7 @@ def __init__(self, raise ValueError('port must be an integer') if root is None: - root = os.path.join(FILES, 'file', 'base') + root = RUNTIME_VARS.BASE_FILES try: self.root = os.path.realpath(root) except AttributeError: diff --git a/tests/support/runtests.py b/tests/support/runtests.py index dc61917c9a1c..97dfa4a6da20 100644 --- a/tests/support/runtests.py +++ b/tests/support/runtests.py @@ -176,6 +176,11 @@ def __setattr__(self, name, value): TMP_PILLAR_TREE=paths.TMP_PILLAR_TREE, TMP_PRODENV_STATE_TREE=paths.TMP_PRODENV_STATE_TREE, RUNNING_TESTS_USER=RUNNING_TESTS_USER, - RUNTIME_CONFIGS={} + RUNTIME_CONFIGS={}, + CODE_DIR=paths.CODE_DIR, + BASE_FILES=paths.BASE_FILES, + PROD_FILES=paths.PROD_FILES, + TESTS_DIR=paths.TESTS_DIR, + PYTEST_SESSION=False ) # <---- Tests Runtime Variables -------------------------------------------------------------------------------------- diff --git a/tests/unit/cache/test_localfs.py b/tests/unit/cache/test_localfs.py index b80cfd2031a2..d0bca2875c30 100644 --- a/tests/unit/cache/test_localfs.py +++ b/tests/unit/cache/test_localfs.py @@ -10,8 +10,8 @@ import tempfile # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.mixins import LoaderModuleMockMixin -from tests.support.paths import TMP from tests.support.unit import skipIf, TestCase from tests.support.mock import ( MagicMock, @@ -93,7 +93,7 @@ def test_store_success(self): Tests that the store function writes the data to the serializer for storage. ''' # Create a temporary cache dir - tmp_dir = tempfile.mkdtemp(dir=TMP) + tmp_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) # Use the helper function to create the cache file using localfs.store() self._create_tmp_cache_file(tmp_dir, salt.payload.Serial(self)) @@ -127,7 +127,7 @@ def test_fetch_success(self): Tests that the fetch function is able to read the cache file and return its data. ''' # Create a temporary cache dir - tmp_dir = tempfile.mkdtemp(dir=TMP) + tmp_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) # Create a new serializer object to use in function patches serializer = salt.payload.Serial(self) @@ -164,7 +164,7 @@ def test_updated_success(self): Test that the updated function returns the modification time of the cache file ''' # Create a temporary cache dir - tmp_dir = tempfile.mkdtemp(dir=TMP) + tmp_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) # Use the helper function to create the cache file using localfs.store() self._create_tmp_cache_file(tmp_dir, salt.payload.Serial(self)) @@ -197,7 +197,7 @@ def test_flush_success(self): ''' with patch('os.path.isfile', MagicMock(return_value=True)): # Create a temporary cache dir - tmp_dir = tempfile.mkdtemp(dir=TMP) + tmp_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) # Use the helper function to create the cache file using localfs.store() self._create_tmp_cache_file(tmp_dir, salt.payload.Serial(self)) @@ -239,7 +239,7 @@ def test_list_success(self): Tests the return of the ls function containing bank entries. ''' # Create a temporary cache dir - tmp_dir = tempfile.mkdtemp(dir=TMP) + tmp_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) # Use the helper function to create the cache file using localfs.store() self._create_tmp_cache_file(tmp_dir, salt.payload.Serial(self)) @@ -256,7 +256,7 @@ def test_contains(self): is provided. ''' # Create a temporary cache dir - tmp_dir = tempfile.mkdtemp(dir=TMP) + tmp_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) # Use the helper function to create the cache file using localfs.store() self._create_tmp_cache_file(tmp_dir, salt.payload.Serial(self)) diff --git a/tests/unit/client/test_ssh.py b/tests/unit/client/test_ssh.py index 0d52ceccec4f..85560ec8bcd1 100644 --- a/tests/unit/client/test_ssh.py +++ b/tests/unit/client/test_ssh.py @@ -10,10 +10,10 @@ import tempfile # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.unit import skipIf, TestCase from tests.support.case import ShellCase from tests.support.mock import NO_MOCK, NO_MOCK_REASON, patch, MagicMock -from tests.support.paths import TMP # Import Salt libs import salt.config @@ -71,7 +71,7 @@ def test_roster_defaults_flat(self): ''' Test Roster Defaults on the flat roster ''' - tempdir = tempfile.mkdtemp(dir=TMP) + tempdir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) expected = { 'self': { 'host': '0.0.0.0', @@ -108,7 +108,7 @@ def test_roster_defaults_flat(self): @skipIf(NO_MOCK, NO_MOCK_REASON) class SSHSingleTests(TestCase): def setUp(self): - self.tmp_cachedir = tempfile.mkdtemp(dir=TMP) + self.tmp_cachedir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) def test_single_opts(self): ''' Sanity check for ssh.Single options diff --git a/tests/unit/cloud/clouds/test_ec2.py b/tests/unit/cloud/clouds/test_ec2.py index 9d7fd6befc47..01b2591a6326 100644 --- a/tests/unit/cloud/clouds/test_ec2.py +++ b/tests/unit/cloud/clouds/test_ec2.py @@ -11,10 +11,10 @@ import salt.utils.files # Import Salt Testing Libs +from tests.support.runtests import RUNTIME_VARS from tests.support.unit import TestCase, skipIf from tests.support.mixins import LoaderModuleMockMixin from tests.support.mock import NO_MOCK, NO_MOCK_REASON, patch, PropertyMock -from tests.support.paths import TMP from tests.unit.test_crypt import PRIVKEY_DATA PASS_DATA = ( @@ -34,7 +34,7 @@ class EC2TestCase(TestCase, LoaderModuleMockMixin): def setUp(self): super(EC2TestCase, self).setUp() - with tempfile.NamedTemporaryFile(dir=TMP, suffix='.pem', delete=True) as fp: + with tempfile.NamedTemporaryFile(dir=RUNTIME_VARS.TMP, suffix='.pem', delete=True) as fp: self.key_file = fp.name def tearDown(self): diff --git a/tests/unit/daemons/test_masterapi.py b/tests/unit/daemons/test_masterapi.py index 441bfd44e323..7347cd920ff2 100644 --- a/tests/unit/daemons/test_masterapi.py +++ b/tests/unit/daemons/test_masterapi.py @@ -13,7 +13,7 @@ import salt.utils.platform # Import Salt Testing Libs -from tests.support.paths import TMP_CONF_DIR +from tests.support.runtests import RUNTIME_VARS from tests.support.unit import TestCase, skipIf from tests.support.mock import ( patch, @@ -570,7 +570,7 @@ class RemoteFuncsTestCase(TestCase): ''' def setUp(self): - opts = salt.config.master_config(os.path.join(TMP_CONF_DIR, 'master')) + opts = salt.config.master_config(os.path.join(RUNTIME_VARS.TMP_CONF_DIR, 'master')) self.funcs = masterapi.RemoteFuncs(opts) self.funcs.cache = FakeCache() diff --git a/tests/unit/fileserver/test_gitfs.py b/tests/unit/fileserver/test_gitfs.py index 09f08dc38e9e..6bf38c3ad9e5 100644 --- a/tests/unit/fileserver/test_gitfs.py +++ b/tests/unit/fileserver/test_gitfs.py @@ -20,10 +20,10 @@ pass # Import Salt Testing Libs +from tests.support.runtests import RUNTIME_VARS from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import NO_MOCK, NO_MOCK_REASON, patch -from tests.support.paths import TMP, FILES # Import salt libs import salt.fileserver.gitfs as gitfs @@ -61,13 +61,12 @@ log = logging.getLogger(__name__) -TMP_SOCK_DIR = tempfile.mkdtemp(dir=TMP) -TMP_REPO_DIR = os.path.join(TMP, 'gitfs_root') +TMP_SOCK_DIR = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) +TMP_REPO_DIR = os.path.join(RUNTIME_VARS.TMP, 'gitfs_root') TMP_FILE_URI = 'file://' if salt.utils.platform.is_windows(): TMP_REPO_DIR = TMP_REPO_DIR.replace('\\', '/') TMP_FILE_URI = TMP_FILE_URI + '/' -INTEGRATION_BASE_FILES = os.path.join(FILES, 'file', 'base') UNICODE_FILENAME = 'питон.txt' UNICODE_DIRNAME = UNICODE_ENVNAME = 'соль' TAG_NAME = 'mytag' @@ -134,8 +133,8 @@ def setUpClass(cls): # Clear the instance map so that we make sure to create a new instance # for this test class. _clear_instance_map() - cls.tmp_cachedir = tempfile.mkdtemp(dir=TMP) - cls.tmp_sock_dir = tempfile.mkdtemp(dir=TMP) + cls.tmp_cachedir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) + cls.tmp_sock_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) @classmethod def tearDownClass(cls): @@ -391,8 +390,8 @@ class GitFSTestBase(object): @classmethod def setUpClass(cls): - cls.tmp_cachedir = tempfile.mkdtemp(dir=TMP) - cls.tmp_sock_dir = tempfile.mkdtemp(dir=TMP) + cls.tmp_cachedir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) + cls.tmp_sock_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) try: shutil.rmtree(TMP_REPO_DIR) @@ -401,7 +400,7 @@ def setUpClass(cls): log.error("Access error removeing file %s", TMP_REPO_DIR) elif exc.errno != errno.ENOENT: raise - shutil.copytree(INTEGRATION_BASE_FILES, TMP_REPO_DIR + '/') + shutil.copytree(RUNTIME_VARS.BASE_FILES, TMP_REPO_DIR + '/') repo = git.Repo.init(TMP_REPO_DIR) diff --git a/tests/unit/fileserver/test_roots.py b/tests/unit/fileserver/test_roots.py index 1044e7bfbae5..cca96fc0e96d 100644 --- a/tests/unit/fileserver/test_roots.py +++ b/tests/unit/fileserver/test_roots.py @@ -11,9 +11,9 @@ # Import Salt Testing libs from tests.support.mixins import AdaptedConfigurationTestCaseMixin, LoaderModuleMockMixin -from tests.support.paths import BASE_FILES, TMP, TMP_STATE_TREE from tests.support.unit import TestCase, skipIf from tests.support.mock import patch, NO_MOCK, NO_MOCK_REASON +from tests.support.runtests import RUNTIME_VARS # Import Salt libs import salt.fileserver.roots as roots @@ -35,10 +35,10 @@ class RootsTest(TestCase, AdaptedConfigurationTestCaseMixin, LoaderModuleMockMixin): def setup_loader_modules(self): - self.tmp_cachedir = tempfile.mkdtemp(dir=TMP) + self.tmp_cachedir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) self.opts = self.get_temp_config('master') self.opts['cachedir'] = self.tmp_cachedir - empty_dir = os.path.join(TMP_STATE_TREE, 'empty_dir') + empty_dir = os.path.join(RUNTIME_VARS.TMP_STATE_TREE, 'empty_dir') if not os.path.isdir(empty_dir): os.makedirs(empty_dir) return {roots: {'__opts__': self.opts}} @@ -49,7 +49,7 @@ def setUpClass(cls): Create special file_roots for symlink test on Windows ''' if salt.utils.platform.is_windows(): - root_dir = tempfile.mkdtemp(dir=TMP) + root_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) source_sym = os.path.join(root_dir, 'source_sym') with salt.utils.files.fopen(source_sym, 'w') as fp_: fp_.write('hello world!\n') @@ -62,8 +62,8 @@ def setUpClass(cls): cls.test_symlink_list_file_roots = {'base': [root_dir]} else: cls.test_symlink_list_file_roots = None - cls.tmp_dir = tempfile.mkdtemp(dir=TMP) - full_path_to_file = os.path.join(BASE_FILES, 'testfile') + cls.tmp_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) + full_path_to_file = os.path.join(RUNTIME_VARS.BASE_FILES, 'testfile') with salt.utils.files.fopen(full_path_to_file, 'rb') as s_fp: with salt.utils.files.fopen(os.path.join(cls.tmp_dir, 'testfile'), 'wb') as d_fp: for line in s_fp: @@ -93,7 +93,7 @@ def test_find_file(self): ret = roots.find_file('testfile') self.assertEqual('testfile', ret['rel']) - full_path_to_file = os.path.join(BASE_FILES, 'testfile') + full_path_to_file = os.path.join(RUNTIME_VARS.BASE_FILES, 'testfile') self.assertEqual(full_path_to_file, ret['path']) def test_serve_file(self): @@ -107,7 +107,7 @@ def test_serve_file(self): ret = roots.serve_file(load, fnd) with salt.utils.files.fopen( - os.path.join(BASE_FILES, 'testfile'), 'rb') as fp_: + os.path.join(RUNTIME_VARS.BASE_FILES, 'testfile'), 'rb') as fp_: data = fp_.read() self.assertDictEqual( @@ -137,7 +137,7 @@ def test_file_hash(self): # Hashes are different in Windows. May be how git translates line # endings with salt.utils.files.fopen( - os.path.join(BASE_FILES, 'testfile'), 'rb') as fp_: + os.path.join(RUNTIME_VARS.BASE_FILES, 'testfile'), 'rb') as fp_: hsum = salt.utils.hashutils.sha256_digest(fp_.read()) self.assertDictEqual( @@ -180,7 +180,7 @@ def test_symlink_list(self): self.opts['file_roots'] = orig_file_roots def test_dynamic_file_roots(self): - dyn_root_dir = tempfile.mkdtemp(dir=TMP) + dyn_root_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) top_sls = os.path.join(dyn_root_dir, 'top.sls') with salt.utils.files.fopen(top_sls, 'w') as fp_: fp_.write("{{saltenv}}:\n '*':\n - dynamo\n") diff --git a/tests/unit/modules/test_beacons.py b/tests/unit/modules/test_beacons.py index 4ea673ef685c..813986a40d98 100644 --- a/tests/unit/modules/test_beacons.py +++ b/tests/unit/modules/test_beacons.py @@ -8,8 +8,8 @@ import os # Import Salt Testing Libs +from tests.support.runtests import RUNTIME_VARS from tests.support.mixins import LoaderModuleMockMixin -from tests.support.paths import TMP from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -22,14 +22,17 @@ import salt.modules.beacons as beacons from salt.utils.event import SaltEvent -SOCK_DIR = os.path.join(TMP, 'test-socks') - @skipIf(NO_MOCK, NO_MOCK_REASON) class BeaconsTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.modules.beacons ''' + + @classmethod + def setUpClass(cls): + cls.sock_dir = os.path.join(RUNTIME_VARS.TMP, 'test-socks') + def setup_loader_modules(self): return {beacons: {}} @@ -44,7 +47,7 @@ def test_delete(self): 'beacons': {}}, ] - with patch.dict(beacons.__opts__, {'beacons': {'ps': [{'processes': {'salt-master': 'stopped', 'apache2': 'stopped'}}]}, 'sock_dir': SOCK_DIR}): + with patch.dict(beacons.__opts__, {'beacons': {'ps': [{'processes': {'salt-master': 'stopped', 'apache2': 'stopped'}}]}, 'sock_dir': self.sock_dir}): mock = MagicMock(return_value=True) with patch.dict(beacons.__salt__, {'event.fire': mock}): with patch.object(SaltEvent, 'get_event', side_effect=event_returns): @@ -70,7 +73,7 @@ def test_add(self): 'tag': '/salt/minion/minion_beacon_add_complete', 'beacons': {'ps': [{'processes': {'salt-master': 'stopped', 'apache2': 'stopped'}}]}}] - with patch.dict(beacons.__opts__, {'beacons': {}, 'sock_dir': SOCK_DIR}): + with patch.dict(beacons.__opts__, {'beacons': {}, 'sock_dir': self.sock_dir}): mock = MagicMock(return_value=True) with patch.dict(beacons.__salt__, {'event.fire': mock}): with patch.object(SaltEvent, 'get_event', side_effect=event_returns): @@ -81,10 +84,10 @@ def test_save(self): ''' Test saving beacons. ''' - comm1 = 'Beacons saved to {0}beacons.conf.'.format(TMP + os.sep) + comm1 = 'Beacons saved to {0}beacons.conf.'.format(RUNTIME_VARS.TMP + os.sep) with patch.dict(beacons.__opts__, {'config_dir': '', 'beacons': {}, - 'default_include': TMP + os.sep, - 'sock_dir': SOCK_DIR}): + 'default_include': RUNTIME_VARS.TMP + os.sep, + 'sock_dir': self.sock_dir}): mock = MagicMock(return_value=True) with patch.dict(beacons.__salt__, {'event.fire': mock}): @@ -104,7 +107,7 @@ def test_disable(self): 'ps': [{'processes': {'salt-master': 'stopped', 'apache2': 'stopped'}}]}}] - with patch.dict(beacons.__opts__, {'beacons': {}, 'sock_dir': SOCK_DIR}): + with patch.dict(beacons.__opts__, {'beacons': {}, 'sock_dir': self.sock_dir}): mock = MagicMock(return_value=True) with patch.dict(beacons.__salt__, {'event.fire': mock}): with patch.object(SaltEvent, 'get_event', side_effect=event_returns): @@ -122,7 +125,7 @@ def test_enable(self): 'ps': [{'processes': {'salt-master': 'stopped', 'apache2': 'stopped'}}]}}] - with patch.dict(beacons.__opts__, {'beacons': {}, 'sock_dir': SOCK_DIR}): + with patch.dict(beacons.__opts__, {'beacons': {}, 'sock_dir': self.sock_dir}): mock = MagicMock(return_value=True) with patch.dict(beacons.__salt__, {'event.fire': mock}): with patch.object(SaltEvent, 'get_event', side_effect=event_returns): diff --git a/tests/unit/modules/test_boto_elb.py b/tests/unit/modules/test_boto_elb.py index e8ec1070e444..dab5c0e034e6 100644 --- a/tests/unit/modules/test_boto_elb.py +++ b/tests/unit/modules/test_boto_elb.py @@ -8,14 +8,14 @@ import os.path import sys -# imprt salt paths -from tests.support.paths import TESTS_DIR +# Import test support libs +from tests.support.runtests import RUNTIME_VARS # import Python Third Party Libs # pylint: disable=import-error try: import boto - boto.ENDPOINTS_PATH = os.path.join(TESTS_DIR, 'unit/files/endpoints.json') + boto.ENDPOINTS_PATH = os.path.join(RUNTIME_VARS.TESTS_DIR, 'unit/files/endpoints.json') import boto.ec2.elb HAS_BOTO = True except ImportError: diff --git a/tests/unit/modules/test_boto_route53.py b/tests/unit/modules/test_boto_route53.py index ed43c12b2168..af955dcbdc46 100644 --- a/tests/unit/modules/test_boto_route53.py +++ b/tests/unit/modules/test_boto_route53.py @@ -19,13 +19,13 @@ from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import NO_MOCK, NO_MOCK_REASON -from tests.support.paths import TESTS_DIR +from tests.support.runtests import RUNTIME_VARS # import Python Third Party Libs # pylint: disable=import-error try: import boto - boto.ENDPOINTS_PATH = os.path.join(TESTS_DIR, 'unit/files/endpoints.json') + boto.ENDPOINTS_PATH = os.path.join(RUNTIME_VARS.TESTS_DIR, 'unit/files/endpoints.json') from moto import mock_route53_deprecated HAS_MOTO = True except ImportError: diff --git a/tests/unit/modules/test_boto_secgroup.py b/tests/unit/modules/test_boto_secgroup.py index d5450c268e71..9990946b06b7 100644 --- a/tests/unit/modules/test_boto_secgroup.py +++ b/tests/unit/modules/test_boto_secgroup.py @@ -12,7 +12,7 @@ from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import NO_MOCK, NO_MOCK_REASON -from tests.support.paths import TESTS_DIR +from tests.support.runtests import RUNTIME_VARS # Import Salt libs import salt.config @@ -26,7 +26,7 @@ from salt.ext.six.moves import range # pylint: disable=redefined-builtin try: import boto - boto.ENDPOINTS_PATH = os.path.join(TESTS_DIR, 'unit/files/endpoints.json') + boto.ENDPOINTS_PATH = os.path.join(RUNTIME_VARS.TESTS_DIR, 'unit/files/endpoints.json') import boto.ec2 # pylint: enable=unused-import HAS_BOTO = True except ImportError: diff --git a/tests/unit/modules/test_boto_vpc.py b/tests/unit/modules/test_boto_vpc.py index 1f30c1644092..6b61c4811de2 100644 --- a/tests/unit/modules/test_boto_vpc.py +++ b/tests/unit/modules/test_boto_vpc.py @@ -18,7 +18,7 @@ from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import NO_MOCK, NO_MOCK_REASON, MagicMock, patch -from tests.support.paths import TESTS_DIR +from tests.support.runtests import RUNTIME_VARS # Import Salt libs import salt.config @@ -35,7 +35,7 @@ # pylint: disable=no-name-in-module,unused-import try: import boto - boto.ENDPOINTS_PATH = os.path.join(TESTS_DIR, 'unit/files/endpoints.json') + boto.ENDPOINTS_PATH = os.path.join(RUNTIME_VARS.TESTS_DIR, 'unit/files/endpoints.json') import boto3 from boto.exception import BotoServerError HAS_BOTO = True diff --git a/tests/unit/modules/test_cmdmod.py b/tests/unit/modules/test_cmdmod.py index 670888e191e4..54a8c7d67ec7 100644 --- a/tests/unit/modules/test_cmdmod.py +++ b/tests/unit/modules/test_cmdmod.py @@ -20,7 +20,7 @@ # Import Salt Testing Libs from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf -from tests.support.paths import FILES +from tests.support.runtests import RUNTIME_VARS from tests.support.mock import ( mock_open, Mock, @@ -357,7 +357,7 @@ def test_run_all_binary_replace(self): /dev/stdout. ''' # Since we're using unicode_literals, read the random bytes from a file - rand_bytes_file = os.path.join(FILES, 'file', 'base', 'random_bytes') + rand_bytes_file = os.path.join(RUNTIME_VARS.BASE_FILES, 'random_bytes') with salt.utils.files.fopen(rand_bytes_file, 'rb') as fp_: stdout_bytes = fp_.read() diff --git a/tests/unit/modules/test_event.py b/tests/unit/modules/test_event.py index e9140670cb30..5e0c6fbf0b77 100644 --- a/tests/unit/modules/test_event.py +++ b/tests/unit/modules/test_event.py @@ -6,8 +6,8 @@ from __future__ import absolute_import, print_function, unicode_literals # Import Salt Testing Libs +from tests.support.runtests import RUNTIME_VARS from tests.support.mixins import LoaderModuleMockMixin -from tests.support.paths import TMP from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -31,7 +31,7 @@ def setup_loader_modules(self): event: { '__opts__': { 'id': 'id', - 'sock_dir': TMP, + 'sock_dir': RUNTIME_VARS.TMP, 'transport': 'zeromq' } } diff --git a/tests/unit/modules/test_file.py b/tests/unit/modules/test_file.py index 3cb1e901c0f8..722d102b9f77 100644 --- a/tests/unit/modules/test_file.py +++ b/tests/unit/modules/test_file.py @@ -8,9 +8,9 @@ import textwrap # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.helpers import with_tempfile from tests.support.mixins import LoaderModuleMockMixin -from tests.support.paths import TMP from tests.support.unit import TestCase, skipIf from tests.support.mock import MagicMock, Mock, patch, mock_open, DEFAULT @@ -2061,7 +2061,7 @@ def setUp(self): self.tfile.close() self.addCleanup(os.remove, self.tfile.name) self.addCleanup(delattr, self, 'tfile') - self.myfile = os.path.join(TMP, 'myfile') + self.myfile = os.path.join(RUNTIME_VARS.TMP, 'myfile') with salt.utils.files.fopen(self.myfile, 'w+') as fp: fp.write(salt.utils.stringutils.to_str('Hello\n')) self.addCleanup(os.remove, self.myfile) diff --git a/tests/unit/modules/test_grains.py b/tests/unit/modules/test_grains.py index 96d44199f1d9..07df4af1c4c4 100644 --- a/tests/unit/modules/test_grains.py +++ b/tests/unit/modules/test_grains.py @@ -6,8 +6,8 @@ import copy # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.mixins import LoaderModuleMockMixin -from tests.support.paths import TMP from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -29,8 +29,8 @@ class GrainsModuleTestCase(TestCase, LoaderModuleMockMixin): def setup_loader_modules(self): - conf_file = os.path.join(TMP, '__salt_test_grains') - cachedir = os.path.join(TMP, '__salt_test_grains_cache_dir') + conf_file = os.path.join(RUNTIME_VARS.TMP, '__salt_test_grains') + cachedir = os.path.join(RUNTIME_VARS.TMP, '__salt_test_grains_cache_dir') if not os.path.isdir(cachedir): os.makedirs(cachedir) return { diff --git a/tests/unit/modules/test_portage_config.py b/tests/unit/modules/test_portage_config.py index c9f642422a97..2ca88a710fd9 100644 --- a/tests/unit/modules/test_portage_config.py +++ b/tests/unit/modules/test_portage_config.py @@ -10,10 +10,10 @@ import re # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import NO_MOCK, NO_MOCK_REASON, MagicMock, patch -from tests.support.paths import TMP import salt.utils.files # Import salt libs @@ -95,7 +95,7 @@ def test_enforce_nice_config(self): ('use', ['apple', '-banana', 'ananas', 'orange']), ] - base_path = TMP + '/package.{0}' + base_path = RUNTIME_VARS.TMP + '/package.{0}' def make_line(atom, addition): return atom + (' ' + addition if addition != '' else '') + '\n' diff --git a/tests/unit/modules/test_schedule.py b/tests/unit/modules/test_schedule.py index 9fb01e94ec7d..0535dbb7a93a 100644 --- a/tests/unit/modules/test_schedule.py +++ b/tests/unit/modules/test_schedule.py @@ -8,8 +8,8 @@ import os # Import Salt Testing Libs +from tests.support.runtests import RUNTIME_VARS from tests.support.mixins import LoaderModuleMockMixin -from tests.support.paths import TMP from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -22,8 +22,6 @@ import salt.modules.schedule as schedule from salt.utils.event import SaltEvent -SOCK_DIR = os.path.join(TMP, 'test-socks') - JOB1 = {'function': 'test.ping', 'maxrunning': 1, 'name': 'job1', 'jid_include': True, 'enabled': True} @@ -33,6 +31,11 @@ class ScheduleTestCase(TestCase, LoaderModuleMockMixin): ''' Test cases for salt.modules.schedule ''' + + @classmethod + def setUpClass(cls): + cls.sock_dir = os.path.join(RUNTIME_VARS.TMP, 'test-socks') + def setup_loader_modules(self): return {schedule: {}} @@ -42,7 +45,7 @@ def test_purge(self): ''' Test if it purge all the jobs currently scheduled on the minion. ''' - with patch.dict(schedule.__opts__, {'schedule': {}, 'sock_dir': SOCK_DIR}): + with patch.dict(schedule.__opts__, {'schedule': {}, 'sock_dir': self.sock_dir}): mock = MagicMock(return_value=True) with patch.dict(schedule.__salt__, {'event.fire': mock}): _ret_value = {'complete': True, 'schedule': {}} @@ -56,7 +59,7 @@ def test_delete(self): ''' Test if it delete a job from the minion's schedule. ''' - with patch.dict(schedule.__opts__, {'schedule': {}, 'sock_dir': SOCK_DIR}): + with patch.dict(schedule.__opts__, {'schedule': {}, 'sock_dir': self.sock_dir}): mock = MagicMock(return_value=True) with patch.dict(schedule.__salt__, {'event.fire': mock}): _ret_value = {'complete': True, 'schedule': {}} @@ -119,7 +122,7 @@ def test_add(self): 'or "days" with "when" or "cron" options.' comm3 = 'Unable to use "when" and "cron" options together. Ignoring.' comm4 = 'Job: job2 would be added to schedule.' - with patch.dict(schedule.__opts__, {'schedule': {'job1': 'salt'}, 'sock_dir': SOCK_DIR}): + with patch.dict(schedule.__opts__, {'schedule': {'job1': 'salt'}, 'sock_dir': self.sock_dir}): mock = MagicMock(return_value=True) with patch.dict(schedule.__salt__, {'event.fire': mock}): _ret_value = {'complete': True, 'schedule': {'job1': {'salt': 'salt'}}} @@ -150,7 +153,7 @@ def test_run_job(self): ''' Test if it run a scheduled job on the minion immediately. ''' - with patch.dict(schedule.__opts__, {'schedule': {'job1': JOB1}, 'sock_dir': SOCK_DIR}): + with patch.dict(schedule.__opts__, {'schedule': {'job1': JOB1}, 'sock_dir': self.sock_dir}): mock = MagicMock(return_value=True) with patch.dict(schedule.__salt__, {'event.fire': mock}): _ret_value = {'complete': True, 'schedule': {'job1': JOB1}} @@ -165,7 +168,7 @@ def test_enable_job(self): ''' Test if it enable a job in the minion's schedule. ''' - with patch.dict(schedule.__opts__, {'schedule': {}, 'sock_dir': SOCK_DIR}): + with patch.dict(schedule.__opts__, {'schedule': {}, 'sock_dir': self.sock_dir}): mock = MagicMock(return_value=True) with patch.dict(schedule.__salt__, {'event.fire': mock}): _ret_value = {'complete': True, 'schedule': {}} @@ -180,7 +183,7 @@ def test_disable_job(self): ''' Test if it disable a job in the minion's schedule. ''' - with patch.dict(schedule.__opts__, {'schedule': {}, 'sock_dir': SOCK_DIR}): + with patch.dict(schedule.__opts__, {'schedule': {}, 'sock_dir': self.sock_dir}): mock = MagicMock(return_value=True) with patch.dict(schedule.__salt__, {'event.fire': mock}): _ret_value = {'complete': True, 'schedule': {}} @@ -198,7 +201,7 @@ def test_save(self): comm1 = 'Schedule (non-pillar items) saved.' with patch.dict(schedule.__opts__, {'config_dir': '', 'schedule': {}, 'default_include': '/tmp', - 'sock_dir': SOCK_DIR}): + 'sock_dir': self.sock_dir}): mock = MagicMock(return_value=True) with patch.dict(schedule.__salt__, {'event.fire': mock}): @@ -236,7 +239,7 @@ def test_move(self): comm1 = 'no servers answered the published schedule.add command' comm2 = 'the following minions return False' comm3 = 'Moved Job job1 from schedule.' - with patch.dict(schedule.__opts__, {'schedule': {'job1': JOB1}, 'sock_dir': SOCK_DIR}): + with patch.dict(schedule.__opts__, {'schedule': {'job1': JOB1}, 'sock_dir': self.sock_dir}): mock = MagicMock(return_value=True) with patch.dict(schedule.__salt__, {'event.fire': mock}): _ret_value = {'complete': True, 'schedule': {'job1': JOB1}} @@ -266,7 +269,7 @@ def test_move(self): 'result': False}) mock = MagicMock(side_effect=[{}, {'job1': {}}]) - with patch.dict(schedule.__opts__, {'schedule': mock, 'sock_dir': SOCK_DIR}): + with patch.dict(schedule.__opts__, {'schedule': mock, 'sock_dir': self.sock_dir}): mock = MagicMock(return_value=True) with patch.dict(schedule.__salt__, {'event.fire': mock}): _ret_value = {'complete': True, 'schedule': {'job1': JOB1}} @@ -303,7 +306,7 @@ def test_copy(self): comm1 = 'no servers answered the published schedule.add command' comm2 = 'the following minions return False' comm3 = 'Copied Job job1 from schedule to minion(s).' - with patch.dict(schedule.__opts__, {'schedule': {'job1': JOB1}, 'sock_dir': SOCK_DIR}): + with patch.dict(schedule.__opts__, {'schedule': {'job1': JOB1}, 'sock_dir': self.sock_dir}): mock = MagicMock(return_value=True) with patch.dict(schedule.__salt__, {'event.fire': mock}): _ret_value = {'complete': True, 'schedule': {'job1': {'job1': JOB1}}} @@ -333,7 +336,7 @@ def test_copy(self): 'result': False}) mock = MagicMock(side_effect=[{}, {'job1': {}}]) - with patch.dict(schedule.__opts__, {'schedule': mock, 'sock_dir': SOCK_DIR}): + with patch.dict(schedule.__opts__, {'schedule': mock, 'sock_dir': self.sock_dir}): with patch.dict(schedule.__pillar__, {'schedule': {'job1': JOB1}}): mock = MagicMock(return_value=True) with patch.dict(schedule.__salt__, {'event.fire': mock}): diff --git a/tests/unit/modules/test_state.py b/tests/unit/modules/test_state.py index 75a3846fef08..8f2805e8f6a9 100644 --- a/tests/unit/modules/test_state.py +++ b/tests/unit/modules/test_state.py @@ -13,8 +13,8 @@ import time # Import Salt Testing Libs +from tests.support.runtests import RUNTIME_VARS from tests.support.mixins import LoaderModuleMockMixin -from tests.support.paths import TMP, TMP_CONF_DIR from tests.support.unit import TestCase, skipIf from tests.support.mock import ( Mock, @@ -1321,7 +1321,7 @@ def setup_loader_modules(self): return { state: { '__opts__': salt.config.minion_config( - os.path.join(TMP_CONF_DIR, 'minion') + os.path.join(RUNTIME_VARS.TMP_CONF_DIR, 'minion') ), '__salt__': { 'saltutil.is_running': MagicMock(return_value=[]), @@ -1330,8 +1330,8 @@ def setup_loader_modules(self): } def setUp(self): - self.cachedir = tempfile.mkdtemp(dir=TMP) - self.fileserver_root = tempfile.mkdtemp(dir=TMP) + self.cachedir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) + self.fileserver_root = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) self.addCleanup(shutil.rmtree, self.cachedir, ignore_errors=True) self.addCleanup(shutil.rmtree, self.fileserver_root, ignore_errors=True) diff --git a/tests/unit/modules/test_win_file.py b/tests/unit/modules/test_win_file.py index 6ad4c6560fe1..12862e3dd566 100644 --- a/tests/unit/modules/test_win_file.py +++ b/tests/unit/modules/test_win_file.py @@ -10,8 +10,8 @@ # Import Salt Testing Libs from tests.support.mixins import LoaderModuleMockMixin from tests.support.mock import MagicMock, NO_MOCK, NO_MOCK_REASON, patch -from tests.support.paths import TMP from tests.support.unit import TestCase, skipIf +from tests.support.runtests import RUNTIME_VARS # Import Salt Libs import salt.modules.temp as temp @@ -84,7 +84,7 @@ def test_issue_52002_check_file_remove_symlink(self): ''' Make sure that directories including symlinks or symlinks can be removed ''' - base = temp.dir(prefix='base-', parent=TMP) + base = temp.dir(prefix='base-', parent=RUNTIME_VARS.TMP) target = os.path.join(base, 'child 1', 'target\\') symlink = os.path.join(base, 'child 2', 'link') try: @@ -126,7 +126,7 @@ def setup_loader_modules(self): } def setUp(self): - self.temp_file = temp.file(parent=TMP) + self.temp_file = temp.file(parent=RUNTIME_VARS.TMP) salt.utils.win_dacl.set_owner(obj_name=self.temp_file, principal=self.current_user) salt.utils.win_dacl.set_inheritance(obj_name=self.temp_file, diff --git a/tests/unit/modules/test_zcbuildout.py b/tests/unit/modules/test_zcbuildout.py index aa678a97913b..6db64a5abe90 100644 --- a/tests/unit/modules/test_zcbuildout.py +++ b/tests/unit/modules/test_zcbuildout.py @@ -15,8 +15,8 @@ # pylint: enable=import-error,no-name-in-module,redefined-builtin # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.mixins import LoaderModuleMockMixin -from tests.support.paths import FILES, TMP from tests.support.unit import TestCase, skipIf from tests.support.helpers import requires_network, skip_if_binaries_missing @@ -26,8 +26,6 @@ import salt.modules.zcbuildout as buildout import salt.modules.cmdmod as cmd -ROOT = os.path.join(FILES, 'file', 'base', 'buildout') - KNOWN_VIRTUALENV_BINARY_NAMES = ( 'virtualenv', 'virtualenv2', @@ -68,9 +66,11 @@ def setup_loader_modules(self): @classmethod def setUpClass(cls): - if not os.path.isdir(TMP): - os.makedirs(TMP) - cls.rdir = tempfile.mkdtemp(dir=TMP) + if not os.path.isdir(RUNTIME_VARS.TMP): + os.makedirs(RUNTIME_VARS.TMP) + + cls.root = os.path.join(RUNTIME_VARS.BASE_FILES, 'buildout') + cls.rdir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) cls.tdir = os.path.join(cls.rdir, 'test') for idx, url in six.iteritems(buildout._URL_VERSIONS): log.debug('Downloading bootstrap from %s', url) @@ -102,7 +102,7 @@ def tearDownClass(cls): def setUp(self): super(Base, self).setUp() self._remove_dir() - shutil.copytree(ROOT, self.tdir) + shutil.copytree(self.root, self.tdir) for idx in BOOT_INIT: path = os.path.join( @@ -277,7 +277,7 @@ def test_logger_loggers(self): @requires_network() def test__find_cfgs(self): result = sorted( - [a.replace(ROOT, '') for a in buildout._find_cfgs(ROOT)]) + [a.replace(self.root, '') for a in buildout._find_cfgs(self.root)]) assertlist = sorted( ['/buildout.cfg', '/c/buildout.cfg', diff --git a/tests/unit/pillar/test_file_tree.py b/tests/unit/pillar/test_file_tree.py index 6d5626ef52cb..c63e5f974230 100644 --- a/tests/unit/pillar/test_file_tree.py +++ b/tests/unit/pillar/test_file_tree.py @@ -11,10 +11,10 @@ import shutil # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import NO_MOCK, NO_MOCK_REASON, patch, MagicMock -from tests.support.paths import TMP from tests.support.helpers import TestsLoggingHandler # Import Salt Libs @@ -52,7 +52,7 @@ class FileTreePillarTestCase(TestCase, LoaderModuleMockMixin): maxDiff = None def setup_loader_modules(self): - self.tmpdir = tempfile.mkdtemp(dir=TMP) + self.tmpdir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) self.addCleanup(shutil.rmtree, self.tmpdir) cachedir = os.path.join(self.tmpdir, 'cachedir') os.makedirs(os.path.join(cachedir, 'file_tree')) diff --git a/tests/unit/pillar/test_hg_pillar.py b/tests/unit/pillar/test_hg_pillar.py index d79ebb168962..78117216afa6 100644 --- a/tests/unit/pillar/test_hg_pillar.py +++ b/tests/unit/pillar/test_hg_pillar.py @@ -13,7 +13,7 @@ from tests.support.mixins import AdaptedConfigurationTestCaseMixin, LoaderModuleMockMixin from tests.support.unit import TestCase, skipIf from tests.support.mock import NO_MOCK, NO_MOCK_REASON -from tests.support.paths import TMP +from tests.support.runtests import RUNTIME_VARS COMMIT_USER_NAME = 'test_user' @@ -38,7 +38,7 @@ class HgPillarTestCase(TestCase, AdaptedConfigurationTestCaseMixin, LoaderModule maxDiff = None def setup_loader_modules(self): - self.tmpdir = tempfile.mkdtemp(dir=TMP) + self.tmpdir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) self.addCleanup(shutil.rmtree, self.tmpdir) cachedir = os.path.join(self.tmpdir, 'cachedir') os.makedirs(os.path.join(cachedir, 'hg_pillar')) diff --git a/tests/unit/returners/test_local_cache.py b/tests/unit/returners/test_local_cache.py index a04eaee20dc5..15c84f7a6e27 100644 --- a/tests/unit/returners/test_local_cache.py +++ b/tests/unit/returners/test_local_cache.py @@ -17,7 +17,7 @@ # Import Salt Testing libs from tests.support.mixins import AdaptedConfigurationTestCaseMixin, LoaderModuleMockMixin -from tests.support.paths import TMP +from tests.support.runtests import RUNTIME_VARS from tests.support.unit import TestCase, skipIf from tests.support.mock import ( MagicMock, @@ -36,17 +36,19 @@ log = logging.getLogger(__name__) -TMP_CACHE_DIR = os.path.join(TMP, 'salt_test_job_cache') -TMP_JID_DIR = os.path.join(TMP_CACHE_DIR, 'jobs') - @skipIf(NO_MOCK, NO_MOCK_REASON) class LocalCacheCleanOldJobsTestCase(TestCase, LoaderModuleMockMixin): ''' Tests for the local_cache.clean_old_jobs function. ''' + @classmethod + def setUpClass(cls): + cls.TMP_CACHE_DIR = os.path.join(RUNTIME_VARS.TMP, 'salt_test_job_cache') + cls.TMP_JID_DIR = os.path.join(cls.TMP_CACHE_DIR, 'jobs') + def setup_loader_modules(self): - return {local_cache: {'__opts__': {'cachedir': TMP_CACHE_DIR, 'keep_jobs': 1}}} + return {local_cache: {'__opts__': {'cachedir': self.TMP_CACHE_DIR, 'keep_jobs': 1}}} def tearDown(self): ''' @@ -55,8 +57,8 @@ def tearDown(self): Note that a setUp function is not used in this TestCase because the _make_tmp_jid_dirs replaces it. ''' - if os.path.exists(TMP_CACHE_DIR): - shutil.rmtree(TMP_CACHE_DIR) + if os.path.exists(self.TMP_CACHE_DIR): + shutil.rmtree(self.TMP_CACHE_DIR) def test_clean_old_jobs_no_jid_root(self): ''' @@ -90,7 +92,7 @@ def test_clean_old_jobs_empty_jid_dir_removed(self): local_cache.clean_old_jobs() # Assert that the JID dir was removed - self.assertEqual([], os.listdir(TMP_JID_DIR)) + self.assertEqual([], os.listdir(self.TMP_JID_DIR)) def test_clean_old_jobs_empty_jid_dir_remains(self): ''' @@ -113,7 +115,7 @@ def test_clean_old_jobs_empty_jid_dir_remains(self): jid_dir_name = jid_dir.rpartition('/')[2] # Assert the JID directory is still present to be cleaned after keep_jobs interval - self.assertEqual([jid_dir_name], os.listdir(TMP_JID_DIR)) + self.assertEqual([jid_dir_name], os.listdir(self.TMP_JID_DIR)) def test_clean_old_jobs_jid_file_corrupted(self): ''' @@ -134,7 +136,7 @@ def test_clean_old_jobs_jid_file_corrupted(self): local_cache.clean_old_jobs() # there should be only 1 dir in TMP_JID_DIR - self.assertEqual(1, len(os.listdir(TMP_JID_DIR))) + self.assertEqual(1, len(os.listdir(self.TMP_JID_DIR))) # top level dir should still be present self.assertEqual(True, os.path.exists(jid_dir)) self.assertEqual(True, os.path.isdir(jid_dir)) @@ -167,7 +169,7 @@ def test_clean_old_jobs_jid_file_is_cleaned(self): local_cache.clean_old_jobs() # there should be only 1 dir in TMP_JID_DIR - self.assertEqual(1, len(os.listdir(TMP_JID_DIR))) + self.assertEqual(1, len(os.listdir(self.TMP_JID_DIR))) # top level dir should still be present self.assertEqual(True, os.path.exists(jid_dir)) self.assertEqual(True, os.path.isdir(jid_dir)) @@ -181,7 +183,7 @@ def _make_tmp_jid_dirs(self, create_files=True): This emulates salt.utils.jid.jid_dir() by creating this structure: - TMP_JID_DIR dir/ + RUNTIME_VARS.TMP_JID_DIR dir/ random dir from tempfile.mkdtemp/ 'jid' directory/ 'jid' file @@ -190,11 +192,11 @@ def _make_tmp_jid_dirs(self, create_files=True): the jid_file_path will be None. ''' # First, create the /tmp/salt_test_job_cache/jobs/ directory to hold jid dirs - if not os.path.exists(TMP_JID_DIR): - os.makedirs(TMP_JID_DIR) + if not os.path.exists(self.TMP_JID_DIR): + os.makedirs(self.TMP_JID_DIR) # Then create a JID temp file in "/tmp/salt_test_job_cache/" - temp_dir = tempfile.mkdtemp(dir=TMP_JID_DIR) + temp_dir = tempfile.mkdtemp(dir=self.TMP_JID_DIR) jid_file_path = None if create_files: @@ -223,7 +225,7 @@ def setup_loader_modules(self): @classmethod def setUpClass(cls): - cls.TMP_CACHE_DIR = os.path.join(TMP, 'rootdir', 'cache') + cls.TMP_CACHE_DIR = os.path.join(RUNTIME_VARS.TMP, 'rootdir', 'cache') cls.JOBS_DIR = os.path.join(cls.TMP_CACHE_DIR, 'jobs') cls.JID_DIR = os.path.join(cls.JOBS_DIR, '31', 'c56eed380a4e899ae12bc42563cfdfc53066fb4a6b53e2378a08ac49064539') cls.JID_FILE = os.path.join(cls.JID_DIR, 'jid') diff --git a/tests/unit/roster/test_ansible.py b/tests/unit/roster/test_ansible.py index 147e9f0b49cc..94191d47710d 100644 --- a/tests/unit/roster/test_ansible.py +++ b/tests/unit/roster/test_ansible.py @@ -13,7 +13,6 @@ from tests.support import mixins from tests.support.unit import skipIf, TestCase from tests.support.runtests import RUNTIME_VARS -from tests.support.paths import TESTS_DIR # Import Salt Libs import salt.config @@ -61,7 +60,7 @@ class AnsibleRosterTestCase(TestCase, mixins.LoaderModuleMockMixin): @classmethod def setUpClass(cls): - cls.roster_dir = os.path.join(TESTS_DIR, 'unit/files/rosters/ansible/') + cls.roster_dir = os.path.join(RUNTIME_VARS.TESTS_DIR, 'unit/files/rosters/ansible/') cls.opts = {'roster_defaults': {'passwd': 'test123'}} @classmethod diff --git a/tests/unit/runners/test_cache.py b/tests/unit/runners/test_cache.py index c493d643bec6..b58d234fbdda 100644 --- a/tests/unit/runners/test_cache.py +++ b/tests/unit/runners/test_cache.py @@ -7,8 +7,8 @@ from __future__ import absolute_import, print_function, unicode_literals # Import Salt Testing Libs +from tests.support.runtests import RUNTIME_VARS from tests.support.mixins import LoaderModuleMockMixin -from tests.support.paths import TMP from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -27,7 +27,7 @@ class CacheTest(TestCase, LoaderModuleMockMixin): Validate the cache runner ''' def setup_loader_modules(self): - return {cache: {'__opts__': {'cache': 'localfs', 'pki_dir': TMP, 'key_cache': True}}} + return {cache: {'__opts__': {'cache': 'localfs', 'pki_dir': RUNTIME_VARS.TMP, 'key_cache': True}}} def test_grains(self): ''' diff --git a/tests/unit/runners/test_queue.py b/tests/unit/runners/test_queue.py index b3a0d1977b27..7d32fcf719e9 100644 --- a/tests/unit/runners/test_queue.py +++ b/tests/unit/runners/test_queue.py @@ -8,8 +8,8 @@ import os # Import Salt Testing Libs +from tests.support.runtests import RUNTIME_VARS from tests.support.mixins import LoaderModuleMockMixin -from tests.support.paths import TMP from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -31,7 +31,7 @@ def setup_loader_modules(self): return { queue_mod: { '__opts__': { - 'sock_dir': os.path.join(TMP, 'queue-runner-sock-dir'), + 'sock_dir': os.path.join(RUNTIME_VARS.TMP, 'queue-runner-sock-dir'), 'transport': 'zeromq' } } diff --git a/tests/unit/runners/test_winrepo.py b/tests/unit/runners/test_winrepo.py index d38c5419f5ae..bd9255bd0497 100644 --- a/tests/unit/runners/test_winrepo.py +++ b/tests/unit/runners/test_winrepo.py @@ -7,8 +7,8 @@ import tempfile # Import Salt Testing Libs +from tests.support.runtests import RUNTIME_VARS from tests.support.mixins import LoaderModuleMockMixin -from tests.support.paths import TMP from tests.support.unit import skipIf, TestCase from tests.support.mock import NO_MOCK, NO_MOCK_REASON @@ -80,9 +80,9 @@ class WinrepoTest(TestCase, LoaderModuleMockMixin): Test the winrepo runner ''' def setup_loader_modules(self): - self.winrepo_dir = tempfile.mkdtemp(dir=TMP) + self.winrepo_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) self.addCleanup(shutil.rmtree, self.winrepo_dir, ignore_errors=True) - self.extmods_dir = tempfile.mkdtemp(dir=TMP) + self.extmods_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) self.addCleanup(shutil.rmtree, self.extmods_dir, ignore_errors=True) self.winrepo_sls_dir = os.path.join(self.winrepo_dir, 'repo_sls') os.mkdir(self.winrepo_sls_dir) diff --git a/tests/unit/states/test_beacon.py b/tests/unit/states/test_beacon.py index fcea3297326c..c1f829ca2ef9 100644 --- a/tests/unit/states/test_beacon.py +++ b/tests/unit/states/test_beacon.py @@ -7,8 +7,8 @@ import os # Import Salt Testing Libs +from tests.support.runtests import RUNTIME_VARS from tests.support.mixins import LoaderModuleMockMixin -from tests.support.paths import TMP from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -20,7 +20,7 @@ # Import Salt Libs import salt.states.beacon as beacon -SOCK_DIR = os.path.join(TMP, 'test-socks') +SOCK_DIR = os.path.join(RUNTIME_VARS.TMP, 'test-socks') @skipIf(NO_MOCK, NO_MOCK_REASON) diff --git a/tests/unit/states/test_boto_vpc.py b/tests/unit/states/test_boto_vpc.py index 5db4781fb283..eca25539e8c3 100644 --- a/tests/unit/states/test_boto_vpc.py +++ b/tests/unit/states/test_boto_vpc.py @@ -11,7 +11,7 @@ from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import NO_MOCK, NO_MOCK_REASON, patch -from tests.support.paths import TESTS_DIR +from tests.support.runtests import RUNTIME_VARS # Import Salt libs @@ -28,7 +28,7 @@ from salt.ext.six.moves import range # pylint: disable=import-error,redefined-builtin try: import boto - boto.ENDPOINTS_PATH = os.path.join(TESTS_DIR, 'unit/files/endpoints.json') + boto.ENDPOINTS_PATH = os.path.join(RUNTIME_VARS.TESTS_DIR, 'unit/files/endpoints.json') import boto3 from boto.exception import BotoServerError diff --git a/tests/unit/states/test_grains.py b/tests/unit/states/test_grains.py index 15aac46adbe6..311ed72676c0 100644 --- a/tests/unit/states/test_grains.py +++ b/tests/unit/states/test_grains.py @@ -10,8 +10,8 @@ import contextlib # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.mixins import LoaderModuleMockMixin -from tests.support.paths import TMP from tests.support.unit import TestCase, skipIf from tests.support.mock import NO_MOCK, NO_MOCK_REASON, MagicMock, patch @@ -29,13 +29,13 @@ class GrainsTestCase(TestCase, LoaderModuleMockMixin): def setup_loader_modules(self): grains_test_dir = '__salt_test_state_grains' - if not os.path.exists(os.path.join(TMP, grains_test_dir)): - os.makedirs(os.path.join(TMP, grains_test_dir)) + if not os.path.exists(os.path.join(RUNTIME_VARS.TMP, grains_test_dir)): + os.makedirs(os.path.join(RUNTIME_VARS.TMP, grains_test_dir)) loader_globals = { '__opts__': { 'test': False, - 'conf_file': os.path.join(TMP, grains_test_dir, 'minion'), - 'cachedir': os.path.join(TMP, grains_test_dir), + 'conf_file': os.path.join(RUNTIME_VARS.TMP, grains_test_dir, 'minion'), + 'cachedir': os.path.join(RUNTIME_VARS.TMP, grains_test_dir), 'local': True, }, '__salt__': { diff --git a/tests/unit/states/test_saltmod.py b/tests/unit/states/test_saltmod.py index a2e8c7054894..acfe13d9a581 100644 --- a/tests/unit/states/test_saltmod.py +++ b/tests/unit/states/test_saltmod.py @@ -9,8 +9,8 @@ import tempfile # Import Salt Testing Libs +from tests.support.runtests import RUNTIME_VARS from tests.support.mixins import LoaderModuleMockMixin -from tests.support.paths import TMP from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -43,7 +43,7 @@ def setup_loader_modules(self): '__opts__': { '__role': 'master', 'file_client': 'remote', - 'sock_dir': tempfile.mkdtemp(dir=TMP), + 'sock_dir': tempfile.mkdtemp(dir=RUNTIME_VARS.TMP), 'transport': 'tcp' }, '__salt__': {'saltutil.cmd': MagicMock()}, @@ -302,7 +302,7 @@ def cmd_mock(*args, **kwargs): @skipIf(NO_MOCK, NO_MOCK_REASON) class StatemodTests(TestCase, LoaderModuleMockMixin): def setup_loader_modules(self): - self.tmp_cachedir = tempfile.mkdtemp(dir=TMP) + self.tmp_cachedir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) return { saltmod: { '__env__': 'base', diff --git a/tests/unit/states/test_virt.py b/tests/unit/states/test_virt.py index 80229899375c..133325ac559f 100644 --- a/tests/unit/states/test_virt.py +++ b/tests/unit/states/test_virt.py @@ -8,8 +8,8 @@ import shutil # Import Salt Testing Libs +from tests.support.runtests import RUNTIME_VARS from tests.support.mixins import LoaderModuleMockMixin -from tests.support.paths import TMP from tests.support.unit import skipIf, TestCase from tests.support.mock import ( NO_MOCK, @@ -57,7 +57,7 @@ def setup_loader_modules(self): @classmethod def setUpClass(cls): - cls.pki_dir = tempfile.mkdtemp(dir=TMP) + cls.pki_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) @classmethod def tearDownClass(cls): diff --git a/tests/unit/states/test_zcbuildout.py b/tests/unit/states/test_zcbuildout.py index 064f07d8249f..26463b7a70e0 100644 --- a/tests/unit/states/test_zcbuildout.py +++ b/tests/unit/states/test_zcbuildout.py @@ -5,7 +5,6 @@ import os # Import Salt Testing libs -from tests.support.paths import FILES from tests.support.unit import skipIf from tests.support.helpers import requires_network @@ -16,8 +15,6 @@ import salt.states.zcbuildout as buildout import salt.modules.cmdmod as cmd -ROOT = os.path.join(FILES, 'file/base/buildout') - @skipIf(salt.utils.path.which_bin(KNOWN_VIRTUALENV_BINARY_NAMES) is None, "The 'virtualenv' packaged needs to be installed") diff --git a/tests/unit/test_config.py b/tests/unit/test_config.py index 3b7fa32efc47..5538cf9714f6 100644 --- a/tests/unit/test_config.py +++ b/tests/unit/test_config.py @@ -12,8 +12,8 @@ # Import Salt Testing libs from tests.support.helpers import with_tempdir, with_tempfile, destructiveTest from tests.support.mixins import AdaptedConfigurationTestCaseMixin -from tests.support.paths import TMP from tests.support.unit import skipIf, TestCase +from tests.support.runtests import RUNTIME_VARS from tests.support.mock import ( NO_MOCK, NO_MOCK_REASON, @@ -336,8 +336,8 @@ def test_default_root_dir_included_in_config_root_dir(self, tempdir): 'root_dir: {0}\n' 'log_file: {1}\n'.format(root_dir, fpath) ) - with patch('salt.syspaths.ROOT_DIR', TMP): - config = sconfig.master_config(fpath) + with patch('salt.syspaths.ROOT_DIR', RUNTIME_VARS.TMP): + config = salt.config.master_config(fpath) self.assertEqual(config['log_file'], fpath) @skipIf( diff --git a/tests/unit/test_doc.py b/tests/unit/test_doc.py index 6ce6159eb67a..4f8735f53456 100644 --- a/tests/unit/test_doc.py +++ b/tests/unit/test_doc.py @@ -11,8 +11,8 @@ import logging # Import Salt Testing libs -from tests.support.paths import CODE_DIR from tests.support.unit import TestCase +from tests.support.runtests import RUNTIME_VARS # Import Salt libs import salt.modules.cmdmod @@ -38,7 +38,7 @@ def test_check_for_doc_inline_markup(self): https://github.com/saltstack/salt/issues/12788 ''' - salt_dir = CODE_DIR + salt_dir = RUNTIME_VARS.CODE_DIR if salt.utils.platform.is_windows(): if salt.utils.path.which('bash'): diff --git a/tests/unit/test_fileclient.py b/tests/unit/test_fileclient.py index 030c9fa953c1..94a3c3d4acb1 100644 --- a/tests/unit/test_fileclient.py +++ b/tests/unit/test_fileclient.py @@ -13,8 +13,8 @@ # Import Salt Testing libs from tests.support.mixins import AdaptedConfigurationTestCaseMixin, LoaderModuleMockMixin from tests.support.mock import patch, Mock, MagicMock, NO_MOCK, NO_MOCK_REASON -from tests.support.paths import TMP from tests.support.unit import TestCase, skipIf +from tests.support.runtests import RUNTIME_VARS # Import Salt libs import salt.utils.files @@ -72,30 +72,30 @@ def test_extrn_path_with_long_filename(self): SALTENVS = ('base', 'dev') -FS_ROOT = os.path.join(TMP, 'fileclient_fs_root') -CACHE_ROOT = os.path.join(TMP, 'fileclient_cache_root') SUBDIR = 'subdir' SUBDIR_FILES = ('foo.txt', 'bar.txt', 'baz.txt') -def _get_file_roots(): +def _get_file_roots(fs_root): return dict( - [(x, [os.path.join(FS_ROOT, x)]) for x in SALTENVS] + [(x, [os.path.join(fs_root, x)]) for x in SALTENVS] ) -MOCKED_OPTS = { - 'file_roots': _get_file_roots(), - 'fileserver_backend': ['roots'], - 'cachedir': CACHE_ROOT, - 'file_client': 'local', -} - - @skipIf(NO_MOCK, NO_MOCK_REASON) class FileClientTest(TestCase, AdaptedConfigurationTestCaseMixin, LoaderModuleMockMixin): def setup_loader_modules(self): + FS_ROOT = os.path.join(RUNTIME_VARS.TMP, 'fileclient_fs_root') + CACHE_ROOT = os.path.join(RUNTIME_VARS.TMP, 'fileclient_cache_root') + MOCKED_OPTS = { + 'file_roots': _get_file_roots(FS_ROOT), + 'fileserver_backend': ['roots'], + 'cachedir': CACHE_ROOT, + 'file_client': 'local', + } + self.addCleanup(shutil.rmtree, FS_ROOT, ignore_errors=True) + self.addCleanup(shutil.rmtree, CACHE_ROOT, ignore_errors=True) return {fileclient: {'__opts__': MOCKED_OPTS}} def setUp(self): @@ -135,7 +135,17 @@ class FileclientCacheTest(TestCase, AdaptedConfigurationTestCaseMixin, LoaderMod ''' def setup_loader_modules(self): - return {fileclient: {'__opts__': MOCKED_OPTS}} + self.FS_ROOT = os.path.join(RUNTIME_VARS.TMP, 'fileclient_fs_root') + self.CACHE_ROOT = os.path.join(RUNTIME_VARS.TMP, 'fileclient_cache_root') + self.MOCKED_OPTS = { + 'file_roots': _get_file_roots(self.FS_ROOT), + 'fileserver_backend': ['roots'], + 'cachedir': self.CACHE_ROOT, + 'file_client': 'local', + } + self.addCleanup(shutil.rmtree, self.FS_ROOT, ignore_errors=True) + self.addCleanup(shutil.rmtree, self.CACHE_ROOT, ignore_errors=True) + return {fileclient: {'__opts__': self.MOCKED_OPTS}} def setUp(self): ''' @@ -161,7 +171,7 @@ def _new_dir(path): # Crete the FS_ROOT for saltenv in SALTENVS: - saltenv_root = os.path.join(FS_ROOT, saltenv) + saltenv_root = os.path.join(self.FS_ROOT, saltenv) # Make sure we have a fresh root dir for this saltenv _new_dir(saltenv_root) @@ -183,21 +193,14 @@ def _new_dir(path): ) # Create the CACHE_ROOT - _new_dir(CACHE_ROOT) - - def tearDown(self): - ''' - Remove the directories created for these tests - ''' - shutil.rmtree(FS_ROOT) - shutil.rmtree(CACHE_ROOT) + _new_dir(self.CACHE_ROOT) def test_cache_dir(self): ''' Ensure entire directory is cached to correct location ''' patched_opts = dict((x, y) for x, y in six.iteritems(self.minion_opts)) - patched_opts.update(MOCKED_OPTS) + patched_opts.update(self.MOCKED_OPTS) with patch.dict(fileclient.__opts__, patched_opts): client = fileclient.get_file_client(fileclient.__opts__, pillar=False) @@ -236,8 +239,8 @@ def test_cache_dir_with_alternate_cachedir_and_absolute_path(self): cachedir is specified and that cachedir is an absolute path ''' patched_opts = dict((x, y) for x, y in six.iteritems(self.minion_opts)) - patched_opts.update(MOCKED_OPTS) - alt_cachedir = os.path.join(TMP, 'abs_cachedir') + patched_opts.update(self.MOCKED_OPTS) + alt_cachedir = os.path.join(RUNTIME_VARS.TMP, 'abs_cachedir') with patch.dict(fileclient.__opts__, patched_opts): client = fileclient.get_file_client(fileclient.__opts__, pillar=False) @@ -276,7 +279,7 @@ def test_cache_dir_with_alternate_cachedir_and_relative_path(self): cachedir is specified and that cachedir is a relative path ''' patched_opts = dict((x, y) for x, y in six.iteritems(self.minion_opts)) - patched_opts.update(MOCKED_OPTS) + patched_opts.update(self.MOCKED_OPTS) alt_cachedir = 'foo' with patch.dict(fileclient.__opts__, patched_opts): @@ -316,7 +319,7 @@ def test_cache_file(self): Ensure file is cached to correct location ''' patched_opts = dict((x, y) for x, y in six.iteritems(self.minion_opts)) - patched_opts.update(MOCKED_OPTS) + patched_opts.update(self.MOCKED_OPTS) with patch.dict(fileclient.__opts__, patched_opts): client = fileclient.get_file_client(fileclient.__opts__, pillar=False) @@ -345,8 +348,8 @@ def test_cache_file_with_alternate_cachedir_and_absolute_path(self): specified and that cachedir is an absolute path ''' patched_opts = dict((x, y) for x, y in six.iteritems(self.minion_opts)) - patched_opts.update(MOCKED_OPTS) - alt_cachedir = os.path.join(TMP, 'abs_cachedir') + patched_opts.update(self.MOCKED_OPTS) + alt_cachedir = os.path.join(RUNTIME_VARS.TMP, 'abs_cachedir') with patch.dict(fileclient.__opts__, patched_opts): client = fileclient.get_file_client(fileclient.__opts__, pillar=False) @@ -379,7 +382,7 @@ def test_cache_file_with_alternate_cachedir_and_relative_path(self): specified and that cachedir is a relative path ''' patched_opts = dict((x, y) for x, y in six.iteritems(self.minion_opts)) - patched_opts.update(MOCKED_OPTS) + patched_opts.update(self.MOCKED_OPTS) alt_cachedir = 'foo' with patch.dict(fileclient.__opts__, patched_opts): diff --git a/tests/unit/test_loader.py b/tests/unit/test_loader.py index 28545b5de3dc..01c4194d2e61 100644 --- a/tests/unit/test_loader.py +++ b/tests/unit/test_loader.py @@ -21,10 +21,10 @@ import textwrap # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.case import ModuleCase from tests.support.unit import TestCase from tests.support.mock import patch -from tests.support.paths import TMP # Import Salt libs import salt.config @@ -76,12 +76,12 @@ class LazyLoaderTest(TestCase): def setUpClass(cls): cls.opts = salt.config.minion_config(None) cls.opts['grains'] = salt.loader.grains(cls.opts) - if not os.path.isdir(TMP): - os.makedirs(TMP) + if not os.path.isdir(RUNTIME_VARS.TMP): + os.makedirs(RUNTIME_VARS.TMP) def setUp(self): # Setup the module - self.module_dir = tempfile.mkdtemp(dir=TMP) + self.module_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) self.module_file = os.path.join(self.module_dir, '{0}.py'.format(self.module_name)) with salt.utils.files.fopen(self.module_file, 'w') as fh: @@ -374,11 +374,11 @@ class LazyLoaderReloadingTest(TestCase): def setUpClass(cls): cls.opts = salt.config.minion_config(None) cls.opts['grains'] = salt.loader.grains(cls.opts) - if not os.path.isdir(TMP): - os.makedirs(TMP) + if not os.path.isdir(RUNTIME_VARS.TMP): + os.makedirs(RUNTIME_VARS.TMP) def setUp(self): - self.tmp_dir = tempfile.mkdtemp(dir=TMP) + self.tmp_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) self.count = 0 opts = copy.deepcopy(self.opts) @@ -517,11 +517,11 @@ class LazyLoaderVirtualAliasTest(TestCase): def setUpClass(cls): cls.opts = salt.config.minion_config(None) cls.opts['grains'] = salt.loader.grains(cls.opts) - if not os.path.isdir(TMP): - os.makedirs(TMP) + if not os.path.isdir(RUNTIME_VARS.TMP): + os.makedirs(RUNTIME_VARS.TMP) def setUp(self): - self.tmp_dir = tempfile.mkdtemp(dir=TMP) + self.tmp_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) opts = copy.deepcopy(self.opts) dirs = salt.loader._module_dirs(opts, 'modules', 'module') dirs.append(self.tmp_dir) @@ -604,11 +604,11 @@ class LazyLoaderSubmodReloadingTest(TestCase): def setUpClass(cls): cls.opts = salt.config.minion_config(None) cls.opts['grains'] = salt.loader.grains(cls.opts) - if not os.path.isdir(TMP): - os.makedirs(TMP) + if not os.path.isdir(RUNTIME_VARS.TMP): + os.makedirs(RUNTIME_VARS.TMP) def setUp(self): - self.tmp_dir = tempfile.mkdtemp(dir=TMP) + self.tmp_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) os.makedirs(self.module_dir) self.count = 0 @@ -777,11 +777,11 @@ class LazyLoaderModulePackageTest(TestCase): def setUpClass(cls): cls.opts = salt.config.minion_config(None) cls.opts['grains'] = salt.loader.grains(cls.opts) - if not os.path.isdir(TMP): - os.makedirs(TMP) + if not os.path.isdir(RUNTIME_VARS.TMP): + os.makedirs(RUNTIME_VARS.TMP) def setUp(self): - self.tmp_dir = tempfile.mkdtemp(dir=TMP) + self.tmp_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) dirs = salt.loader._module_dirs(copy.deepcopy(self.opts), 'modules', 'module') dirs.append(self.tmp_dir) @@ -882,11 +882,11 @@ class LazyLoaderDeepSubmodReloadingTest(TestCase): def setUpClass(cls): cls.opts = salt.config.minion_config(None) cls.opts['grains'] = salt.loader.grains(cls.opts) - if not os.path.isdir(TMP): - os.makedirs(TMP) + if not os.path.isdir(RUNTIME_VARS.TMP): + os.makedirs(RUNTIME_VARS.TMP) def setUp(self): - self.tmp_dir = tempfile.mkdtemp(dir=TMP) + self.tmp_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) os.makedirs(self.module_dir) self.lib_count = collections.defaultdict(int) # mapping of path -> count @@ -1161,7 +1161,7 @@ def setUpClass(cls): def setUp(self): # Setup the module - self.module_dir = tempfile.mkdtemp(dir=TMP) + self.module_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) self.module_file = os.path.join(self.module_dir, '{0}.py'.format(self.module_name)) diff --git a/tests/unit/test_module_names.py b/tests/unit/test_module_names.py index 594aa0437688..dd18f22c9d53 100644 --- a/tests/unit/test_module_names.py +++ b/tests/unit/test_module_names.py @@ -15,7 +15,8 @@ # Import Salt Testing libs from tests.support.unit import TestCase -from tests.support.paths import CODE_DIR, list_test_mods +from tests.support.paths import list_test_mods +from tests.support.runtests import RUNTIME_VARS EXCLUDED_DIRS = [ os.path.join('tests', 'pkg'), @@ -70,10 +71,10 @@ def test_module_name(self): Make sure all test modules conform to the test_*.py naming scheme ''' excluded_dirs, included_dirs = tuple(EXCLUDED_DIRS), tuple(INCLUDED_DIRS) - tests_dir = os.path.join(CODE_DIR, 'tests') + tests_dir = os.path.join(RUNTIME_VARS.CODE_DIR, 'tests') bad_names = [] for root, _, files in salt.utils.path.os_walk(tests_dir): - reldir = os.path.relpath(root, CODE_DIR) + reldir = os.path.relpath(root, RUNTIME_VARS.CODE_DIR) if (reldir.startswith(excluded_dirs) and not self._match_dirs(reldir, included_dirs)) \ or reldir.endswith('__pycache__'): continue @@ -228,7 +229,7 @@ def _format_errors(errors): '.'.join((flower[5:], 'py'))) # The full path to the file we expect to find - abspath = salt.utils.path.join(CODE_DIR, relpath) + abspath = salt.utils.path.join(RUNTIME_VARS.CODE_DIR, relpath) if not os.path.isfile(abspath): # Maybe this is in a dunder init? diff --git a/tests/unit/test_pillar.py b/tests/unit/test_pillar.py index 487101819108..6562958c6d73 100644 --- a/tests/unit/test_pillar.py +++ b/tests/unit/test_pillar.py @@ -13,10 +13,10 @@ import tempfile # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.helpers import with_tempdir from tests.support.unit import skipIf, TestCase from tests.support.mock import NO_MOCK, NO_MOCK_REASON, MagicMock, patch -from tests.support.paths import TMP # Import salt libs import salt.fileclient @@ -351,7 +351,7 @@ def test_ext_pillar_first(self): 'kernel': 'Linux' } - tempdir = tempfile.mkdtemp(dir=TMP) + tempdir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) try: sls_files = self._setup_test_topfile_sls_pillar_match( tempdir,) @@ -599,7 +599,7 @@ def test_topfile_order(self): } def _run_test(nodegroup_order, glob_order, expected): - tempdir = tempfile.mkdtemp(dir=TMP) + tempdir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) try: sls_files = self._setup_test_topfile_sls( tempdir, diff --git a/tests/unit/test_state.py b/tests/unit/test_state.py index 8722655eabbc..719fcfd115df 100644 --- a/tests/unit/test_state.py +++ b/tests/unit/test_state.py @@ -17,7 +17,6 @@ MagicMock, patch) from tests.support.mixins import AdaptedConfigurationTestCaseMixin -from tests.support.paths import BASE_FILES from tests.support.runtests import RUNTIME_VARS # Import Salt libs @@ -155,7 +154,7 @@ def test_find_sls_ids_with_exclude(self): ''' sls_dir = 'issue-47182' shutil.copytree( - os.path.join(BASE_FILES, sls_dir), + os.path.join(RUNTIME_VARS.BASE_FILES, sls_dir), os.path.join(self.state_tree_dir, sls_dir) ) shutil.move( diff --git a/tests/unit/test_virtualname.py b/tests/unit/test_virtualname.py index 4bc91fdf7155..85b62d110e40 100644 --- a/tests/unit/test_virtualname.py +++ b/tests/unit/test_virtualname.py @@ -18,8 +18,8 @@ import salt.ext.six as six # Import Salt Testing libs -from tests.support.paths import CODE_DIR from tests.support.unit import TestCase +from tests.support.runtests import RUNTIME_VARS log = logging.getLogger(__name__) @@ -86,14 +86,14 @@ def test_check_virtualname(self): Test that the virtualname is in __name__ of the module ''' errors = [] - for entry in os.listdir(os.path.join(CODE_DIR, 'salt/')): + for entry in os.listdir(os.path.join(RUNTIME_VARS.CODE_DIR, 'salt/')): name, path = os.path.splitext(os.path.basename(entry))[0], entry if name.startswith('.') or name.startswith('_') or not os.path.isdir(path): continue if name in ('cli', 'defaults', 'spm', 'daemons', 'ext', 'templates'): continue if name == 'cloud': - entry = os.path.join(CODE_DIR, 'salt', 'cloud', 'clouds') + entry = os.path.join(RUNTIME_VARS.CODE_DIR, 'salt', 'cloud', 'clouds') errors.extend(self._check_modules(entry)) for error in errors: log.critical(error) diff --git a/tests/unit/transport/test_ipc.py b/tests/unit/transport/test_ipc.py index d7495b93c70c..4deddf4a459f 100644 --- a/tests/unit/transport/test_ipc.py +++ b/tests/unit/transport/test_ipc.py @@ -26,8 +26,8 @@ from salt.ext.six.moves import range # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.mock import MagicMock -from tests.support.paths import TMP from tests.support.unit import skipIf log = logging.getLogger(__name__) @@ -41,7 +41,7 @@ class BaseIPCReqCase(tornado.testing.AsyncTestCase): def setUp(self): super(BaseIPCReqCase, self).setUp() #self._start_handlers = dict(self.io_loop._handlers) - self.socket_path = os.path.join(TMP, 'ipc_test.ipc') + self.socket_path = os.path.join(RUNTIME_VARS.TMP, 'ipc_test.ipc') self.server_channel = salt.transport.ipc.IPCMessageServer( self.socket_path, @@ -181,7 +181,7 @@ class IPCMessagePubSubCase(tornado.testing.AsyncTestCase): def setUp(self): super(IPCMessagePubSubCase, self).setUp() self.opts = {'ipc_write_buffer': 0} - self.socket_path = os.path.join(TMP, 'ipc_test.ipc') + self.socket_path = os.path.join(RUNTIME_VARS.TMP, 'ipc_test.ipc') self.pub_channel = self._get_pub_channel() self.sub_channel = self._get_sub_channel() diff --git a/tests/unit/transport/test_zeromq.py b/tests/unit/transport/test_zeromq.py index f7dcadba4beb..dde7e47cc87e 100644 --- a/tests/unit/transport/test_zeromq.py +++ b/tests/unit/transport/test_zeromq.py @@ -39,7 +39,7 @@ from salt.transport.zeromq import AsyncReqMessageClientPool # Import test support libs -from tests.support.paths import TMP_CONF_DIR +from tests.support.runtests import RUNTIME_VARS from tests.support.unit import TestCase, skipIf from tests.support.helpers import flaky, get_unused_localhost_port from tests.support.mixins import AdaptedConfigurationTestCaseMixin @@ -217,7 +217,7 @@ def setUpClass(cls): 'tcp_master_workers': tcp_master_workers} ) - cls.minion_config = salt.config.minion_config(os.path.join(TMP_CONF_DIR, 'minion')) + cls.minion_config = salt.config.minion_config(os.path.join(RUNTIME_VARS.TMP_CONF_DIR, 'minion')) cls.minion_config = cls.get_temp_config( 'minion', **{'transport': 'zeromq', diff --git a/tests/unit/utils/test_botomod.py b/tests/unit/utils/test_botomod.py index 1aa45c5a815b..e18d80f58794 100644 --- a/tests/unit/utils/test_botomod.py +++ b/tests/unit/utils/test_botomod.py @@ -8,7 +8,7 @@ from tests.support.mixins import LoaderModuleMockMixin from tests.support.unit import skipIf, TestCase from tests.support.mock import NO_MOCK, NO_MOCK_REASON, patch, MagicMock -from tests.support.paths import TESTS_DIR +from tests.support.runtests import RUNTIME_VARS # Import Salt libs import salt.utils.botomod as botomod @@ -21,7 +21,7 @@ # pylint: disable=import-error try: import boto - boto.ENDPOINTS_PATH = os.path.join(TESTS_DIR, 'unit/files/endpoints.json') + boto.ENDPOINTS_PATH = os.path.join(RUNTIME_VARS.TESTS_DIR, 'unit/files/endpoints.json') import boto.exception from boto.exception import BotoServerError diff --git a/tests/unit/utils/test_cloud.py b/tests/unit/utils/test_cloud.py index 101a8a5b016a..7e7e317c1ec8 100644 --- a/tests/unit/utils/test_cloud.py +++ b/tests/unit/utils/test_cloud.py @@ -15,15 +15,15 @@ import tempfile # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.unit import TestCase, skipIf -from tests.support.paths import TMP, CODE_DIR # Import salt libs import salt.utils.cloud as cloud import salt.utils.platform from salt.ext import six -GPG_KEYDIR = os.path.join(TMP, 'gpg-keydir') +GPG_KEYDIR = os.path.join(RUNTIME_VARS.TMP, 'gpg-keydir') # The keyring library uses `getcwd()`, let's make sure we in a good directory # before importing keyring @@ -63,8 +63,8 @@ def delete_password(self, servicename, username): HAS_KEYRING = True except ImportError: HAS_KEYRING = False - -os.chdir(CODE_DIR) +finally: + os.chdir(RUNTIME_VARS.CODE_DIR) class CloudUtilsTestCase(TestCase): diff --git a/tests/unit/utils/test_configparser.py b/tests/unit/utils/test_configparser.py index dc8cf4339df7..52864d9c2535 100644 --- a/tests/unit/utils/test_configparser.py +++ b/tests/unit/utils/test_configparser.py @@ -15,8 +15,8 @@ log = logging.getLogger(__name__) # Import Salt Testing Libs +from tests.support.runtests import RUNTIME_VARS from tests.support.unit import TestCase -from tests.support.paths import TMP # Import salt libs import salt.utils.files @@ -56,8 +56,8 @@ class TestGitConfigParser(TestCase): Tests for salt.utils.configparser.GitConfigParser ''' maxDiff = None - orig_config = os.path.join(TMP, 'test_gitconfig.orig') - new_config = os.path.join(TMP, 'test_gitconfig.new') + orig_config = os.path.join(RUNTIME_VARS.TMP, 'test_gitconfig.orig') + new_config = os.path.join(RUNTIME_VARS.TMP, 'test_gitconfig.new') remote = 'remote "origin"' def tearDown(self): diff --git a/tests/unit/utils/test_extend.py b/tests/unit/utils/test_extend.py index fd09071de93f..27dbbf387fff 100644 --- a/tests/unit/utils/test_extend.py +++ b/tests/unit/utils/test_extend.py @@ -16,7 +16,7 @@ # Import Salt Testing libs from tests.support.unit import TestCase, skipIf from tests.support.mock import MagicMock, patch -from tests.support.paths import CODE_DIR +from tests.support.runtests import RUNTIME_VARS # Import salt libs import salt.utils.extend @@ -26,7 +26,7 @@ class ExtendTestCase(TestCase): def setUp(self): self.starting_dir = os.getcwd() - os.chdir(CODE_DIR) + os.chdir(RUNTIME_VARS.CODE_DIR) self.out = None def tearDown(self): @@ -35,11 +35,11 @@ def tearDown(self): shutil.rmtree(self.out, True) os.chdir(self.starting_dir) - @skipIf(not os.path.exists(os.path.join(CODE_DIR, 'templates')), + @skipIf(not os.path.exists(os.path.join(RUNTIME_VARS.CODE_DIR, 'templates')), "Test template directory 'templates/' missing.") def test_run(self): with patch('sys.exit', MagicMock): - out = salt.utils.extend.run('test', 'test', 'this description', CODE_DIR, False) + out = salt.utils.extend.run('test', 'test', 'this description', RUNTIME_VARS.CODE_DIR, False) self.out = out year = date.today().strftime('%Y') self.assertTrue(os.path.exists(out)) diff --git a/tests/unit/utils/test_find.py b/tests/unit/utils/test_find.py index 2b558a66e3ca..ac78fe596b6f 100644 --- a/tests/unit/utils/test_find.py +++ b/tests/unit/utils/test_find.py @@ -9,8 +9,8 @@ import stat # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.unit import skipIf, TestCase -from tests.support.paths import TMP # Import salt libs import salt.utils.files @@ -286,7 +286,7 @@ class TestGrepOption(TestCase): def setUp(self): super(TestGrepOption, self).setUp() - self.tmpdir = tempfile.mkdtemp(dir=TMP) + self.tmpdir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) def tearDown(self): shutil.rmtree(self.tmpdir) @@ -331,7 +331,7 @@ class TestPrintOption(TestCase): def setUp(self): super(TestPrintOption, self).setUp() - self.tmpdir = tempfile.mkdtemp(dir=TMP) + self.tmpdir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) def tearDown(self): shutil.rmtree(self.tmpdir) @@ -435,7 +435,7 @@ class TestFinder(TestCase): def setUp(self): super(TestFinder, self).setUp() - self.tmpdir = tempfile.mkdtemp(dir=TMP) + self.tmpdir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) def tearDown(self): shutil.rmtree(self.tmpdir) diff --git a/tests/unit/utils/test_jinja.py b/tests/unit/utils/test_jinja.py index 48d824e1cc4d..8e008da8661c 100644 --- a/tests/unit/utils/test_jinja.py +++ b/tests/unit/utils/test_jinja.py @@ -14,11 +14,11 @@ import tempfile # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.unit import skipIf, TestCase from tests.support.case import ModuleCase from tests.support.helpers import flaky from tests.support.mock import NO_MOCK, NO_MOCK_REASON, patch, MagicMock, Mock -from tests.support.paths import BASE_FILES, TMP, TMP_CONF_DIR # Import Salt libs import salt.config @@ -52,7 +52,6 @@ except ImportError: HAS_TIMELIB = False -CACHEDIR = os.path.join(TMP, 'jinja-template-cache') BLINESEP = salt.utils.stringutils.to_bytes(os.linesep) @@ -112,7 +111,7 @@ def setUp(self): self.tempdir = tempfile.mkdtemp() self.template_dir = os.path.join(self.tempdir, 'files', 'test') _setup_test_dir( - os.path.join(BASE_FILES, 'templates'), + os.path.join(RUNTIME_VARS.BASE_FILES, 'templates'), self.template_dir ) self.opts = { @@ -264,7 +263,7 @@ def setUp(self): self.tempdir = tempfile.mkdtemp() self.template_dir = os.path.join(self.tempdir, 'files', 'test') _setup_test_dir( - os.path.join(BASE_FILES, 'templates'), + os.path.join(RUNTIME_VARS.BASE_FILES, 'templates'), self.template_dir ) self.local_opts = { @@ -601,16 +600,16 @@ class TestJinjaDefaultOptions(TestCase): def __init__(self, *args, **kws): TestCase.__init__(self, *args, **kws) self.local_opts = { - 'cachedir': CACHEDIR, + 'cachedir': os.path.join(RUNTIME_VARS.TMP, 'jinja-template-cache'), 'file_buffer_size': 1048576, 'file_client': 'local', 'file_ignore_regex': None, 'file_ignore_glob': None, 'file_roots': { - 'test': [os.path.join(BASE_FILES, 'templates')] + 'test': [os.path.join(RUNTIME_VARS.BASE_FILES, 'templates')] }, 'pillar_roots': { - 'test': [os.path.join(BASE_FILES, 'templates')] + 'test': [os.path.join(RUNTIME_VARS.BASE_FILES, 'templates')] }, 'fileserver_backend': ['roots'], 'hash_type': 'md5', @@ -663,16 +662,16 @@ class TestCustomExtensions(TestCase): def __init__(self, *args, **kws): super(TestCustomExtensions, self).__init__(*args, **kws) self.local_opts = { - 'cachedir': CACHEDIR, + 'cachedir': os.path.join(RUNTIME_VARS.TMP, 'jinja-template-cache'), 'file_buffer_size': 1048576, 'file_client': 'local', 'file_ignore_regex': None, 'file_ignore_glob': None, 'file_roots': { - 'test': [os.path.join(BASE_FILES, 'templates')] + 'test': [os.path.join(RUNTIME_VARS.BASE_FILES, 'templates')] }, 'pillar_roots': { - 'test': [os.path.join(BASE_FILES, 'templates')] + 'test': [os.path.join(RUNTIME_VARS.BASE_FILES, 'templates')] }, 'fileserver_backend': ['roots'], 'hash_type': 'md5', @@ -1343,7 +1342,7 @@ def setUp(self, *args, **kwargs): 'mocktest.ping': lambda: True, 'mockgrains.get': lambda x: 'jerry', } - minion_opts = salt.config.minion_config(os.path.join(TMP_CONF_DIR, 'minion')) + minion_opts = salt.config.minion_config(os.path.join(RUNTIME_VARS.TMP_CONF_DIR, 'minion')) render = salt.loader.render(minion_opts, functions) self.jinja = render.get('jinja') diff --git a/tests/unit/utils/test_pydsl.py b/tests/unit/utils/test_pydsl.py index c3a5330b1b14..5a232db30e73 100644 --- a/tests/unit/utils/test_pydsl.py +++ b/tests/unit/utils/test_pydsl.py @@ -10,9 +10,9 @@ import copy # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.helpers import with_tempdir from tests.support.unit import TestCase -from tests.support.paths import TMP # Import Salt libs import salt.loader @@ -34,7 +34,7 @@ class CommonTestCaseBoilerplate(TestCase): def setUp(self): - self.root_dir = tempfile.mkdtemp(dir=TMP) + self.root_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) self.addCleanup(shutil.rmtree, self.root_dir, ignore_errors=True) self.state_tree_dir = os.path.join(self.root_dir, 'state_tree') self.cache_dir = os.path.join(self.root_dir, 'cachedir') diff --git a/tests/unit/utils/test_sdb.py b/tests/unit/utils/test_sdb.py index 3278989cc0e5..dd3f99078257 100644 --- a/tests/unit/utils/test_sdb.py +++ b/tests/unit/utils/test_sdb.py @@ -19,30 +19,31 @@ # Import Salt Libs import salt.utils.sdb as sdb -TEMP_DATABASE_FILE = os.path.join(RUNTIME_VARS.TMP, 'test_sdb.sqlite') -SDB_OPTS = { +@skipIf(NO_MOCK, NO_MOCK_REASON) +class SdbTestCase(TestCase, LoaderModuleMockMixin): + ''' + Test cases for salt.modules.sdb + ''' + + @classmethod + def setUpClass(cls): + cls.TEMP_DATABASE_FILE = os.path.join(RUNTIME_VARS.TMP, 'test_sdb.sqlite') + cls.sdb_opts = { 'extension_modules': '', 'optimization_order': [0, 1, 2], 'test_sdb_data': { 'driver': 'sqlite3', - 'database': TEMP_DATABASE_FILE, + 'database': cls.TEMP_DATABASE_FILE, 'table': 'sdb', 'create_table': True } - } - - -@skipIf(NO_MOCK, NO_MOCK_REASON) -class SdbTestCase(TestCase, LoaderModuleMockMixin): - ''' - Test cases for salt.modules.sdb - ''' + } @classmethod def tearDownClass(cls): try: - os.unlink(TEMP_DATABASE_FILE) + os.unlink(cls.TEMP_DATABASE_FILE) except OSError: pass @@ -53,13 +54,13 @@ def setup_loader_modules(self): def test_sqlite_get_not_found(self): what = sdb.sdb_get( - 'sdb://test_sdb_data/thisKeyDoesNotExist', SDB_OPTS) + 'sdb://test_sdb_data/thisKeyDoesNotExist', self.sdb_opts) self.assertEqual(what, None) # test with SQLite database write and read def test_sqlite_get_found(self): expected = {b'name': b'testone', b'number': 46} - sdb.sdb_set('sdb://test_sdb_data/test1', expected, SDB_OPTS) - resp = sdb.sdb_get('sdb://test_sdb_data/test1', SDB_OPTS) + sdb.sdb_set('sdb://test_sdb_data/test1', expected, self.sdb_opts) + resp = sdb.sdb_get('sdb://test_sdb_data/test1', self.sdb_opts) self.assertEqual(resp, expected) diff --git a/tests/unit/utils/test_verify.py b/tests/unit/utils/test_verify.py index 23e1bbfdbe72..fa60fc4d72cf 100644 --- a/tests/unit/utils/test_verify.py +++ b/tests/unit/utils/test_verify.py @@ -20,8 +20,8 @@ import resource # Import Salt Testing libs +from tests.support.runtests import RUNTIME_VARS from tests.support.unit import skipIf, TestCase -from tests.support.paths import TMP from tests.support.helpers import ( requires_network, TestsLoggingHandler @@ -113,7 +113,7 @@ def write(self, data): @skipIf(salt.utils.platform.is_windows(), 'No verify_env Windows') def test_verify_env(self): - root_dir = tempfile.mkdtemp(dir=TMP) + root_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) var_dir = os.path.join(root_dir, 'var', 'log', 'salt') key_dir = os.path.join(root_dir, 'key_dir') verify_env([var_dir], getpass.getuser(), root_dir=root_dir) diff --git a/tests/unit/utils/test_vmware.py b/tests/unit/utils/test_vmware.py index 0df0d7652f3e..583cfaed34aa 100644 --- a/tests/unit/utils/test_vmware.py +++ b/tests/unit/utils/test_vmware.py @@ -13,6 +13,7 @@ import sys # Import Salt testing libraries +from tests.support.runtests import RUNTIME_VARS from tests.support.unit import TestCase, skipIf from tests.support.mixins import LoaderModuleMockMixin from tests.support.mock import ( @@ -2655,7 +2656,9 @@ def test_wait_for_tasks(self): dvs_create_spec=self.mock_dvs_create_spec) self.mock_wait_for_task.assert_called_once_with( self.mock_task, 'fake_dvs', - '') + ''.format( + 'tests.' if RUNTIME_VARS.PYTEST_SESSION else '') + ) @skipIf(NO_MOCK, NO_MOCK_REASON) @@ -2724,7 +2727,9 @@ def test_wait_for_tasks(self): salt.utils.vmware.update_dvs(self.mock_dvs_ref, self.mock_dvs_spec) self.mock_wait_for_task.assert_called_once_with( self.mock_task, 'fake_dvs', - '') + ''.format( + 'tests.' if RUNTIME_VARS.PYTEST_SESSION else '') + ) @skipIf(NO_MOCK, NO_MOCK_REASON) @@ -3023,7 +3028,9 @@ def test_wait_for_tasks(self): salt.utils.vmware.create_dvportgroup(self.mock_dvs_ref, self.mock_pg_spec) self.mock_wait_for_task.assert_called_once_with( self.mock_task, 'fake_dvs', - '') + ''.format( + 'tests.' if RUNTIME_VARS.PYTEST_SESSION else '') + ) @skipIf(NO_MOCK, NO_MOCK_REASON) @@ -3096,7 +3103,9 @@ def test_wait_for_tasks(self): salt.utils.vmware.update_dvportgroup(self.mock_pg_ref, self.mock_pg_spec) self.mock_wait_for_task.assert_called_once_with( self.mock_task, 'fake_pg', - '') + ''.format( + 'tests.' if RUNTIME_VARS.PYTEST_SESSION else '') + ) @skipIf(NO_MOCK, NO_MOCK_REASON) @@ -3163,7 +3172,9 @@ def test_wait_for_tasks(self): salt.utils.vmware.remove_dvportgroup(self.mock_pg_ref) self.mock_wait_for_task.assert_called_once_with( self.mock_task, 'fake_pg', - '') + ''.format( + 'tests.' if RUNTIME_VARS.PYTEST_SESSION else '') + ) @skipIf(NO_MOCK, NO_MOCK_REASON) From 395b8fbd3a0ea9c9423c6bd17670813b6148a7a0 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Tue, 15 Jan 2019 10:14:39 +0000 Subject: [PATCH 2/5] Respect `RUNTIME_VARS.TMP` for tests temp files Conflicts: * tests/integration/states/test_file.py --- .../files/file/base/file-pillardefaultget.sls | 8 +---- .../files/file/base/file-pillarget.sls | 8 +---- .../files/file/base/file_contents_pillar.sls | 8 +---- tests/integration/states/test_file.py | 36 +++++++++---------- 4 files changed, 20 insertions(+), 40 deletions(-) diff --git a/tests/integration/files/file/base/file-pillardefaultget.sls b/tests/integration/files/file/base/file-pillardefaultget.sls index b2d73ac92955..b0f80236daf6 100644 --- a/tests/integration/files/file/base/file-pillardefaultget.sls +++ b/tests/integration/files/file/base/file-pillardefaultget.sls @@ -1,11 +1,5 @@ -{% if grains['kernel'] == 'Windows' %} - {% set TMP = "C:\\Windows\\Temp\\" %} -{% else %} - {% set TMP = "/tmp/" %} -{% endif %} - {% set file = salt['pillar.get']('pillardoesnotexist', 'defaultvalue') %} create_file: file.managed: - - name: {{ TMP }}filepillar-{{ file }} + - name: {{ salt['runtests_helpers.get_salt_temp_dir_for_path']('filepillar-' + file) }} diff --git a/tests/integration/files/file/base/file-pillarget.sls b/tests/integration/files/file/base/file-pillarget.sls index 44adf16c801a..a8381ada662e 100644 --- a/tests/integration/files/file/base/file-pillarget.sls +++ b/tests/integration/files/file/base/file-pillarget.sls @@ -1,11 +1,5 @@ -{% if grains['kernel'] == 'Windows' %} - {% set TMP = "C:\\Windows\\Temp\\" %} -{% else %} - {% set TMP = "/tmp/" %} -{% endif %} - {% set file = salt['pillar.get']('monty', '') %} create_file: file.managed: - - name: {{ TMP }}filepillar-{{ file }} + - name: {{ salt['runtests_helpers.get_salt_temp_dir_for_path']('filepillar-' + file) }} diff --git a/tests/integration/files/file/base/file_contents_pillar.sls b/tests/integration/files/file/base/file_contents_pillar.sls index 06069d147978..2a5ae8baff4a 100644 --- a/tests/integration/files/file/base/file_contents_pillar.sls +++ b/tests/integration/files/file/base/file_contents_pillar.sls @@ -1,10 +1,4 @@ -{% if grains['kernel'] == 'Windows' %} - {% set TMP = "C:\\Windows\\Temp\\" %} -{% else %} - {% set TMP = "/tmp/" %} -{% endif %} - add_contents_pillar_sls: file.managed: - - name: {{ TMP }}test-lists-content-pillars + - name: {{ salt['runtests_helpers.get_salt_temp_dir_for_path']('test-lists-content-pillars') }} - contents_pillar: companions:three diff --git a/tests/integration/states/test_file.py b/tests/integration/states/test_file.py index ef7e3075902f..c1a0b1793585 100644 --- a/tests/integration/states/test_file.py +++ b/tests/integration/states/test_file.py @@ -30,7 +30,6 @@ with_tempdir, with_tempfile, Webserver, - destructiveTest, dedent, ) from tests.support.mixins import SaltReturnAssertsMixin @@ -65,15 +64,6 @@ BINARY_FILE = b'GIF89a\x01\x00\x01\x00\x80\x00\x00\x05\x04\x04\x00\x00\x00,\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02D\x01\x00;' -if IS_WINDOWS: - FILEPILLAR = 'C:\\Windows\\Temp\\filepillar-python' - FILEPILLARDEF = 'C:\\Windows\\Temp\\filepillar-defaultvalue' - FILEPILLARGIT = 'C:\\Windows\\Temp\\filepillar-bar' -else: - FILEPILLAR = '/tmp/filepillar-python' - FILEPILLARDEF = '/tmp/filepillar-defaultvalue' - FILEPILLARGIT = '/tmp/filepillar-bar' - TEST_SYSTEM_USER = 'test_system_user' TEST_SYSTEM_GROUP = 'test_system_group' @@ -147,6 +137,14 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin): ''' Validate the file state ''' + + def _delete_file(self, path): + try: + os.remove(path) + except OSError as exc: + if exc.errno != errno.ENOENT: + log.error('Failed to remove %s: %s', path, exc) + def tearDown(self): ''' remove files created in previous tests @@ -155,13 +153,6 @@ def tearDown(self): if user in str(self.run_function('user.list_users')): self.run_function('user.delete', [user]) - for path in (FILEPILLAR, FILEPILLARDEF, FILEPILLARGIT): - try: - os.remove(path) - except OSError as exc: - if exc.errno != errno.ENOENT: - log.error('Failed to remove %s: %s', path, exc) - def test_symlink(self): ''' file.symlink @@ -382,13 +373,17 @@ def test_managed_file_with_pillar_sls(self): Test to ensure pillar data in sls file is rendered properly and file is created. ''' + + file_pillar = os.path.join(RUNTIME_VARS.TMP, 'filepillar-python') + self.addCleanup(self._delete_file, file_pillar) state_name = 'file-pillarget' + log.warning('File Path: %s', file_pillar) ret = self.run_function('state.sls', [state_name]) self.assertSaltTrueReturn(ret) # Check to make sure the file was created - check_file = self.run_function('file.file_exists', [FILEPILLAR]) + check_file = self.run_function('file.file_exists', [file_pillar]) self.assertTrue(check_file) def test_managed_file_with_pillardefault_sls(self): @@ -397,13 +392,16 @@ def test_managed_file_with_pillardefault_sls(self): in sls file with pillar.get it uses the default value. ''' + file_pillar_def = os.path.join(RUNTIME_VARS.TMP, 'filepillar-defaultvalue') + self.addCleanup(self._delete_file, file_pillar_def) state_name = 'file-pillardefaultget' + log.warning('File Path: %s', file_pillar_def) ret = self.run_function('state.sls', [state_name]) self.assertSaltTrueReturn(ret) # Check to make sure the file was created - check_file = self.run_function('file.file_exists', [FILEPILLARDEF]) + check_file = self.run_function('file.file_exists', [file_pillar_def]) self.assertTrue(check_file) @skip_if_not_root From 8b181159b9eda06ebea3213a02dbcee0f16d7441 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Fri, 11 Oct 2019 13:17:24 +0100 Subject: [PATCH 3/5] Fix circular imports issue --- tests/integration/modules/test_cmdmod.py | 5 ++--- tests/minionswarm.py | 4 ++-- tests/support/helpers.py | 11 ----------- tests/support/runtests.py | 20 ++++++++++++++++---- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/integration/modules/test_cmdmod.py b/tests/integration/modules/test_cmdmod.py index 0631f95d802b..008b750423f6 100644 --- a/tests/integration/modules/test_cmdmod.py +++ b/tests/integration/modules/test_cmdmod.py @@ -14,7 +14,6 @@ destructiveTest, skip_if_binaries_missing, skip_if_not_root, - this_user, ) from tests.support.runtests import RUNTIME_VARS from tests.support.unit import skipIf @@ -304,7 +303,7 @@ def test_quotes_runas(self): expected_result = 'SELECT * FROM foo WHERE bar="baz"' - runas = this_user() + runas = RUNTIME_VARS.RUNNING_TESTS_USER result = self.run_function('cmd.run_stdout', [cmd], runas=runas).strip() @@ -321,7 +320,7 @@ def test_avoid_injecting_shell_code_as_root(self): cmd = 'echo $(id -u)' root_id = self.run_function('cmd.run_stdout', [cmd]) - runas_root_id = self.run_function('cmd.run_stdout', [cmd], runas=this_user()) + runas_root_id = self.run_function('cmd.run_stdout', [cmd], runas=RUNTIME_VARS.RUNNING_TESTS_USER) with self._ensure_user_exists(self.runas_usr): user_id = self.run_function('cmd.run_stdout', [cmd], runas=self.runas_usr) diff --git a/tests/minionswarm.py b/tests/minionswarm.py index 86f3a24a6811..de899e5d5139 100644 --- a/tests/minionswarm.py +++ b/tests/minionswarm.py @@ -28,7 +28,7 @@ # Import third party libs from salt.ext import six from salt.ext.six.moves import range # pylint: disable=import-error,redefined-builtin -import tests.support.helpers +import tests.support.runtests OSES = [ @@ -148,7 +148,7 @@ def parse(): '-c', '--config-dir', default='', help=('Pass in a configuration directory containing base configuration.') ) - parser.add_option('-u', '--user', default=tests.support.helpers.this_user()) + parser.add_option('-u', '--user', default=tests.support.runtests.this_user()) options, _args = parser.parse_args() diff --git a/tests/support/helpers.py b/tests/support/helpers.py index 67b7c927bd6d..75e13414e155 100644 --- a/tests/support/helpers.py +++ b/tests/support/helpers.py @@ -53,8 +53,6 @@ if salt.utils.platform.is_windows(): import salt.utils.win_functions -else: - import pwd log = logging.getLogger(__name__) @@ -1624,15 +1622,6 @@ def win32_kill_process_tree(pid, sig=signal.SIGTERM, include_parent=True, return (gone, alive) -def this_user(): - ''' - Get the user associated with the current process. - ''' - if salt.utils.platform.is_windows(): - return salt.utils.win_functions.get_current_user(with_domain=False) - return pwd.getpwuid(os.getuid())[0] - - def dedent(text, linesep=os.linesep): ''' A wrapper around textwrap.dedent that also sets line endings. diff --git a/tests/support/runtests.py b/tests/support/runtests.py index 97dfa4a6da20..b9e2a67372ca 100644 --- a/tests/support/runtests.py +++ b/tests/support/runtests.py @@ -52,17 +52,29 @@ import shutil import logging +import salt.utils.platform + +try: + import pwd +except ImportError: + import salt.utils.win_functions + # Import tests support libs import tests.support.paths as paths -import tests.support.helpers # Import 3rd-party libs from salt.ext import six -RUNNING_TESTS_USER = tests.support.helpers.this_user() +log = logging.getLogger(__name__) -log = logging.getLogger(__name__) +def this_user(): + ''' + Get the user associated with the current process. + ''' + if salt.utils.platform.is_windows(): + return salt.utils.win_functions.get_current_user(with_domain=False) + return pwd.getpwuid(os.getuid())[0] class RootsDict(dict): @@ -175,7 +187,7 @@ def __setattr__(self, name, value): TMP_STATE_TREE=paths.TMP_STATE_TREE, TMP_PILLAR_TREE=paths.TMP_PILLAR_TREE, TMP_PRODENV_STATE_TREE=paths.TMP_PRODENV_STATE_TREE, - RUNNING_TESTS_USER=RUNNING_TESTS_USER, + RUNNING_TESTS_USER=this_user(), RUNTIME_CONFIGS={}, CODE_DIR=paths.CODE_DIR, BASE_FILES=paths.BASE_FILES, From f47100c83b67ee7314c33037409009a0dcc95243 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Fri, 18 Jan 2019 16:57:23 +0000 Subject: [PATCH 4/5] Beware of unicode filenames --- tests/unit/fileserver/test_gitfs.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/unit/fileserver/test_gitfs.py b/tests/unit/fileserver/test_gitfs.py index 6bf38c3ad9e5..23dd0b33a466 100644 --- a/tests/unit/fileserver/test_gitfs.py +++ b/tests/unit/fileserver/test_gitfs.py @@ -400,7 +400,11 @@ def setUpClass(cls): log.error("Access error removeing file %s", TMP_REPO_DIR) elif exc.errno != errno.ENOENT: raise - shutil.copytree(RUNTIME_VARS.BASE_FILES, TMP_REPO_DIR + '/') + + shutil.copytree( + salt.ext.six.text_type(RUNTIME_VARS.BASE_FILES), + salt.ext.six.text_type(TMP_REPO_DIR + '/') + ) repo = git.Repo.init(TMP_REPO_DIR) From cb4c28fb363f9fc012fc9d1b42509b3364cd4bb5 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Tue, 3 Dec 2019 15:21:53 +0000 Subject: [PATCH 5/5] Account for salt-ssh tests and non importable `RUNTIME_VARS` --- .../file/base/_modules/runtests_helpers.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/integration/files/file/base/_modules/runtests_helpers.py b/tests/integration/files/file/base/_modules/runtests_helpers.py index 436fb85939e1..22dc6e2e9ff3 100644 --- a/tests/integration/files/file/base/_modules/runtests_helpers.py +++ b/tests/integration/files/file/base/_modules/runtests_helpers.py @@ -9,11 +9,11 @@ # Import python libs from __future__ import absolute_import -import fnmatch import os import re import sys import fnmatch +import tempfile # Import salt libs import salt.utils.platform @@ -22,7 +22,22 @@ from salt.ext import six # Import tests libs -from tests.support.runtests import RUNTIME_VARS +try: + from tests.support.runtests import RUNTIME_VARS +except ImportError: + # Salt SSH Tests + SYS_TMP_DIR = os.path.realpath( + # Avoid ${TMPDIR} and gettempdir() on MacOS as they yield a base path too long + # for unix sockets: ``error: AF_UNIX path too long`` + # Gentoo Portage prefers ebuild tests are rooted in ${TMPDIR} + os.environ.get('TMPDIR', tempfile.gettempdir()) if not salt.utils.platform.is_darwin() else '/tmp' + ) + # This tempdir path is defined on tests.integration.__init__ + TMP = os.path.join(SYS_TMP_DIR, 'salt-tests-tmpdir') + + class RUNTIME_VARS(object): + TMP = TMP + SYS_TMP_DIR = SYS_TMP_DIR def get_salt_temp_dir():