mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Test fixes when running with the onedir build
Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
parent
1ed20998c8
commit
3012dc42d6
6 changed files with 36 additions and 94 deletions
|
@ -6,6 +6,7 @@ include NOTICE
|
||||||
include README.rst
|
include README.rst
|
||||||
include SUPPORT.rst
|
include SUPPORT.rst
|
||||||
include run.py
|
include run.py
|
||||||
|
include pyproject.toml
|
||||||
include tests/*.py
|
include tests/*.py
|
||||||
recursive-include tests *
|
recursive-include tests *
|
||||||
recursive-include requirements *.txt
|
recursive-include requirements *.txt
|
||||||
|
|
|
@ -59,6 +59,8 @@ if str(CODE_DIR) in sys.path:
|
||||||
sys.path.remove(str(CODE_DIR))
|
sys.path.remove(str(CODE_DIR))
|
||||||
sys.path.insert(0, str(CODE_DIR))
|
sys.path.insert(0, str(CODE_DIR))
|
||||||
|
|
||||||
|
os.environ["REPO_ROOT_DIR"] = str(CODE_DIR)
|
||||||
|
|
||||||
# Coverage
|
# Coverage
|
||||||
if "COVERAGE_PROCESS_START" in os.environ:
|
if "COVERAGE_PROCESS_START" in os.environ:
|
||||||
MAYBE_RUN_COVERAGE = True
|
MAYBE_RUN_COVERAGE = True
|
||||||
|
|
|
@ -1,75 +0,0 @@
|
||||||
"""
|
|
||||||
Helpers for testing man pages
|
|
||||||
"""
|
|
||||||
|
|
||||||
import logging
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
|
|
||||||
import salt.utils.files
|
|
||||||
import salt.utils.path
|
|
||||||
import salt.utils.stringutils
|
|
||||||
from salt.exceptions import CommandExecutionError
|
|
||||||
from tests.support.runtests import RUNTIME_VARS
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
def install(rootdir):
|
|
||||||
if not os.path.exists(rootdir):
|
|
||||||
os.makedirs(rootdir)
|
|
||||||
return __salt__["cmd.run_all"](
|
|
||||||
[
|
|
||||||
sys.executable,
|
|
||||||
os.path.join(RUNTIME_VARS.CODE_DIR, "setup.py"),
|
|
||||||
"install",
|
|
||||||
"--root={}".format(rootdir),
|
|
||||||
],
|
|
||||||
redirect_stderr=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def search(manpages, rootdir):
|
|
||||||
manpage_fns = set(manpages)
|
|
||||||
manpage_paths = {}
|
|
||||||
for root, _, files in os.walk(rootdir):
|
|
||||||
if not manpage_fns:
|
|
||||||
# All manpages found, no need to keep walking
|
|
||||||
break
|
|
||||||
# Using list because we will be modifying the set during iteration
|
|
||||||
for manpage_fn in list(manpage_fns):
|
|
||||||
if manpage_fn in files:
|
|
||||||
manpage_path = salt.utils.path.join(root, manpage_fn)
|
|
||||||
manpage_paths[manpage_fn] = manpage_path
|
|
||||||
manpage_fns.remove(manpage_fn)
|
|
||||||
|
|
||||||
if manpage_fns:
|
|
||||||
raise CommandExecutionError(
|
|
||||||
"The following manpages were not found under {}: {}".format(
|
|
||||||
rootdir, ", ".join(sorted(manpage_fns))
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
failed = {}
|
|
||||||
for manpage in sorted(manpages):
|
|
||||||
with salt.utils.files.fopen(manpage_paths[manpage]) as fp_:
|
|
||||||
contents = salt.utils.stringutils.to_unicode(fp_.read())
|
|
||||||
# Check for search string in contents
|
|
||||||
for search_string in manpages[manpage]:
|
|
||||||
if search_string not in contents:
|
|
||||||
failed.setdefault(manpage, []).append(
|
|
||||||
"No match for search string '{}' found in {}".format(
|
|
||||||
search_string, manpage_paths[manpage]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
# Check for correct install dir
|
|
||||||
path = "/man{}/".format(manpage.rsplit(".", 1)[-1])
|
|
||||||
if path not in manpage_paths[manpage]:
|
|
||||||
failed.setdefault(manpage, []).append(
|
|
||||||
"{} not found in manpage path {}".format(path, manpage_paths[manpage])
|
|
||||||
)
|
|
||||||
|
|
||||||
if failed:
|
|
||||||
raise CommandExecutionError("One or more manpages failed", info=failed)
|
|
||||||
|
|
||||||
return True
|
|
|
@ -1,18 +1,24 @@
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import pathlib
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import salt.utils.decorators
|
import salt.utils.decorators
|
||||||
from tests.support.runtests import RUNTIME_VARS
|
|
||||||
|
|
||||||
EXIT_CODE_SH = os.path.join(RUNTIME_VARS.BASE_FILES, "exit_code.sh")
|
log = logging.getLogger(__name__)
|
||||||
EXIT_CODE_CMD = os.path.join(RUNTIME_VARS.BASE_FILES, "exit_code.cmd")
|
|
||||||
|
REPO_ROOT_DIR = pathlib.Path(os.environ["REPO_ROOT_DIR"]).resolve()
|
||||||
|
STATE_BASE_DIR = REPO_ROOT_DIR / "tests" / "integration" / "files" / "file" / "base"
|
||||||
|
EXIT_CODE_SH = STATE_BASE_DIR / "exit_code.sh"
|
||||||
|
EXIT_CODE_CMD = STATE_BASE_DIR / "exit_code.cmd"
|
||||||
|
|
||||||
|
|
||||||
def _exit_code(code):
|
def _exit_code(code):
|
||||||
if os.name == "nt":
|
if os.name == "nt":
|
||||||
return "cmd /c {} {}".format(EXIT_CODE_CMD, code)
|
cmd = "cmd /c {} {}".format(EXIT_CODE_CMD, code)
|
||||||
else:
|
else:
|
||||||
return "/usr/bin/env sh {} {}".format(EXIT_CODE_SH, code)
|
cmd = "/usr/bin/env sh {} {}".format(EXIT_CODE_SH, code)
|
||||||
|
return cmd
|
||||||
|
|
||||||
|
|
||||||
def _fallbackfunc():
|
def _fallbackfunc():
|
||||||
|
|
|
@ -41,7 +41,6 @@ def test_sync_all(salt_call_cli):
|
||||||
"modules": [
|
"modules": [
|
||||||
"modules.depends_versioned",
|
"modules.depends_versioned",
|
||||||
"modules.depends_versionless",
|
"modules.depends_versionless",
|
||||||
"modules.mantest",
|
|
||||||
"modules.override_test",
|
"modules.override_test",
|
||||||
"modules.runtests_decorators",
|
"modules.runtests_decorators",
|
||||||
"modules.runtests_helpers",
|
"modules.runtests_helpers",
|
||||||
|
@ -109,7 +108,6 @@ def test_sync_all_blacklist(salt_call_cli):
|
||||||
"utils": [],
|
"utils": [],
|
||||||
"returners": [],
|
"returners": [],
|
||||||
"modules": [
|
"modules": [
|
||||||
"modules.mantest",
|
|
||||||
"modules.override_test",
|
"modules.override_test",
|
||||||
"modules.runtests_helpers",
|
"modules.runtests_helpers",
|
||||||
"modules.salttest",
|
"modules.salttest",
|
||||||
|
|
|
@ -47,7 +47,6 @@ import salt.utils.stringutils
|
||||||
import salt.utils.versions
|
import salt.utils.versions
|
||||||
from tests.support.mock import patch
|
from tests.support.mock import patch
|
||||||
from tests.support.runtests import RUNTIME_VARS
|
from tests.support.runtests import RUNTIME_VARS
|
||||||
from tests.support.sminion import create_sminion
|
|
||||||
from tests.support.unit import SkipTest, _id, skip
|
from tests.support.unit import SkipTest, _id, skip
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
@ -1722,12 +1721,16 @@ class VirtualEnv:
|
||||||
|
|
||||||
def run(self, *args, **kwargs):
|
def run(self, *args, **kwargs):
|
||||||
check = kwargs.pop("check", True)
|
check = kwargs.pop("check", True)
|
||||||
kwargs.setdefault("cwd", str(self.venv_dir))
|
kwargs.setdefault("cwd", tempfile.gettempdir())
|
||||||
kwargs.setdefault("stdout", subprocess.PIPE)
|
kwargs.setdefault("stdout", subprocess.PIPE)
|
||||||
kwargs.setdefault("stderr", subprocess.PIPE)
|
kwargs.setdefault("stderr", subprocess.PIPE)
|
||||||
kwargs.setdefault("universal_newlines", True)
|
kwargs.setdefault("universal_newlines", True)
|
||||||
kwargs.setdefault("env", self.environ)
|
env = kwargs.pop("env", None)
|
||||||
proc = subprocess.run(args, check=False, **kwargs)
|
if env:
|
||||||
|
env = self.environ.copy().update(env)
|
||||||
|
else:
|
||||||
|
env = self.environ
|
||||||
|
proc = subprocess.run(args, check=False, env=env, **kwargs)
|
||||||
ret = ProcessResult(
|
ret = ProcessResult(
|
||||||
returncode=proc.returncode,
|
returncode=proc.returncode,
|
||||||
stdout=proc.stdout,
|
stdout=proc.stdout,
|
||||||
|
@ -1778,14 +1781,16 @@ class VirtualEnv:
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
return sys.executable
|
return sys.executable
|
||||||
|
|
||||||
def run_code(self, code_string, **kwargs):
|
def run_code(self, code_string, python=None, **kwargs):
|
||||||
if code_string.startswith("\n"):
|
if code_string.startswith("\n"):
|
||||||
code_string = code_string[1:]
|
code_string = code_string[1:]
|
||||||
code_string = textwrap.dedent(code_string).rstrip()
|
code_string = textwrap.dedent(code_string).rstrip()
|
||||||
log.debug(
|
log.debug(
|
||||||
"Code to run passed to python:\n>>>>>>>>>>\n%s\n<<<<<<<<<<", code_string
|
"Code to run passed to python:\n>>>>>>>>>>\n%s\n<<<<<<<<<<", code_string
|
||||||
)
|
)
|
||||||
return self.run(str(self.venv_python), "-c", code_string, **kwargs)
|
if python is None:
|
||||||
|
python = str(self.venv_python)
|
||||||
|
return self.run(python, "-c", code_string, **kwargs)
|
||||||
|
|
||||||
def get_installed_packages(self):
|
def get_installed_packages(self):
|
||||||
data = {}
|
data = {}
|
||||||
|
@ -1795,12 +1800,17 @@ class VirtualEnv:
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def _create_virtualenv(self):
|
def _create_virtualenv(self):
|
||||||
sminion = create_sminion()
|
virtualenv = shutil.which("virtualenv")
|
||||||
sminion.functions.virtualenv.create(
|
if not virtualenv:
|
||||||
str(self.venv_dir),
|
pytest.fail("'virtualenv' binary not found")
|
||||||
python=self.get_real_python(),
|
cmd = [
|
||||||
system_site_packages=self.system_site_packages,
|
virtualenv,
|
||||||
)
|
"--python={}".format(self.get_real_python()),
|
||||||
|
]
|
||||||
|
if self.system_site_packages:
|
||||||
|
cmd.append("--system-site-packages")
|
||||||
|
cmd.append(str(self.venv_dir))
|
||||||
|
self.run(*cmd, cwd=str(self.venv_dir.parent))
|
||||||
self.install("-U", self.pip_requirement, self.setuptools_requirement)
|
self.install("-U", self.pip_requirement, self.setuptools_requirement)
|
||||||
log.debug("Created virtualenv in %s", self.venv_dir)
|
log.debug("Created virtualenv in %s", self.venv_dir)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue