Stop relying on the self.config_dir attribute

This commit is contained in:
Pedro Algarvio 2020-04-11 18:42:29 +01:00 committed by Daniel Wozniak
parent 34fb50b134
commit 8b7a575f69
12 changed files with 65 additions and 83 deletions

View file

@ -3,22 +3,16 @@
:codeauthor: Nicole Thomas <nicole@saltstack.com>
"""
# Import Python Libs
from __future__ import absolute_import, print_function, unicode_literals
import os
# Import Salt Libs
import salt.utils.cloud
import salt.utils.files
import salt.utils.yaml
import yaml
# Create the cloud instance name to be used throughout the tests
from tests.integration.cloud.helpers.cloud_test_base import CloudTest
from tests.support import win_installer
# Import Salt Testing Libs
from tests.support.runtests import RUNTIME_VARS
from tests.support.unit import skipIf
@ -76,7 +70,9 @@ class EC2Test(CloudTest):
super(EC2Test, self).setUp()
def override_profile_config(self, name, data):
conf_path = os.path.join(self.config_dir, "cloud.profiles.d", "ec2.conf")
conf_path = os.path.join(
RUNTIME_VARS.TMP_CONF_DIR, "cloud.profiles.d", "ec2.conf"
)
with salt.utils.files.fopen(conf_path, "r") as fp:
conf = yaml.safe_load(fp)
conf[name].update(data)
@ -90,7 +86,7 @@ class EC2Test(CloudTest):
returned.
"""
src = os.path.join(RUNTIME_VARS.FILES, name)
dst = os.path.join(self.config_dir, name)
dst = os.path.join(RUNTIME_VARS.TMP_CONF_DIR, name)
with salt.utils.files.fopen(src, "rb") as sfp:
with salt.utils.files.fopen(dst, "wb") as dfp:
dfp.write(sfp.read())

View file

@ -173,7 +173,9 @@ class CloudTest(ShellCase):
if not hasattr(self, "_provider_config"):
self._provider_config = cloud_providers_config(
os.path.join(
self.config_dir, "cloud.providers.d", self.PROVIDER + ".conf"
RUNTIME_VARS.TMP_CONF_DIR,
"cloud.providers.d",
self.PROVIDER + ".conf",
)
)
return self._provider_config[self.profile_str][self.PROVIDER]
@ -183,7 +185,9 @@ class CloudTest(ShellCase):
if not hasattr(self, "_config"):
self._config = cloud_config(
os.path.join(
self.config_dir, "cloud.profiles.d", self.PROVIDER + ".conf"
RUNTIME_VARS.TMP_CONF_DIR,
"cloud.profiles.d",
self.PROVIDER + ".conf",
)
)
return self._config

View file

@ -7,7 +7,6 @@ tests.integration.master.test_event_return
https://github.com/saltstack/salt/pull/54731
"""
# Import Python libs
from __future__ import absolute_import, print_function, unicode_literals
import logging
@ -16,19 +15,15 @@ import shutil
import subprocess
import time
# Import 3rd-party libs
import pytest
# Import Salt libs
import salt.ext.six as six
from salt.utils.nb_popen import NonBlockingPopen
# Import Salt Testing libs
from tests.support.case import TestCase
from tests.support.cli_scripts import ScriptPathMixin
from tests.support.helpers import get_unused_localhost_port
from tests.support.mixins import AdaptedConfigurationTestCaseMixin
from tests.support.processes import terminate_process
from tests.support.runtests import RUNTIME_VARS
log = logging.getLogger(__name__)
@ -62,7 +57,13 @@ class TestEventReturn(AdaptedConfigurationTestCaseMixin, ScriptPathMixin, TestCa
def test_master_startup(self):
proc = NonBlockingPopen(
[self.get_script_path("master"), "-c", self.config_dir, "-l", "info"],
[
self.get_script_path("master"),
"-c",
RUNTIME_VARS.TMP_CONF_DIR,
"-l",
"info",
],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)

View file

@ -32,7 +32,7 @@ class RunnerReturnsTest(ShellCase):
"""
self.job_dir = os.path.join(self.master_opts["cachedir"], "jobs")
self.hash_type = self.master_opts["hash_type"]
self.master_d_dir = os.path.join(self.config_dir, "master.d")
self.master_d_dir = os.path.join(RUNTIME_VARS.TMP_CONF_DIR, "master.d")
try:
os.makedirs(self.master_d_dir)
except OSError as exc:

View file

@ -359,7 +359,7 @@ class OrchEventTest(ShellCase):
def setUp(self):
self.timeout = 60
self.master_d_dir = os.path.join(self.config_dir, "master.d")
self.master_d_dir = os.path.join(RUNTIME_VARS.TMP_CONF_DIR, "master.d")
try:
os.makedirs(self.master_d_dir)
except OSError as exc:

View file

@ -210,7 +210,7 @@ class CallTest(ShellCase, testprogram.TestProgramCase, ShellCaseCommonTestsMixin
_ = self.run_script(
"salt-call",
"-c {0} --output-file={1} test.versions".format(
self.config_dir, output_file_append
RUNTIME_VARS.TMP_MINION_CONF_DIR, output_file_append
),
catch_stderr=True,
with_retcode=True,
@ -243,7 +243,7 @@ class CallTest(ShellCase, testprogram.TestProgramCase, ShellCaseCommonTestsMixin
self.run_script(
"salt-call",
"-c {0} --output-file={1} -l trace -g".format(
self.config_dir, output_file
RUNTIME_VARS.TMP_MINION_CONF_DIR, output_file
),
catch_stderr=True,
with_retcode=True,
@ -259,7 +259,7 @@ class CallTest(ShellCase, testprogram.TestProgramCase, ShellCaseCommonTestsMixin
self.run_script(
"salt-call",
"-c {0} --output-file={1} --output-file-append -g".format(
self.config_dir, output_file
RUNTIME_VARS.TMP_MINION_CONF_DIR, output_file
),
catch_stderr=True,
with_retcode=True,
@ -278,7 +278,9 @@ class CallTest(ShellCase, testprogram.TestProgramCase, ShellCaseCommonTestsMixin
# Not appending data
self.run_script(
"salt-call",
"-c {0} --output-file={1} -g".format(self.config_dir, output_file),
"-c {0} --output-file={1} -g".format(
RUNTIME_VARS.TMP_MINION_CONF_DIR, output_file
),
catch_stderr=True,
with_retcode=True,
)

View file

@ -20,6 +20,7 @@ import salt.utils.files
import salt.utils.path
from tests.integration.utils import testprogram
from tests.support.case import ShellCase
from tests.support.runtests import RUNTIME_VARS
from tests.support.unit import skipIf
log = logging.getLogger(__name__)
@ -31,7 +32,6 @@ class SaltTest(testprogram.TestProgramCase):
Various integration tests for the salt executable.
"""
# pylint: disable=invalid-name
@skipIf(True, "SLOWTEST skip")
def test_exit_status_unknown_argument(self):
"""
@ -194,7 +194,7 @@ class RetcodeTestCase(ShellCase):
fhw.write(fhr.read())
retcode = self.run_script(
"salt",
"-c {0} -t 5 minion2 test.ping".format(self.config_dir),
"-c {0} -t 5 minion2 test.ping".format(RUNTIME_VARS.TMP_CONF_DIR),
with_retcode=True,
timeout=60,
)[1]

View file

@ -121,7 +121,7 @@ class TestProgram(six.with_metaclass(TestProgramMeta, object)):
self._parent_dir = parent_dir or None
self.clean_on_exit = clean_on_exit
self._root_dir = kwargs.pop("root_dir", self.name)
self.config_dir = kwargs.pop("config_dir", copy.copy(self.config_dir))
self.config_dir = kwargs.pop("config_dir", copy.copy(RUNTIME_VARS.TMP_CONF_DIR))
config_attrs = copy.copy(self.config_attrs)
config_attrs.update(kwargs.pop("config_attrs", set()))

View file

@ -10,9 +10,6 @@
Custom reusable :class:`TestCase<python2:unittest.TestCase>`
implementations.
"""
# pylint: disable=repr-flag-used-in-string
# Import python libs
from __future__ import absolute_import, unicode_literals
import errno
@ -26,25 +23,19 @@ import textwrap
import time
from datetime import datetime, timedelta
# Import 3rd-party libs
import salt.utils.files
from salt.ext import six
from salt.ext.six.moves import cStringIO # pylint: disable=import-error
from salt.ext.six.moves import cStringIO
from tests.support.cli_scripts import ScriptPathMixin
from tests.support.helpers import RedirectStdStreams, requires_sshd_server
# ----- Backwards Compatible Imports -------------------------------------------------------------------------------->
from tests.support.mixins import ( # pylint: disable=unused-import
from tests.support.mixins import (
AdaptedConfigurationTestCaseMixin,
SaltClientTestCaseMixin,
SaltMultimasterClientTestCaseMixin,
ShellCaseCommonTestsMixin,
)
from tests.support.paths import CODE_DIR, INTEGRATION_TEST_DIR, PYEXEC, SCRIPT_DIR
from tests.support.processes import terminate_process
from tests.support.runtests import RUNTIME_VARS
# Import salt testing libs
from tests.support.unit import TestCase
STATE_FUNCTION_RUNNING_RE = re.compile(
@ -75,7 +66,9 @@ class ShellTestCase(TestCase, AdaptedConfigurationTestCaseMixin, ScriptPathMixin
data = '\n'.join(data)
self.assertIn('minion', data)
'''
arg_str = "-c {0} -t {1} {2}".format(self.config_dir, timeout, arg_str)
arg_str = "-c {0} -t {1} {2}".format(
RUNTIME_VARS.TMP_CONF_DIR, timeout, arg_str
)
return self.run_script(
"salt",
arg_str,
@ -105,7 +98,7 @@ class ShellTestCase(TestCase, AdaptedConfigurationTestCaseMixin, ScriptPathMixin
arg_str = "{0} {1} -c {2} -i --priv {3} --roster-file {4} {5} localhost {6} --out=json".format(
" -W" if wipe else "",
" -r" if raw else "",
self.config_dir,
RUNTIME_VARS.TMP_CONF_DIR,
os.path.join(RUNTIME_VARS.TMP_CONF_DIR, "key_test"),
roster_file,
ssh_opts,
@ -136,7 +129,7 @@ class ShellTestCase(TestCase, AdaptedConfigurationTestCaseMixin, ScriptPathMixin
"""
asynchronous = kwargs.get("async", asynchronous)
arg_str = "-c {0}{async_flag} -t {timeout} {1}".format(
config_dir or self.config_dir,
config_dir or RUNTIME_VARS.TMP_CONF_DIR,
arg_str,
timeout=timeout,
async_flag=" --async" if asynchronous else "",
@ -193,7 +186,7 @@ class ShellTestCase(TestCase, AdaptedConfigurationTestCaseMixin, ScriptPathMixin
"""
Execute salt-key
"""
arg_str = "-c {0} {1}".format(self.config_dir, arg_str)
arg_str = "-c {0} {1}".format(RUNTIME_VARS.TMP_CONF_DIR, arg_str)
return self.run_script(
"salt-key", arg_str, catch_stderr=catch_stderr, with_retcode=with_retcode
)
@ -202,7 +195,7 @@ class ShellTestCase(TestCase, AdaptedConfigurationTestCaseMixin, ScriptPathMixin
"""
Execute salt-cp
"""
arg_str = "--config-dir {0} {1}".format(self.config_dir, arg_str)
arg_str = "--config-dir {0} {1}".format(RUNTIME_VARS.TMP_CONF_DIR, arg_str)
return self.run_script(
"salt-cp", arg_str, with_retcode=with_retcode, catch_stderr=catch_stderr
)
@ -217,7 +210,7 @@ class ShellTestCase(TestCase, AdaptedConfigurationTestCaseMixin, ScriptPathMixin
config_dir=None,
):
if not config_dir:
config_dir = self.config_dir
config_dir = RUNTIME_VARS.TMP_MINION_CONF_DIR
arg_str = "{0} --config-dir {1} {2}".format(
"--local" if local else "", config_dir, arg_str
)
@ -246,7 +239,7 @@ class ShellTestCase(TestCase, AdaptedConfigurationTestCaseMixin, ScriptPathMixin
"""
Execute salt-cloud
"""
arg_str = "-c {0} {1}".format(self.config_dir, arg_str)
arg_str = "-c {0} {1}".format(RUNTIME_VARS.TMP_CONF_DIR, arg_str)
return self.run_script("salt-cloud", arg_str, catch_stderr, timeout)
def run_script(
@ -494,8 +487,7 @@ class ShellCase(ShellTestCase, AdaptedConfigurationTestCaseMixin, ScriptPathMixi
except OSError:
os.chdir(INTEGRATION_TEST_DIR)
# pylint: disable=arguments-differ
def run_salt(
def run_salt( # pylint: disable=arguments-differ
self,
arg_str,
with_retcode=False,
@ -506,7 +498,9 @@ class ShellCase(ShellTestCase, AdaptedConfigurationTestCaseMixin, ScriptPathMixi
"""
Execute salt
"""
arg_str = "-c {0} -t {1} {2}".format(self.config_dir, timeout, arg_str)
arg_str = "-c {0} -t {1} {2}".format(
RUNTIME_VARS.TMP_CONF_DIR, timeout, arg_str
)
ret = self.run_script(
"salt",
arg_str,
@ -520,7 +514,7 @@ class ShellCase(ShellTestCase, AdaptedConfigurationTestCaseMixin, ScriptPathMixi
def run_spm(
self, arg_str, with_retcode=False, catch_stderr=False, timeout=RUN_TIMEOUT
):
): # pylint: disable=arguments-differ
"""
Execute spm
"""
@ -534,7 +528,7 @@ class ShellCase(ShellTestCase, AdaptedConfigurationTestCaseMixin, ScriptPathMixi
log.debug("Result of run_spm for command '%s': %s", arg_str, ret)
return ret
def run_ssh(
def run_ssh( # pylint: disable=arguments-differ
self,
arg_str,
with_retcode=False,
@ -555,7 +549,7 @@ class ShellCase(ShellTestCase, AdaptedConfigurationTestCaseMixin, ScriptPathMixi
arg_str = "{0} -ldebug{1} -c {2} -i --priv {3} --roster-file {4} {5} --out=json localhost {6}".format(
" -W" if wipe else "",
" -r" if raw else "",
self.config_dir,
RUNTIME_VARS.TMP_CONF_DIR,
os.path.join(RUNTIME_VARS.TMP_CONF_DIR, "key_test"),
roster_file,
ssh_opts,
@ -573,8 +567,6 @@ class ShellCase(ShellTestCase, AdaptedConfigurationTestCaseMixin, ScriptPathMixi
log.debug("Result of run_ssh for command '%s %s': %s", arg_str, kwargs, ret)
return ret
# pylint: enable=arguments-differ
def run_run(
self,
arg_str,
@ -590,7 +582,7 @@ class ShellCase(ShellTestCase, AdaptedConfigurationTestCaseMixin, ScriptPathMixi
"""
asynchronous = kwargs.get("async", asynchronous)
arg_str = "-c {0}{async_flag} -t {timeout} {1}".format(
config_dir or self.config_dir,
config_dir or RUNTIME_VARS.TMP_CONF_DIR,
arg_str,
timeout=timeout,
async_flag=" --async" if asynchronous else "",
@ -647,14 +639,13 @@ class ShellCase(ShellTestCase, AdaptedConfigurationTestCaseMixin, ScriptPathMixi
)
return ret
# pylint: disable=arguments-differ
def run_key(
def run_key( # pylint: disable=arguments-differ
self, arg_str, catch_stderr=False, with_retcode=False, timeout=RUN_TIMEOUT,
):
"""
Execute salt-key
"""
arg_str = "-c {0} {1}".format(self.config_dir, arg_str)
arg_str = "-c {0} {1}".format(RUNTIME_VARS.TMP_CONF_DIR, arg_str)
ret = self.run_script(
"salt-key",
arg_str,
@ -665,10 +656,7 @@ class ShellCase(ShellTestCase, AdaptedConfigurationTestCaseMixin, ScriptPathMixi
log.debug("Result of run_key for command '%s': %s", arg_str, ret)
return ret
# pylint: disable=arguments-differ
# pylint: disable=arguments-differ
def run_cp(
def run_cp( # pylint: disable=arguments-differ
self, arg_str, with_retcode=False, catch_stderr=False, timeout=RUN_TIMEOUT,
):
"""
@ -676,7 +664,7 @@ class ShellCase(ShellTestCase, AdaptedConfigurationTestCaseMixin, ScriptPathMixi
"""
# Note: not logging result of run_cp because it will log a bunch of
# bytes which will not be very helpful.
arg_str = "--config-dir {0} {1}".format(self.config_dir, arg_str)
arg_str = "--config-dir {0} {1}".format(RUNTIME_VARS.TMP_CONF_DIR, arg_str)
return self.run_script(
"salt-cp",
arg_str,
@ -685,8 +673,6 @@ class ShellCase(ShellTestCase, AdaptedConfigurationTestCaseMixin, ScriptPathMixi
timeout=timeout,
)
# pylint: enable=arguments-differ
# pylint: disable=arguments-differ
def run_call(
self,
arg_str,
@ -700,7 +686,7 @@ class ShellCase(ShellTestCase, AdaptedConfigurationTestCaseMixin, ScriptPathMixi
Execute salt-call.
"""
if not config_dir:
config_dir = self.config_dir
config_dir = RUNTIME_VARS.TMP_MINION_CONF_DIR
arg_str = "{0} --config-dir {1} {2}".format(
"--local" if local else "", config_dir, arg_str
)
@ -720,7 +706,7 @@ class ShellCase(ShellTestCase, AdaptedConfigurationTestCaseMixin, ScriptPathMixi
"""
Execute salt-cloud
"""
arg_str = "-c {0} {1}".format(self.config_dir, arg_str)
arg_str = "-c {0} {1}".format(RUNTIME_VARS.TMP_CONF_DIR, arg_str)
ret = self.run_script("salt-cloud", arg_str, catch_stderr, timeout=timeout)
log.debug("Result of run_cloud for command '%s': %s", arg_str, ret)
return ret
@ -1172,6 +1158,3 @@ class ClientCase(AdaptedConfigurationTestCaseMixin, TestCase):
pass
else:
raise
# <---- Backwards Compatible Imports ---------------------------------------------------------------------------------

View file

@ -11,7 +11,6 @@
Tests related paths
"""
# Import python libs
from __future__ import absolute_import
import logging
@ -70,12 +69,15 @@ SCRIPT_DIR = os.path.join(CODE_DIR, "scripts")
TMP_STATE_TREE = os.path.join(SYS_TMP_DIR, "salt-temp-state-tree")
TMP_PILLAR_TREE = os.path.join(SYS_TMP_DIR, "salt-temp-pillar-tree")
TMP_PRODENV_STATE_TREE = os.path.join(SYS_TMP_DIR, "salt-temp-prodenv-state-tree")
TMP_CONF_DIR = os.path.join(TMP, "config")
TMP_PRODENV_PILLAR_TREE = os.path.join(SYS_TMP_DIR, "salt-temp-prodenv-pillar-tree")
TMP_CONF_DIR = TMP_MINION_CONF_DIR = os.path.join(TMP, "config")
TMP_SUB_MINION_CONF_DIR = os.path.join(TMP_CONF_DIR, "sub-minion")
TMP_SYNDIC_MINION_CONF_DIR = os.path.join(TMP_CONF_DIR, "syndic-minion")
TMP_SYNDIC_MASTER_CONF_DIR = os.path.join(TMP_CONF_DIR, "syndic-master")
TMP_MM_CONF_DIR = os.path.join(TMP_CONF_DIR, "multimaster")
TMP_MM_SUB_CONF_DIR = os.path.join(TMP_CONF_DIR, "sub-multimaster")
TMP_MM_CONF_DIR = TMP_MM_MINION_CONF_DIR = os.path.join(TMP_CONF_DIR, "multimaster")
TMP_MM_SUB_CONF_DIR = TMP_MM_SUB_MINION_CONF_DIR = os.path.join(
TMP_CONF_DIR, "sub-multimaster"
)
TMP_PROXY_CONF_DIR = os.path.join(TMP_CONF_DIR, "proxy")
CONF_DIR = os.path.join(INTEGRATION_TEST_DIR, "files", "conf")
PILLAR_DIR = os.path.join(FILES, "pillar")

View file

@ -46,21 +46,15 @@
.. _`nose`: https://nose.readthedocs.org
"""
# Import Python modules
from __future__ import absolute_import, print_function
import logging
import os
import shutil
# Import Salt libs
import salt.utils.path
import salt.utils.platform
# Import tests support libs
import tests.support.paths as paths
# Import 3rd-party libs
from salt.ext import six
try:
@ -183,6 +177,7 @@ RUNTIME_VARS = RuntimeVars(
LOG_HANDLERS_DIR=paths.LOG_HANDLERS_DIR,
TMP_ROOT_DIR=paths.TMP_ROOT_DIR,
TMP_CONF_DIR=paths.TMP_CONF_DIR,
TMP_MINION_CONF_DIR=paths.TMP_MINION_CONF_DIR,
TMP_CONF_MASTER_INCLUDES=os.path.join(paths.TMP_CONF_DIR, "master.d"),
TMP_CONF_MINION_INCLUDES=os.path.join(paths.TMP_CONF_DIR, "minion.d"),
TMP_CONF_PROXY_INCLUDES=os.path.join(paths.TMP_CONF_DIR, "proxy.d"),
@ -197,11 +192,14 @@ RUNTIME_VARS = RuntimeVars(
TMP_SYNDIC_MASTER_CONF_DIR=paths.TMP_SYNDIC_MASTER_CONF_DIR,
TMP_SYNDIC_MINION_CONF_DIR=paths.TMP_SYNDIC_MINION_CONF_DIR,
TMP_MM_CONF_DIR=paths.TMP_MM_CONF_DIR,
TMP_MM_MINION_CONF_DIR=paths.TMP_MM_MINION_CONF_DIR,
TMP_MM_SUB_CONF_DIR=paths.TMP_MM_SUB_CONF_DIR,
TMP_MM_SUB_MINION_CONF_DIR=paths.TMP_MM_SUB_CONF_DIR,
TMP_SCRIPT_DIR=paths.TMP_SCRIPT_DIR,
TMP_STATE_TREE=paths.TMP_STATE_TREE,
TMP_PILLAR_TREE=paths.TMP_PILLAR_TREE,
TMP_PRODENV_STATE_TREE=paths.TMP_PRODENV_STATE_TREE,
TMP_PRODENV_PILLAR_TREE=paths.TMP_PRODENV_PILLAR_TREE,
SHELL_TRUE_PATH=salt.utils.path.which("true")
if not salt.utils.platform.is_windows()
else "cmd /c exit 0 > nul",

View file

@ -3,7 +3,6 @@
:codeauthor: :email:`Daniel Wallace <dwallace@saltstack.com`
"""
# Import python libs
from __future__ import absolute_import, print_function, unicode_literals
import os
@ -11,7 +10,6 @@ import re
import shutil
import tempfile
# Import Salt libs
import salt.config
import salt.roster
import salt.utils.files
@ -21,8 +19,6 @@ import salt.utils.yaml
from salt.client import ssh
from tests.support.case import ShellCase
from tests.support.mock import MagicMock, call, patch
# Import Salt Testing libs
from tests.support.runtests import RUNTIME_VARS
from tests.support.unit import TestCase, skipIf
@ -49,7 +45,7 @@ class SSHPasswordTests(ShellCase):
opts["selected_target_option"] = "glob"
opts["tgt"] = "localhost"
opts["arg"] = []
roster = os.path.join(self.config_dir, "roster")
roster = os.path.join(RUNTIME_VARS.TMP_CONF_DIR, "roster")
handle_ssh_ret = [
{
"localhost": {