Migrate unit.setup to PyTest

This commit is contained in:
Pedro Algarvio 2020-12-28 07:16:41 +00:00
parent 6d5047492c
commit d9c163f9b0
8 changed files with 494 additions and 482 deletions

View file

@ -6,8 +6,8 @@
- unit.utils.test_versions
setup.py:
- unit.setup.test_man
- unit.setup.test_install
- pytests.scenarios.setup.test_man
- pytests.scenarios.setup.test_install
salt/modules/(apkpkg|aptpkg|ebuildpkg|dpkg_lowpkg|freebsdpkg|mac_brew_pkg|mac_ports_pkg|openbsdpkg|opkg|pacmanpkg|pkgin|pkgng|pkg_resource|rpm_lowpkg|solarisipspkg|solarispkg|win_pkg|xbpspkg|yumpkg|zypperpkg)\.py:
- unit.states.test_pkg

View file

@ -0,0 +1,28 @@
import os
import pathlib
import shutil
import pytest
from tests.support.helpers import VirtualEnv
@pytest.fixture
def virtualenv(tmp_path):
return VirtualEnv(venv_dir=str(tmp_path / ".venv"))
@pytest.fixture
def cache_dir(tmp_path):
if "CI_RUN" in os.environ and os.environ["CI_RUN"] == "1":
# Some of our golden images, at least, Arch Linux and Fedora 33, mount /tmp as a tmpfs.
# These setup tests will currently consume all of the freespace on /tmp in these distributions.
# To bypass that issue, we'll use the users `.cache` directory to store the downloads we need
# to run these tests.
_cache_dir = pathlib.Path.home() / ".cache" / "salt-setup-tests"
else:
_cache_dir = tmp_path / ".cache"
_cache_dir.mkdir(parents=True, exist_ok=True)
try:
yield _cache_dir
finally:
shutil.rmtree(str(_cache_dir), ignore_errors=True)

View file

@ -0,0 +1,355 @@
"""
Tests for building and installing salt
"""
import json
import logging
import pathlib
import re
import sys
import pytest
import salt.utils.path
import salt.utils.platform
import salt.version
from salt.modules.virtualenv_mod import KNOWN_BINARY_NAMES
from tests.support.helpers import slowTest
from tests.support.runtests import RUNTIME_VARS
log = logging.getLogger(__name__)
pytestmark = [
pytest.mark.windows_whitelisted,
pytest.mark.skip_if_binaries_missing(*KNOWN_BINARY_NAMES, check_all=False),
]
@slowTest
def test_wheel(virtualenv, cache_dir):
"""
test building and installing a bdist_wheel package
"""
# Let's create the testing virtualenv
with virtualenv as venv:
venv.run(venv.venv_python, "setup.py", "clean", cwd=RUNTIME_VARS.CODE_DIR)
venv.run(
venv.venv_python,
"setup.py",
"bdist_wheel",
"--dist-dir",
str(cache_dir),
cwd=RUNTIME_VARS.CODE_DIR,
)
venv.run(venv.venv_python, "setup.py", "clean", cwd=RUNTIME_VARS.CODE_DIR)
salt_generated_package = list(cache_dir.glob("*.whl"))
if not salt_generated_package:
pytest.fail("Could not find the generated wheel file")
salt_generated_package = salt_generated_package[0]
# Assert generate wheel version matches what salt reports as its version
whl_ver = [
x
for x in salt_generated_package.name.split("-")
if re.search(r"^\d.\d*", x)
][0]
whl_ver_cmp = whl_ver.replace("_", "-")
salt_ver_cmp = salt.version.__version__.replace("/", "-")
assert whl_ver_cmp == salt_ver_cmp, "{} != {}".format(whl_ver_cmp, salt_ver_cmp)
# Because bdist_wheel supports pep517, we don't have to pre-install Salt's
# dependencies before installing the wheel package
venv.install(str(salt_generated_package))
# Let's ensure the version is correct
cmd = venv.run(venv.venv_python, "-m", "pip", "list", "--format", "json")
for details in json.loads(cmd.stdout):
if details["name"] != "salt":
continue
installed_version = details["version"]
break
else:
pytest.fail("Salt was not found installed")
# Let's compare the installed version with the version salt reports
assert installed_version == salt_ver_cmp, "{} != {}".format(
installed_version, salt_ver_cmp
)
# Let's also ensure we have a salt/_version.py from the installed salt wheel
subdir = [
"lib",
"python{}.{}".format(*sys.version_info),
"site-packages",
"salt",
]
if salt.utils.platform.is_windows():
subdir.pop(1)
installed_salt_path = pathlib.Path(venv.venv_dir)
installed_salt_path = installed_salt_path.joinpath(*subdir)
assert installed_salt_path.is_dir()
salt_generated_version_file_path = installed_salt_path / "_version.py"
assert salt_generated_version_file_path.is_file()
@slowTest
def test_egg(virtualenv, cache_dir):
"""
test building and installing a bdist_egg package
"""
# TODO: We should actually dissallow generating an egg file
# Let's create the testing virtualenv
with virtualenv as venv:
venv.run(venv.venv_python, "setup.py", "clean", cwd=RUNTIME_VARS.CODE_DIR)
# Setuptools installs pre-release packages if we don't pin to an exact version
# Let's download and install requirements before, running salt's install test
venv.run(
venv.venv_python,
"-m",
"pip",
"download",
"--dest",
str(cache_dir),
RUNTIME_VARS.CODE_DIR,
)
packages = []
for fname in cache_dir.iterdir():
packages.append(fname)
venv.install(*[str(pkg) for pkg in packages])
for package in packages:
package.unlink()
venv.run(
venv.venv_python,
"setup.py",
"bdist_egg",
"--dist-dir",
str(cache_dir),
cwd=RUNTIME_VARS.CODE_DIR,
)
venv.run(venv.venv_python, "setup.py", "clean", cwd=RUNTIME_VARS.CODE_DIR)
salt_generated_package = list(cache_dir.glob("*.egg"))
if not salt_generated_package:
pytest.fail("Could not find the generated egg file")
salt_generated_package = salt_generated_package[0]
# Assert generate wheel version matches what salt reports as its version
egg_ver = [
x
for x in salt_generated_package.name.split("-")
if re.search(r"^\d.\d*", x)
][0]
egg_ver_cmp = egg_ver.replace("_", "-")
salt_ver_cmp = salt.version.__version__.replace("/", "-")
assert egg_ver_cmp == salt_ver_cmp, "{} != {}".format(egg_ver_cmp, salt_ver_cmp)
# We cannot pip install an egg file, let's go old school
venv.run(venv.venv_python, "-m", "easy_install", str(salt_generated_package))
# Let's ensure the version is correct
cmd = venv.run(venv.venv_python, "-m", "pip", "list", "--format", "json")
for details in json.loads(cmd.stdout):
if details["name"] != "salt":
continue
installed_version = details["version"]
break
else:
pytest.fail("Salt was not found installed")
# Let's compare the installed version with the version salt reports
assert installed_version == salt_ver_cmp, "{} != {}".format(
installed_version, salt_ver_cmp
)
# Let's also ensure we have a salt/_version.py from the installed salt egg
subdir = [
"lib",
"python{}.{}".format(*sys.version_info),
"site-packages",
]
if salt.utils.platform.is_windows():
subdir.pop(1)
site_packages_dir = pathlib.Path(venv.venv_dir)
site_packages_dir = site_packages_dir.joinpath(*subdir)
assert site_packages_dir.is_dir()
installed_salt_path = list(site_packages_dir.glob("salt*.egg"))
if not installed_salt_path:
pytest.fail("Failed to find the installed salt path")
log.debug("Installed salt path glob matches: %s", installed_salt_path)
installed_salt_path = installed_salt_path[0] / "salt"
assert installed_salt_path.is_dir()
salt_generated_version_file_path = installed_salt_path / "_version.py"
assert salt_generated_version_file_path.is_file(), "{} is not a file".format(
salt_generated_version_file_path
)
# On python 3.5 Windows sdist fails with encoding errors. This is resolved
# in later versions.
@pytest.mark.skipif(
salt.utils.platform.is_windows()
and sys.version_info > (3,)
and sys.version_info < (3, 6),
reason="Skip on python 3.5",
)
@slowTest
def test_sdist(virtualenv, cache_dir):
"""
test building and installing a sdist package
"""
# Let's create the testing virtualenv
with virtualenv as venv:
venv.run(venv.venv_python, "setup.py", "clean", cwd=RUNTIME_VARS.CODE_DIR)
# Setuptools installs pre-release packages if we don't pin to an exact version
# Let's download and install requirements before, running salt's install test
venv.run(
venv.venv_python,
"-m",
"pip",
"download",
"--dest",
str(cache_dir),
RUNTIME_VARS.CODE_DIR,
)
packages = []
for fname in cache_dir.iterdir():
packages.append(fname)
venv.install(*[str(pkg) for pkg in packages])
for package in packages:
package.unlink()
venv.run(
venv.venv_python,
"setup.py",
"sdist",
"--dist-dir",
str(cache_dir),
cwd=RUNTIME_VARS.CODE_DIR,
)
venv.run(venv.venv_python, "setup.py", "clean", cwd=RUNTIME_VARS.CODE_DIR)
salt_generated_package = list(cache_dir.glob("*.tar.gz"))
if not salt_generated_package:
pytest.fail("Could not find the generated sdist file")
salt_generated_package = salt_generated_package[0]
log.info("Generated sdist file: %s", salt_generated_package.name)
# Assert generated sdist version matches what salt reports as its version
sdist_ver_cmp = salt_generated_package.name.split(".tar.gz")[0].split("salt-")[
-1
]
salt_ver_cmp = salt.version.__version__.replace("/", "-")
assert sdist_ver_cmp == salt_ver_cmp, "{} != {}".format(
sdist_ver_cmp, salt.version.__version__
)
venv.install(str(salt_generated_package))
# Let's also ensure we have a salt/_version.py from the installed salt wheel
subdir = [
"lib",
"python{}.{}".format(*sys.version_info),
"site-packages",
"salt",
]
if salt.utils.platform.is_windows():
subdir.pop(1)
installed_salt_path = pathlib.Path(venv.venv_dir)
installed_salt_path = installed_salt_path.joinpath(*subdir)
assert installed_salt_path.is_dir()
salt_generated_version_file_path = installed_salt_path / "_version.py"
assert salt_generated_version_file_path.is_file()
with salt_generated_version_file_path.open() as rfh:
log.debug("_version.py contents:\n >>>>>>\n%s\n <<<<<<", rfh.read())
# Let's ensure the version is correct
cmd = venv.run(venv.venv_python, "-m", "pip", "list", "--format", "json")
for details in json.loads(cmd.stdout):
if details["name"] != "salt":
continue
installed_version = details["version"]
break
else:
pytest.fail("Salt was not found installed")
# Let's compare the installed version with the version salt reports
assert installed_version == salt_ver_cmp, "{} != {}".format(
installed_version, salt_ver_cmp
)
@slowTest
def test_setup_install(virtualenv, cache_dir):
"""
test installing directly from source
"""
# Let's create the testing virtualenv
with virtualenv as venv:
venv.run(venv.venv_python, "setup.py", "clean", cwd=RUNTIME_VARS.CODE_DIR)
# Setuptools installs pre-release packages if we don't pin to an exact version
# Let's download and install requirements before, running salt's install test
venv.run(
venv.venv_python,
"-m",
"pip",
"download",
"--dest",
str(cache_dir),
RUNTIME_VARS.CODE_DIR,
)
packages = []
for fname in cache_dir.iterdir():
packages.append(fname)
venv.install(*[str(pkg) for pkg in packages])
for package in packages:
package.unlink()
venv.run(
venv.venv_python,
"setup.py",
"install",
"--prefix",
venv.venv_dir,
cwd=RUNTIME_VARS.CODE_DIR,
)
venv.run(venv.venv_python, "setup.py", "clean", cwd=RUNTIME_VARS.CODE_DIR)
# Let's ensure the version is correct
cmd = venv.run(venv.venv_python, "-m", "pip", "list", "--format", "json")
for details in json.loads(cmd.stdout):
if details["name"] != "salt":
continue
installed_version = details["version"]
break
else:
pytest.fail("Salt was not found installed")
salt_ver_cmp = salt.version.__version__.replace("/", "-")
# Let's compare the installed version with the version salt reports
assert installed_version == salt_ver_cmp, "{} != {}".format(
installed_version, salt_ver_cmp
)
# Let's also ensure we have a salt/_version.py from the installed salt
subdir = [
"lib",
"python{}.{}".format(*sys.version_info),
"site-packages",
]
if salt.utils.platform.is_windows():
subdir.pop(1)
site_packages_dir = pathlib.Path(venv.venv_dir)
site_packages_dir = site_packages_dir.joinpath(*subdir)
assert site_packages_dir.is_dir()
installed_salt_path = list(site_packages_dir.glob("salt*.egg"))
if not installed_salt_path:
pytest.fail("Failed to find the installed salt path")
installed_salt_path = installed_salt_path[0] / "salt"
salt_generated_version_file_path = installed_salt_path / "_version.py"
assert salt_generated_version_file_path.is_file()

View file

@ -0,0 +1,109 @@
"""
Tests for existence of manpages
"""
import os
import pprint
import pytest
import salt.utils.platform
from salt.modules.virtualenv_mod import KNOWN_BINARY_NAMES
from tests.support.helpers import slowTest
from tests.support.runtests import RUNTIME_VARS
pytestmark = [
pytest.mark.skip_on_windows,
pytest.mark.skip_on_aix,
pytest.mark.skip_if_binaries_missing(*KNOWN_BINARY_NAMES, check_all=False),
]
@slowTest
def test_man_pages(virtualenv):
"""
Make sure that man pages are installed
"""
# 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",
],
}
with virtualenv as venv:
rootdir = os.path.join(venv.venv_dir, "installed")
venv.run(
venv.venv_python,
"setup.py",
"install",
"--root={}".format(rootdir),
cwd=RUNTIME_VARS.CODE_DIR,
)
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)
assert (
not manpage_fns
), "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]
)
)
assert not failed, "One or more manpages failed:\n{}".format(
pprint.pformat(failed)
)

View file

@ -1 +0,0 @@
# -*- coding: utf-8 -*-

View file

@ -1,368 +0,0 @@
"""
tests.unit.setup.test_install
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""
import json
import logging
import os
import pathlib
import re
import sys
import salt.utils.path
import salt.utils.platform
import salt.version
from salt.modules.virtualenv_mod import KNOWN_BINARY_NAMES
from tests.support.helpers import VirtualEnv, slowTest, with_tempdir
from tests.support.runtests import RUNTIME_VARS
from tests.support.unit import TestCase, skipIf
log = logging.getLogger(__name__)
@skipIf(
salt.utils.path.which_bin(KNOWN_BINARY_NAMES) is None, "virtualenv not installed"
)
class InstallTest(TestCase):
"""
Tests for building and installing salt
"""
@slowTest
@with_tempdir()
def test_wheel(self, tempdir):
"""
test building and installing a bdist_wheel package
"""
# Let's create the testing virtualenv
with VirtualEnv() as venv:
venv.run(venv.venv_python, "setup.py", "clean", cwd=RUNTIME_VARS.CODE_DIR)
venv.run(
venv.venv_python,
"setup.py",
"bdist_wheel",
"--dist-dir",
tempdir,
cwd=RUNTIME_VARS.CODE_DIR,
)
venv.run(venv.venv_python, "setup.py", "clean", cwd=RUNTIME_VARS.CODE_DIR)
salt_generated_package = list(pathlib.Path(tempdir).glob("*.whl"))
if not salt_generated_package:
self.fail("Could not find the generated wheel file")
salt_generated_package = salt_generated_package[0]
# Assert generate wheel version matches what salt reports as its version
whl_ver = [
x
for x in salt_generated_package.name.split("-")
if re.search(r"^\d.\d*", x)
][0]
whl_ver_cmp = whl_ver.replace("_", "-")
salt_ver_cmp = salt.version.__version__.replace("/", "-")
assert whl_ver_cmp == salt_ver_cmp, "{} != {}".format(
whl_ver_cmp, salt_ver_cmp
)
# Because bdist_wheel supports pep517, we don't have to pre-install Salt's
# dependencies before installing the wheel package
venv.install(str(salt_generated_package))
# Let's ensure the version is correct
cmd = venv.run(venv.venv_python, "-m", "pip", "list", "--format", "json")
for details in json.loads(cmd.stdout):
if details["name"] != "salt":
continue
installed_version = details["version"]
break
else:
self.fail("Salt was not found installed")
# Let's compare the installed version with the version salt reports
assert installed_version == salt_ver_cmp, "{} != {}".format(
installed_version, salt_ver_cmp
)
# Let's also ensure we have a salt/_version.py from the installed salt wheel
subdir = [
"lib",
"python{}.{}".format(*sys.version_info),
"site-packages",
"salt",
]
if salt.utils.platform.is_windows():
subdir.pop(1)
installed_salt_path = pathlib.Path(venv.venv_dir)
installed_salt_path = installed_salt_path.joinpath(*subdir)
assert installed_salt_path.is_dir()
salt_generated_version_file_path = installed_salt_path / "_version.py"
assert salt_generated_version_file_path.is_file()
@slowTest
@with_tempdir()
def test_egg(self, tempdir):
"""
test building and installing a bdist_egg package
"""
# TODO: We should actually dissallow generating an egg file
# Let's create the testing virtualenv
with VirtualEnv() as venv:
venv.run(venv.venv_python, "setup.py", "clean", cwd=RUNTIME_VARS.CODE_DIR)
# Setuptools installs pre-release packages if we don't pin to an exact version
# Let's download and install requirements before, running salt's install test
venv.run(
venv.venv_python,
"-m",
"pip",
"download",
"--dest",
tempdir,
RUNTIME_VARS.CODE_DIR,
)
packages = []
for fname in os.listdir(tempdir):
packages.append(os.path.join(tempdir, fname))
venv.install(*packages)
for package in packages:
os.unlink(package)
venv.run(
venv.venv_python,
"setup.py",
"bdist_egg",
"--dist-dir",
tempdir,
cwd=RUNTIME_VARS.CODE_DIR,
)
venv.run(venv.venv_python, "setup.py", "clean", cwd=RUNTIME_VARS.CODE_DIR)
salt_generated_package = list(pathlib.Path(tempdir).glob("*.egg"))
if not salt_generated_package:
self.fail("Could not find the generated egg file")
salt_generated_package = salt_generated_package[0]
# Assert generate wheel version matches what salt reports as its version
egg_ver = [
x
for x in salt_generated_package.name.split("-")
if re.search(r"^\d.\d*", x)
][0]
egg_ver_cmp = egg_ver.replace("_", "-")
salt_ver_cmp = salt.version.__version__.replace("/", "-")
assert egg_ver_cmp == salt_ver_cmp, "{} != {}".format(
egg_ver_cmp, salt_ver_cmp
)
# We cannot pip install an egg file, let's go old school
venv.run(
venv.venv_python, "-m", "easy_install", str(salt_generated_package)
)
# Let's ensure the version is correct
cmd = venv.run(venv.venv_python, "-m", "pip", "list", "--format", "json")
for details in json.loads(cmd.stdout):
if details["name"] != "salt":
continue
installed_version = details["version"]
break
else:
self.fail("Salt was not found installed")
# Let's compare the installed version with the version salt reports
assert installed_version == salt_ver_cmp, "{} != {}".format(
installed_version, salt_ver_cmp
)
# Let's also ensure we have a salt/_version.py from the installed salt egg
subdir = [
"lib",
"python{}.{}".format(*sys.version_info),
"site-packages",
]
if salt.utils.platform.is_windows():
subdir.pop(1)
site_packages_dir = pathlib.Path(venv.venv_dir)
site_packages_dir = site_packages_dir.joinpath(*subdir)
assert site_packages_dir.is_dir()
installed_salt_path = list(site_packages_dir.glob("salt*.egg"))
if not installed_salt_path:
self.fail("Failed to find the installed salt path")
log.debug("Installed salt path glob matches: %s", installed_salt_path)
installed_salt_path = installed_salt_path[0] / "salt"
assert installed_salt_path.is_dir()
salt_generated_version_file_path = installed_salt_path / "_version.py"
assert (
salt_generated_version_file_path.is_file()
), "{} is not a file".format(salt_generated_version_file_path)
# On python 3.5 Windows sdist fails with encoding errors. This is resolved
# in later versions.
@skipIf(
salt.utils.platform.is_windows()
and sys.version_info > (3,)
and sys.version_info < (3, 6),
"Skip on python 3.5",
)
@slowTest
@with_tempdir()
def test_sdist(self, tempdir):
"""
test building and installing a sdist package
"""
# Let's create the testing virtualenv
with VirtualEnv() as venv:
venv.run(venv.venv_python, "setup.py", "clean", cwd=RUNTIME_VARS.CODE_DIR)
# Setuptools installs pre-release packages if we don't pin to an exact version
# Let's download and install requirements before, running salt's install test
venv.run(
venv.venv_python,
"-m",
"pip",
"download",
"--dest",
tempdir,
RUNTIME_VARS.CODE_DIR,
)
packages = []
for fname in os.listdir(tempdir):
packages.append(os.path.join(tempdir, fname))
venv.install(*packages)
for package in packages:
os.unlink(package)
venv.run(
venv.venv_python,
"setup.py",
"sdist",
"--dist-dir",
tempdir,
cwd=RUNTIME_VARS.CODE_DIR,
)
venv.run(venv.venv_python, "setup.py", "clean", cwd=RUNTIME_VARS.CODE_DIR)
salt_generated_package = list(pathlib.Path(tempdir).glob("*.tar.gz"))
if not salt_generated_package:
self.fail("Could not find the generated sdist file")
salt_generated_package = salt_generated_package[0]
log.info("Generated sdist file: %s", salt_generated_package.name)
# Assert generated sdist version matches what salt reports as its version
sdist_ver_cmp = salt_generated_package.name.split(".tar.gz")[0].split(
"salt-"
)[-1]
salt_ver_cmp = salt.version.__version__.replace("/", "-")
assert sdist_ver_cmp == salt_ver_cmp, "{} != {}".format(
sdist_ver_cmp, salt.version.__version__
)
venv.install(str(salt_generated_package))
# Let's also ensure we have a salt/_version.py from the installed salt wheel
subdir = [
"lib",
"python{}.{}".format(*sys.version_info),
"site-packages",
"salt",
]
if salt.utils.platform.is_windows():
subdir.pop(1)
installed_salt_path = pathlib.Path(venv.venv_dir)
installed_salt_path = installed_salt_path.joinpath(*subdir)
assert installed_salt_path.is_dir()
salt_generated_version_file_path = installed_salt_path / "_version.py"
assert salt_generated_version_file_path.is_file()
with salt_generated_version_file_path.open() as rfh:
log.debug("_version.py contents:\n >>>>>>\n%s\n <<<<<<", rfh.read())
# Let's ensure the version is correct
cmd = venv.run(venv.venv_python, "-m", "pip", "list", "--format", "json")
for details in json.loads(cmd.stdout):
if details["name"] != "salt":
continue
installed_version = details["version"]
break
else:
self.fail("Salt was not found installed")
# Let's compare the installed version with the version salt reports
assert installed_version == salt_ver_cmp, "{} != {}".format(
installed_version, salt_ver_cmp
)
@slowTest
@with_tempdir()
def test_setup_install(self, tempdir):
"""
test installing directly from source
"""
# Let's create the testing virtualenv
with VirtualEnv() as venv:
venv.run(venv.venv_python, "setup.py", "clean", cwd=RUNTIME_VARS.CODE_DIR)
# Setuptools installs pre-release packages if we don't pin to an exact version
# Let's download and install requirements before, running salt's install test
venv.run(
venv.venv_python,
"-m",
"pip",
"download",
"--dest",
tempdir,
RUNTIME_VARS.CODE_DIR,
)
packages = []
for fname in os.listdir(tempdir):
packages.append(os.path.join(tempdir, fname))
venv.install(*packages)
for package in packages:
os.unlink(package)
venv.run(
venv.venv_python,
"setup.py",
"install",
"--prefix",
venv.venv_dir,
cwd=RUNTIME_VARS.CODE_DIR,
)
venv.run(venv.venv_python, "setup.py", "clean", cwd=RUNTIME_VARS.CODE_DIR)
# Let's ensure the version is correct
cmd = venv.run(venv.venv_python, "-m", "pip", "list", "--format", "json")
for details in json.loads(cmd.stdout):
if details["name"] != "salt":
continue
installed_version = details["version"]
break
else:
self.fail("Salt was not found installed")
salt_ver_cmp = salt.version.__version__.replace("/", "-")
# Let's compare the installed version with the version salt reports
assert installed_version == salt_ver_cmp, "{} != {}".format(
installed_version, salt_ver_cmp
)
# Let's also ensure we have a salt/_version.py from the installed salt
subdir = [
"lib",
"python{}.{}".format(*sys.version_info),
"site-packages",
]
if salt.utils.platform.is_windows():
subdir.pop(1)
site_packages_dir = pathlib.Path(venv.venv_dir)
site_packages_dir = site_packages_dir.joinpath(*subdir)
assert site_packages_dir.is_dir()
installed_salt_path = list(site_packages_dir.glob("salt*.egg"))
if not installed_salt_path:
self.fail("Failed to find the installed salt path")
installed_salt_path = installed_salt_path[0] / "salt"
salt_generated_version_file_path = installed_salt_path / "_version.py"
assert salt_generated_version_file_path.is_file()

View file

@ -1,111 +0,0 @@
# -*- coding: utf-8 -*-
"""
Tests for existence of manpages
"""
from __future__ import absolute_import, print_function, unicode_literals
import os
import pprint
import salt.utils.platform
from salt.modules.virtualenv_mod import KNOWN_BINARY_NAMES
from tests.support.helpers import VirtualEnv, slowTest
from tests.support.runtests import RUNTIME_VARS
from tests.support.unit import TestCase, skipIf
@skipIf(salt.utils.platform.is_windows(), "minion is windows")
@skipIf(salt.utils.platform.is_aix(), "minion is AIX")
@skipIf(
salt.utils.path.which_bin(KNOWN_BINARY_NAMES) is None, "virtualenv not installed"
)
class ManPagesTest(TestCase):
@slowTest
def test_man_pages(self):
"""
Make sure that man pages are installed
"""
# 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",
],
}
with VirtualEnv() as venv:
rootdir = os.path.join(venv.venv_dir, "installed")
venv.run(
venv.venv_python,
"setup.py",
"install",
"--root={}".format(rootdir),
cwd=RUNTIME_VARS.CODE_DIR,
)
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)
assert (
not manpage_fns
), "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]
)
)
assert not failed, "One or more manpages failed:\n{}".format(
pprint.pformat(failed)
)