Updates required for `pytest-salt-factories>=1.0.0rc16`

Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
Pedro Algarvio 2022-05-31 17:35:38 +01:00 committed by Megan Wilhite
parent 23598fad13
commit 29b6fe207c
118 changed files with 1655 additions and 1843 deletions

View file

@ -686,6 +686,7 @@ allowed-3rd-party-modules=msgpack,
pytestsalt, pytestsalt,
saltfactories, saltfactories,
psutil, psutil,
pytestshellutils,
distro, distro,
os, os,
re, re,

View file

@ -6,8 +6,8 @@ import os
import pytest import pytest
from salt.config import cloud_providers_config from salt.config import cloud_providers_config
from saltfactories.utils import random_string
from tests.support.case import ShellCase from tests.support.case import ShellCase
from tests.support.helpers import random_string
from tests.support.runtests import RUNTIME_VARS from tests.support.runtests import RUNTIME_VARS
# Create the cloud instance name to be used throughout the tests # Create the cloud instance name to be used throughout the tests

View file

@ -12,8 +12,8 @@ import pytest
import salt.utils.files import salt.utils.files
from salt.config import cloud_config, cloud_providers_config from salt.config import cloud_config, cloud_providers_config
from salt.utils.yaml import safe_load from salt.utils.yaml import safe_load
from saltfactories.utils import random_string
from tests.support.case import ShellCase from tests.support.case import ShellCase
from tests.support.helpers import random_string
from tests.support.paths import FILES from tests.support.paths import FILES
from tests.support.runtests import RUNTIME_VARS from tests.support.runtests import RUNTIME_VARS

View file

@ -36,7 +36,7 @@ def salt_minion(salt_minion_factory):
# Sync All # Sync All
salt_call_cli = salt_minion_factory.salt_call_cli() salt_call_cli = salt_minion_factory.salt_call_cli()
ret = salt_call_cli.run("saltutil.sync_all", _timeout=120) ret = salt_call_cli.run("saltutil.sync_all", _timeout=120)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
yield salt_minion_factory yield salt_minion_factory
@ -49,5 +49,5 @@ def salt_sub_minion(salt_sub_minion_factory):
# Sync All # Sync All
salt_call_cli = salt_sub_minion_factory.salt_call_cli() salt_call_cli = salt_sub_minion_factory.salt_call_cli()
ret = salt_call_cli.run("saltutil.sync_all", _timeout=120) ret = salt_call_cli.run("saltutil.sync_all", _timeout=120)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
yield salt_sub_minion_factory yield salt_sub_minion_factory

View file

@ -14,9 +14,9 @@ import subprocess
import sys import sys
import time import time
from pytestshellutils.utils import ports
from pytestshellutils.utils.processes import terminate_process
from salt.utils.nb_popen import NonBlockingPopen from salt.utils.nb_popen import NonBlockingPopen
from saltfactories.utils.ports import get_unused_localhost_port
from saltfactories.utils.processes import terminate_process
from tests.support.cli_scripts import ScriptPathMixin from tests.support.cli_scripts import ScriptPathMixin
from tests.support.mixins import AdaptedConfigurationTestCaseMixin from tests.support.mixins import AdaptedConfigurationTestCaseMixin
from tests.support.runtests import RUNTIME_VARS from tests.support.runtests import RUNTIME_VARS
@ -29,14 +29,14 @@ class TestEventReturn(AdaptedConfigurationTestCaseMixin, ScriptPathMixin, TestCa
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
overrides = { overrides = {
"publish_port": get_unused_localhost_port(), "publish_port": ports.get_unused_localhost_port(),
"ret_port": get_unused_localhost_port(), "ret_port": ports.get_unused_localhost_port(),
"tcp_master_pub_port": get_unused_localhost_port(), "tcp_master_pub_port": ports.get_unused_localhost_port(),
"tcp_master_pull_port": get_unused_localhost_port(), "tcp_master_pull_port": ports.get_unused_localhost_port(),
"tcp_master_publish_pull": get_unused_localhost_port(), "tcp_master_publish_pull": ports.get_unused_localhost_port(),
"tcp_master_workers": get_unused_localhost_port(), "tcp_master_workers": ports.get_unused_localhost_port(),
"runtests_conn_check_port": get_unused_localhost_port(), "runtests_conn_check_port": ports.get_unused_localhost_port(),
"runtests_log_port": get_unused_localhost_port(), "runtests_log_port": ports.get_unused_localhost_port(),
} }
overrides["pytest_engine_port"] = overrides["runtests_conn_check_port"] overrides["pytest_engine_port"] = overrides["runtests_conn_check_port"]
temp_config = AdaptedConfigurationTestCaseMixin.get_temp_config( temp_config = AdaptedConfigurationTestCaseMixin.get_temp_config(

View file

@ -14,7 +14,7 @@ import salt.utils.files
import salt.utils.path import salt.utils.path
import salt.utils.platform import salt.utils.platform
import salt.utils.stringutils import salt.utils.stringutils
from saltfactories.utils.ports import get_unused_localhost_port from pytestshellutils.utils import ports
from saltfactories.utils.tempfiles import temp_file from saltfactories.utils.tempfiles import temp_file
from tests.support.case import ModuleCase from tests.support.case import ModuleCase
from tests.support.helpers import with_tempfile from tests.support.helpers import with_tempfile
@ -423,7 +423,7 @@ class CPModuleTest(ModuleCase):
""" """
cp.cache_file cp.cache_file
""" """
nginx_port = get_unused_localhost_port() nginx_port = ports.get_unused_localhost_port()
url_prefix = "http://localhost:{}/".format(nginx_port) url_prefix = "http://localhost:{}/".format(nginx_port)
temp_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP) temp_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP)
self.addCleanup(shutil.rmtree, temp_dir, ignore_errors=True) self.addCleanup(shutil.rmtree, temp_dir, ignore_errors=True)

View file

@ -2,8 +2,9 @@ import pytest
import salt.utils.files import salt.utils.files
import salt.utils.platform import salt.utils.platform
import salt.utils.stringutils import salt.utils.stringutils
from saltfactories.utils import random_string
from tests.support.case import ModuleCase from tests.support.case import ModuleCase
from tests.support.helpers import random_string, runs_on from tests.support.helpers import runs_on
from tests.support.unit import skipIf from tests.support.unit import skipIf
if not salt.utils.platform.is_windows(): if not salt.utils.platform.is_windows():

View file

@ -8,8 +8,8 @@ import pytest
import salt.modules.linux_shadow import salt.modules.linux_shadow
import salt.utils.files import salt.utils.files
import salt.utils.platform import salt.utils.platform
from saltfactories.utils import random_string
from tests.support.case import ModuleCase from tests.support.case import ModuleCase
from tests.support.helpers import random_string
@pytest.mark.skip_if_not_root @pytest.mark.skip_if_not_root

View file

@ -4,8 +4,9 @@
import pytest import pytest
from salt.exceptions import CommandExecutionError from salt.exceptions import CommandExecutionError
from saltfactories.utils import random_string
from tests.support.case import ModuleCase from tests.support.case import ModuleCase
from tests.support.helpers import random_string, runs_on from tests.support.helpers import runs_on
# Create group name strings for tests # Create group name strings for tests
ADD_GROUP = random_string("RS-", lowercase=False) ADD_GROUP = random_string("RS-", lowercase=False)

View file

@ -5,8 +5,9 @@ integration tests for mac_shadow
import datetime import datetime
import pytest import pytest
from saltfactories.utils import random_string
from tests.support.case import ModuleCase from tests.support.case import ModuleCase
from tests.support.helpers import random_string, runs_on from tests.support.helpers import runs_on
TEST_USER = random_string("RS-", lowercase=False) TEST_USER = random_string("RS-", lowercase=False)
NO_USER = random_string("RS-", lowercase=False) NO_USER = random_string("RS-", lowercase=False)

View file

@ -5,8 +5,8 @@ integration tests for mac_system
import logging import logging
import pytest import pytest
from saltfactories.utils import random_string
from tests.support.case import ModuleCase from tests.support.case import ModuleCase
from tests.support.helpers import random_string
from tests.support.unit import skipIf from tests.support.unit import skipIf
log = logging.getLogger(__name__) log = logging.getLogger(__name__)

View file

@ -7,8 +7,9 @@ import os
import pytest import pytest
import salt.utils.files import salt.utils.files
from salt.exceptions import CommandExecutionError from salt.exceptions import CommandExecutionError
from saltfactories.utils import random_string
from tests.support.case import ModuleCase from tests.support.case import ModuleCase
from tests.support.helpers import random_string, runs_on from tests.support.helpers import runs_on
# Create user strings for tests # Create user strings for tests
ADD_USER = random_string("RS-", lowercase=False) ADD_USER = random_string("RS-", lowercase=False)

View file

@ -4,8 +4,9 @@ tests.integration.modules.pw_user
""" """
import pytest import pytest
from saltfactories.utils import random_string
from tests.support.case import ModuleCase from tests.support.case import ModuleCase
from tests.support.helpers import random_string, runs_on from tests.support.helpers import runs_on
@runs_on(kernel="FreeBSD") @runs_on(kernel="FreeBSD")

View file

@ -6,8 +6,8 @@ import pytest
import salt.utils.files import salt.utils.files
import salt.utils.platform import salt.utils.platform
import salt.utils.win_reg as reg import salt.utils.win_reg as reg
from saltfactories.utils import random_string
from tests.support.case import ModuleCase from tests.support.case import ModuleCase
from tests.support.helpers import random_string
from tests.support.runtests import RUNTIME_VARS from tests.support.runtests import RUNTIME_VARS
from tests.support.unit import skipIf from tests.support.unit import skipIf

View file

@ -7,8 +7,8 @@ import logging
import pytest import pytest
import salt.utils.platform import salt.utils.platform
import salt.utils.win_reg as reg import salt.utils.win_reg as reg
from saltfactories.utils import random_string
from tests.support.case import ModuleCase from tests.support.case import ModuleCase
from tests.support.helpers import random_string
from tests.support.mixins import SaltReturnAssertsMixin from tests.support.mixins import SaltReturnAssertsMixin
from tests.support.unit import skipIf from tests.support.unit import skipIf

View file

@ -17,9 +17,9 @@ import pytest
import salt.ext.tornado.ioloop import salt.ext.tornado.ioloop
import salt.utils.files import salt.utils.files
import salt.utils.platform import salt.utils.platform
from pytestshellutils.utils import ports
from salt.serializers import yaml from salt.serializers import yaml
from saltfactories.utils import random_string from saltfactories.utils import random_string
from saltfactories.utils.ports import get_unused_localhost_port
from tests.support.helpers import get_virtualenv_binary_path from tests.support.helpers import get_virtualenv_binary_path
from tests.support.runtests import RUNTIME_VARS from tests.support.runtests import RUNTIME_VARS
@ -38,12 +38,12 @@ def salt_sub_minion_id():
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
def sdb_etcd_port(): def sdb_etcd_port():
return get_unused_localhost_port() return ports.get_unused_localhost_port()
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
def vault_port(): def vault_port():
return get_unused_localhost_port() return ports.get_unused_localhost_port()
@attr.s(slots=True, frozen=True) @attr.s(slots=True, frozen=True)

View file

@ -7,9 +7,9 @@ import time
import pytest import pytest
import salt.cache import salt.cache
import salt.loader import salt.loader
from pytestshellutils.utils import ports
from salt.exceptions import SaltCacheError from salt.exceptions import SaltCacheError
from saltfactories.utils import random_string from saltfactories.utils import random_string
from saltfactories.utils.ports import get_unused_localhost_port
from tests.support.mock import MagicMock, patch from tests.support.mock import MagicMock, patch
docker = pytest.importorskip("docker") docker = pytest.importorskip("docker")
@ -42,17 +42,17 @@ class Timer:
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def etcd_port(): def etcd_port():
return get_unused_localhost_port() return ports.get_unused_localhost_port()
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def redis_port(): def redis_port():
return get_unused_localhost_port() return ports.get_unused_localhost_port()
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def consul_port(): def consul_port():
return get_unused_localhost_port() return ports.get_unused_localhost_port()
# GIVE ME FIXTURES ON FIXTURES NOW # GIVE ME FIXTURES ON FIXTURES NOW
@ -60,62 +60,62 @@ def consul_port():
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def mysql_5_6_port(): def mysql_5_6_port():
return get_unused_localhost_port() return ports.get_unused_localhost_port()
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def mysql_5_7_port(): def mysql_5_7_port():
return get_unused_localhost_port() return ports.get_unused_localhost_port()
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def mysql_8_0_port(): def mysql_8_0_port():
return get_unused_localhost_port() return ports.get_unused_localhost_port()
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def mariadb_10_1_port(): def mariadb_10_1_port():
return get_unused_localhost_port() return ports.get_unused_localhost_port()
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def mariadb_10_2_port(): def mariadb_10_2_port():
return get_unused_localhost_port() return ports.get_unused_localhost_port()
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def mariadb_10_3_port(): def mariadb_10_3_port():
return get_unused_localhost_port() return ports.get_unused_localhost_port()
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def mariadb_10_4_port(): def mariadb_10_4_port():
return get_unused_localhost_port() return ports.get_unused_localhost_port()
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def mariadb_10_5_port(): def mariadb_10_5_port():
return get_unused_localhost_port() return ports.get_unused_localhost_port()
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def percona_5_5_port(): def percona_5_5_port():
return get_unused_localhost_port() return ports.get_unused_localhost_port()
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def percona_5_6_port(): def percona_5_6_port():
return get_unused_localhost_port() return ports.get_unused_localhost_port()
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def percona_5_7_port(): def percona_5_7_port():
return get_unused_localhost_port() return ports.get_unused_localhost_port()
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def percona_8_0_port(): def percona_8_0_port():
return get_unused_localhost_port() return ports.get_unused_localhost_port()
# TODO: We should probably be building our own etcd docker image - fine to base it off of this one (or... others) -W. Werner, 2021-07-27 # TODO: We should probably be building our own etcd docker image - fine to base it off of this one (or... others) -W. Werner, 2021-07-27

View file

@ -16,8 +16,8 @@ import salt.master
import salt.utils.platform import salt.utils.platform
import salt.utils.process import salt.utils.process
import salt.utils.stringutils import salt.utils.stringutils
from pytestshellutils.utils import ports
from saltfactories.utils import random_string from saltfactories.utils import random_string
from saltfactories.utils.ports import get_unused_localhost_port
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -64,8 +64,8 @@ def master_config(root_dir, transport):
master_conf["root_dir"] = str(root_dir) master_conf["root_dir"] = str(root_dir)
master_conf["sock_dir"] = str(root_dir) master_conf["sock_dir"] = str(root_dir)
master_conf["interface"] = "127.0.0.1" master_conf["interface"] = "127.0.0.1"
master_conf["publish_port"] = get_unused_localhost_port() master_conf["publish_port"] = ports.get_unused_localhost_port()
master_conf["ret_port"] = get_unused_localhost_port() master_conf["ret_port"] = ports.get_unused_localhost_port()
master_conf["pki_dir"] = str(root_dir / "pki") master_conf["pki_dir"] = str(root_dir / "pki")
os.makedirs(master_conf["pki_dir"]) os.makedirs(master_conf["pki_dir"])
salt.crypt.gen_keys(master_conf["pki_dir"], "master", 4096) salt.crypt.gen_keys(master_conf["pki_dir"], "master", 4096)

View file

@ -9,7 +9,7 @@ pytest.importorskip("libcloud", reason="salt-cloud requires >= libcloud 0.11.4")
def test_function_arguments(salt_cloud_cli): def test_function_arguments(salt_cloud_cli):
ret = salt_cloud_cli.run("--function", "show_image", "-h") ret = salt_cloud_cli.run("--function", "show_image", "-h")
assert ret.exitcode != 0 assert ret.returncode != 0
assert ( assert (
"error: --function expects two arguments: <function-name> <provider>" "error: --function expects two arguments: <function-name> <provider>"
in ret.stderr in ret.stderr
@ -18,7 +18,7 @@ def test_function_arguments(salt_cloud_cli):
def test_list_providers_accepts_no_arguments(salt_cloud_cli): def test_list_providers_accepts_no_arguments(salt_cloud_cli):
ret = salt_cloud_cli.run("--list-providers", "ec2") ret = salt_cloud_cli.run("--list-providers", "ec2")
assert ret.exitcode != 0 assert ret.returncode != 0
assert "error: '--list-providers' does not accept any arguments" in ret.stderr assert "error: '--list-providers' does not accept any arguments" in ret.stderr
@ -36,7 +36,7 @@ def test_mutually_exclusive_query_options(salt_cloud_cli, query_option):
conflicting_option = "--list-providers" conflicting_option = "--list-providers"
ret = salt_cloud_cli.run(query_option, conflicting_option) ret = salt_cloud_cli.run(query_option, conflicting_option)
assert ret.exitcode != 0 assert ret.returncode != 0
assert "are mutually exclusive. Please only choose one of them" in ret.stderr assert "are mutually exclusive. Please only choose one of them" in ret.stderr
@ -52,5 +52,5 @@ def test_mutually_exclusive_list_options(salt_cloud_cli, list_option):
conflicting__option = "--list-sizes" conflicting__option = "--list-sizes"
ret = salt_cloud_cli.run(list_option, "ec2", conflicting__option, "ec2") ret = salt_cloud_cli.run(list_option, "ec2", conflicting__option, "ec2")
assert ret.exitcode != 0 assert ret.returncode != 0
assert "are mutually exclusive. Please only choose one of them" in ret.stderr assert "are mutually exclusive. Please only choose one of them" in ret.stderr

View file

@ -2,7 +2,7 @@ import logging
import pytest import pytest
import salt.defaults.exitcodes import salt.defaults.exitcodes
from saltfactories.exceptions import FactoryNotStarted from pytestshellutils.exceptions import FactoryNotStarted
from saltfactories.utils import random_string from saltfactories.utils import random_string
pytestmark = [ pytestmark = [
@ -31,8 +31,8 @@ def test_exit_status_unknown_user(salt_factories, master_id):
# We should not get here # We should not get here
pass pass
assert exc.value.exitcode == salt.defaults.exitcodes.EX_NOUSER, exc.value assert exc.value.process_result.returncode == salt.defaults.exitcodes.EX_NOUSER
assert "The user is not available." in exc.value.stderr, exc.value assert "The user is not available." in exc.value.process_result.stderr
def test_exit_status_unknown_argument(salt_factories, master_id): def test_exit_status_unknown_argument(salt_factories, master_id):
@ -42,6 +42,6 @@ def test_exit_status_unknown_argument(salt_factories, master_id):
with pytest.raises(FactoryNotStarted) as exc: with pytest.raises(FactoryNotStarted) as exc:
factory = salt_factories.salt_master_daemon(master_id) factory = salt_factories.salt_master_daemon(master_id)
factory.start("--unknown-argument", start_timeout=10, max_start_attempts=1) factory.start("--unknown-argument", start_timeout=10, max_start_attempts=1)
assert exc.value.exitcode == salt.defaults.exitcodes.EX_USAGE, exc.value assert exc.value.process_result.returncode == salt.defaults.exitcodes.EX_USAGE
assert "Usage" in exc.value.stderr, exc.value assert "Usage" in exc.value.process_result.stderr
assert "no such option: --unknown-argument" in exc.value.stderr, exc.value assert "no such option: --unknown-argument" in exc.value.process_result.stderr

View file

@ -1,5 +1,4 @@
import logging import logging
import pathlib
import shutil import shutil
import pytest import pytest
@ -88,11 +87,6 @@ def loaders(minion_opts):
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def reset_loaders_state(loaders): def reset_loaders_state(loaders):
# Delete the files cache after each test
cachedir = pathlib.Path(loaders.opts["cachedir"])
shutil.rmtree(str(cachedir), ignore_errors=True)
cachedir.mkdir(parents=True, exist_ok=True)
# The above can be deleted after pytest-salt-factories>=1.0.0rc7 has been merged
try: try:
# Run the tests # Run the tests
yield yield

View file

@ -6,7 +6,7 @@ import psutil # pylint: disable=3rd-party-module-not-gated
import pytest import pytest
import salt.config import salt.config
import salt.fileserver.hgfs as hgfs import salt.fileserver.hgfs as hgfs
from saltfactories.utils.processes import terminate_process from pytestshellutils.utils.processes import terminate_process
from tests.support.mock import patch from tests.support.mock import patch
try: try:

View file

@ -6,8 +6,8 @@ import time
import pytest import pytest
import salt.utils.stringutils import salt.utils.stringutils
import zmq import zmq
from pytestshellutils.utils import ports
from salt.log_handlers.logstash_mod import DatagramLogstashHandler, ZMQLogstashHander from salt.log_handlers.logstash_mod import DatagramLogstashHandler, ZMQLogstashHander
from saltfactories.utils.ports import get_unused_localhost_port
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -16,7 +16,7 @@ log = logging.getLogger(__name__)
def datagram_server(): def datagram_server():
logger = logging.getLogger("test_logstash_logger") logger = logging.getLogger("test_logstash_logger")
server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
port = get_unused_localhost_port() port = ports.get_unused_localhost_port()
handler = DatagramLogstashHandler("127.0.0.1", port) handler = DatagramLogstashHandler("127.0.0.1", port)
try: try:
server.bind(("127.0.0.1", port)) server.bind(("127.0.0.1", port))
@ -34,7 +34,7 @@ def zmq_server():
logger = logging.getLogger("test_logstash_logger") logger = logging.getLogger("test_logstash_logger")
context = zmq.Context() context = zmq.Context()
server = context.socket(zmq.SUB) server = context.socket(zmq.SUB)
port = get_unused_localhost_port() port = ports.get_unused_localhost_port()
handler = ZMQLogstashHander("tcp://127.0.0.1:{}".format(port)) handler = ZMQLogstashHander("tcp://127.0.0.1:{}".format(port))
try: try:
server.setsockopt(zmq.SUBSCRIBE, b"") server.setsockopt(zmq.SUBSCRIBE, b"")

View file

@ -4,10 +4,9 @@ import time
import pytest import pytest
import salt.modules.etcd_mod as etcd_mod import salt.modules.etcd_mod as etcd_mod
from pytestshellutils.utils import ports
from salt.utils.etcd_util import HAS_ETCD_V2, HAS_ETCD_V3, get_conn from salt.utils.etcd_util import HAS_ETCD_V2, HAS_ETCD_V3, get_conn
from saltfactories.daemons.container import Container
from saltfactories.utils import random_string from saltfactories.utils import random_string
from saltfactories.utils.ports import get_unused_localhost_port
docker = pytest.importorskip("docker") docker = pytest.importorskip("docker")
@ -31,40 +30,17 @@ def configure_loader_modules(minion_opts):
} }
@pytest.fixture(scope="module")
def docker_client():
try:
client = docker.from_env()
except docker.errors.DockerException:
pytest.skip("Failed to get a connection to docker running on the system")
connectable = Container.client_connectable(client)
if connectable is not True: # pragma: nocover
pytest.skip(connectable)
return client
@pytest.fixture(scope="module")
def docker_image_name(docker_client):
image_name = "bitnami/etcd:3"
try:
docker_client.images.pull(image_name)
except docker.errors.APIError as exc:
pytest.skip("Failed to pull docker image '{}': {}".format(image_name, exc))
return image_name
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def etcd_port(): def etcd_port():
return get_unused_localhost_port() return ports.get_unused_localhost_port()
# TODO: Use our own etcd image to avoid reliance on a third party # TODO: Use our own etcd image to avoid reliance on a third party
@pytest.fixture(scope="module", autouse=True) @pytest.fixture(scope="module", autouse=True)
def etcd_apiv2_container(salt_factories, docker_client, etcd_port, docker_image_name): def etcd_apiv2_container(salt_factories, etcd_port):
container = salt_factories.get_container( container = salt_factories.get_container(
random_string("etcd-server-"), random_string("etcd-server-"),
image_name=docker_image_name, image_name="bitnami/etcd:3",
docker_client=docker_client,
check_ports=[etcd_port], check_ports=[etcd_port],
container_run_kwargs={ container_run_kwargs={
"environment": { "environment": {
@ -73,6 +49,9 @@ def etcd_apiv2_container(salt_factories, docker_client, etcd_port, docker_image_
}, },
"ports": {"2379/tcp": etcd_port}, "ports": {"2379/tcp": etcd_port},
}, },
pull_before_start=True,
skip_on_pull_failure=True,
skip_if_docker_client_not_connectable=True,
) )
with container.started() as factory: with container.started() as factory:
yield factory yield factory

View file

@ -2,10 +2,10 @@ import logging
import pytest import pytest
import salt.pillar.etcd_pillar as etcd_pillar import salt.pillar.etcd_pillar as etcd_pillar
from pytestshellutils.utils import ports
from salt.utils.etcd_util import HAS_ETCD_V2, HAS_ETCD_V3, get_conn from salt.utils.etcd_util import HAS_ETCD_V2, HAS_ETCD_V3, get_conn
from saltfactories.daemons.container import Container from saltfactories.daemons.container import Container
from saltfactories.utils import random_string from saltfactories.utils import random_string
from saltfactories.utils.ports import get_unused_localhost_port
docker = pytest.importorskip("docker") docker = pytest.importorskip("docker")
@ -26,40 +26,17 @@ def configure_loader_modules(minion_opts):
} }
@pytest.fixture(scope="module")
def docker_client():
try:
client = docker.from_env()
except docker.errors.DockerException:
pytest.skip("Failed to get a connection to docker running on the system")
connectable = Container.client_connectable(client)
if connectable is not True: # pragma: nocover
pytest.skip(connectable)
return client
@pytest.fixture(scope="module")
def docker_image_name(docker_client):
image_name = "bitnami/etcd:3"
try:
docker_client.images.pull(image_name)
except docker.errors.APIError as exc:
pytest.skip("Failed to pull docker image '{}': {}".format(image_name, exc))
return image_name
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def etcd_port(): def etcd_port():
return get_unused_localhost_port() return ports.get_unused_localhost_port()
# TODO: Use our own etcd image to avoid reliance on a third party # TODO: Use our own etcd image to avoid reliance on a third party
@pytest.fixture(scope="module", autouse=True) @pytest.fixture(scope="module", autouse=True)
def etcd_apiv2_container(salt_factories, docker_client, etcd_port, docker_image_name): def etcd_apiv2_container(salt_factories, etcd_port):
container = salt_factories.get_container( container = salt_factories.get_container(
random_string("etcd-server-"), random_string("etcd-server-"),
image_name=docker_image_name, image_name="bitnami/etcd:3",
docker_client=docker_client,
check_ports=[etcd_port], check_ports=[etcd_port],
container_run_kwargs={ container_run_kwargs={
"environment": { "environment": {
@ -68,6 +45,9 @@ def etcd_apiv2_container(salt_factories, docker_client, etcd_port, docker_image_
}, },
"ports": {"2379/tcp": etcd_port}, "ports": {"2379/tcp": etcd_port},
}, },
pull_before_start=True,
skip_on_pull_failure=True,
skip_if_docker_client_not_connectable=True,
) )
with container.started() as factory: with container.started() as factory:
yield factory yield factory

View file

@ -8,7 +8,7 @@ import textwrap
import pytest import pytest
import salt.pillar import salt.pillar
import salt.utils.stringutils import salt.utils.stringutils
from saltfactories.utils.processes import ProcessResult from pytestshellutils.utils.processes import ProcessResult
pytestmark = [ pytestmark = [
pytest.mark.skip_if_binaries_missing("gpg"), pytest.mark.skip_if_binaries_missing("gpg"),
@ -265,9 +265,9 @@ def gpg_homedir(salt_master, test_key):
universal_newlines=True, universal_newlines=True,
) )
ret = ProcessResult( ret = ProcessResult(
exitcode=proc.returncode, returncode=proc.returncode,
stdout=proc.stdout, stdout=proc.stdout,
stderr=proc.stderr, stderr=proc.stderr or "",
cmdline=proc.args, cmdline=proc.args,
) )
log.debug("Instantiating gpg keyring...\n%s", ret) log.debug("Instantiating gpg keyring...\n%s", ret)
@ -282,9 +282,9 @@ def gpg_homedir(salt_master, test_key):
input=test_key, input=test_key,
) )
ret = ProcessResult( ret = ProcessResult(
exitcode=proc.returncode, returncode=proc.returncode,
stdout=proc.stdout, stdout=proc.stdout,
stderr=proc.stderr, stderr=proc.stderr or "",
cmdline=proc.args, cmdline=proc.args,
) )
log.debug("Importing keypair...:\n%s", ret) log.debug("Importing keypair...:\n%s", ret)
@ -305,9 +305,9 @@ def gpg_homedir(salt_master, test_key):
input="KILLAGENT", input="KILLAGENT",
) )
ret = ProcessResult( ret = ProcessResult(
exitcode=proc.returncode, returncode=proc.returncode,
stdout=proc.stdout, stdout=proc.stdout,
stderr=proc.stderr, stderr=proc.stderr or "",
cmdline=proc.args, cmdline=proc.args,
) )
log.debug("Killed gpg-agent...\n%s", ret) log.debug("Killed gpg-agent...\n%s", ret)

View file

@ -3,10 +3,10 @@ import logging
import pytest import pytest
import salt.returners.etcd_return as etcd_return import salt.returners.etcd_return as etcd_return
import salt.utils.json import salt.utils.json
from pytestshellutils.utils import ports
from salt.utils.etcd_util import HAS_ETCD_V2, HAS_ETCD_V3, get_conn from salt.utils.etcd_util import HAS_ETCD_V2, HAS_ETCD_V3, get_conn
from saltfactories.daemons.container import Container from saltfactories.daemons.container import Container
from saltfactories.utils import random_string from saltfactories.utils import random_string
from saltfactories.utils.ports import get_unused_localhost_port
docker = pytest.importorskip("docker") docker = pytest.importorskip("docker")
@ -27,40 +27,17 @@ def configure_loader_modules(minion_opts):
} }
@pytest.fixture(scope="module")
def docker_client():
try:
client = docker.from_env()
except docker.errors.DockerException:
pytest.skip("Failed to get a connection to docker running on the system")
connectable = Container.client_connectable(client)
if connectable is not True: # pragma: nocover
pytest.skip(connectable)
return client
@pytest.fixture(scope="module")
def docker_image_name(docker_client):
image_name = "bitnami/etcd:3"
try:
docker_client.images.pull(image_name)
except docker.errors.APIError as exc:
pytest.skip("Failed to pull docker image '{}': {}".format(image_name, exc))
return image_name
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def etcd_port(): def etcd_port():
return get_unused_localhost_port() return ports.get_unused_localhost_port()
# TODO: Use our own etcd image to avoid reliance on a third party # TODO: Use our own etcd image to avoid reliance on a third party
@pytest.fixture(scope="module", autouse=True) @pytest.fixture(scope="module", autouse=True)
def etcd_apiv2_container(salt_factories, docker_client, etcd_port, docker_image_name): def etcd_apiv2_container(salt_factories, etcd_port):
container = salt_factories.get_container( container = salt_factories.get_container(
random_string("etcd-server-"), random_string("etcd-server-"),
image_name=docker_image_name, image_name="bitnami/etcd:3",
docker_client=docker_client,
check_ports=[etcd_port], check_ports=[etcd_port],
container_run_kwargs={ container_run_kwargs={
"environment": { "environment": {
@ -69,6 +46,9 @@ def etcd_apiv2_container(salt_factories, docker_client, etcd_port, docker_image_
}, },
"ports": {"2379/tcp": etcd_port}, "ports": {"2379/tcp": etcd_port},
}, },
pull_before_start=True,
skip_on_pull_failure=True,
skip_if_docker_client_not_connectable=True,
) )
with container.started() as factory: with container.started() as factory:
yield factory yield factory

View file

@ -2,12 +2,11 @@ import logging
import pytest import pytest
import salt.sdb.etcd_db as etcd_db import salt.sdb.etcd_db as etcd_db
from pytestshellutils.utils import ports
from salt.utils.etcd_util import HAS_ETCD_V2, HAS_ETCD_V3, get_conn from salt.utils.etcd_util import HAS_ETCD_V2, HAS_ETCD_V3, get_conn
from saltfactories.daemons.container import Container
from saltfactories.utils import random_string from saltfactories.utils import random_string
from saltfactories.utils.ports import get_unused_localhost_port
docker = pytest.importorskip("docker") pytest.importorskip("docker")
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -18,40 +17,17 @@ pytestmark = [
] ]
@pytest.fixture(scope="module")
def docker_client():
try:
client = docker.from_env()
except docker.errors.DockerException:
pytest.skip("Failed to get a connection to docker running on the system")
connectable = Container.client_connectable(client)
if connectable is not True: # pragma: nocover
pytest.skip(connectable)
return client
@pytest.fixture(scope="module")
def docker_image_name(docker_client):
image_name = "bitnami/etcd:3"
try:
docker_client.images.pull(image_name)
except docker.errors.APIError as exc:
pytest.skip("Failed to pull docker image '{}': {}".format(image_name, exc))
return image_name
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def etcd_port(): def etcd_port():
return get_unused_localhost_port() return ports.get_unused_localhost_port()
# TODO: Use our own etcd image to avoid reliance on a third party # TODO: Use our own etcd image to avoid reliance on a third party
@pytest.fixture(scope="module", autouse=True) @pytest.fixture(scope="module", autouse=True)
def etcd_apiv2_container(salt_factories, docker_client, etcd_port, docker_image_name): def etcd_apiv2_container(salt_factories, etcd_port):
container = salt_factories.get_container( container = salt_factories.get_container(
random_string("etcd-server-"), random_string("etcd-server-"),
image_name=docker_image_name, image_name="bitnami/etcd:3",
docker_client=docker_client,
check_ports=[etcd_port], check_ports=[etcd_port],
container_run_kwargs={ container_run_kwargs={
"environment": { "environment": {
@ -60,6 +36,9 @@ def etcd_apiv2_container(salt_factories, docker_client, etcd_port, docker_image_
}, },
"ports": {"2379/tcp": etcd_port}, "ports": {"2379/tcp": etcd_port},
}, },
pull_before_start=True,
skip_on_pull_failure=True,
skip_if_docker_client_not_connectable=True,
) )
with container.started() as factory: with container.started() as factory:
yield factory yield factory

View file

@ -3,12 +3,10 @@ import time
import attr import attr
import pytest import pytest
from saltfactories.daemons.container import Container from pytestshellutils.utils import ports
from saltfactories.utils import random_string from saltfactories.utils import random_string
from saltfactories.utils.ports import get_unused_localhost_port
docker = pytest.importorskip("docker") pytest.importorskip("docker")
docker_errors = pytest.importorskip("docker.errors")
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -31,19 +29,7 @@ class RabbitMQCombo:
@rabbitmq_port.default @rabbitmq_port.default
def _rabbitmq_port(self): def _rabbitmq_port(self):
return get_unused_localhost_port() return ports.get_unused_localhost_port()
@pytest.fixture(scope="module")
def docker_client():
try:
client = docker.from_env()
except docker.errors.DockerException:
pytest.skip("Failed to get a connection to docker running on the system")
connectable = Container.client_connectable(client)
if connectable is not True: # pragma: nocover
pytest.skip(connectable)
return client
def get_test_versions(): def get_test_versions():
@ -68,19 +54,12 @@ def get_test_version_id(value):
@pytest.fixture(scope="module", params=get_test_versions(), ids=get_test_version_id) @pytest.fixture(scope="module", params=get_test_versions(), ids=get_test_version_id)
def rabbitmq_image(request, docker_client): def rabbitmq_image(request):
image = request.param return request.param
try:
docker_client.images.pull(image.name, tag=image.tag)
except docker.errors.APIError as exc:
pytest.skip(
"Failed to pull docker image '{}:{}': {}".format(image.name, image.tag, exc)
)
return image
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def rabbitmq_container(salt_factories, docker_client, rabbitmq_image): def rabbitmq_container(salt_factories, rabbitmq_image):
combo = RabbitMQCombo( combo = RabbitMQCombo(
rabbitmq_name=rabbitmq_image.name, rabbitmq_name=rabbitmq_image.name,
@ -89,7 +68,9 @@ def rabbitmq_container(salt_factories, docker_client, rabbitmq_image):
container = salt_factories.get_container( container = salt_factories.get_container(
rabbitmq_image.container_id, rabbitmq_image.container_id,
"{}:{}".format(combo.rabbitmq_name, combo.rabbitmq_version), "{}:{}".format(combo.rabbitmq_name, combo.rabbitmq_version),
docker_client=docker_client, pull_before_start=True,
skip_on_pull_failure=True,
skip_if_docker_client_not_connectable=True,
) )
with container.started(): with container.started():
# Sleep # Sleep
@ -100,7 +81,7 @@ def rabbitmq_container(salt_factories, docker_client, rabbitmq_image):
while login_attempts: while login_attempts:
login_attempts -= 1 login_attempts -= 1
ret = container.run("rabbitmqctl status --formatter=json") ret = container.run("rabbitmqctl status --formatter=json")
authenticated = ret.exitcode == 0 authenticated = ret.returncode == 0
if authenticated: if authenticated:
break break
@ -124,7 +105,7 @@ def docker_cmd_run_all_wrapper(rabbitmq_container):
cmd[0] = "/opt/rabbitmq/sbin/rabbitmqctl" cmd[0] = "/opt/rabbitmq/sbin/rabbitmqctl"
ret = rabbitmq_container.run(cmd) ret = rabbitmq_container.run(cmd)
res = {"retcode": ret.exitcode, "stdout": ret.stdout, "stderr": ret.stderr} res = {"retcode": ret.returncode, "stdout": ret.stdout, "stderr": ret.stderr}
return res return res
return run_command return run_command

View file

@ -3,10 +3,10 @@ import logging
import pytest import pytest
import salt.modules.etcd_mod as etcd_mod import salt.modules.etcd_mod as etcd_mod
import salt.states.etcd_mod as etcd_state import salt.states.etcd_mod as etcd_state
from pytestshellutils.utils import ports
from salt.utils.etcd_util import HAS_ETCD_V2, HAS_ETCD_V3, get_conn from salt.utils.etcd_util import HAS_ETCD_V2, HAS_ETCD_V3, get_conn
from saltfactories.daemons.container import Container from saltfactories.daemons.container import Container
from saltfactories.utils import random_string from saltfactories.utils import random_string
from saltfactories.utils.ports import get_unused_localhost_port
docker = pytest.importorskip("docker") docker = pytest.importorskip("docker")
@ -37,40 +37,17 @@ def configure_loader_modules(minion_opts):
} }
@pytest.fixture(scope="module")
def docker_client():
try:
client = docker.from_env()
except docker.errors.DockerException:
pytest.skip("Failed to get a connection to docker running on the system")
connectable = Container.client_connectable(client)
if connectable is not True: # pragma: nocover
pytest.skip(connectable)
return client
@pytest.fixture(scope="module")
def docker_image_name(docker_client):
image_name = "bitnami/etcd:3"
try:
docker_client.images.pull(image_name)
except docker.errors.APIError as exc:
pytest.skip("Failed to pull docker image '{}': {}".format(image_name, exc))
return image_name
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def etcd_port(): def etcd_port():
return get_unused_localhost_port() return ports.get_unused_localhost_port()
# TODO: Use our own etcd image to avoid reliance on a third party # TODO: Use our own etcd image to avoid reliance on a third party
@pytest.fixture(scope="module", autouse=True) @pytest.fixture(scope="module", autouse=True)
def etcd_apiv2_container(salt_factories, docker_client, etcd_port, docker_image_name): def etcd_apiv2_container(salt_factories, etcd_port):
container = salt_factories.get_container( container = salt_factories.get_container(
random_string("etcd-server-"), random_string("etcd-server-"),
image_name=docker_image_name, image_name="bitnami/etcd:3",
docker_client=docker_client,
check_ports=[etcd_port], check_ports=[etcd_port],
container_run_kwargs={ container_run_kwargs={
"environment": { "environment": {
@ -79,6 +56,9 @@ def etcd_apiv2_container(salt_factories, docker_client, etcd_port, docker_image_
}, },
"ports": {"2379/tcp": etcd_port}, "ports": {"2379/tcp": etcd_port},
}, },
pull_before_start=True,
skip_on_pull_failure=True,
skip_if_docker_client_not_connectable=True,
) )
with container.started() as factory: with container.started() as factory:
yield factory yield factory

View file

@ -5,12 +5,11 @@ Integration tests for the zookeeper states
import logging import logging
import pytest import pytest
from saltfactories.daemons.container import Container from pytestshellutils.utils import ports
from saltfactories.utils import random_string from saltfactories.utils import random_string
from saltfactories.utils.ports import get_unused_localhost_port
pytest.importorskip("kazoo") pytest.importorskip("kazoo")
docker = pytest.importorskip("docker") pytest.importorskip("docker")
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -20,21 +19,9 @@ pytestmark = [
] ]
@pytest.fixture(scope="module")
def docker_client():
try:
client = docker.from_env()
except docker.errors.DockerException:
pytest.skip("Failed to get a connection to docker running on the system")
connectable = Container.client_connectable(client)
if connectable is not True: # pragma: nocover
pytest.skip(connectable)
return client
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def zookeeper_port(): def zookeeper_port():
return get_unused_localhost_port() return ports.get_unused_localhost_port()
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
@ -75,23 +62,19 @@ def minion_config_overrides(zookeeper_port):
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def zookeeper_image(docker_client): def zookeeper_container(salt_factories, zookeeper_port):
image_name = "zookeeper"
try:
docker_client.images.pull(image_name)
except docker.errors.APIError as exc:
pytest.skip("Failed to pull docker image '{}': {}".format(image_name, exc))
return image_name
@pytest.fixture(scope="module")
def zookeeper_container(salt_factories, docker_client, zookeeper_port, zookeeper_image):
container = salt_factories.get_container( container = salt_factories.get_container(
random_string("zookeeper-"), random_string("zookeeper-"),
zookeeper_image, "zookeeper",
docker_client=docker_client,
check_ports=[zookeeper_port], check_ports=[zookeeper_port],
container_run_kwargs={"ports": {"2181/tcp": zookeeper_port}}, pull_before_start=True,
skip_on_pull_failure=True,
skip_if_docker_client_not_connectable=True,
container_run_kwargs={
"ports": {
"2181/tcp": zookeeper_port,
}
},
) )
with container.started() as factory: with container.started() as factory:
yield factory yield factory

View file

@ -195,7 +195,7 @@ def test_extension_discovery_without_reload_with_importlib_metadata_installed(
# Exitcode 1 - Extension was already installed # Exitcode 1 - Extension was already installed
# Exitcode 2 - Failed to install the extension # Exitcode 2 - Failed to install the extension
# Exitcode 3 - Extension was not found within the same python process after being installed # Exitcode 3 - Extension was not found within the same python process after being installed
assert ret.exitcode == 0 assert ret.returncode == 0
installed_packages = venv.get_installed_packages() installed_packages = venv.get_installed_packages()
assert salt_extension.name in installed_packages assert salt_extension.name in installed_packages
@ -259,7 +259,7 @@ def test_extension_discovery_without_reload_with_bundled_importlib_metadata(
# Exitcode 1 - Extension was already installed # Exitcode 1 - Extension was already installed
# Exitcode 2 - Failed to install the extension # Exitcode 2 - Failed to install the extension
# Exitcode 3 - Extension was not found within the same python process after being installed # Exitcode 3 - Extension was not found within the same python process after being installed
assert ret.exitcode == 0 assert ret.returncode == 0
installed_packages = venv.get_installed_packages() installed_packages = venv.get_installed_packages()
assert salt_extension.name in installed_packages assert salt_extension.name in installed_packages

View file

@ -14,7 +14,7 @@ import salt.transport.server
import salt.utils.platform import salt.utils.platform
import salt.utils.process import salt.utils.process
import salt.utils.stringutils import salt.utils.stringutils
from saltfactories.utils.processes import terminate_process from pytestshellutils.utils.processes import terminate_process
log = logging.getLogger(__name__) log = logging.getLogger(__name__)

View file

@ -16,7 +16,7 @@ import salt.transport.zeromq
import salt.utils.process import salt.utils.process
import salt.utils.stringutils import salt.utils.stringutils
import zmq import zmq
from saltfactories.utils.processes import terminate_process from pytestshellutils.utils.processes import terminate_process
from tests.support.mock import MagicMock, patch from tests.support.mock import MagicMock, patch
log = logging.getLogger(__name__) log = logging.getLogger(__name__)

View file

@ -4,6 +4,7 @@ import threading
import time import time
import pytest import pytest
from pytestshellutils.utils import ports
from salt.utils.etcd_util import ( from salt.utils.etcd_util import (
HAS_ETCD_V2, HAS_ETCD_V2,
HAS_ETCD_V3, HAS_ETCD_V3,
@ -11,11 +12,9 @@ from salt.utils.etcd_util import (
EtcdClientV3, EtcdClientV3,
get_conn, get_conn,
) )
from saltfactories.daemons.container import Container
from saltfactories.utils import random_string from saltfactories.utils import random_string
from saltfactories.utils.ports import get_unused_localhost_port
docker = pytest.importorskip("docker") pytest.importorskip("docker")
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -26,40 +25,17 @@ pytestmark = [
] ]
@pytest.fixture(scope="module")
def docker_client():
try:
client = docker.from_env()
except docker.errors.DockerException:
pytest.skip("Failed to get a connection to docker running on the system")
connectable = Container.client_connectable(client)
if connectable is not True: # pragma: nocover
pytest.skip(connectable)
return client
@pytest.fixture(scope="module")
def docker_image_name(docker_client):
image_name = "bitnami/etcd:3"
try:
docker_client.images.pull(image_name)
except docker.errors.APIError as exc:
pytest.skip("Failed to pull docker image '{}': {}".format(image_name, exc))
return image_name
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def etcd_port(): def etcd_port():
return get_unused_localhost_port() return ports.get_unused_localhost_port()
# TODO: Use our own etcd image to avoid reliance on a third party # TODO: Use our own etcd image to avoid reliance on a third party
@pytest.fixture(scope="module", autouse=True) @pytest.fixture(scope="module", autouse=True)
def etcd_container(salt_factories, docker_client, etcd_port, docker_image_name): def etcd_container(salt_factories, etcd_port):
container = salt_factories.get_container( container = salt_factories.get_container(
random_string("etcd-server-"), random_string("etcd-server-"),
image_name=docker_image_name, image_name="elcolio/etcd",
docker_client=docker_client,
check_ports=[etcd_port], check_ports=[etcd_port],
container_run_kwargs={ container_run_kwargs={
"environment": { "environment": {
@ -68,6 +44,9 @@ def etcd_container(salt_factories, docker_client, etcd_port, docker_image_name):
}, },
"ports": {"2379/tcp": etcd_port}, "ports": {"2379/tcp": etcd_port},
}, },
pull_before_start=True,
skip_on_pull_failure=True,
skip_if_docker_client_not_connectable=True,
) )
with container.started() as factory: with container.started() as factory:
yield factory yield factory

View file

@ -19,8 +19,8 @@ def test_jid_in_logs(caplog, salt_call_cli):
try: try:
caplog.handler.setFormatter(formatter) caplog.handler.setFormatter(formatter)
ret = salt_call_cli.run("test.ping") ret = salt_call_cli.run("test.ping")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
assert_error_msg = ( assert_error_msg = (
"'{}' not found in log messages:\n>>>>>>>>>{}\n<<<<<<<<<".format( "'{}' not found in log messages:\n>>>>>>>>>{}\n<<<<<<<<<".format(

View file

@ -52,7 +52,7 @@ def test_batch_run_number(salt_cli, salt_minion, salt_sub_minion, run_timeout):
def test_batch_run_grains_targeting( def test_batch_run_grains_targeting(
salt_cli, salt_minion, salt_sub_minion, run_timeout grains, salt_cli, salt_minion, salt_sub_minion, run_timeout
): ):
""" """
Tests executing a batch command using a percentage divisor as well as grains Tests executing a batch command using a percentage divisor as well as grains
@ -60,14 +60,11 @@ def test_batch_run_grains_targeting(
""" """
sub_min_ret = "Executing run on [{}]".format(repr(salt_sub_minion.id)) sub_min_ret = "Executing run on [{}]".format(repr(salt_sub_minion.id))
min_ret = "Executing run on [{}]".format(repr(salt_minion.id)) min_ret = "Executing run on [{}]".format(repr(salt_minion.id))
os_grain = salt_cli.run("grains.get", "os", minion_tgt=salt_minion.id).json
os_grain = os_grain.strip()
cmd = salt_cli.run( cmd = salt_cli.run(
"-C", "-C",
"-b 25%", "-b 25%",
"test.ping", "test.ping",
minion_tgt="G@os:{} and not localhost".format(os_grain.replace(" ", "?")), minion_tgt="G@os:{} and not localhost".format(grains["os"].replace(" ", "?")),
_timeout=run_timeout, _timeout=run_timeout,
) )
assert sub_min_ret in cmd.stdout assert sub_min_ret in cmd.stdout
@ -86,7 +83,7 @@ def test_batch_exit_code(salt_cli, salt_minion, salt_sub_minion, run_timeout):
minion_tgt="*minion*", minion_tgt="*minion*",
_timeout=run_timeout, _timeout=run_timeout,
) )
assert cmd.exitcode == 2 assert cmd.returncode == 2
# Test for failhard + batch. The best possible solution here was to do something like that: # Test for failhard + batch. The best possible solution here was to do something like that:
@ -180,7 +177,7 @@ def test_batch_retcode(salt_cli, salt_minion, salt_sub_minion, run_timeout):
_timeout=run_timeout, _timeout=run_timeout,
) )
assert cmd.exitcode == 23 assert cmd.returncode == 23
assert not cmd.stderr assert not cmd.stderr
assert "true" in cmd.stdout assert "true" in cmd.stdout
@ -199,7 +196,7 @@ def test_multiple_modules_in_batch(salt_cli, salt_minion, salt_sub_minion, run_t
_timeout=run_timeout, _timeout=run_timeout,
) )
assert cmd.exitcode == 23 assert cmd.returncode == 23
assert not cmd.stderr assert not cmd.stderr

View file

@ -58,20 +58,20 @@ def pillar_tree(salt_master, salt_minion, salt_sub_minion, salt_cli):
try: try:
with top_tempfile, basic_tempfile, sub_tempfile: with top_tempfile, basic_tempfile, sub_tempfile:
ret = salt_cli.run("saltutil.refresh_pillar", wait=True, minion_tgt="*") ret = salt_cli.run("saltutil.refresh_pillar", wait=True, minion_tgt="*")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert ret.json[salt_minion.id] is True assert ret.data[salt_minion.id] is True
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
assert ret.json[salt_sub_minion.id] is True assert ret.data[salt_sub_minion.id] is True
yield yield
finally: finally:
# Refresh pillar again to cleaup the temp pillar # Refresh pillar again to cleaup the temp pillar
ret = salt_cli.run("saltutil.refresh_pillar", wait=True, minion_tgt="*") ret = salt_cli.run("saltutil.refresh_pillar", wait=True, minion_tgt="*")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert ret.json[salt_minion.id] is True assert ret.data[salt_minion.id] is True
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
assert ret.json[salt_sub_minion.id] is True assert ret.data[salt_sub_minion.id] is True
def test_list(salt_cli, salt_minion, salt_sub_minion): def test_list(salt_cli, salt_minion, salt_sub_minion):
@ -79,16 +79,16 @@ def test_list(salt_cli, salt_minion, salt_sub_minion):
test salt -L matcher test salt -L matcher
""" """
ret = salt_cli.run("-L", "test.ping", minion_tgt=salt_minion.id) ret = salt_cli.run("-L", "test.ping", minion_tgt=salt_minion.id)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
assert salt_minion.id in ret.stdout assert salt_minion.id in ret.stdout
assert salt_sub_minion.id not in ret.stdout assert salt_sub_minion.id not in ret.stdout
ret = salt_cli.run( ret = salt_cli.run(
"-L", "test.ping", minion_tgt="{},{}".format(salt_minion.id, salt_sub_minion.id) "-L", "test.ping", minion_tgt="{},{}".format(salt_minion.id, salt_sub_minion.id)
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
def test_compound_min_with_grain(salt_cli, salt_minion, salt_sub_minion): def test_compound_min_with_grain(salt_cli, salt_minion, salt_sub_minion):
@ -96,104 +96,104 @@ def test_compound_min_with_grain(salt_cli, salt_minion, salt_sub_minion):
test salt compound matcher test salt compound matcher
""" """
ret = salt_cli.run("-C", "test.ping", minion_tgt="min* and G@test_grain:cheese") ret = salt_cli.run("-C", "test.ping", minion_tgt="min* and G@test_grain:cheese")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id not in ret.json assert salt_sub_minion.id not in ret.data
def test_compound_and_not_grain(salt_cli, salt_minion, salt_sub_minion): def test_compound_and_not_grain(salt_cli, salt_minion, salt_sub_minion):
ret = salt_cli.run("-C", "test.ping", minion_tgt="min* and not G@test_grain:foo") ret = salt_cli.run("-C", "test.ping", minion_tgt="min* and not G@test_grain:foo")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id not in ret.json assert salt_sub_minion.id not in ret.data
def test_compound_not_grain(salt_cli, salt_minion, salt_sub_minion): def test_compound_not_grain(salt_cli, salt_minion, salt_sub_minion):
ret = salt_cli.run("-C", "test.ping", minion_tgt="min* not G@test_grain:foo") ret = salt_cli.run("-C", "test.ping", minion_tgt="min* not G@test_grain:foo")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id not in ret.json assert salt_sub_minion.id not in ret.data
def test_compound_pcre_grain_and_grain(salt_cli, salt_minion, salt_sub_minion): def test_compound_pcre_grain_and_grain(salt_cli, salt_minion, salt_sub_minion):
match = "P@test_grain:^cheese$ and * and G@test_grain:cheese" match = "P@test_grain:^cheese$ and * and G@test_grain:cheese"
ret = salt_cli.run("-C", "test.ping", minion_tgt=match) ret = salt_cli.run("-C", "test.ping", minion_tgt=match)
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id not in ret.json assert salt_sub_minion.id not in ret.data
def test_compound_list_and_pcre_minion(salt_cli, salt_minion, salt_sub_minion): def test_compound_list_and_pcre_minion(salt_cli, salt_minion, salt_sub_minion):
match = "L@{} and E@.*".format(salt_sub_minion.id) match = "L@{} and E@.*".format(salt_sub_minion.id)
ret = salt_cli.run("-C", "test.ping", minion_tgt=match) ret = salt_cli.run("-C", "test.ping", minion_tgt=match)
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
assert salt_minion.id not in ret.json assert salt_minion.id not in ret.data
def test_compound_not_sub_minion(salt_cli, salt_minion, salt_sub_minion): def test_compound_not_sub_minion(salt_cli, salt_minion, salt_sub_minion):
ret = salt_cli.run( ret = salt_cli.run(
"-C", "test.ping", minion_tgt="not {}".format(salt_sub_minion.id) "-C", "test.ping", minion_tgt="not {}".format(salt_sub_minion.id)
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id not in ret.json assert salt_sub_minion.id not in ret.data
def test_compound_all_and_not_grains(salt_cli, salt_minion, salt_sub_minion): def test_compound_all_and_not_grains(salt_cli, salt_minion, salt_sub_minion):
ret = salt_cli.run( ret = salt_cli.run(
"-C", "test.ping", minion_tgt="* and ( not G@test_grain:cheese )" "-C", "test.ping", minion_tgt="* and ( not G@test_grain:cheese )"
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id not in ret.json assert salt_minion.id not in ret.data
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
def test_compound_grain_regex(salt_cli, salt_minion, salt_sub_minion): def test_compound_grain_regex(salt_cli, salt_minion, salt_sub_minion):
ret = salt_cli.run("-C", "test.ping", minion_tgt="G%@planets%merc*") ret = salt_cli.run("-C", "test.ping", minion_tgt="G%@planets%merc*")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id not in ret.json assert salt_sub_minion.id not in ret.data
def test_coumpound_pcre_grain_regex(salt_cli, salt_minion, salt_sub_minion): def test_coumpound_pcre_grain_regex(salt_cli, salt_minion, salt_sub_minion):
ret = salt_cli.run("-C", "test.ping", minion_tgt="P%@planets%^(mercury|saturn)$") ret = salt_cli.run("-C", "test.ping", minion_tgt="P%@planets%^(mercury|saturn)$")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
def test_compound_pillar(salt_cli, salt_minion, salt_sub_minion, pillar_tree): def test_compound_pillar(salt_cli, salt_minion, salt_sub_minion, pillar_tree):
# FYI, This test was previously being skipped because it was unreliable # FYI, This test was previously being skipped because it was unreliable
ret = salt_cli.run("-C", "test.ping", minion_tgt="I%@companions%three%sarah*") ret = salt_cli.run("-C", "test.ping", minion_tgt="I%@companions%three%sarah*")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
def test_compound_pillar_pcre(salt_cli, salt_minion, salt_sub_minion, pillar_tree): def test_compound_pillar_pcre(salt_cli, salt_minion, salt_sub_minion, pillar_tree):
# FYI, This test was previously being skipped because it was unreliable # FYI, This test was previously being skipped because it was unreliable
ret = salt_cli.run("-C", "test.ping", minion_tgt="J%@knights%^(Lancelot|Galahad)$") ret = salt_cli.run("-C", "test.ping", minion_tgt="J%@knights%^(Lancelot|Galahad)$")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
def test_compound_nodegroup(salt_cli, salt_minion, salt_sub_minion): def test_compound_nodegroup(salt_cli, salt_minion, salt_sub_minion):
ret = salt_cli.run("-C", "test.ping", minion_tgt="N@multiline_nodegroup") ret = salt_cli.run("-C", "test.ping", minion_tgt="N@multiline_nodegroup")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
target = "N@multiline_nodegroup not {}".format(salt_sub_minion.id) target = "N@multiline_nodegroup not {}".format(salt_sub_minion.id)
ret = salt_cli.run("-C", "test.ping", minion_tgt=target) ret = salt_cli.run("-C", "test.ping", minion_tgt=target)
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id not in ret.json assert salt_sub_minion.id not in ret.data
target = "N@multiline_nodegroup not @fakenodegroup not {}".format( target = "N@multiline_nodegroup not @fakenodegroup not {}".format(
salt_sub_minion.id salt_sub_minion.id
) )
ret = salt_cli.run("-C", "test.ping", minion_tgt=target) ret = salt_cli.run("-C", "test.ping", minion_tgt=target)
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id not in ret.json assert salt_sub_minion.id not in ret.data
def test_nodegroup(salt_cli, salt_minion, salt_sub_minion): def test_nodegroup(salt_cli, salt_minion, salt_sub_minion):
@ -201,52 +201,52 @@ def test_nodegroup(salt_cli, salt_minion, salt_sub_minion):
test salt nodegroup matcher test salt nodegroup matcher
""" """
ret = salt_cli.run("-N", "test.ping", minion_tgt="min") ret = salt_cli.run("-N", "test.ping", minion_tgt="min")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id not in ret.json assert salt_sub_minion.id not in ret.data
ret = salt_cli.run("-N", "test.ping", minion_tgt="sub_min") ret = salt_cli.run("-N", "test.ping", minion_tgt="sub_min")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id not in ret.json assert salt_minion.id not in ret.data
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
ret = salt_cli.run("-N", "test.ping", minion_tgt="mins") ret = salt_cli.run("-N", "test.ping", minion_tgt="mins")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
ret = salt_cli.run("-N", "test.ping", minion_tgt="unknown_nodegroup") ret = salt_cli.run("-N", "test.ping", minion_tgt="unknown_nodegroup")
assert ret.exitcode == 0 assert ret.returncode == 0
assert not ret.json assert not ret.data
ret = salt_cli.run("-N", "test.ping", minion_tgt="redundant_minions") ret = salt_cli.run("-N", "test.ping", minion_tgt="redundant_minions")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
ret = salt_cli.run("-N", "test.ping", minion_tgt="nodegroup_loop_a") ret = salt_cli.run("-N", "test.ping", minion_tgt="nodegroup_loop_a")
assert ret.exitcode == 2 # No minions matched assert ret.returncode == 2 # No minions matched
ret = salt_cli.run("-N", "test.ping", minion_tgt="multiline_nodegroup") ret = salt_cli.run("-N", "test.ping", minion_tgt="multiline_nodegroup")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
def test_nodegroup_list(salt_cli, salt_minion, salt_sub_minion): def test_nodegroup_list(salt_cli, salt_minion, salt_sub_minion):
ret = salt_cli.run("-N", "test.ping", minion_tgt="list_group") ret = salt_cli.run("-N", "test.ping", minion_tgt="list_group")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
ret = salt_cli.run("-N", "test.ping", minion_tgt="list_group2") ret = salt_cli.run("-N", "test.ping", minion_tgt="list_group2")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
ret = salt_cli.run("-N", "test.ping", minion_tgt="one_list_group") ret = salt_cli.run("-N", "test.ping", minion_tgt="one_list_group")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id not in ret.json assert salt_sub_minion.id not in ret.data
ret = salt_cli.run("-N", "test.ping", minion_tgt="one_minion_list") ret = salt_cli.run("-N", "test.ping", minion_tgt="one_minion_list")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id not in ret.json assert salt_sub_minion.id not in ret.data
def test_glob(salt_cli, salt_minion, salt_sub_minion): def test_glob(salt_cli, salt_minion, salt_sub_minion):
@ -254,14 +254,14 @@ def test_glob(salt_cli, salt_minion, salt_sub_minion):
test salt glob matcher test salt glob matcher
""" """
ret = salt_cli.run("test.ping", minion_tgt=salt_minion.id) ret = salt_cli.run("test.ping", minion_tgt=salt_minion.id)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
assert salt_minion.id in ret.stdout assert salt_minion.id in ret.stdout
assert salt_sub_minion.id not in ret.stdout assert salt_sub_minion.id not in ret.stdout
ret = salt_cli.run("test.ping", minion_tgt="*") ret = salt_cli.run("test.ping", minion_tgt="*")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
def test_regex(salt_cli, salt_minion, salt_sub_minion): def test_regex(salt_cli, salt_minion, salt_sub_minion):
@ -269,13 +269,13 @@ def test_regex(salt_cli, salt_minion, salt_sub_minion):
test salt regex matcher test salt regex matcher
""" """
ret = salt_cli.run("-E", "test.ping", minion_tgt="^{}$".format(salt_minion.id)) ret = salt_cli.run("-E", "test.ping", minion_tgt="^{}$".format(salt_minion.id))
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id not in ret.json assert salt_sub_minion.id not in ret.data
ret = salt_cli.run("-E", "test.ping", minion_tgt=".*") ret = salt_cli.run("-E", "test.ping", minion_tgt=".*")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
def test_grain(salt_cli, salt_master, salt_minion, salt_sub_minion): def test_grain(salt_cli, salt_master, salt_minion, salt_sub_minion):
@ -284,65 +284,65 @@ def test_grain(salt_cli, salt_master, salt_minion, salt_sub_minion):
""" """
# Sync grains # Sync grains
ret = salt_cli.run("saltutil.sync_grains", minion_tgt="*") ret = salt_cli.run("saltutil.sync_grains", minion_tgt="*")
assert ret.exitcode == 0 assert ret.returncode == 0
# First-level grain (string value) # First-level grain (string value)
ret = salt_cli.run("-G", "test.ping", minion_tgt="test_grain:cheese") ret = salt_cli.run("-G", "test.ping", minion_tgt="test_grain:cheese")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id not in ret.json assert salt_sub_minion.id not in ret.data
ret = salt_cli.run("-G", "test.ping", minion_tgt="test_grain:spam") ret = salt_cli.run("-G", "test.ping", minion_tgt="test_grain:spam")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
assert salt_minion.id not in ret.json assert salt_minion.id not in ret.data
# Custom grain # Custom grain
ret = salt_cli.run("-G", "test.ping", minion_tgt="match:maker") ret = salt_cli.run("-G", "test.ping", minion_tgt="match:maker")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
# First-level grain (list member) # First-level grain (list member)
ret = salt_cli.run("-G", "test.ping", minion_tgt="planets:earth") ret = salt_cli.run("-G", "test.ping", minion_tgt="planets:earth")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id not in ret.json assert salt_sub_minion.id not in ret.data
ret = salt_cli.run("-G", "test.ping", minion_tgt="planets:saturn") ret = salt_cli.run("-G", "test.ping", minion_tgt="planets:saturn")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
assert salt_minion.id not in ret.json assert salt_minion.id not in ret.data
ret = salt_cli.run("-G", "test.ping", minion_tgt="planets:pluto") ret = salt_cli.run("-G", "test.ping", minion_tgt="planets:pluto")
assert ret.exitcode == 2 # No match assert ret.returncode == 2 # No match
# Nested grain (string value) # Nested grain (string value)
ret = salt_cli.run("-G", "test.ping", minion_tgt="level1:level2:foo") ret = salt_cli.run("-G", "test.ping", minion_tgt="level1:level2:foo")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id not in ret.json assert salt_sub_minion.id not in ret.data
ret = salt_cli.run("-G", "test.ping", minion_tgt="level1:level2:bar") ret = salt_cli.run("-G", "test.ping", minion_tgt="level1:level2:bar")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
assert salt_minion.id not in ret.json assert salt_minion.id not in ret.data
# Nested grain (list member) # Nested grain (list member)
ret = salt_cli.run("-G", "test.ping", minion_tgt="companions:one:ian") ret = salt_cli.run("-G", "test.ping", minion_tgt="companions:one:ian")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id not in ret.json assert salt_sub_minion.id not in ret.data
ret = salt_cli.run("-G", "test.ping", minion_tgt="companions:two:jamie") ret = salt_cli.run("-G", "test.ping", minion_tgt="companions:two:jamie")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
assert salt_minion.id not in ret.json assert salt_minion.id not in ret.data
# Test for issue: https://github.com/saltstack/salt/issues/19651 # Test for issue: https://github.com/saltstack/salt/issues/19651
ret = salt_cli.run("-G", "test.ping", minion_tgt="companions:*:susan") ret = salt_cli.run("-G", "test.ping", minion_tgt="companions:*:susan")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id not in ret.json assert salt_sub_minion.id not in ret.data
# Test to ensure wildcard at end works correctly # Test to ensure wildcard at end works correctly
ret = salt_cli.run("-G", "test.ping", minion_tgt="companions:one:*") ret = salt_cli.run("-G", "test.ping", minion_tgt="companions:one:*")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id not in ret.json assert salt_sub_minion.id not in ret.data
# Test to ensure multiple wildcards works correctly # Test to ensure multiple wildcards works correctly
ret = salt_cli.run("-G", "test.ping", minion_tgt="companions:*:*") ret = salt_cli.run("-G", "test.ping", minion_tgt="companions:*:*")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
def test_grains_targeting_os_running(grains, salt_cli, salt_minion, salt_sub_minion): def test_grains_targeting_os_running(grains, salt_cli, salt_minion, salt_sub_minion):
@ -350,11 +350,11 @@ def test_grains_targeting_os_running(grains, salt_cli, salt_minion, salt_sub_min
Tests running "salt -G 'os:<system-os>' test.ping and minions both return True Tests running "salt -G 'os:<system-os>' test.ping and minions both return True
""" """
ret = salt_cli.run("-G", "test.ping", minion_tgt="os:{}".format(grains["os"])) ret = salt_cli.run("-G", "test.ping", minion_tgt="os:{}".format(grains["os"]))
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert ret.json[salt_minion.id] is True assert ret.data[salt_minion.id] is True
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
assert ret.json[salt_sub_minion.id] is True assert ret.data[salt_sub_minion.id] is True
def test_grains_targeting_minion_id_running(salt_cli, salt_minion, salt_sub_minion): def test_grains_targeting_minion_id_running(salt_cli, salt_minion, salt_sub_minion):
@ -362,14 +362,14 @@ def test_grains_targeting_minion_id_running(salt_cli, salt_minion, salt_sub_mini
Tests return of each running test minion targeting with minion id grain Tests return of each running test minion targeting with minion id grain
""" """
ret = salt_cli.run("-G", "test.ping", minion_tgt="id:{}".format(salt_minion.id)) ret = salt_cli.run("-G", "test.ping", minion_tgt="id:{}".format(salt_minion.id))
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert ret.json[salt_minion.id] is True assert ret.data[salt_minion.id] is True
ret = salt_cli.run("-G", "test.ping", minion_tgt="id:{}".format(salt_sub_minion.id)) ret = salt_cli.run("-G", "test.ping", minion_tgt="id:{}".format(salt_sub_minion.id))
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
assert ret.json[salt_sub_minion.id] is True assert ret.data[salt_sub_minion.id] is True
def test_grains_targeting_minion_id_disconnected(salt_master, salt_minion, salt_cli): def test_grains_targeting_minion_id_disconnected(salt_master, salt_minion, salt_cli):
@ -389,13 +389,14 @@ def test_grains_targeting_minion_id_disconnected(salt_master, salt_minion, salt_
): ):
ret = salt_cli.run( ret = salt_cli.run(
"--timeout=1", "--timeout=1",
"--log-level=debug",
"-G", "-G",
"test.ping", "test.ping",
minion_tgt="id:{}".format(disconnected_minion_id), minion_tgt="id:{}".format(disconnected_minion_id),
) )
assert ret.exitcode == 1 assert ret.returncode == 1
assert disconnected_minion_id in ret.json assert disconnected_minion_id in ret.data
assert expected_output in ret.json[disconnected_minion_id] assert expected_output in ret.data[disconnected_minion_id]
def test_regrain(salt_cli, salt_minion, salt_sub_minion): def test_regrain(salt_cli, salt_minion, salt_sub_minion):
@ -403,13 +404,13 @@ def test_regrain(salt_cli, salt_minion, salt_sub_minion):
test salt grain matcher test salt grain matcher
""" """
ret = salt_cli.run("--grain-pcre", "test.ping", minion_tgt="test_grain:^cheese$") ret = salt_cli.run("--grain-pcre", "test.ping", minion_tgt="test_grain:^cheese$")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id not in ret.json assert salt_sub_minion.id not in ret.data
ret = salt_cli.run("--grain-pcre", "test.ping", minion_tgt="test_grain:.*am$") ret = salt_cli.run("--grain-pcre", "test.ping", minion_tgt="test_grain:.*am$")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
assert salt_minion.id not in ret.json assert salt_minion.id not in ret.data
def test_pillar(salt_cli, salt_minion, salt_sub_minion, pillar_tree): def test_pillar(salt_cli, salt_minion, salt_sub_minion, pillar_tree):
@ -418,31 +419,31 @@ def test_pillar(salt_cli, salt_minion, salt_sub_minion, pillar_tree):
""" """
# First-level pillar (string value) # First-level pillar (string value)
ret = salt_cli.run("-I", "test.ping", minion_tgt="monty:python") ret = salt_cli.run("-I", "test.ping", minion_tgt="monty:python")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
# First-level pillar (string value, only in sub_minion) # First-level pillar (string value, only in sub_minion)
ret = salt_cli.run( ret = salt_cli.run(
"-I", "test.ping", minion_tgt="sub:{}".format(salt_sub_minion.id) "-I", "test.ping", minion_tgt="sub:{}".format(salt_sub_minion.id)
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
assert salt_minion.id not in ret.json assert salt_minion.id not in ret.data
# First-level pillar (list member) # First-level pillar (list member)
ret = salt_cli.run("-I", "test.ping", minion_tgt="knights:Bedevere") ret = salt_cli.run("-I", "test.ping", minion_tgt="knights:Bedevere")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
# Nested pillar (string value) # Nested pillar (string value)
ret = salt_cli.run("-I", "test.ping", minion_tgt="level1:level2:foo") ret = salt_cli.run("-I", "test.ping", minion_tgt="level1:level2:foo")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
# Nested pillar (list member) # Nested pillar (list member)
ret = salt_cli.run("-I", "test.ping", minion_tgt="companions:three:sarah jane") ret = salt_cli.run("-I", "test.ping", minion_tgt="companions:three:sarah jane")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
def test_repillar(salt_cli, salt_minion, salt_sub_minion, pillar_tree): def test_repillar(salt_cli, salt_minion, salt_sub_minion, pillar_tree):
@ -450,29 +451,29 @@ def test_repillar(salt_cli, salt_minion, salt_sub_minion, pillar_tree):
test salt pillar PCRE matcher test salt pillar PCRE matcher
""" """
ret = salt_cli.run("-J", "test.ping", minion_tgt="monty:^(python|hall)$") ret = salt_cli.run("-J", "test.ping", minion_tgt="monty:^(python|hall)$")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
ret = salt_cli.run( ret = salt_cli.run(
"--pillar-pcre", "test.ping", minion_tgt="knights:^(Robin|Lancelot)$" "--pillar-pcre", "test.ping", minion_tgt="knights:^(Robin|Lancelot)$"
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
def test_ipcidr(salt_cli, salt_minion, salt_sub_minion): def test_ipcidr(salt_cli, salt_minion, salt_sub_minion):
ret = salt_cli.run("network.subnets", minion_tgt=salt_minion.id) ret = salt_cli.run("network.subnets", minion_tgt=salt_minion.id)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
# We're just after the first defined subnet from 'minion' # We're just after the first defined subnet from 'minion'
subnet = ret.json[0] subnet = ret.data[0]
ret = salt_cli.run("-S", "test.ping", minion_tgt=subnet) ret = salt_cli.run("-S", "test.ping", minion_tgt=subnet)
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
def test_static(salt_cli, salt_minion, salt_sub_minion): def test_static(salt_cli, salt_minion, salt_sub_minion):
@ -480,8 +481,8 @@ def test_static(salt_cli, salt_minion, salt_sub_minion):
test salt static call test salt static call
""" """
ret = salt_cli.run("test.ping", "--static", minion_tgt=salt_minion.id) ret = salt_cli.run("test.ping", "--static", minion_tgt=salt_minion.id)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
assert salt_minion.id in ret.stdout assert salt_minion.id in ret.stdout
@ -490,8 +491,8 @@ def test_salt_documentation(salt_cli, salt_minion):
Test to see if we're supporting --doc Test to see if we're supporting --doc
""" """
ret = salt_cli.run("-d", "test", minion_tgt=salt_minion.id) ret = salt_cli.run("-d", "test", minion_tgt=salt_minion.id)
assert ret.exitcode == 0 assert ret.returncode == 0
assert "test.ping" in ret.json assert "test.ping" in ret.data
def test_salt_documentation_too_many_arguments(salt_cli, salt_minion): def test_salt_documentation_too_many_arguments(salt_cli, salt_minion):
@ -501,5 +502,5 @@ def test_salt_documentation_too_many_arguments(salt_cli, salt_minion):
ret = salt_cli.run( ret = salt_cli.run(
"-d", "salt", "ldap.search", "filter=ou=People", minion_tgt=salt_cli.id "-d", "salt", "ldap.search", "filter=ou=People", minion_tgt=salt_cli.id
) )
assert ret.exitcode == salt.defaults.exitcodes.EX_USAGE assert ret.returncode == salt.defaults.exitcodes.EX_USAGE
assert "You can only get documentation for one method at one time" in ret.stderr assert "You can only get documentation for one method at one time" in ret.stderr

View file

@ -13,7 +13,7 @@ import time
import pytest import pytest
import salt.defaults.exitcodes import salt.defaults.exitcodes
import salt.utils.path import salt.utils.path
from saltfactories.utils.processes import ProcessResult, terminate_process from pytestshellutils.utils.processes import ProcessResult, terminate_process
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -30,9 +30,9 @@ def test_context_retcode_salt(salt_cli, salt_minion):
""" """
# test.retcode will set the retcode in the context dunder # test.retcode will set the retcode in the context dunder
ret = salt_cli.run("test.retcode", "0", minion_tgt=salt_minion.id) ret = salt_cli.run("test.retcode", "0", minion_tgt=salt_minion.id)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
ret = salt_cli.run("test.retcode", "42", minion_tgt=salt_minion.id) ret = salt_cli.run("test.retcode", "42", minion_tgt=salt_minion.id)
assert ret.exitcode == salt.defaults.exitcodes.EX_GENERIC, ret assert ret.returncode == salt.defaults.exitcodes.EX_GENERIC, ret
def test_salt_error(salt_cli, salt_minion): def test_salt_error(salt_cli, salt_minion):
@ -41,28 +41,28 @@ def test_salt_error(salt_cli, salt_minion):
an exception. an exception.
""" """
ret = salt_cli.run("test.raise_exception", "TypeError", minion_tgt=salt_minion.id) ret = salt_cli.run("test.raise_exception", "TypeError", minion_tgt=salt_minion.id)
assert ret.exitcode == salt.defaults.exitcodes.EX_GENERIC, ret assert ret.returncode == salt.defaults.exitcodes.EX_GENERIC, ret
ret = salt_cli.run( ret = salt_cli.run(
"test.raise_exception", "test.raise_exception",
"salt.exceptions.CommandNotFoundError", "salt.exceptions.CommandNotFoundError",
minion_tgt=salt_minion.id, minion_tgt=salt_minion.id,
) )
assert ret.exitcode == salt.defaults.exitcodes.EX_GENERIC, ret assert ret.returncode == salt.defaults.exitcodes.EX_GENERIC, ret
ret = salt_cli.run( ret = salt_cli.run(
"test.raise_exception", "test.raise_exception",
"salt.exceptions.CommandExecutionError", "salt.exceptions.CommandExecutionError",
minion_tgt=salt_minion.id, minion_tgt=salt_minion.id,
) )
assert ret.exitcode == salt.defaults.exitcodes.EX_GENERIC, ret assert ret.returncode == salt.defaults.exitcodes.EX_GENERIC, ret
ret = salt_cli.run( ret = salt_cli.run(
"test.raise_exception", "test.raise_exception",
"salt.exceptions.SaltInvocationError", "salt.exceptions.SaltInvocationError",
minion_tgt=salt_minion.id, minion_tgt=salt_minion.id,
) )
assert ret.exitcode == salt.defaults.exitcodes.EX_GENERIC, ret assert ret.returncode == salt.defaults.exitcodes.EX_GENERIC, ret
ret = salt_cli.run( ret = salt_cli.run(
"test.raise_exception", "test.raise_exception",
@ -71,17 +71,17 @@ def test_salt_error(salt_cli, salt_minion):
'"No such file or directory" /tmp/foo.txt', '"No such file or directory" /tmp/foo.txt',
minion_tgt=salt_minion.id, minion_tgt=salt_minion.id,
) )
assert ret.exitcode == salt.defaults.exitcodes.EX_GENERIC, ret assert ret.returncode == salt.defaults.exitcodes.EX_GENERIC, ret
ret = salt_cli.run( ret = salt_cli.run(
"test.echo", "{foo: bar, result: False}", minion_tgt=salt_minion.id "test.echo", "{foo: bar, result: False}", minion_tgt=salt_minion.id
) )
assert ret.exitcode == salt.defaults.exitcodes.EX_GENERIC, ret assert ret.returncode == salt.defaults.exitcodes.EX_GENERIC, ret
ret = salt_cli.run( ret = salt_cli.run(
"test.echo", "{foo: bar, success: False}", minion_tgt=salt_minion.id "test.echo", "{foo: bar, success: False}", minion_tgt=salt_minion.id
) )
assert ret.exitcode == salt.defaults.exitcodes.EX_GENERIC, ret assert ret.returncode == salt.defaults.exitcodes.EX_GENERIC, ret
def test_missing_minion(salt_cli, salt_master, salt_minion): def test_missing_minion(salt_cli, salt_master, salt_minion):
@ -98,7 +98,7 @@ def test_missing_minion(salt_cli, salt_master, salt_minion):
ret = salt_cli.run( ret = salt_cli.run(
"--timeout=5", "test.ping", minion_tgt="minion2", _timeout=120 "--timeout=5", "test.ping", minion_tgt="minion2", _timeout=120
) )
assert ret.exitcode == salt.defaults.exitcodes.EX_GENERIC, ret assert ret.returncode == salt.defaults.exitcodes.EX_GENERIC, ret
finally: finally:
# Now get rid of it # Now get rid of it
try: try:
@ -117,7 +117,7 @@ def test_exit_status_unknown_argument(salt_cli):
ret = salt_cli.run( ret = salt_cli.run(
"--unknown-argument", minion_tgt="minion-tgt-is-mandatory-by-salt-factories" "--unknown-argument", minion_tgt="minion-tgt-is-mandatory-by-salt-factories"
) )
assert ret.exitcode == salt.defaults.exitcodes.EX_USAGE, ret assert ret.returncode == salt.defaults.exitcodes.EX_USAGE, ret
assert "Usage" in ret.stderr assert "Usage" in ret.stderr
assert "no such option: --unknown-argument" in ret.stderr assert "no such option: --unknown-argument" in ret.stderr
@ -128,7 +128,7 @@ def test_exit_status_correct_usage(salt_cli, salt_minion):
""" """
ret = salt_cli.run("test.ping", minion_tgt=salt_minion.id) ret = salt_cli.run("test.ping", minion_tgt=salt_minion.id)
assert ret.exitcode == salt.defaults.exitcodes.EX_OK, ret assert ret.returncode == salt.defaults.exitcodes.EX_OK, ret
@pytest.mark.slow_test @pytest.mark.slow_test
@ -144,8 +144,8 @@ def test_interrupt_on_long_running_job(salt_cli, salt_master, salt_minion):
start = time.time() start = time.time()
ret = salt_cli.run("test.sleep", "1", minion_tgt=salt_minion.id) ret = salt_cli.run("test.sleep", "1", minion_tgt=salt_minion.id)
stop = time.time() stop = time.time()
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
assert stop - start > 1, "The command should have taken more than 1 second" assert stop - start > 1, "The command should have taken more than 1 second"
# Now the real test # Now the real test
@ -228,7 +228,9 @@ def test_interrupt_on_long_running_job(salt_cli, salt_master, salt_minion):
terminal_stderr.read(), __salt_system_encoding__, sys.stderr.errors terminal_stderr.read(), __salt_system_encoding__, sys.stderr.errors
) )
terminal_stderr.close() terminal_stderr.close()
ret = ProcessResult(proc.returncode, stdout, stderr, cmdline=proc.args) ret = ProcessResult(
returncode=proc.returncode, stdout=stdout, stderr=stderr, cmdline=proc.args
)
log.debug(ret) log.debug(ret)
# If the minion ID is on stdout it means that the command finished and wasn't terminated # If the minion ID is on stdout it means that the command finished and wasn't terminated
assert ( assert (

View file

@ -89,8 +89,8 @@ def test_pam_auth_valid_user(salt_minion, salt_cli, saltdev_account):
"test.ping", "test.ping",
minion_tgt=salt_minion.id, minion_tgt=salt_minion.id,
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
def test_pam_auth_invalid_user(salt_minion, salt_cli, saltdev_account): def test_pam_auth_invalid_user(salt_minion, salt_cli, saltdev_account):
@ -126,5 +126,5 @@ def test_pam_auth_valid_group(salt_minion, salt_cli, saltadm_account):
"test.ping", "test.ping",
minion_tgt=salt_minion.id, minion_tgt=salt_minion.id,
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True

View file

@ -23,14 +23,14 @@ log = logging.getLogger(__name__)
def test_fib(salt_call_cli): def test_fib(salt_call_cli):
ret = salt_call_cli.run("test.fib", "3") ret = salt_call_cli.run("test.fib", "3")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json[0] == 2 assert ret.data[0] == 2
def test_fib_txt_output(salt_call_cli): def test_fib_txt_output(salt_call_cli):
ret = salt_call_cli.run("--output=txt", "test.fib", "3") ret = salt_call_cli.run("--output=txt", "test.fib", "3")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is None assert ret.data is None
assert ( assert (
re.match(r"local: \(2, [0-9]{1}\.(([0-9]+)(e-([0-9]+))?)\)\s", ret.stdout) re.match(r"local: \(2, [0-9]{1}\.(([0-9]+)(e-([0-9]+))?)\)\s", ret.stdout)
is not None is not None
@ -40,8 +40,8 @@ def test_fib_txt_output(salt_call_cli):
@pytest.mark.parametrize("indent", [-1, 0, 1]) @pytest.mark.parametrize("indent", [-1, 0, 1])
def test_json_out_indent(salt_call_cli, indent): def test_json_out_indent(salt_call_cli, indent):
ret = salt_call_cli.run("--out=json", "--out-indent={}".format(indent), "test.ping") ret = salt_call_cli.run("--out=json", "--out-indent={}".format(indent), "test.ping")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
if indent == -1: if indent == -1:
expected_output = '{"local": true}\n' expected_output = '{"local": true}\n'
elif indent == 0: elif indent == 0:
@ -67,8 +67,8 @@ def test_local_sls_call(salt_master, salt_call_cli):
"state.sls", "state.sls",
"saltcalllocal", "saltcalllocal",
) )
assert ret.exitcode == 0 assert ret.returncode == 0
state_run_dict = next(iter(ret.json.values())) state_run_dict = next(iter(ret.data.values()))
assert state_run_dict["name"] == "test.echo" assert state_run_dict["name"] == "test.echo"
assert state_run_dict["result"] is True assert state_run_dict["result"] is True
assert state_run_dict["changes"]["ret"] == "hello" assert state_run_dict["changes"]["ret"] == "hello"
@ -84,9 +84,9 @@ def test_local_salt_call(salt_call_cli):
ret = salt_call_cli.run( ret = salt_call_cli.run(
"--local", "state.single", "file.append", name=str(filename), text="foo" "--local", "state.single", "file.append", name=str(filename), text="foo"
) )
assert ret.exitcode == 0 assert ret.returncode == 0
state_run_dict = next(iter(ret.json.values())) state_run_dict = next(iter(ret.data.values()))
assert state_run_dict["changes"] assert state_run_dict["changes"]
# 2nd sanity check: make sure that "foo" only exists once in the file # 2nd sanity check: make sure that "foo" only exists once in the file
@ -97,7 +97,7 @@ def test_local_salt_call(salt_call_cli):
@pytest.mark.skip_on_windows(reason=PRE_PYTEST_SKIP_REASON) @pytest.mark.skip_on_windows(reason=PRE_PYTEST_SKIP_REASON)
def test_user_delete_kw_output(salt_call_cli): def test_user_delete_kw_output(salt_call_cli):
ret = salt_call_cli.run("-d", "user.delete", _timeout=120) ret = salt_call_cli.run("-d", "user.delete", _timeout=120)
assert ret.exitcode == 0 assert ret.returncode == 0
expected_output = "salt '*' user.delete name" expected_output = "salt '*' user.delete name"
if not salt.utils.platform.is_windows(): if not salt.utils.platform.is_windows():
expected_output += " remove=True force=True" expected_output += " remove=True force=True"
@ -109,7 +109,7 @@ def test_salt_documentation_too_many_arguments(salt_call_cli):
Test to see if passing additional arguments shows an error Test to see if passing additional arguments shows an error
""" """
ret = salt_call_cli.run("-d", "virtualenv.create", "/tmp/ve") ret = salt_call_cli.run("-d", "virtualenv.create", "/tmp/ve")
assert ret.exitcode != 0 assert ret.returncode != 0
assert "You can only get documentation for one method at one time" in ret.stderr assert "You can only get documentation for one method at one time" in ret.stderr
@ -121,7 +121,7 @@ def test_issue_6973_state_highstate_exit_code(salt_call_cli):
""" """
expected_comment = "No states found for this minion" expected_comment = "No states found for this minion"
ret = salt_call_cli.run("--retcode-passthrough", "state.highstate") ret = salt_call_cli.run("--retcode-passthrough", "state.highstate")
assert ret.exitcode != 0 assert ret.returncode != 0
assert expected_comment in ret.stdout assert expected_comment in ret.stdout
@ -132,7 +132,7 @@ def test_issue_15074_output_file_append(salt_call_cli):
ret = salt_call_cli.run( ret = salt_call_cli.run(
"--output-file", str(output_file_append), "test.versions" "--output-file", str(output_file_append), "test.versions"
) )
assert ret.exitcode == 0 assert ret.returncode == 0
first_run_output = output_file_append.read_text() first_run_output = output_file_append.read_text()
@ -144,7 +144,7 @@ def test_issue_15074_output_file_append(salt_call_cli):
"--output-file-append", "--output-file-append",
"test.versions", "test.versions",
) )
assert ret.exitcode == 0 assert ret.returncode == 0
second_run_output = output_file_append.read_text() second_run_output = output_file_append.read_text()
@ -159,7 +159,7 @@ def test_issue_14979_output_file_permissions(salt_call_cli):
with salt.utils.files.set_umask(0o077): with salt.utils.files.set_umask(0o077):
# Let's create an initial output file with some data # Let's create an initial output file with some data
ret = salt_call_cli.run("--output-file", str(output_file), "--grains") ret = salt_call_cli.run("--output-file", str(output_file), "--grains")
assert ret.exitcode == 0 assert ret.returncode == 0
try: try:
stat1 = output_file.stat() stat1 = output_file.stat()
except OSError: except OSError:
@ -171,7 +171,7 @@ def test_issue_14979_output_file_permissions(salt_call_cli):
ret = salt_call_cli.run( ret = salt_call_cli.run(
"--output-file", str(output_file), "--output-file-append", "--grains" "--output-file", str(output_file), "--output-file-append", "--grains"
) )
assert ret.exitcode == 0 assert ret.returncode == 0
stat2 = output_file.stat() stat2 = output_file.stat()
assert stat1.st_mode == stat2.st_mode assert stat1.st_mode == stat2.st_mode
# Data was appeneded to file # Data was appeneded to file
@ -182,7 +182,7 @@ def test_issue_14979_output_file_permissions(salt_call_cli):
# Not appending data # Not appending data
ret = salt_call_cli.run("--output-file", str(output_file), "--grains") ret = salt_call_cli.run("--output-file", str(output_file), "--grains")
assert ret.exitcode == 0 assert ret.returncode == 0
try: try:
stat3 = output_file.stat() stat3 = output_file.stat()
except OSError: except OSError:
@ -198,7 +198,7 @@ def test_42116_cli_pillar_override(salt_call_cli):
"issue-42116-cli-pillar-override", "issue-42116-cli-pillar-override",
pillar={"myhost": "localhost"}, pillar={"myhost": "localhost"},
) )
state_run_dict = next(iter(ret.json.values())) state_run_dict = next(iter(ret.data.values()))
assert state_run_dict["changes"] assert state_run_dict["changes"]
assert ( assert (
state_run_dict["comment"] == 'Command "ping -c 2 localhost" run' state_run_dict["comment"] == 'Command "ping -c 2 localhost" run'
@ -234,13 +234,13 @@ def test_pillar_items_masterless(salt_minion, salt_call_cli):
with top_tempfile, basic_tempfile: with top_tempfile, basic_tempfile:
ret = salt_call_cli.run("--local", "pillar.items") ret = salt_call_cli.run("--local", "pillar.items")
assert ret.exitcode == 0 assert ret.returncode == 0
assert "knights" in ret.json assert "knights" in ret.data
assert sorted(ret.json["knights"]) == sorted( assert sorted(ret.data["knights"]) == sorted(
["Lancelot", "Galahad", "Bedevere", "Robin"] ["Lancelot", "Galahad", "Bedevere", "Robin"]
) )
assert "monty" in ret.json assert "monty" in ret.data
assert ret.json["monty"] == "python" assert ret.data["monty"] == "python"
def test_masterless_highstate(salt_minion, salt_call_cli, tmp_path): def test_masterless_highstate(salt_minion, salt_call_cli, tmp_path):
@ -270,8 +270,8 @@ def test_masterless_highstate(salt_minion, salt_call_cli, tmp_path):
"top.sls", top_sls "top.sls", top_sls
), salt_minion.state_tree.base.temp_file("core.sls", core_state): ), salt_minion.state_tree.base.temp_file("core.sls", core_state):
ret = salt_call_cli.run("--local", "state.highstate") ret = salt_call_cli.run("--local", "state.highstate")
assert ret.exitcode == 0 assert ret.returncode == 0
state_run_dict = next(iter(ret.json.values())) state_run_dict = next(iter(ret.data.values()))
assert state_run_dict["result"] is True assert state_run_dict["result"] is True
assert state_run_dict["__id__"] == expected_id assert state_run_dict["__id__"] == expected_id
@ -295,14 +295,14 @@ def test_syslog_file_not_found(salt_minion, salt_call_cli, tmp_path):
"echo foo", "echo foo",
) )
if sys.version_info >= (3, 5, 4): if sys.version_info >= (3, 5, 4):
assert ret.exitcode == 0 assert ret.returncode == 0
assert ( assert (
"[WARNING ] The log_file does not exist. Logging not setup correctly or" "[WARNING ] The log_file does not exist. Logging not setup correctly or"
" syslog service not started." in ret.stderr " syslog service not started." in ret.stderr
) )
assert ret.json == "foo", ret assert ret.data == "foo", ret
else: else:
assert ret.exitcode == salt.defaults.exitcodes.EX_UNAVAILABLE assert ret.returncode == salt.defaults.exitcodes.EX_UNAVAILABLE
assert "Failed to setup the Syslog logging handler" in ret.stderr assert "Failed to setup the Syslog logging handler" in ret.stderr
@ -311,21 +311,21 @@ def test_syslog_file_not_found(salt_minion, salt_call_cli, tmp_path):
def test_return(salt_call_cli, salt_run_cli): def test_return(salt_call_cli, salt_run_cli):
command = "echo returnTOmaster" command = "echo returnTOmaster"
ret = salt_call_cli.run("cmd.run", command) ret = salt_call_cli.run("cmd.run", command)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json == "returnTOmaster" assert ret.data == "returnTOmaster"
ret = salt_run_cli.run("jobs.list_jobs") ret = salt_run_cli.run("jobs.list_jobs")
assert ret.exitcode == 0 assert ret.returncode == 0
jid = target = None jid = target = None
for jid, details in ret.json.items(): for jid, details in ret.data.items():
if command in details["Arguments"]: if command in details["Arguments"]:
target = details["Target"] target = details["Target"]
break break
ret = salt_run_cli.run("jobs.lookup_jid", jid, _timeout=60) ret = salt_run_cli.run("jobs.lookup_jid", jid, _timeout=60)
assert ret.exitcode == 0 assert ret.returncode == 0
assert target in ret.json assert target in ret.data
assert ret.json[target] == "returnTOmaster" assert ret.data[target] == "returnTOmaster"
def test_exit_status_unknown_argument(salt_call_cli): def test_exit_status_unknown_argument(salt_call_cli):
@ -333,7 +333,7 @@ def test_exit_status_unknown_argument(salt_call_cli):
Ensure correct exit status when an unknown argument is passed to salt CLI. Ensure correct exit status when an unknown argument is passed to salt CLI.
""" """
ret = salt_call_cli.run("--unknown-argument") ret = salt_call_cli.run("--unknown-argument")
assert ret.exitcode == salt.defaults.exitcodes.EX_USAGE, ret assert ret.returncode == salt.defaults.exitcodes.EX_USAGE, ret
assert "Usage" in ret.stderr assert "Usage" in ret.stderr
assert "no such option: --unknown-argument" in ret.stderr assert "no such option: --unknown-argument" in ret.stderr
@ -344,7 +344,7 @@ def test_exit_status_correct_usage(salt_call_cli):
""" """
ret = salt_call_cli.run("test.true") ret = salt_call_cli.run("test.true")
assert ret.exitcode == salt.defaults.exitcodes.EX_OK, ret assert ret.returncode == salt.defaults.exitcodes.EX_OK, ret
def test_context_retcode_salt_call(salt_call_cli): def test_context_retcode_salt_call(salt_call_cli):
@ -355,27 +355,27 @@ def test_context_retcode_salt_call(salt_call_cli):
# Test salt-call, making sure to also confirm the behavior of # Test salt-call, making sure to also confirm the behavior of
# retcode_passthrough. # retcode_passthrough.
ret = salt_call_cli.run("test.retcode", "0") ret = salt_call_cli.run("test.retcode", "0")
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
ret = salt_call_cli.run("test.retcode", "42") ret = salt_call_cli.run("test.retcode", "42")
assert ret.exitcode == salt.defaults.exitcodes.EX_GENERIC, ret assert ret.returncode == salt.defaults.exitcodes.EX_GENERIC, ret
ret = salt_call_cli.run("--retcode-passthrough", "test.retcode", "42") ret = salt_call_cli.run("--retcode-passthrough", "test.retcode", "42")
assert ret.exitcode == 42, ret assert ret.returncode == 42, ret
# Test a state run that exits with one or more failures # Test a state run that exits with one or more failures
ret = salt_call_cli.run("state.single", "test.fail_without_changes", "foo") ret = salt_call_cli.run("state.single", "test.fail_without_changes", "foo")
assert ret.exitcode == salt.defaults.exitcodes.EX_GENERIC, ret assert ret.returncode == salt.defaults.exitcodes.EX_GENERIC, ret
ret = salt_call_cli.run( ret = salt_call_cli.run(
"--retcode-passthrough", "state.single", "test.fail_without_changes", "foo" "--retcode-passthrough", "state.single", "test.fail_without_changes", "foo"
) )
assert ret.exitcode == salt.defaults.exitcodes.EX_STATE_FAILURE, ret assert ret.returncode == salt.defaults.exitcodes.EX_STATE_FAILURE, ret
# Test a state compiler error # Test a state compiler error
ret = salt_call_cli.run("state.apply", "thisslsfiledoesnotexist") ret = salt_call_cli.run("state.apply", "thisslsfiledoesnotexist")
assert ret.exitcode == salt.defaults.exitcodes.EX_GENERIC, ret assert ret.returncode == salt.defaults.exitcodes.EX_GENERIC, ret
ret = salt_call_cli.run( ret = salt_call_cli.run(
"--retcode-passthrough", "state.apply", "thisslsfiledoesnotexist" "--retcode-passthrough", "state.apply", "thisslsfiledoesnotexist"
) )
assert ret.exitcode == salt.defaults.exitcodes.EX_STATE_COMPILER_ERROR, ret assert ret.returncode == salt.defaults.exitcodes.EX_STATE_COMPILER_ERROR, ret
def test_salt_call_error(salt_call_cli): def test_salt_call_error(salt_call_cli):
@ -384,22 +384,22 @@ def test_salt_call_error(salt_call_cli):
an exception. an exception.
""" """
ret = salt_call_cli.run("test.raise_exception", "TypeError") ret = salt_call_cli.run("test.raise_exception", "TypeError")
assert ret.exitcode == salt.defaults.exitcodes.EX_GENERIC, ret assert ret.returncode == salt.defaults.exitcodes.EX_GENERIC, ret
ret = salt_call_cli.run( ret = salt_call_cli.run(
"test.raise_exception", "salt.exceptions.CommandNotFoundError" "test.raise_exception", "salt.exceptions.CommandNotFoundError"
) )
assert ret.exitcode == salt.defaults.exitcodes.EX_GENERIC, ret assert ret.returncode == salt.defaults.exitcodes.EX_GENERIC, ret
ret = salt_call_cli.run( ret = salt_call_cli.run(
"test.raise_exception", "salt.exceptions.CommandExecutionError" "test.raise_exception", "salt.exceptions.CommandExecutionError"
) )
assert ret.exitcode == salt.defaults.exitcodes.EX_GENERIC, ret assert ret.returncode == salt.defaults.exitcodes.EX_GENERIC, ret
ret = salt_call_cli.run( ret = salt_call_cli.run(
"test.raise_exception", "salt.exceptions.SaltInvocationError" "test.raise_exception", "salt.exceptions.SaltInvocationError"
) )
assert ret.exitcode == salt.defaults.exitcodes.EX_GENERIC, ret assert ret.returncode == salt.defaults.exitcodes.EX_GENERIC, ret
ret = salt_call_cli.run( ret = salt_call_cli.run(
"test.raise_exception", "test.raise_exception",
@ -408,10 +408,10 @@ def test_salt_call_error(salt_call_cli):
"No such file or directory", "No such file or directory",
"/tmp/foo.txt", "/tmp/foo.txt",
) )
assert ret.exitcode == salt.defaults.exitcodes.EX_GENERIC, ret assert ret.returncode == salt.defaults.exitcodes.EX_GENERIC, ret
ret = salt_call_cli.run("test.echo", "{foo: bar, result: False}") ret = salt_call_cli.run("test.echo", "{foo: bar, result: False}")
assert ret.exitcode == salt.defaults.exitcodes.EX_GENERIC, ret assert ret.returncode == salt.defaults.exitcodes.EX_GENERIC, ret
def test_local_salt_call_no_function_no_retcode(salt_call_cli): def test_local_salt_call_no_function_no_retcode(salt_call_cli):
@ -425,9 +425,9 @@ def test_local_salt_call_no_function_no_retcode(salt_call_cli):
with pytest.helpers.temp_file() as filename: with pytest.helpers.temp_file() as filename:
ret = salt_call_cli.run("--local", "test") ret = salt_call_cli.run("--local", "test")
assert ret.exitcode == 1 assert ret.returncode == 1
state_run_dict = ret.json state_run_dict = ret.data
assert "test" in state_run_dict assert "test" in state_run_dict
assert state_run_dict["test"] == "'test' is not available." assert state_run_dict["test"] == "'test' is not available."

View file

@ -38,8 +38,8 @@ def test_cp_testfile(salt_minion, salt_cp_cli, source_testfile, dest_testfile):
test salt-cp test salt-cp
""" """
ret = salt_cp_cli.run(source_testfile, dest_testfile, minion_tgt=salt_minion.id) ret = salt_cp_cli.run(source_testfile, dest_testfile, minion_tgt=salt_minion.id)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json[dest_testfile] is True assert ret.data[dest_testfile] is True
assert os.path.exists(dest_testfile) assert os.path.exists(dest_testfile)
with salt.utils.files.fopen(source_testfile) as rfh: with salt.utils.files.fopen(source_testfile) as rfh:
source_testfile_contents = rfh.read() source_testfile_contents = rfh.read()

View file

@ -7,8 +7,7 @@ import os
import pytest import pytest
import salt.defaults.exitcodes import salt.defaults.exitcodes
import salt.utils.platform from pytestshellutils.exceptions import FactoryNotStarted
from saltfactories.exceptions import FactoryNotStarted
from saltfactories.utils import random_string from saltfactories.utils import random_string
from tests.support.helpers import PRE_PYTEST_SKIP_REASON from tests.support.helpers import PRE_PYTEST_SKIP_REASON
@ -16,8 +15,7 @@ log = logging.getLogger(__name__)
pytestmark = [ pytestmark = [
pytest.mark.skipif( pytest.mark.skip_on_spawning_platform(
salt.utils.platform.spawning_platform(),
reason="Deltaproxy minions do not currently work on spawning platforms.", reason="Deltaproxy minions do not currently work on spawning platforms.",
) )
] ]
@ -66,9 +64,9 @@ def test_exit_status_no_proxyid(salt_master, proxy_minion_id):
) )
factory.start(start_timeout=10, max_start_attempts=1) factory.start(start_timeout=10, max_start_attempts=1)
assert exc.value.exitcode == salt.defaults.exitcodes.EX_USAGE, exc.value assert exc.value.process_result.returncode == salt.defaults.exitcodes.EX_USAGE
assert "Usage" in exc.value.stderr, exc.value assert "Usage" in exc.value.process_result.stderr, exc.value
assert "error: salt-proxy requires --proxyid" in exc.value.stderr, exc.value assert "error: salt-proxy requires --proxyid" in exc.value.process_result.stderr
@pytest.mark.skip_on_windows(reason="Windows does not do user checks") @pytest.mark.skip_on_windows(reason="Windows does not do user checks")
@ -89,8 +87,8 @@ def test_exit_status_unknown_user(salt_master, proxy_minion_id):
) )
factory.start(start_timeout=10, max_start_attempts=1) factory.start(start_timeout=10, max_start_attempts=1)
assert exc.value.exitcode == salt.defaults.exitcodes.EX_NOUSER, exc.value assert exc.value.process_result.returncode == salt.defaults.exitcodes.EX_NOUSER
assert "The user is not available." in exc.value.stderr, exc.value assert "The user is not available." in exc.value.process_result.stderr
@pytest.mark.slow_test @pytest.mark.slow_test
@ -109,9 +107,9 @@ def test_exit_status_unknown_argument(salt_master, proxy_minion_id):
) )
factory.start("--unknown-argument", start_timeout=10, max_start_attempts=1) factory.start("--unknown-argument", start_timeout=10, max_start_attempts=1)
assert exc.value.exitcode == salt.defaults.exitcodes.EX_USAGE, exc.value assert exc.value.process_result.returncode == salt.defaults.exitcodes.EX_USAGE
assert "Usage" in exc.value.stderr, exc.value assert "Usage" in exc.value.process_result.stderr
assert "no such option: --unknown-argument" in exc.value.stderr, exc.value assert "no such option: --unknown-argument" in exc.value.process_result.stderr
# Hangs on Windows. You can add a timeout to the proxy.run command, but then # Hangs on Windows. You can add a timeout to the proxy.run command, but then
@ -207,22 +205,22 @@ def test_exit_status_correct_usage(
# Let's issue a ping the control proxy # Let's issue a ping the control proxy
ret = salt_cli.run("test.ping", minion_tgt=proxy_minion_id) ret = salt_cli.run("test.ping", minion_tgt=proxy_minion_id)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
# Let's issue a ping to one of the controlled proxies # Let's issue a ping to one of the controlled proxies
ret = salt_cli.run("test.ping", minion_tgt=proxy_one) ret = salt_cli.run("test.ping", minion_tgt=proxy_one)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
# Let's issue a ping to one of the controlled proxies # Let's issue a ping to one of the controlled proxies
ret = salt_cli.run("test.ping", minion_tgt=proxy_two) ret = salt_cli.run("test.ping", minion_tgt=proxy_two)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
# Terminate the proxy minion # Terminate the proxy minion
ret = factory.terminate() ret = factory.terminate()
assert ret.exitcode == salt.defaults.exitcodes.EX_OK, ret assert ret.returncode == salt.defaults.exitcodes.EX_OK, ret
# Hangs on Windows. You can add a timeout to the proxy.run command, but then # Hangs on Windows. You can add a timeout to the proxy.run command, but then
@ -303,17 +301,17 @@ def test_missing_pillar_file(
# Let's issue a ping the control proxy # Let's issue a ping the control proxy
ret = salt_cli.run("test.ping", minion_tgt=proxy_minion_id) ret = salt_cli.run("test.ping", minion_tgt=proxy_minion_id)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
# Let's issue a ping to one of the controlled proxies # Let's issue a ping to one of the controlled proxies
ret = salt_cli.run("test.ping", minion_tgt="dummy_proxy_one") ret = salt_cli.run("test.ping", minion_tgt="dummy_proxy_one")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
# Terminate the proxy minion # Terminate the proxy minion
ret = factory.terminate() ret = factory.terminate()
assert ret.exitcode == salt.defaults.exitcodes.EX_OK, ret assert ret.returncode == salt.defaults.exitcodes.EX_OK, ret
# Hangs on Windows. You can add a timeout to the proxy.run command, but then # Hangs on Windows. You can add a timeout to the proxy.run command, but then
@ -423,12 +421,12 @@ def test_invalid_connection(
with factory.started(): with factory.started():
# Let's issue a ping the control proxy # Let's issue a ping the control proxy
ret = salt_cli.run("test.ping", minion_tgt=proxy_minion_id) ret = salt_cli.run("test.ping", minion_tgt=proxy_minion_id)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
# Let's issue a ping to one of the controlled proxies # Let's issue a ping to one of the controlled proxies
ret = salt_cli.run("test.ping", minion_tgt=proxy_one) ret = salt_cli.run("test.ping", minion_tgt=proxy_one)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
assert not factory.is_running() assert not factory.is_running()
assert ret.exitcode == salt.defaults.exitcodes.EX_OK, ret assert ret.returncode == salt.defaults.exitcodes.EX_OK, ret

View file

@ -63,13 +63,13 @@ def test_remove_key(salt_master, salt_key_cli):
try: try:
# Check Key # Check Key
ret = salt_key_cli.run("-p", min_name) ret = salt_key_cli.run("-p", min_name)
assert ret.exitcode == 0 assert ret.returncode == 0
assert "minions" in ret.json assert "minions" in ret.data
assert min_name in ret.json["minions"] assert min_name in ret.data["minions"]
assert "-----BEGIN PUBLIC KEY-----" in ret.json["minions"][min_name] assert "-----BEGIN PUBLIC KEY-----" in ret.data["minions"][min_name]
# Remove Key # Remove Key
ret = salt_key_cli.run("-d", min_name, "-y") ret = salt_key_cli.run("-d", min_name, "-y")
assert ret.exitcode == 0 assert ret.returncode == 0
# We can't load JSON because we print to stdout! # We can't load JSON because we print to stdout!
# >>>>> STDOUT >>>>> # >>>>> STDOUT >>>>>
# The following keys are going to be deleted: # The following keys are going to be deleted:
@ -84,8 +84,8 @@ def test_remove_key(salt_master, salt_key_cli):
assert min_name in ret.stdout assert min_name in ret.stdout
# Check Key # Check Key
ret = salt_key_cli.run("-p", min_name) ret = salt_key_cli.run("-p", min_name)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json == {} assert ret.data == {}
finally: finally:
if os.path.exists(key): if os.path.exists(key):
os.unlink(key) os.unlink(key)
@ -108,10 +108,10 @@ def test_remove_key_eauth(salt_key_cli, salt_master, saltdev_account):
try: try:
# Check Key # Check Key
ret = salt_key_cli.run("-p", min_name) ret = salt_key_cli.run("-p", min_name)
assert ret.exitcode == 0 assert ret.returncode == 0
assert "minions" in ret.json assert "minions" in ret.data
assert min_name in ret.json["minions"] assert min_name in ret.data["minions"]
assert "-----BEGIN PUBLIC KEY-----" in ret.json["minions"][min_name] assert "-----BEGIN PUBLIC KEY-----" in ret.data["minions"][min_name]
# Remove Key # Remove Key
ret = salt_key_cli.run( ret = salt_key_cli.run(
"-d", "-d",
@ -124,7 +124,7 @@ def test_remove_key_eauth(salt_key_cli, salt_master, saltdev_account):
"--password", "--password",
USERA_PWD, USERA_PWD,
) )
assert ret.exitcode == 0 assert ret.returncode == 0
# We can't load JSON because we print to stdout! # We can't load JSON because we print to stdout!
# >>>>> STDOUT >>>>> # >>>>> STDOUT >>>>>
# The following keys are going to be deleted: # The following keys are going to be deleted:
@ -139,8 +139,8 @@ def test_remove_key_eauth(salt_key_cli, salt_master, saltdev_account):
assert min_name in ret.stdout assert min_name in ret.stdout
# Check Key # Check Key
ret = salt_key_cli.run("-p", min_name) ret = salt_key_cli.run("-p", min_name)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json == {} assert ret.data == {}
finally: finally:
if os.path.exists(key): if os.path.exists(key):
os.unlink(key) os.unlink(key)
@ -153,11 +153,11 @@ def test_list_accepted_args(salt_key_cli, key_type):
""" """
# Should not trigger any error # Should not trigger any error
ret = salt_key_cli.run("-l", key_type) ret = salt_key_cli.run("-l", key_type)
assert ret.exitcode == 0 assert ret.returncode == 0
assert "error:" not in ret.stdout assert "error:" not in ret.stdout
# Should throw an error now # Should throw an error now
ret = salt_key_cli.run("-l", "foo-{}".format(key_type)) ret = salt_key_cli.run("-l", "foo-{}".format(key_type))
assert ret.exitcode != 0 assert ret.returncode != 0
assert "error:" in ret.stderr assert "error:" in ret.stderr
@ -166,14 +166,14 @@ def test_list_all(salt_key_cli, salt_minion, salt_sub_minion):
test salt-key -L test salt-key -L
""" """
ret = salt_key_cli.run("-L") ret = salt_key_cli.run("-L")
assert ret.exitcode == 0 assert ret.returncode == 0
expected = { expected = {
"minions_rejected": [], "minions_rejected": [],
"minions_denied": [], "minions_denied": [],
"minions_pre": [], "minions_pre": [],
"minions": [salt_minion.id, salt_sub_minion.id], "minions": [salt_minion.id, salt_sub_minion.id],
} }
assert ret.json == expected assert ret.data == expected
def test_list_all_yaml_out(salt_key_cli, salt_minion, salt_sub_minion): def test_list_all_yaml_out(salt_key_cli, salt_minion, salt_sub_minion):
@ -181,8 +181,8 @@ def test_list_all_yaml_out(salt_key_cli, salt_minion, salt_sub_minion):
test salt-key -L --out=yaml test salt-key -L --out=yaml
""" """
ret = salt_key_cli.run("-L", "--out=yaml") ret = salt_key_cli.run("-L", "--out=yaml")
assert ret.exitcode == 0 assert ret.returncode == 0
output = salt.utils.yaml.safe_load(ret.stdout) output = salt.utils.yaml.safe_load(str(ret.stdout))
expected = { expected = {
"minions_rejected": [], "minions_rejected": [],
"minions_denied": [], "minions_denied": [],
@ -197,7 +197,7 @@ def test_list_all_raw_out(salt_key_cli, salt_minion, salt_sub_minion):
test salt-key -L --out=raw test salt-key -L --out=raw
""" """
ret = salt_key_cli.run("-L", "--out=raw") ret = salt_key_cli.run("-L", "--out=raw")
assert ret.exitcode == 0 assert ret.returncode == 0
output = ast.literal_eval(ret.stdout) output = ast.literal_eval(ret.stdout)
expected = { expected = {
"minions_rejected": [], "minions_rejected": [],
@ -213,9 +213,9 @@ def test_list_acc(salt_key_cli, salt_minion, salt_sub_minion):
test salt-key -l acc test salt-key -l acc
""" """
ret = salt_key_cli.run("-l", "acc") ret = salt_key_cli.run("-l", "acc")
assert ret.exitcode == 0 assert ret.returncode == 0
expected = {"minions": [salt_minion.id, salt_sub_minion.id]} expected = {"minions": [salt_minion.id, salt_sub_minion.id]}
assert ret.json == expected assert ret.data == expected
@pytest.mark.skip_if_not_root @pytest.mark.skip_if_not_root
@ -228,9 +228,9 @@ def test_list_acc_eauth(salt_key_cli, saltdev_account, salt_minion, salt_sub_min
ret = salt_key_cli.run( ret = salt_key_cli.run(
"-l", "acc", "--eauth", "pam", "--username", USERA, "--password", USERA_PWD "-l", "acc", "--eauth", "pam", "--username", USERA, "--password", USERA_PWD
) )
assert ret.exitcode == 0 assert ret.returncode == 0
expected = {"minions": [salt_minion.id, salt_sub_minion.id]} expected = {"minions": [salt_minion.id, salt_sub_minion.id]}
assert ret.json == expected assert ret.data == expected
@pytest.mark.skip_if_not_root @pytest.mark.skip_if_not_root
@ -270,7 +270,7 @@ def test_list_acc_wrong_eauth(salt_key_cli):
"--password", "--password",
USERA_PWD, USERA_PWD,
) )
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
assert re.search( assert re.search(
r"^The specified external authentication system \"wrongeauth\" is not" r"^The specified external authentication system \"wrongeauth\" is not"
r" available\nAvailable eauth types: auto, .*", r" available\nAvailable eauth types: auto, .*",
@ -283,14 +283,14 @@ def test_list_un(salt_key_cli):
test salt-key -l un test salt-key -l un
""" """
ret = salt_key_cli.run("-l", "un") ret = salt_key_cli.run("-l", "un")
assert ret.exitcode == 0 assert ret.returncode == 0
expected = {"minions_pre": []} expected = {"minions_pre": []}
assert ret.json == expected assert ret.data == expected
def test_keys_generation(salt_key_cli, tmp_path): def test_keys_generation(salt_key_cli, tmp_path):
ret = salt_key_cli.run("--gen-keys", "minibar", "--gen-keys-dir", str(tmp_path)) ret = salt_key_cli.run("--gen-keys", "minibar", "--gen-keys-dir", str(tmp_path))
assert ret.exitcode == 0 assert ret.returncode == 0
try: try:
key_names = ("minibar.pub", "minibar.pem") key_names = ("minibar.pub", "minibar.pem")
for fname in key_names: for fname in key_names:
@ -305,7 +305,7 @@ def test_keys_generation_keysize_min(salt_key_cli, tmp_path):
ret = salt_key_cli.run( ret = salt_key_cli.run(
"--gen-keys", "minibar", "--gen-keys-dir", str(tmp_path), "--keysize", "1024" "--gen-keys", "minibar", "--gen-keys-dir", str(tmp_path), "--keysize", "1024"
) )
assert ret.exitcode != 0 assert ret.returncode != 0
assert "error: The minimum value for keysize is 2048" in ret.stderr assert "error: The minimum value for keysize is 2048" in ret.stderr
@ -313,7 +313,7 @@ def test_keys_generation_keysize_max(salt_key_cli, tmp_path):
ret = salt_key_cli.run( ret = salt_key_cli.run(
"--gen-keys", "minibar", "--gen-keys-dir", str(tmp_path), "--keysize", "32769" "--gen-keys", "minibar", "--gen-keys-dir", str(tmp_path), "--keysize", "32769"
) )
assert ret.exitcode != 0 assert ret.returncode != 0
assert "error: The maximum value for keysize is 32768" in ret.stderr assert "error: The maximum value for keysize is 32768" in ret.stderr
@ -331,7 +331,7 @@ def test_accept_bad_key(salt_master, salt_key_cli):
try: try:
# Check Key # Check Key
ret = salt_key_cli.run("-y", "-a", min_name) ret = salt_key_cli.run("-y", "-a", min_name)
assert ret.exitcode == 0 assert ret.returncode == 0
assert "invalid key for {}".format(min_name) in ret.stderr assert "invalid key for {}".format(min_name) in ret.stderr
finally: finally:
if os.path.exists(key): if os.path.exists(key):

View file

@ -26,4 +26,4 @@ def test_exit_status_correct_usage(salt_factories, master_id):
assert factory.is_running() assert factory.is_running()
time.sleep(0.5) time.sleep(0.5)
ret = factory.terminate() ret = factory.terminate()
assert ret.exitcode == salt.defaults.exitcodes.EX_OK, ret assert ret.returncode == salt.defaults.exitcodes.EX_OK, ret

View file

@ -3,7 +3,7 @@ import os
import pytest import pytest
import salt.defaults.exitcodes import salt.defaults.exitcodes
from saltfactories.exceptions import FactoryNotStarted from pytestshellutils.exceptions import FactoryNotStarted
from saltfactories.utils import random_string from saltfactories.utils import random_string
from tests.support.helpers import PRE_PYTEST_SKIP_REASON from tests.support.helpers import PRE_PYTEST_SKIP_REASON
@ -42,8 +42,8 @@ def test_exit_status_unknown_user(salt_master, minion_id):
) )
factory.start(start_timeout=10, max_start_attempts=1) factory.start(start_timeout=10, max_start_attempts=1)
assert exc.value.exitcode == salt.defaults.exitcodes.EX_NOUSER, exc.value assert exc.value.process_result.returncode == salt.defaults.exitcodes.EX_NOUSER
assert "The user is not available." in exc.value.stderr, exc.value assert "The user is not available." in exc.value.process_result.stderr
def test_exit_status_unknown_argument(salt_master, minion_id): def test_exit_status_unknown_argument(salt_master, minion_id):
@ -54,9 +54,9 @@ def test_exit_status_unknown_argument(salt_master, minion_id):
factory = salt_master.salt_minion_daemon(minion_id) factory = salt_master.salt_minion_daemon(minion_id)
factory.start("--unknown-argument", start_timeout=10, max_start_attempts=1) factory.start("--unknown-argument", start_timeout=10, max_start_attempts=1)
assert exc.value.exitcode == salt.defaults.exitcodes.EX_USAGE, exc.value assert exc.value.process_result.returncode == salt.defaults.exitcodes.EX_USAGE
assert "Usage" in exc.value.stderr, exc.value assert "Usage" in exc.value.process_result.stderr
assert "no such option: --unknown-argument" in exc.value.stderr, exc.value assert "no such option: --unknown-argument" in exc.value.process_result.stderr
@pytest.mark.skip_on_windows(reason=PRE_PYTEST_SKIP_REASON) @pytest.mark.skip_on_windows(reason=PRE_PYTEST_SKIP_REASON)
@ -70,8 +70,8 @@ def test_exit_status_correct_usage(salt_master, minion_id, salt_cli):
assert factory.is_running() assert factory.is_running()
# Let's issue a ping before terminating # Let's issue a ping before terminating
ret = salt_cli.run("test.ping", minion_tgt=minion_id) ret = salt_cli.run("test.ping", minion_tgt=minion_id)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
# Terminate # Terminate
ret = factory.terminate() ret = factory.terminate()
assert ret.exitcode == salt.defaults.exitcodes.EX_OK, ret assert ret.returncode == salt.defaults.exitcodes.EX_OK, ret

View file

@ -6,7 +6,7 @@ import logging
import pytest import pytest
import salt.defaults.exitcodes import salt.defaults.exitcodes
from saltfactories.exceptions import FactoryNotStarted from pytestshellutils.exceptions import FactoryNotStarted
from saltfactories.utils import random_string from saltfactories.utils import random_string
from tests.support.helpers import PRE_PYTEST_SKIP_REASON from tests.support.helpers import PRE_PYTEST_SKIP_REASON
@ -35,9 +35,9 @@ def test_exit_status_no_proxyid(salt_master, proxy_minion_id):
) )
factory.start(start_timeout=10, max_start_attempts=1) factory.start(start_timeout=10, max_start_attempts=1)
assert exc.value.exitcode == salt.defaults.exitcodes.EX_USAGE, exc.value assert exc.value.process_result.returncode == salt.defaults.exitcodes.EX_USAGE
assert "Usage" in exc.value.stderr, exc.value assert "Usage" in exc.value.process_result.stderr
assert "error: salt-proxy requires --proxyid" in exc.value.stderr, exc.value assert "error: salt-proxy requires --proxyid" in exc.value.process_result.stderr
@pytest.mark.skip_on_windows(reason="Windows does not do user checks") @pytest.mark.skip_on_windows(reason="Windows does not do user checks")
@ -52,8 +52,8 @@ def test_exit_status_unknown_user(salt_master, proxy_minion_id):
) )
factory.start(start_timeout=10, max_start_attempts=1) factory.start(start_timeout=10, max_start_attempts=1)
assert exc.value.exitcode == salt.defaults.exitcodes.EX_NOUSER, exc.value assert exc.value.process_result.returncode == salt.defaults.exitcodes.EX_NOUSER
assert "The user is not available." in exc.value.stderr, exc.value assert "The user is not available." in exc.value.process_result.stderr
@pytest.mark.slow_test @pytest.mark.slow_test
@ -66,9 +66,9 @@ def test_exit_status_unknown_argument(salt_master, proxy_minion_id):
factory = salt_master.salt_proxy_minion_daemon(proxy_minion_id) factory = salt_master.salt_proxy_minion_daemon(proxy_minion_id)
factory.start("--unknown-argument", start_timeout=10, max_start_attempts=1) factory.start("--unknown-argument", start_timeout=10, max_start_attempts=1)
assert exc.value.exitcode == salt.defaults.exitcodes.EX_USAGE, exc.value assert exc.value.process_result.returncode == salt.defaults.exitcodes.EX_USAGE
assert "Usage" in exc.value.stderr, exc.value assert "Usage" in exc.value.process_result.stderr
assert "no such option: --unknown-argument" in exc.value.stderr, exc.value assert "no such option: --unknown-argument" in exc.value.process_result.stderr
# Hangs on Windows. You can add a timeout to the proxy.run command, but then # Hangs on Windows. You can add a timeout to the proxy.run command, but then
@ -89,8 +89,8 @@ def test_exit_status_correct_usage(salt_master, proxy_minion_id, salt_cli):
assert factory.is_running() assert factory.is_running()
# Let's issue a ping before terminating # Let's issue a ping before terminating
ret = salt_cli.run("test.ping", minion_tgt=proxy_minion_id) ret = salt_cli.run("test.ping", minion_tgt=proxy_minion_id)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
# Terminate the proxy minion # Terminate the proxy minion
ret = factory.terminate() ret = factory.terminate()
assert ret.exitcode == salt.defaults.exitcodes.EX_OK, ret assert ret.returncode == salt.defaults.exitcodes.EX_OK, ret

View file

@ -57,7 +57,7 @@ def test_salt_documentation_too_many_arguments(salt_run_cli):
Test to see if passing additional arguments shows an error Test to see if passing additional arguments shows an error
""" """
ret = salt_run_cli.run("-d", "virt.list", "foo") ret = salt_run_cli.run("-d", "virt.list", "foo")
assert ret.exitcode != 0 assert ret.returncode != 0
assert "You can only get documentation for one method at one time" in ret.stderr assert "You can only get documentation for one method at one time" in ret.stderr
@ -66,7 +66,7 @@ def test_exit_status_unknown_argument(salt_run_cli):
Ensure correct exit status when an unknown argument is passed to salt-run. Ensure correct exit status when an unknown argument is passed to salt-run.
""" """
ret = salt_run_cli.run("--unknown-argument") ret = salt_run_cli.run("--unknown-argument")
assert ret.exitcode == salt.defaults.exitcodes.EX_USAGE, ret assert ret.returncode == salt.defaults.exitcodes.EX_USAGE, ret
assert "Usage" in ret.stderr assert "Usage" in ret.stderr
assert "no such option: --unknown-argument" in ret.stderr assert "no such option: --unknown-argument" in ret.stderr
@ -76,7 +76,7 @@ def test_exit_status_correct_usage(salt_run_cli):
Ensure correct exit status when salt-run starts correctly. Ensure correct exit status when salt-run starts correctly.
""" """
ret = salt_run_cli.run("test.arg", "arg1", kwarg1="kwarg1") ret = salt_run_cli.run("test.arg", "arg1", kwarg1="kwarg1")
assert ret.exitcode == salt.defaults.exitcodes.EX_OK, ret assert ret.returncode == salt.defaults.exitcodes.EX_OK, ret
@pytest.mark.skip_if_not_root @pytest.mark.skip_if_not_root
@ -99,10 +99,10 @@ def test_salt_run_with_eauth_all_args(salt_run_cli, saltdev_account, flag):
kwarg="kwarg1", kwarg="kwarg1",
_timeout=240, _timeout=240,
) )
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
assert ret.json, ret assert ret.data, ret
expected = {"args": ["arg"], "kwargs": {"kwarg": "kwarg1"}} expected = {"args": ["arg"], "kwargs": {"kwarg": "kwarg1"}}
assert ret.json == expected, ret assert ret.data == expected, ret
@pytest.mark.skip_if_not_root @pytest.mark.skip_if_not_root
@ -145,7 +145,7 @@ def test_salt_run_with_wrong_eauth(salt_run_cli, saltdev_account):
"arg", "arg",
kwarg="kwarg1", kwarg="kwarg1",
) )
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
assert re.search( assert re.search(
r"^The specified external authentication system \"wrongeauth\" is not" r"^The specified external authentication system \"wrongeauth\" is not"
r" available\nAvailable eauth types: auto, .*", r" available\nAvailable eauth types: auto, .*",

View file

@ -4,7 +4,7 @@ import time
import pytest import pytest
import salt.defaults.exitcodes import salt.defaults.exitcodes
from saltfactories.exceptions import FactoryNotStarted from pytestshellutils.exceptions import FactoryNotStarted
from saltfactories.utils import random_string from saltfactories.utils import random_string
from tests.support.helpers import PRE_PYTEST_SKIP, PRE_PYTEST_SKIP_REASON from tests.support.helpers import PRE_PYTEST_SKIP, PRE_PYTEST_SKIP_REASON
@ -45,8 +45,8 @@ def test_exit_status_unknown_user(salt_master, syndic_id):
factory.before_start_callbacks.clear() factory.before_start_callbacks.clear()
factory.start(start_timeout=10, max_start_attempts=1) factory.start(start_timeout=10, max_start_attempts=1)
assert exc.value.exitcode == salt.defaults.exitcodes.EX_NOUSER, exc.value assert exc.value.process_result.returncode == salt.defaults.exitcodes.EX_NOUSER
assert "The user is not available." in exc.value.stderr, exc.value assert "The user is not available." in exc.value.process_result.stderr
@PRE_PYTEST_SKIP @PRE_PYTEST_SKIP
@ -59,9 +59,9 @@ def test_exit_status_unknown_argument(salt_master, syndic_id):
factory.before_start_callbacks.clear() factory.before_start_callbacks.clear()
factory.start("--unknown-argument", start_timeout=10, max_start_attempts=1) factory.start("--unknown-argument", start_timeout=10, max_start_attempts=1)
assert exc.value.exitcode == salt.defaults.exitcodes.EX_USAGE, exc.value assert exc.value.process_result.returncode == salt.defaults.exitcodes.EX_USAGE
assert "Usage" in exc.value.stderr, exc.value assert "Usage" in exc.value.process_result.stderr
assert "no such option: --unknown-argument" in exc.value.stderr, exc.value assert "no such option: --unknown-argument" in exc.value.process_result.stderr
@PRE_PYTEST_SKIP @PRE_PYTEST_SKIP
@ -76,4 +76,4 @@ def test_exit_status_correct_usage(salt_master, syndic_id):
assert factory.is_running() assert factory.is_running()
time.sleep(0.5) time.sleep(0.5)
ret = factory.terminate() ret = factory.terminate()
assert ret.exitcode == salt.defaults.exitcodes.EX_OK, ret assert ret.returncode == salt.defaults.exitcodes.EX_OK, ret

View file

@ -31,7 +31,7 @@ def salt_minion(salt_master, salt_minion_factory):
# Sync All # Sync All
salt_call_cli = salt_minion_factory.salt_call_cli() salt_call_cli = salt_minion_factory.salt_call_cli()
ret = salt_call_cli.run("saltutil.sync_all", _timeout=120) ret = salt_call_cli.run("saltutil.sync_all", _timeout=120)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
yield salt_minion_factory yield salt_minion_factory
@ -45,7 +45,7 @@ def salt_sub_minion(salt_master, salt_sub_minion_factory):
# Sync All # Sync All
salt_call_cli = salt_sub_minion_factory.salt_call_cli() salt_call_cli = salt_sub_minion_factory.salt_call_cli()
ret = salt_call_cli.run("saltutil.sync_all", _timeout=120) ret = salt_call_cli.run("saltutil.sync_all", _timeout=120)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
yield salt_sub_minion_factory yield salt_sub_minion_factory

View file

@ -35,7 +35,7 @@ def test_publish_retry(salt_master, salt_minion_retry, salt_cli, salt_run_cli):
# stop the salt master for some time # stop the salt master for some time
with salt_master.stopped(): with salt_master.stopped():
# verify we don't yet have the result and sleep # verify we don't yet have the result and sleep
assert salt_run_cli.run("jobs.lookup_jid", jid, _timeout=60).json == {} assert salt_run_cli.run("jobs.lookup_jid", jid, _timeout=60).data == {}
# the 70s sleep (and 60s timer value) is to reduce flakiness due to slower test runs # the 70s sleep (and 60s timer value) is to reduce flakiness due to slower test runs
# and should be addresses when number of tries is configurable through minion opts # and should be addresses when number of tries is configurable through minion opts
@ -44,7 +44,7 @@ def test_publish_retry(salt_master, salt_minion_retry, salt_cli, salt_run_cli):
data = None data = None
for i in range(1, 30): for i in range(1, 30):
time.sleep(1) time.sleep(1)
data = salt_run_cli.run("jobs.lookup_jid", jid, _timeout=60).json data = salt_run_cli.run("jobs.lookup_jid", jid, _timeout=60).data
if data: if data:
break break

View file

@ -29,9 +29,9 @@ def append_grain_module(salt_call_cli, wait_for_pillar_refresh_complete):
# Start off with an empty list # Start off with an empty list
start_time = time.time() start_time = time.time()
ret = salt_call_cli.run("grains.setval", grain.key, val=[]) ret = salt_call_cli.run("grains.setval", grain.key, val=[])
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json == {grain.key: []} assert ret.data == {grain.key: []}
# Let's wait for the pillar refresh, at which stage we know grains are also refreshed # Let's wait for the pillar refresh, at which stage we know grains are also refreshed
wait_for_pillar_refresh_complete(start_time) wait_for_pillar_refresh_complete(start_time)
@ -39,8 +39,8 @@ def append_grain_module(salt_call_cli, wait_for_pillar_refresh_complete):
finally: finally:
start_time = time.time() start_time = time.time()
ret = salt_call_cli.run("grains.delkey", grain.key, force=True) ret = salt_call_cli.run("grains.delkey", grain.key, force=True)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
# Let's wait for the pillar refresh, at which stage we know grains are also refreshed # Let's wait for the pillar refresh, at which stage we know grains are also refreshed
wait_for_pillar_refresh_complete(start_time) wait_for_pillar_refresh_complete(start_time)
@ -53,9 +53,9 @@ def append_grain(append_grain_module, salt_call_cli, wait_for_pillar_refresh_com
finally: finally:
start_time = time.time() start_time = time.time()
ret = salt_call_cli.run("grains.setval", append_grain_module.key, val=[]) ret = salt_call_cli.run("grains.setval", append_grain_module.key, val=[])
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json == {append_grain_module.key: []} assert ret.data == {append_grain_module.key: []}
# Let's wait for the pillar refresh, at which stage we know grains are also refreshed # Let's wait for the pillar refresh, at which stage we know grains are also refreshed
wait_for_pillar_refresh_complete(start_time) wait_for_pillar_refresh_complete(start_time)
@ -66,9 +66,9 @@ def test_grains_append(salt_call_cli, append_grain):
Tests the return of a simple grains.append call. Tests the return of a simple grains.append call.
""" """
ret = salt_call_cli.run("grains.append", append_grain.key, append_grain.value) ret = salt_call_cli.run("grains.append", append_grain.key, append_grain.value)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json == {append_grain.key: [append_grain.value]} assert ret.data == {append_grain.key: [append_grain.value]}
def test_grains_append_val_already_present(salt_call_cli, append_grain): def test_grains_append_val_already_present(salt_call_cli, append_grain):
@ -82,15 +82,15 @@ def test_grains_append_val_already_present(salt_call_cli, append_grain):
# First, make sure the test grain is present # First, make sure the test grain is present
ret = salt_call_cli.run("grains.append", append_grain.key, append_grain.value) ret = salt_call_cli.run("grains.append", append_grain.key, append_grain.value)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json == {append_grain.key: [append_grain.value]} assert ret.data == {append_grain.key: [append_grain.value]}
# Now try to append again # Now try to append again
ret = salt_call_cli.run("grains.append", append_grain.key, append_grain.value) ret = salt_call_cli.run("grains.append", append_grain.key, append_grain.value)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json == msg assert ret.data == msg
def test_grains_append_val_is_list(salt_call_cli, append_grain): def test_grains_append_val_is_list(salt_call_cli, append_grain):
@ -101,9 +101,9 @@ def test_grains_append_val_is_list(salt_call_cli, append_grain):
ret = salt_call_cli.run( ret = salt_call_cli.run(
"grains.append", append_grain.key, val=[append_grain.value, second_grain] "grains.append", append_grain.key, val=[append_grain.value, second_grain]
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json == {append_grain.key: [append_grain.value, second_grain]} assert ret.data == {append_grain.key: [append_grain.value, second_grain]}
def test_grains_remove_add( def test_grains_remove_add(
@ -111,8 +111,8 @@ def test_grains_remove_add(
): ):
second_grain = append_grain.value + "-2" second_grain = append_grain.value + "-2"
ret = salt_call_cli.run("grains.get", append_grain.key) ret = salt_call_cli.run("grains.get", append_grain.key)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json == [] assert ret.data == []
# The range was previously set to 10. Honestly, I don't know why testing 2 iterations # The range was previously set to 10. Honestly, I don't know why testing 2 iterations
# would be any different than 10. Maybe because we're making salt work harder... # would be any different than 10. Maybe because we're making salt work harder...
@ -120,42 +120,42 @@ def test_grains_remove_add(
for _ in range(3): for _ in range(3):
start_time = time.time() start_time = time.time()
ret = salt_call_cli.run("grains.setval", append_grain.key, val=[]) ret = salt_call_cli.run("grains.setval", append_grain.key, val=[])
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json == {append_grain.key: []} assert ret.data == {append_grain.key: []}
wait_for_pillar_refresh_complete(start_time) wait_for_pillar_refresh_complete(start_time)
ret = salt_call_cli.run("grains.get", append_grain.key) ret = salt_call_cli.run("grains.get", append_grain.key)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json == [] assert ret.data == []
start_time = time.time() start_time = time.time()
ret = salt_call_cli.run("grains.append", append_grain.key, append_grain.value) ret = salt_call_cli.run("grains.append", append_grain.key, append_grain.value)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json == {append_grain.key: [append_grain.value]} assert ret.data == {append_grain.key: [append_grain.value]}
wait_for_pillar_refresh_complete(start_time) wait_for_pillar_refresh_complete(start_time)
ret = salt_call_cli.run("grains.get", append_grain.key) ret = salt_call_cli.run("grains.get", append_grain.key)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json == [append_grain.value] assert ret.data == [append_grain.value]
start_time = time.time() start_time = time.time()
ret = salt_call_cli.run("grains.setval", append_grain.key, val=[]) ret = salt_call_cli.run("grains.setval", append_grain.key, val=[])
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json == {append_grain.key: []} assert ret.data == {append_grain.key: []}
wait_for_pillar_refresh_complete(start_time) wait_for_pillar_refresh_complete(start_time)
ret = salt_call_cli.run("grains.get", append_grain.key) ret = salt_call_cli.run("grains.get", append_grain.key)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json == [] assert ret.data == []
start_time = time.time() start_time = time.time()
ret = salt_call_cli.run( ret = salt_call_cli.run(
"grains.append", append_grain.key, val=[append_grain.value, second_grain] "grains.append", append_grain.key, val=[append_grain.value, second_grain]
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json == {append_grain.key: [append_grain.value, second_grain]} assert ret.data == {append_grain.key: [append_grain.value, second_grain]}
wait_for_pillar_refresh_complete(start_time) wait_for_pillar_refresh_complete(start_time)
ret = salt_call_cli.run("grains.get", append_grain.key) ret = salt_call_cli.run("grains.get", append_grain.key)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json == [append_grain.value, second_grain] assert ret.data == [append_grain.value, second_grain]

View file

@ -26,10 +26,10 @@ def test_items(salt_call_cli, minion_test_grain):
grains.items grains.items
""" """
ret = salt_call_cli.run("grains.items") ret = salt_call_cli.run("grains.items")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert isinstance(ret.json, dict) assert isinstance(ret.data, dict)
assert ret.json["test_grain"] == minion_test_grain assert ret.data["test_grain"] == minion_test_grain
def test_item(salt_call_cli, minion_test_grain): def test_item(salt_call_cli, minion_test_grain):
@ -37,10 +37,10 @@ def test_item(salt_call_cli, minion_test_grain):
grains.item grains.item
""" """
ret = salt_call_cli.run("grains.item", "test_grain") ret = salt_call_cli.run("grains.item", "test_grain")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert isinstance(ret.json, dict) assert isinstance(ret.data, dict)
assert ret.json["test_grain"] == minion_test_grain assert ret.data["test_grain"] == minion_test_grain
def test_ls(salt_call_cli, grains): def test_ls(salt_call_cli, grains):
@ -77,8 +77,8 @@ def test_ls(salt_call_cli, grains):
"virtual", "virtual",
) )
ret = salt_call_cli.run("grains.ls") ret = salt_call_cli.run("grains.ls")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
for grain in check_for: for grain in check_for:
if grains["os"] == "Windows" and grain in ( if grains["os"] == "Windows" and grain in (
"cpu_flags", "cpu_flags",
@ -87,7 +87,7 @@ def test_ls(salt_call_cli, grains):
"uid", "uid",
): ):
continue continue
assert grain in ret.json assert grain in ret.data
def test_set_val(salt_call_cli, wait_for_pillar_refresh_complete): def test_set_val(salt_call_cli, wait_for_pillar_refresh_complete):
@ -96,16 +96,16 @@ def test_set_val(salt_call_cli, wait_for_pillar_refresh_complete):
""" """
start_time = time.time() start_time = time.time()
ret = salt_call_cli.run("grains.setval", "setgrain", "grainval") ret = salt_call_cli.run("grains.setval", "setgrain", "grainval")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json == {"setgrain": "grainval"} assert ret.data == {"setgrain": "grainval"}
# Let's wait for the pillar refresh, at which stage we know grains are also refreshed # Let's wait for the pillar refresh, at which stage we know grains are also refreshed
wait_for_pillar_refresh_complete(start_time) wait_for_pillar_refresh_complete(start_time)
ret = salt_call_cli.run("grains.item", "setgrain") ret = salt_call_cli.run("grains.item", "setgrain")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json == {"setgrain": "grainval"} assert ret.data == {"setgrain": "grainval"}
def test_get(salt_call_cli): def test_get(salt_call_cli):
@ -113,9 +113,9 @@ def test_get(salt_call_cli):
test grains.get test grains.get
""" """
ret = salt_call_cli.run("grains.get", "level1:level2") ret = salt_call_cli.run("grains.get", "level1:level2")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json == "foo" assert ret.data == "foo"
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -126,12 +126,12 @@ def test_get_core_grains(salt_call_cli, grains, grain):
test to ensure some core grains are returned test to ensure some core grains are returned
""" """
ret = salt_call_cli.run("grains.get", grain) ret = salt_call_cli.run("grains.get", grain)
assert ret.exitcode == 0 assert ret.returncode == 0
log.debug("Value of '%s' grain: '%s'", grain, ret.json) log.debug("Value of '%s' grain: '%s'", grain, ret.data)
if grains["os"] in ("Arch", "Windows") and grain in ["osmajorrelease"]: if grains["os"] in ("Arch", "Windows") and grain in ["osmajorrelease"]:
assert ret.json == "" assert ret.data == ""
else: else:
assert ret.json assert ret.data
@pytest.mark.parametrize("grain", ("num_cpus", "mem_total", "num_gpus", "uid")) @pytest.mark.parametrize("grain", ("num_cpus", "mem_total", "num_gpus", "uid"))
@ -141,11 +141,11 @@ def test_get_grains_int(salt_call_cli, grains, grain):
are returned as integers are returned as integers
""" """
ret = salt_call_cli.run("grains.get", grain) ret = salt_call_cli.run("grains.get", grain)
assert ret.exitcode == 0 assert ret.returncode == 0
log.debug("Value of '%s' grain: %r", grain, ret.json) log.debug("Value of '%s' grain: %r", grain, ret.data)
if grains["os"] == "Windows" and grain in ["uid"]: if grains["os"] == "Windows" and grain in ["uid"]:
assert ret.json == "" assert ret.data == ""
else: else:
assert isinstance(ret.json, int), "grain: {} is not an int or empty".format( assert isinstance(ret.data, int), "grain: {} is not an int or empty".format(
grain grain
) )

View file

@ -8,5 +8,5 @@ pytestmark = [
@pytest.mark.slow_test @pytest.mark.slow_test
def test_sync_grains(salt_call_cli): def test_sync_grains(salt_call_cli):
ret = salt_call_cli.run("saltutil.sync_grains") ret = salt_call_cli.run("saltutil.sync_grains")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json == [] assert ret.data == []

View file

@ -16,14 +16,14 @@ def refresh_pillar(salt_call_cli, salt_minion, salt_sub_minion):
"modules": [], "modules": [],
} }
ret = salt_call_cli.run("saltutil.sync_all", extmod_whitelist=whitelist) ret = salt_call_cli.run("saltutil.sync_all", extmod_whitelist=whitelist)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
try: try:
yield yield
finally: finally:
ret = salt_call_cli.run("saltutil.sync_all") ret = salt_call_cli.run("saltutil.sync_all")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
@pytest.mark.slow_test @pytest.mark.slow_test
@ -59,9 +59,9 @@ def test_sync_all(salt_call_cli):
"serializers": [], "serializers": [],
} }
ret = salt_call_cli.run("saltutil.sync_all") ret = salt_call_cli.run("saltutil.sync_all")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json == expected_return assert ret.data == expected_return
@pytest.mark.slow_test @pytest.mark.slow_test
@ -91,9 +91,9 @@ def test_sync_all_whitelist(salt_call_cli):
ret = salt_call_cli.run( ret = salt_call_cli.run(
"saltutil.sync_all", extmod_whitelist={"modules": ["salttest"]} "saltutil.sync_all", extmod_whitelist={"modules": ["salttest"]}
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json == expected_return assert ret.data == expected_return
@pytest.mark.slow_test @pytest.mark.slow_test
@ -135,9 +135,9 @@ def test_sync_all_blacklist(salt_call_cli):
] ]
}, },
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json == expected_return assert ret.data == expected_return
@pytest.mark.slow_test @pytest.mark.slow_test
@ -169,6 +169,6 @@ def test_sync_all_blacklist_and_whitelist(salt_call_cli):
extmod_whitelist={"modules": ["runtests_decorators"]}, extmod_whitelist={"modules": ["runtests_decorators"]},
extmod_blacklist={"modules": ["runtests_decorators"]}, extmod_blacklist={"modules": ["runtests_decorators"]},
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json == expected_return assert ret.data == expected_return

View file

@ -19,14 +19,14 @@ pytestmark = [
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def refresh_pillar(salt_call_cli, salt_minion): def refresh_pillar(salt_call_cli, salt_minion):
ret = salt_call_cli.run("saltutil.refresh_pillar", wait=True) ret = salt_call_cli.run("saltutil.refresh_pillar", wait=True)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
try: try:
yield yield
finally: finally:
ret = salt_call_cli.run("saltutil.refresh_pillar", wait=True) ret = salt_call_cli.run("saltutil.refresh_pillar", wait=True)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
@pytest.mark.slow_test @pytest.mark.slow_test
@ -56,9 +56,9 @@ def test_pillar_refresh(
) )
ret = salt_call_cli.run("pillar.raw") ret = salt_call_cli.run("pillar.raw")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
pre_pillar = ret.json pre_pillar = ret.data
# Remove keys which are not important and consume too much output when reading through failures # Remove keys which are not important and consume too much output when reading through failures
for key in ("master", "ext_pillar_opts"): for key in ("master", "ext_pillar_opts"):
pre_pillar.pop(key, None) pre_pillar.pop(key, None)
@ -78,7 +78,7 @@ def test_pillar_refresh(
"saltutil.refresh_pillar", "saltutil.refresh_pillar",
wait=sync_refresh, wait=sync_refresh,
) )
assert ret.exitcode == 0 assert ret.returncode == 0
expected_tag = salt.defaults.events.MINION_PILLAR_REFRESH_COMPLETE expected_tag = salt.defaults.events.MINION_PILLAR_REFRESH_COMPLETE
event_pattern = (salt_minion.id, expected_tag) event_pattern = (salt_minion.id, expected_tag)
@ -91,9 +91,9 @@ def test_pillar_refresh(
log.debug("Refresh pillar complete event received: %s", matched_events.matches) log.debug("Refresh pillar complete event received: %s", matched_events.matches)
ret = salt_call_cli.run("pillar.raw") ret = salt_call_cli.run("pillar.raw")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
post_pillar = ret.json post_pillar = ret.data
# Remove keys which are not important and consume too much output when reading through failures # Remove keys which are not important and consume too much output when reading through failures
for key in ("master", "ext_pillar_opts"): for key in ("master", "ext_pillar_opts"):
post_pillar.pop(key, None) post_pillar.pop(key, None)

View file

@ -32,12 +32,12 @@ def setup_test_module(salt_call_cli, salt_master, salt_minion):
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def refresh_pillar(salt_cli, salt_minion, salt_sub_minion): def refresh_pillar(salt_cli, salt_minion, salt_sub_minion):
ret = salt_cli.run("saltutil.refresh_pillar", wait=True, minion_tgt="*") ret = salt_cli.run("saltutil.refresh_pillar", wait=True, minion_tgt="*")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert ret.json[salt_minion.id] is True assert ret.data[salt_minion.id] is True
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
assert ret.json[salt_sub_minion.id] is True assert ret.data[salt_sub_minion.id] is True
@pytest.mark.slow_test @pytest.mark.slow_test
@ -46,10 +46,10 @@ def test_wheel_just_function(salt_call_cli, salt_minion, salt_sub_minion):
Tests using the saltutil.wheel function when passing only a function. Tests using the saltutil.wheel function when passing only a function.
""" """
ret = salt_call_cli.run("saltutil.wheel", "minions.connected") ret = salt_call_cli.run("saltutil.wheel", "minions.connected")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert salt_minion.id in ret.json["return"] assert salt_minion.id in ret.data["return"]
assert salt_sub_minion.id in ret.json["return"] assert salt_sub_minion.id in ret.data["return"]
@pytest.mark.slow_test @pytest.mark.slow_test
@ -58,8 +58,8 @@ def test_wheel_with_arg(salt_call_cli):
Tests using the saltutil.wheel function when passing a function and an arg. Tests using the saltutil.wheel function when passing a function and an arg.
""" """
ret = salt_call_cli.run("saltutil.wheel", "key.list", "minion") ret = salt_call_cli.run("saltutil.wheel", "key.list", "minion")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json["return"] == {} assert ret.data["return"] == {}
@pytest.mark.slow_test @pytest.mark.slow_test
@ -69,7 +69,7 @@ def test_wheel_no_arg_raise_error(salt_call_cli):
an arg, but one isn't supplied. an arg, but one isn't supplied.
""" """
ret = salt_call_cli.run("--retcode-passthrough", "saltutil.wheel", "key.list") ret = salt_call_cli.run("--retcode-passthrough", "saltutil.wheel", "key.list")
assert ret.exitcode == 0 assert ret.returncode == 0
@pytest.mark.slow_test @pytest.mark.slow_test
@ -80,6 +80,6 @@ def test_wheel_with_kwarg(salt_call_cli):
just need this for testing purposes. just need this for testing purposes.
""" """
ret = salt_call_cli.run("saltutil.wheel", "key.gen", keysize=1024) ret = salt_call_cli.run("saltutil.wheel", "key.gen", keysize=1024)
assert ret.exitcode == 0 assert ret.returncode == 0
assert "pub" in ret.json["return"] assert "pub" in ret.data["return"]
assert "priv" in ret.json["return"] assert "priv" in ret.data["return"]

View file

@ -13,7 +13,7 @@ def test_get_file_from_env_in_top_match(salt_cli, salt_sub_minion):
tgt = os.path.join(RUNTIME_VARS.TMP, "prod-cheese-file") tgt = os.path.join(RUNTIME_VARS.TMP, "prod-cheese-file")
try: try:
ret = salt_cli.run("state.highstate", minion_tgt=salt_sub_minion.id) ret = salt_cli.run("state.highstate", minion_tgt=salt_sub_minion.id)
assert ret.exitcode == 0 assert ret.returncode == 0
assert os.path.isfile(tgt) assert os.path.isfile(tgt)
with salt.utils.files.fopen(tgt, "r") as cheese: with salt.utils.files.fopen(tgt, "r") as cheese:
data = salt.utils.stringutils.to_unicode(cheese.read()) data = salt.utils.stringutils.to_unicode(cheese.read())
@ -66,8 +66,8 @@ def test_issue_56131(salt_minion, base_env_state_tree_root_dir, tmp_path):
"issue-56131.sls", sls_contents, base_env_state_tree_root_dir "issue-56131.sls", sls_contents, base_env_state_tree_root_dir
): ):
ret = salt_call_cli.run("state.sls", "issue-56131") ret = salt_call_cli.run("state.sls", "issue-56131")
assert ret.exitcode == 0 assert ret.returncode == 0
for state_return in MultiStateResult(ret.json): for state_return in MultiStateResult(ret.data):
assert state_return.result is True assert state_return.result is True
assert extract_path.exists() assert extract_path.exists()
finally: finally:
@ -93,9 +93,9 @@ def test_pydsl(salt_call_cli, base_env_state_tree_root_dir, tmp_path):
"pydsl.sls", sls_contents, base_env_state_tree_root_dir "pydsl.sls", sls_contents, base_env_state_tree_root_dir
): ):
ret = salt_call_cli.run("state.sls", "pydsl") ret = salt_call_cli.run("state.sls", "pydsl")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
for state_return in MultiStateResult(ret.json): for state_return in MultiStateResult(ret.data):
assert state_return.result is True assert state_return.result is True
assert testfile.exists() assert testfile.exists()
@ -116,7 +116,7 @@ def test_state_sls_unicode_characters(salt_call_cli, base_env_state_tree_root_di
"issue-46672.sls", sls_contents, base_env_state_tree_root_dir "issue-46672.sls", sls_contents, base_env_state_tree_root_dir
): ):
ret = salt_call_cli.run("state.sls", "issue-46672") ret = salt_call_cli.run("state.sls", "issue-46672")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
expected = "cmd_|-echo1_|-echo 'This is Æ test!'_|-run" expected = "cmd_|-echo1_|-echo 'This is Æ test!'_|-run"
assert expected in ret.json assert expected in ret.data

View file

@ -16,8 +16,8 @@ def reset_pillar(salt_call_cli):
finally: finally:
# Refresh pillar once all tests are done. # Refresh pillar once all tests are done.
ret = salt_call_cli.run("saltutil.refresh_pillar", wait=True) ret = salt_call_cli.run("saltutil.refresh_pillar", wait=True)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
@ -40,8 +40,8 @@ def pillar_test_true(
"basic.sls", basic_pillar_file, base_env_pillar_tree_root_dir "basic.sls", basic_pillar_file, base_env_pillar_tree_root_dir
): ):
ret = salt_call_cli.run("saltutil.refresh_pillar", wait=True) ret = salt_call_cli.run("saltutil.refresh_pillar", wait=True)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
yield yield
@ -63,8 +63,8 @@ def pillar_test_empty(
"basic.sls", basic_pillar_file, base_env_pillar_tree_root_dir "basic.sls", basic_pillar_file, base_env_pillar_tree_root_dir
): ):
ret = salt_call_cli.run("saltutil.refresh_pillar", wait=True) ret = salt_call_cli.run("saltutil.refresh_pillar", wait=True)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
yield yield
@ -88,8 +88,8 @@ def pillar_test_false(
"basic.sls", basic_pillar_file, base_env_pillar_tree_root_dir "basic.sls", basic_pillar_file, base_env_pillar_tree_root_dir
): ):
ret = salt_call_cli.run("saltutil.refresh_pillar", wait=True) ret = salt_call_cli.run("saltutil.refresh_pillar", wait=True)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
yield yield
@ -122,8 +122,8 @@ def test_state_sls_id_test(salt_call_cli, testfile_path):
"be different due to other states." "be different due to other states."
).format(testfile_path) ).format(testfile_path)
ret = salt_call_cli.run("state.sls", "sls-id-test") ret = salt_call_cli.run("state.sls", "sls-id-test")
assert ret.exitcode == 0 assert ret.returncode == 0
for val in ret.json.values(): for val in ret.data.values():
assert val["comment"] == expected_comment assert val["comment"] == expected_comment
assert val["changes"] == {"newfile": str(testfile_path)} assert val["changes"] == {"newfile": str(testfile_path)}
@ -138,8 +138,8 @@ def test_state_sls_id_test_state_test_post_run(salt_call_cli, testfile_path):
testfile_path.write_text(source.read_text()) testfile_path.write_text(source.read_text())
testfile_path.chmod(0o644) testfile_path.chmod(0o644)
ret = salt_call_cli.run("state.sls", "sls-id-test") ret = salt_call_cli.run("state.sls", "sls-id-test")
assert ret.exitcode == 0 assert ret.returncode == 0
for val in ret.json.values(): for val in ret.data.values():
assert val["comment"] == "The file {} is in the correct state".format( assert val["comment"] == "The file {} is in the correct state".format(
testfile_path testfile_path
) )
@ -156,8 +156,8 @@ def test_state_sls_id_test_true(salt_call_cli, testfile_path):
"be different due to other states." "be different due to other states."
).format(testfile_path) ).format(testfile_path)
ret = salt_call_cli.run("state.sls", "sls-id-test", test=True) ret = salt_call_cli.run("state.sls", "sls-id-test", test=True)
assert ret.exitcode == 0 assert ret.returncode == 0
for val in ret.json.values(): for val in ret.data.values():
assert val["comment"] == expected_comment assert val["comment"] == expected_comment
assert val["changes"] == {"newfile": str(testfile_path)} assert val["changes"] == {"newfile": str(testfile_path)}
@ -169,15 +169,15 @@ def test_state_sls_id_test_true_post_run(salt_call_cli, testfile_path):
arg post the state already being run previously arg post the state already being run previously
""" """
ret = salt_call_cli.run("state.sls", "sls-id-test") ret = salt_call_cli.run("state.sls", "sls-id-test")
assert ret.exitcode == 0 assert ret.returncode == 0
assert testfile_path.exists() assert testfile_path.exists()
for val in ret.json.values(): for val in ret.data.values():
assert val["comment"] == "File {} updated".format(testfile_path) assert val["comment"] == "File {} updated".format(testfile_path)
assert val["changes"]["diff"] == "New file" assert val["changes"]["diff"] == "New file"
ret = salt_call_cli.run("state.sls", "sls-id-test", test=True) ret = salt_call_cli.run("state.sls", "sls-id-test", test=True)
assert ret.exitcode == 0 assert ret.returncode == 0
for val in ret.json.values(): for val in ret.data.values():
assert val["comment"] == "The file {} is in the correct state".format( assert val["comment"] == "The file {} is in the correct state".format(
testfile_path testfile_path
) )
@ -192,8 +192,8 @@ def test_state_sls_id_test_false_pillar_true(salt_call_cli, testfile_path):
return test=False. return test=False.
""" """
ret = salt_call_cli.run("state.sls", "sls-id-test", test=False) ret = salt_call_cli.run("state.sls", "sls-id-test", test=False)
assert ret.exitcode == 0 assert ret.returncode == 0
for val in ret.json.values(): for val in ret.data.values():
assert val["comment"] == "File {} updated".format(testfile_path) assert val["comment"] == "File {} updated".format(testfile_path)
assert val["changes"]["diff"] == "New file" assert val["changes"]["diff"] == "New file"
@ -208,8 +208,8 @@ def test_state_test_pillar_false(salt_call_cli, testfile_path):
"be different due to other states." "be different due to other states."
).format(testfile_path) ).format(testfile_path)
ret = salt_call_cli.run("state.test", "sls-id-test") ret = salt_call_cli.run("state.test", "sls-id-test")
assert ret.exitcode == 0 assert ret.returncode == 0
for val in ret.json.values(): for val in ret.data.values():
assert val["comment"] == expected_comment assert val["comment"] == expected_comment
assert val["changes"] == {"newfile": str(testfile_path)} assert val["changes"] == {"newfile": str(testfile_path)}
@ -225,7 +225,7 @@ def test_state_test_test_false_pillar_false(salt_call_cli, testfile_path):
"be different due to other states." "be different due to other states."
).format(testfile_path) ).format(testfile_path)
ret = salt_call_cli.run("state.test", "sls-id-test", test=False) ret = salt_call_cli.run("state.test", "sls-id-test", test=False)
assert ret.exitcode == 0 assert ret.returncode == 0
for val in ret.json.values(): for val in ret.data.values():
assert val["comment"] == expected_comment assert val["comment"] == expected_comment
assert val["changes"] == {"newfile": str(testfile_path)} assert val["changes"] == {"newfile": str(testfile_path)}

View file

@ -41,9 +41,9 @@ def cleanup_beacons_config_module(salt_minion, salt_call_cli):
minion_conf_d_dir.mkdir() minion_conf_d_dir.mkdir()
beacons_config_file_path = minion_conf_d_dir / "beacons.conf" beacons_config_file_path = minion_conf_d_dir / "beacons.conf"
ret = salt_call_cli.run("beacons.reset") ret = salt_call_cli.run("beacons.reset")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json["result"] is True assert ret.data["result"] is True
if beacons_config_file_path.exists(): if beacons_config_file_path.exists():
beacons_config_file_path.unlink() beacons_config_file_path.unlink()
try: try:
@ -59,9 +59,9 @@ def cleanup_beacons_config(cleanup_beacons_config_module, salt_call_cli):
yield cleanup_beacons_config_module yield cleanup_beacons_config_module
finally: finally:
ret = salt_call_cli.run("beacons.reset") ret = salt_call_cli.run("beacons.reset")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json["result"] is True assert ret.data["result"] is True
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
@ -105,14 +105,14 @@ def pillar_tree(
try: try:
with top_tempfile, beacon_tempfile: with top_tempfile, beacon_tempfile:
ret = salt_call_cli.run("saltutil.refresh_pillar", wait=True) ret = salt_call_cli.run("saltutil.refresh_pillar", wait=True)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
yield yield
finally: finally:
# Refresh pillar again to cleaup the temp pillar # Refresh pillar again to cleaup the temp pillar
ret = salt_call_cli.run("saltutil.refresh_pillar", wait=True) ret = salt_call_cli.run("saltutil.refresh_pillar", wait=True)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
@attr.s(frozen=True, slots=True) @attr.s(frozen=True, slots=True)
@ -147,21 +147,21 @@ def test_add_and_delete(salt_call_cli, beacon_instance):
ret = salt_call_cli.run( ret = salt_call_cli.run(
"beacons.add", beacon_instance.name, beacon_data=beacon_instance.data "beacons.add", beacon_instance.name, beacon_data=beacon_instance.data
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json["result"] is True assert ret.data["result"] is True
# Save beacons # Save beacons
ret = salt_call_cli.run("beacons.save") ret = salt_call_cli.run("beacons.save")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json["result"] is True assert ret.data["result"] is True
# Delete beacon # Delete beacon
ret = salt_call_cli.run("beacons.delete", beacon_instance.name) ret = salt_call_cli.run("beacons.delete", beacon_instance.name)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json["result"] is True assert ret.data["result"] is True
@pytest.fixture @pytest.fixture
@ -169,21 +169,21 @@ def beacon(beacon_instance, salt_call_cli):
ret = salt_call_cli.run( ret = salt_call_cli.run(
"beacons.add", beacon_instance.name, beacon_data=beacon_instance.data "beacons.add", beacon_instance.name, beacon_data=beacon_instance.data
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json["result"] is True assert ret.data["result"] is True
# Save beacons # Save beacons
ret = salt_call_cli.run("beacons.save") ret = salt_call_cli.run("beacons.save")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json["result"] is True assert ret.data["result"] is True
# assert beacon exists # assert beacon exists
ret = salt_call_cli.run("beacons.list", return_yaml=False) ret = salt_call_cli.run("beacons.list", return_yaml=False)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert beacon_instance.name in ret.json assert beacon_instance.name in ret.data
yield beacon_instance yield beacon_instance
@ -193,28 +193,28 @@ def test_disable(salt_call_cli, beacon):
Test disabling beacons Test disabling beacons
""" """
ret = salt_call_cli.run("beacons.disable") ret = salt_call_cli.run("beacons.disable")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json["result"] is True assert ret.data["result"] is True
# assert beacons are disabled # assert beacons are disabled
ret = salt_call_cli.run("beacons.list", return_yaml=False) ret = salt_call_cli.run("beacons.list", return_yaml=False)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json["enabled"] is False assert ret.data["enabled"] is False
# disable added beacon # disable added beacon
ret = salt_call_cli.run("beacons.disable_beacon", beacon.name) ret = salt_call_cli.run("beacons.disable_beacon", beacon.name)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json["result"] is True assert ret.data["result"] is True
# assert beacon is disabled # assert beacon is disabled
ret = salt_call_cli.run("beacons.list", return_yaml=False) ret = salt_call_cli.run("beacons.list", return_yaml=False)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert beacon.name in ret.json assert beacon.name in ret.data
for beacon_data in ret.json[beacon.name]: for beacon_data in ret.data[beacon.name]:
if "enabled" in beacon_data: if "enabled" in beacon_data:
assert beacon_data["enabled"] is False assert beacon_data["enabled"] is False
break break
@ -225,9 +225,9 @@ def test_disable(salt_call_cli, beacon):
@pytest.fixture @pytest.fixture
def disabled_beacon(beacon, salt_call_cli): def disabled_beacon(beacon, salt_call_cli):
ret = salt_call_cli.run("beacons.disable") ret = salt_call_cli.run("beacons.disable")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json["result"] is True assert ret.data["result"] is True
return beacon return beacon
@ -237,15 +237,15 @@ def test_enable(salt_call_cli, disabled_beacon):
""" """
# enable beacons on minion # enable beacons on minion
ret = salt_call_cli.run("beacons.enable") ret = salt_call_cli.run("beacons.enable")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json["result"] is True assert ret.data["result"] is True
# assert beacons are enabled # assert beacons are enabled
ret = salt_call_cli.run("beacons.list", return_yaml=False) ret = salt_call_cli.run("beacons.list", return_yaml=False)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json["enabled"] is True assert ret.data["enabled"] is True
@pytest.mark.skipif( @pytest.mark.skipif(
@ -261,17 +261,17 @@ def test_enabled_beacons(salt_call_cli, beacon):
""" """
# enable added beacon # enable added beacon
ret = salt_call_cli.run("beacons.enable_beacon", beacon.name) ret = salt_call_cli.run("beacons.enable_beacon", beacon.name)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json["result"] is True assert ret.data["result"] is True
# assert beacon ps is enabled # assert beacon ps is enabled
ret = salt_call_cli.run("beacons.list", return_yaml=False) ret = salt_call_cli.run("beacons.list", return_yaml=False)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json["enabled"] is True assert ret.data["enabled"] is True
assert beacon.name in ret.json assert beacon.name in ret.data
for beacon_data in ret.json[beacon.name]: for beacon_data in ret.data[beacon.name]:
if "enabled" in beacon_data: if "enabled" in beacon_data:
assert beacon_data["enabled"] is False assert beacon_data["enabled"] is False
break break
@ -286,9 +286,9 @@ def test_list(salt_call_cli, beacon, inotify_file_path):
""" """
# list beacons # list beacons
ret = salt_call_cli.run("beacons.list", return_yaml=False) ret = salt_call_cli.run("beacons.list", return_yaml=False)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json == { assert ret.data == {
beacon.name: beacon.data, beacon.name: beacon.data,
"inotify": [ "inotify": [
{ {
@ -316,9 +316,9 @@ def test_list_only_include_opts(salt_call_cli, beacon):
ret = salt_call_cli.run( ret = salt_call_cli.run(
"beacons.list", return_yaml=False, include_opts=True, include_pillar=False "beacons.list", return_yaml=False, include_opts=True, include_pillar=False
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json == {beacon.name: beacon.data} assert ret.data == {beacon.name: beacon.data}
@pytest.mark.usefixtures("pillar_tree", "beacon") @pytest.mark.usefixtures("pillar_tree", "beacon")
@ -330,9 +330,9 @@ def test_list_only_include_pillar(salt_call_cli, inotify_file_path):
ret = salt_call_cli.run( ret = salt_call_cli.run(
"beacons.list", return_yaml=False, include_opts=False, include_pillar=True "beacons.list", return_yaml=False, include_opts=False, include_pillar=True
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json == { assert ret.data == {
"inotify": [ "inotify": [
{ {
"files": { "files": {
@ -349,6 +349,6 @@ def test_list_available(salt_call_cli):
""" """
# list beacons # list beacons
ret = salt_call_cli.run("beacons.list_available", return_yaml=False) ret = salt_call_cli.run("beacons.list_available", return_yaml=False)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert "ps" in ret.json assert "ps" in ret.data

View file

@ -12,4 +12,4 @@ def test_exec_code_all(salt_call_cli, non_root_account):
ret = salt_call_cli.run( ret = salt_call_cli.run(
"cmd.exec_code_all", "bash", "echo good", runas=non_root_account.username "cmd.exec_code_all", "bash", "echo good", runas=non_root_account.username
) )
assert ret.exitcode == 0 assert ret.returncode == 0

View file

@ -22,9 +22,9 @@ def test_fire_master(event_listener, salt_master, salt_minion, salt_call_cli):
ret = salt_call_cli.run( ret = salt_call_cli.run(
"event.fire_master", "event.fire_master: just test it!!!!", event_tag "event.fire_master", "event.fire_master: just test it!!!!", event_tag
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json is True assert ret.data is True
event_pattern = (salt_master.id, event_tag) event_pattern = (salt_master.id, event_tag)
matched_events = event_listener.wait_for_events( matched_events = event_listener.wait_for_events(
@ -48,9 +48,9 @@ def test_event_fire(event_listener, salt_minion, salt_sub_minion, salt_cli):
ret = salt_cli.run( ret = salt_cli.run(
"event.fire", data=data, tag=event_tag, minion_tgt=minion_tgt "event.fire", data=data, tag=event_tag, minion_tgt=minion_tgt
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json is True assert ret.data is True
event_pattern = (minion_tgt, event_tag) event_pattern = (minion_tgt, event_tag)
matched_events = event_listener.wait_for_events( matched_events = event_listener.wait_for_events(
@ -76,9 +76,9 @@ def test_send(event_listener, salt_master, salt_minion, salt_call_cli):
with_pillar=True, with_pillar=True,
preload={"foo": "bar"}, preload={"foo": "bar"},
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json is True assert ret.data is True
event_pattern = (salt_master.id, event_tag) event_pattern = (salt_master.id, event_tag)
matched_events = event_listener.wait_for_events( matched_events = event_listener.wait_for_events(

View file

@ -24,10 +24,10 @@ def test_get_source_sum_verify_ssl_false(
) )
if not verify_ssl: if not verify_ssl:
assert ( assert (
ret.json["hsum"] ret.data["hsum"]
== "f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2" == "f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2"
) )
assert ret.json["hash_type"] == "sha256" assert ret.data["hash_type"] == "sha256"
else: else:
assert "SSL: CERTIFICATE_VERIFY_FAILED" in ret.stderr assert "SSL: CERTIFICATE_VERIFY_FAILED" in ret.stderr
@ -58,7 +58,7 @@ def test_get_managed_verify_ssl(salt_call_cli, tmpdir, ssl_webserver, verify_ssl
"verify_ssl={}".format(verify_ssl), "verify_ssl={}".format(verify_ssl),
) )
if not verify_ssl: if not verify_ssl:
assert "this.txt" in ret.json[0] assert "this.txt" in ret.data[0]
else: else:
assert "SSL: CERTIFICATE_VERIFY_FAILED" in ret.stdout assert "SSL: CERTIFICATE_VERIFY_FAILED" in ret.stdout
@ -88,8 +88,8 @@ def test_manage_file_verify_ssl(salt_call_cli, tmpdir, ssl_webserver, verify_ssl
"verify_ssl={}".format(verify_ssl), "verify_ssl={}".format(verify_ssl),
) )
if not verify_ssl: if not verify_ssl:
assert ret.json["changes"] == {"diff": "New file", "mode": "0000"} assert ret.data["changes"] == {"diff": "New file", "mode": "0000"}
assert ret.json["comment"] == "File {} updated".format(test_file) assert ret.data["comment"] == "File {} updated".format(test_file)
else: else:
assert "SSL: CERTIFICATE_VERIFY_FAILED" in ret.stderr assert "SSL: CERTIFICATE_VERIFY_FAILED" in ret.stderr
@ -123,7 +123,7 @@ def test_check_managed_changes_verify_ssl(
) )
if not verify_ssl: if not verify_ssl:
assert ret.json["newfile"] == test_file assert ret.data["newfile"] == test_file
else: else:
assert "SSL: CERTIFICATE_VERIFY_FAILED" in ret.stderr assert "SSL: CERTIFICATE_VERIFY_FAILED" in ret.stderr
@ -156,7 +156,7 @@ def test_check_file_meta_verify_ssl(salt_call_cli, tmpdir, ssl_webserver, verify
if not verify_ssl: if not verify_ssl:
assert ( assert (
len([x for x in ["diff", "user", "group", "mode"] if x in ret.json.keys()]) len([x for x in ["diff", "user", "group", "mode"] if x in ret.data.keys()])
== 4 == 4
) )
else: else:

View file

@ -16,4 +16,4 @@ pytestmark = [
@contextmanager @contextmanager
def test_exec(salt_call_cli): def test_exec(salt_call_cli):
ret = salt_call_cli.run("--local", "idem.exec", "test.ping") ret = salt_call_cli.run("--local", "idem.exec", "test.ping")
assert ret.json is True assert ret.data is True

View file

@ -40,32 +40,32 @@ def salt_call_cli_wrapper(salt_call_cli, mysql_container):
def test_query(salt_call_cli_wrapper): def test_query(salt_call_cli_wrapper):
ret = salt_call_cli_wrapper("mysql.query", "mysql", "SELECT 1") ret = salt_call_cli_wrapper("mysql.query", "mysql", "SELECT 1")
assert ret.json assert ret.data
assert ret.json["results"] == [["1"]] assert ret.data["results"] == [["1"]]
def test_version(salt_call_cli_wrapper, mysql_container): def test_version(salt_call_cli_wrapper, mysql_container):
ret = salt_call_cli_wrapper("mysql.version") ret = salt_call_cli_wrapper("mysql.version")
assert ret.json assert ret.data
assert mysql_container.mysql_version in ret.json assert mysql_container.mysql_version in ret.data
def test_status(salt_call_cli_wrapper): def test_status(salt_call_cli_wrapper):
ret = salt_call_cli_wrapper("mysql.status") ret = salt_call_cli_wrapper("mysql.status")
assert ret.json assert ret.data
def test_db_list(salt_call_cli_wrapper): def test_db_list(salt_call_cli_wrapper):
ret = salt_call_cli_wrapper("mysql.db_list") ret = salt_call_cli_wrapper("mysql.db_list")
assert ret.json assert ret.data
assert "mysql" in ret.json assert "mysql" in ret.data
def test_db_create_alter_remove(salt_call_cli_wrapper): def test_db_create_alter_remove(salt_call_cli_wrapper):
ret = salt_call_cli_wrapper("mysql.db_create", "salt") ret = salt_call_cli_wrapper("mysql.db_create", "salt")
assert ret.json assert ret.data
ret = salt_call_cli_wrapper( ret = salt_call_cli_wrapper(
"mysql.alter_db", "mysql.alter_db",
@ -73,21 +73,21 @@ def test_db_create_alter_remove(salt_call_cli_wrapper):
character_set="latin1", character_set="latin1",
collate="latin1_general_ci", collate="latin1_general_ci",
) )
assert ret.json assert ret.data
ret = salt_call_cli_wrapper("mysql.db_remove", name="salt") ret = salt_call_cli_wrapper("mysql.db_remove", name="salt")
assert ret.json assert ret.data
def test_user_list(salt_call_cli_wrapper): def test_user_list(salt_call_cli_wrapper):
ret = salt_call_cli_wrapper("mysql.user_list") ret = salt_call_cli_wrapper("mysql.user_list")
assert ret.json assert ret.data
assert {"User": "root", "Host": "%"} in ret.json assert {"User": "root", "Host": "%"} in ret.data
def test_user_exists(salt_call_cli_wrapper): def test_user_exists(salt_call_cli_wrapper):
ret = salt_call_cli_wrapper("mysql.user_exists", "root", "%", "password") ret = salt_call_cli_wrapper("mysql.user_exists", "root", "%", "password")
assert ret.json assert ret.data
ret = salt_call_cli_wrapper( ret = salt_call_cli_wrapper(
"mysql.user_exists", "mysql.user_exists",
@ -95,12 +95,12 @@ def test_user_exists(salt_call_cli_wrapper):
"hostname", "hostname",
"badpassword", "badpassword",
) )
assert not ret.json assert not ret.data
def test_user_info(salt_call_cli_wrapper): def test_user_info(salt_call_cli_wrapper):
ret = salt_call_cli_wrapper("mysql.user_info", "root", "%") ret = salt_call_cli_wrapper("mysql.user_info", "root", "%")
assert ret.json assert ret.data
# Check that a subset of the information # Check that a subset of the information
# is available in the returned user information. # is available in the returned user information.
@ -137,7 +137,7 @@ def test_user_info(salt_call_cli_wrapper):
"Trigger_priv": "Y", "Trigger_priv": "Y",
"Create_tablespace_priv": "Y", "Create_tablespace_priv": "Y",
} }
assert all(ret.json.get(key, None) == val for key, val in expected.items()) assert all(ret.data.get(key, None) == val for key, val in expected.items())
def test_user_create_chpass_delete(salt_call_cli_wrapper): def test_user_create_chpass_delete(salt_call_cli_wrapper):
@ -147,7 +147,7 @@ def test_user_create_chpass_delete(salt_call_cli_wrapper):
host="localhost", host="localhost",
password="badpassword", password="badpassword",
) )
assert ret.json assert ret.data
ret = salt_call_cli_wrapper( ret = salt_call_cli_wrapper(
"mysql.user_chpass", "mysql.user_chpass",
@ -155,21 +155,21 @@ def test_user_create_chpass_delete(salt_call_cli_wrapper):
host="localhost", host="localhost",
password="different_password", password="different_password",
) )
assert ret.json assert ret.data
ret = salt_call_cli_wrapper("mysql.user_remove", "george", host="localhost") ret = salt_call_cli_wrapper("mysql.user_remove", "george", host="localhost")
assert ret.json assert ret.data
def test_user_grants(salt_call_cli_wrapper): def test_user_grants(salt_call_cli_wrapper):
ret = salt_call_cli_wrapper("mysql.user_grants", "root", host="%") ret = salt_call_cli_wrapper("mysql.user_grants", "root", host="%")
assert ret.json assert ret.data
def test_grant_add_revoke(salt_call_cli_wrapper): def test_grant_add_revoke(salt_call_cli_wrapper):
# Create the database # Create the database
ret = salt_call_cli_wrapper("mysql.db_create", "salt") ret = salt_call_cli_wrapper("mysql.db_create", "salt")
assert ret.json assert ret.data
# Create a user # Create a user
ret = salt_call_cli_wrapper( ret = salt_call_cli_wrapper(
@ -178,7 +178,7 @@ def test_grant_add_revoke(salt_call_cli_wrapper):
host="localhost", host="localhost",
password="badpassword", password="badpassword",
) )
assert ret.json assert ret.data
# Grant privileges to user to specific table # Grant privileges to user to specific table
ret = salt_call_cli_wrapper( ret = salt_call_cli_wrapper(
@ -188,7 +188,7 @@ def test_grant_add_revoke(salt_call_cli_wrapper):
user="george", user="george",
host="localhost", host="localhost",
) )
assert ret.json assert ret.data
# Check the grant exists # Check the grant exists
ret = salt_call_cli_wrapper( ret = salt_call_cli_wrapper(
@ -198,7 +198,7 @@ def test_grant_add_revoke(salt_call_cli_wrapper):
user="george", user="george",
host="localhost", host="localhost",
) )
assert ret.json assert ret.data
# Revoke the grant # Revoke the grant
ret = salt_call_cli_wrapper( ret = salt_call_cli_wrapper(
@ -208,7 +208,7 @@ def test_grant_add_revoke(salt_call_cli_wrapper):
user="george", user="george",
host="localhost", host="localhost",
) )
assert ret.json assert ret.data
# Check the grant does not exist # Check the grant does not exist
ret = salt_call_cli_wrapper( ret = salt_call_cli_wrapper(
@ -218,7 +218,7 @@ def test_grant_add_revoke(salt_call_cli_wrapper):
user="george", user="george",
host="localhost", host="localhost",
) )
assert not ret.json assert not ret.data
# Grant privileges to user globally # Grant privileges to user globally
ret = salt_call_cli_wrapper( ret = salt_call_cli_wrapper(
@ -228,7 +228,7 @@ def test_grant_add_revoke(salt_call_cli_wrapper):
user="george", user="george",
host="localhost", host="localhost",
) )
assert ret.json assert ret.data
# Check the global exists # Check the global exists
ret = salt_call_cli_wrapper( ret = salt_call_cli_wrapper(
@ -238,7 +238,7 @@ def test_grant_add_revoke(salt_call_cli_wrapper):
user="george", user="george",
host="localhost", host="localhost",
) )
assert ret.json assert ret.data
# Revoke the global grant # Revoke the global grant
ret = salt_call_cli_wrapper( ret = salt_call_cli_wrapper(
@ -248,7 +248,7 @@ def test_grant_add_revoke(salt_call_cli_wrapper):
user="george", user="george",
host="localhost", host="localhost",
) )
assert ret.json assert ret.data
# Check the grant does not exist # Check the grant does not exist
ret = salt_call_cli_wrapper( ret = salt_call_cli_wrapper(
@ -258,15 +258,15 @@ def test_grant_add_revoke(salt_call_cli_wrapper):
user="george", user="george",
host="localhost", host="localhost",
) )
assert not ret.json assert not ret.data
# Remove the user # Remove the user
ret = salt_call_cli_wrapper("mysql.user_remove", "george", host="localhost") ret = salt_call_cli_wrapper("mysql.user_remove", "george", host="localhost")
assert ret.json assert ret.data
# Remove the database # Remove the database
ret = salt_call_cli_wrapper("mysql.db_remove", "salt") ret = salt_call_cli_wrapper("mysql.db_remove", "salt")
assert ret.json assert ret.data
def test_plugin_add_status_remove(salt_call_cli_wrapper, mysql_container): def test_plugin_add_status_remove(salt_call_cli_wrapper, mysql_container):
@ -277,20 +277,20 @@ def test_plugin_add_status_remove(salt_call_cli_wrapper, mysql_container):
plugin = "auth_socket" plugin = "auth_socket"
ret = salt_call_cli_wrapper("mysql.plugin_status", plugin, host="%") ret = salt_call_cli_wrapper("mysql.plugin_status", plugin, host="%")
assert not ret.json assert not ret.data
ret = salt_call_cli_wrapper("mysql.plugin_add", plugin) ret = salt_call_cli_wrapper("mysql.plugin_add", plugin)
assert ret.json assert ret.data
ret = salt_call_cli_wrapper("mysql.plugin_status", plugin, host="%") ret = salt_call_cli_wrapper("mysql.plugin_status", plugin, host="%")
assert ret.json assert ret.data
assert ret.json == "ACTIVE" assert ret.data == "ACTIVE"
ret = salt_call_cli_wrapper("mysql.plugin_remove", plugin) ret = salt_call_cli_wrapper("mysql.plugin_remove", plugin)
assert ret.json assert ret.data
ret = salt_call_cli_wrapper("mysql.plugin_status", plugin, host="%") ret = salt_call_cli_wrapper("mysql.plugin_status", plugin, host="%")
assert not ret.json assert not ret.data
def test_plugin_list(salt_call_cli_wrapper, mysql_container): def test_plugin_list(salt_call_cli_wrapper, mysql_container):
@ -300,24 +300,24 @@ def test_plugin_list(salt_call_cli_wrapper, mysql_container):
plugin = "auth_socket" plugin = "auth_socket"
ret = salt_call_cli_wrapper("mysql.plugins_list") ret = salt_call_cli_wrapper("mysql.plugins_list")
assert {"name": plugin, "status": "ACTIVE"} not in ret.json assert {"name": plugin, "status": "ACTIVE"} not in ret.data
assert ret.json assert ret.data
ret = salt_call_cli_wrapper("mysql.plugin_add", plugin) ret = salt_call_cli_wrapper("mysql.plugin_add", plugin)
assert ret.json assert ret.data
ret = salt_call_cli_wrapper("mysql.plugins_list") ret = salt_call_cli_wrapper("mysql.plugins_list")
assert ret.json assert ret.data
assert {"name": plugin, "status": "ACTIVE"} in ret.json assert {"name": plugin, "status": "ACTIVE"} in ret.data
ret = salt_call_cli_wrapper("mysql.plugin_remove", plugin) ret = salt_call_cli_wrapper("mysql.plugin_remove", plugin)
assert ret.json assert ret.data
def test_grant_add_revoke_password_hash(salt_call_cli_wrapper): def test_grant_add_revoke_password_hash(salt_call_cli_wrapper):
# Create the database # Create the database
ret = salt_call_cli_wrapper("mysql.db_create", "salt") ret = salt_call_cli_wrapper("mysql.db_create", "salt")
assert ret.json assert ret.data
# Create a user # Create a user
ret = salt_call_cli_wrapper( ret = salt_call_cli_wrapper(
@ -326,7 +326,7 @@ def test_grant_add_revoke_password_hash(salt_call_cli_wrapper):
host="%", host="%",
password_hash="*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19", password_hash="*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19",
) )
assert ret.json assert ret.data
# Grant privileges to user to specific table # Grant privileges to user to specific table
ret = salt_call_cli_wrapper( ret = salt_call_cli_wrapper(
@ -336,7 +336,7 @@ def test_grant_add_revoke_password_hash(salt_call_cli_wrapper):
user="george", user="george",
host="%", host="%",
) )
assert ret.json assert ret.data
# Check the grant exists # Check the grant exists
ret = salt_call_cli_wrapper( ret = salt_call_cli_wrapper(
@ -346,7 +346,7 @@ def test_grant_add_revoke_password_hash(salt_call_cli_wrapper):
user="george", user="george",
host="%", host="%",
) )
assert ret.json assert ret.data
# Check the grant exists via a query # Check the grant exists via a query
ret = salt_call_cli_wrapper( ret = salt_call_cli_wrapper(
@ -357,7 +357,7 @@ def test_grant_add_revoke_password_hash(salt_call_cli_wrapper):
connection_pass="password", connection_pass="password",
connection_db="salt", connection_db="salt",
) )
assert ret.json assert ret.data
# Revoke the grant # Revoke the grant
ret = salt_call_cli_wrapper( ret = salt_call_cli_wrapper(
@ -367,7 +367,7 @@ def test_grant_add_revoke_password_hash(salt_call_cli_wrapper):
user="george", user="george",
host="%", host="%",
) )
assert ret.json assert ret.data
# Check the grant does not exist # Check the grant does not exist
ret = salt_call_cli_wrapper( ret = salt_call_cli_wrapper(
@ -377,21 +377,21 @@ def test_grant_add_revoke_password_hash(salt_call_cli_wrapper):
user="george", user="george",
host="%", host="%",
) )
assert not ret.json assert not ret.data
# Remove the user # Remove the user
ret = salt_call_cli_wrapper("mysql.user_remove", "george", host="%") ret = salt_call_cli_wrapper("mysql.user_remove", "george", host="%")
assert ret.json assert ret.data
# Remove the database # Remove the database
ret = salt_call_cli_wrapper("mysql.db_remove", "salt") ret = salt_call_cli_wrapper("mysql.db_remove", "salt")
assert ret.json assert ret.data
def test_create_alter_password_hash(salt_call_cli_wrapper): def test_create_alter_password_hash(salt_call_cli_wrapper):
# Create the database # Create the database
ret = salt_call_cli_wrapper("mysql.db_create", "salt") ret = salt_call_cli_wrapper("mysql.db_create", "salt")
assert ret.json assert ret.data
# Create a user # Create a user
ret = salt_call_cli_wrapper( ret = salt_call_cli_wrapper(
@ -400,7 +400,7 @@ def test_create_alter_password_hash(salt_call_cli_wrapper):
host="%", host="%",
password_hash="*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19", password_hash="*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19",
) )
assert ret.json assert ret.data
# Grant privileges to user to specific table # Grant privileges to user to specific table
ret = salt_call_cli_wrapper( ret = salt_call_cli_wrapper(
@ -410,7 +410,7 @@ def test_create_alter_password_hash(salt_call_cli_wrapper):
user="george", user="george",
host="%", host="%",
) )
assert ret.json assert ret.data
# Check the grant exists # Check the grant exists
ret = salt_call_cli_wrapper( ret = salt_call_cli_wrapper(
@ -420,7 +420,7 @@ def test_create_alter_password_hash(salt_call_cli_wrapper):
user="george", user="george",
host="%", host="%",
) )
assert ret.json assert ret.data
# Check we can query as the new user # Check we can query as the new user
ret = salt_call_cli_wrapper( ret = salt_call_cli_wrapper(
@ -431,7 +431,7 @@ def test_create_alter_password_hash(salt_call_cli_wrapper):
connection_pass="password", connection_pass="password",
connection_db="salt", connection_db="salt",
) )
assert ret.json assert ret.data
# Change the user password # Change the user password
ret = salt_call_cli_wrapper( ret = salt_call_cli_wrapper(
@ -440,7 +440,7 @@ def test_create_alter_password_hash(salt_call_cli_wrapper):
host="%", host="%",
password_hash="*F4A5147613F01DEC0C5226BF24CD1D5762E6AAF2", password_hash="*F4A5147613F01DEC0C5226BF24CD1D5762E6AAF2",
) )
assert ret.json assert ret.data
# Check we can query with the new password # Check we can query with the new password
ret = salt_call_cli_wrapper( ret = salt_call_cli_wrapper(
@ -451,7 +451,7 @@ def test_create_alter_password_hash(salt_call_cli_wrapper):
connection_pass="badpassword", connection_pass="badpassword",
connection_db="salt", connection_db="salt",
) )
assert ret.json assert ret.data
# Revoke the grant # Revoke the grant
ret = salt_call_cli_wrapper( ret = salt_call_cli_wrapper(
@ -461,7 +461,7 @@ def test_create_alter_password_hash(salt_call_cli_wrapper):
user="george", user="george",
host="%", host="%",
) )
assert ret.json assert ret.data
# Check the grant does not exist # Check the grant does not exist
ret = salt_call_cli_wrapper( ret = salt_call_cli_wrapper(
@ -471,12 +471,12 @@ def test_create_alter_password_hash(salt_call_cli_wrapper):
user="george", user="george",
host="%", host="%",
) )
assert not ret.json assert not ret.data
# Remove the user # Remove the user
ret = salt_call_cli_wrapper("mysql.user_remove", "george", host="%") ret = salt_call_cli_wrapper("mysql.user_remove", "george", host="%")
assert ret.json assert ret.data
# Remove the database # Remove the database
ret = salt_call_cli_wrapper("mysql.db_remove", "salt") ret = salt_call_cli_wrapper("mysql.db_remove", "salt")
assert ret.json assert ret.data

View file

@ -45,14 +45,14 @@ def pillar_tree(salt_master, salt_minion, salt_call_cli):
try: try:
with top_tempfile, basic_tempfile: with top_tempfile, basic_tempfile:
ret = salt_call_cli.run("saltutil.refresh_pillar", wait=True) ret = salt_call_cli.run("saltutil.refresh_pillar", wait=True)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
yield yield
finally: finally:
# Refresh pillar again to cleaup the temp pillar # Refresh pillar again to cleaup the temp pillar
ret = salt_call_cli.run("saltutil.refresh_pillar", wait=True) ret = salt_call_cli.run("saltutil.refresh_pillar", wait=True)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
@pytest.mark.slow_test @pytest.mark.slow_test
@ -61,13 +61,13 @@ def test_data(salt_call_cli, pillar_tree):
pillar.data pillar.data
""" """
ret = salt_call_cli.run("grains.items") ret = salt_call_cli.run("grains.items")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
grains = ret.json grains = ret.data
ret = salt_call_cli.run("pillar.data") ret = salt_call_cli.run("pillar.data")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
pillar = ret.json pillar = ret.data
assert pillar["os"] == grains["os"] assert pillar["os"] == grains["os"]
assert pillar["monty"] == "python" assert pillar["monty"] == "python"
if grains["os"] == "Fedora": if grains["os"] == "Fedora":
@ -87,9 +87,9 @@ def test_issue_5449_report_actual_file_roots_in_pillar(
the pillar back to the minion. the pillar back to the minion.
""" """
ret = salt_call_cli.run("pillar.data") ret = salt_call_cli.run("pillar.data")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
file_roots = ret.json["master"]["file_roots"]["base"] file_roots = ret.data["master"]["file_roots"]["base"]
assert pathlib.Path(base_env_state_tree_root_dir).resolve() in [ assert pathlib.Path(base_env_state_tree_root_dir).resolve() in [
pathlib.Path(p).resolve() for p in file_roots pathlib.Path(p).resolve() for p in file_roots
] ]
@ -101,9 +101,9 @@ def test_ext_cmd_yaml(salt_call_cli, pillar_tree):
pillar.data for ext_pillar cmd.yaml pillar.data for ext_pillar cmd.yaml
""" """
ret = salt_call_cli.run("pillar.data") ret = salt_call_cli.run("pillar.data")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
pillar = ret.json pillar = ret.data
assert pillar["ext_spam"] == "eggs" assert pillar["ext_spam"] == "eggs"
@ -112,9 +112,9 @@ def test_issue_5951_actual_file_roots_in_opts(
salt_call_cli, pillar_tree, base_env_state_tree_root_dir salt_call_cli, pillar_tree, base_env_state_tree_root_dir
): ):
ret = salt_call_cli.run("pillar.data") ret = salt_call_cli.run("pillar.data")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
pillar_data = ret.json pillar_data = ret.data
file_roots = pillar_data["ext_pillar_opts"]["file_roots"]["base"] file_roots = pillar_data["ext_pillar_opts"]["file_roots"]["base"]
assert pathlib.Path(base_env_state_tree_root_dir).resolve() in [ assert pathlib.Path(base_env_state_tree_root_dir).resolve() in [
pathlib.Path(p).resolve() for p in file_roots pathlib.Path(p).resolve() for p in file_roots
@ -128,9 +128,9 @@ def test_pillar_items(salt_call_cli, pillar_tree):
from pillar.items from pillar.items
""" """
ret = salt_call_cli.run("pillar.items") ret = salt_call_cli.run("pillar.items")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
pillar_items = ret.json pillar_items = ret.data
assert "monty" in pillar_items assert "monty" in pillar_items
assert pillar_items["monty"] == "python" assert pillar_items["monty"] == "python"
assert "knights" in pillar_items assert "knights" in pillar_items
@ -145,17 +145,17 @@ def test_pillar_command_line(salt_call_cli, pillar_tree):
""" """
# test when pillar is overwriting previous pillar # test when pillar is overwriting previous pillar
ret = salt_call_cli.run("pillar.items", pillar={"monty": "overwrite"}) ret = salt_call_cli.run("pillar.items", pillar={"monty": "overwrite"})
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
pillar_items = ret.json pillar_items = ret.data
assert "monty" in pillar_items assert "monty" in pillar_items
assert pillar_items["monty"] == "overwrite" assert pillar_items["monty"] == "overwrite"
# test when using additional pillar # test when using additional pillar
ret = salt_call_cli.run("pillar.items", pillar={"new": "additional"}) ret = salt_call_cli.run("pillar.items", pillar={"new": "additional"})
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
pillar_items = ret.json pillar_items = ret.data
assert "new" in pillar_items assert "new" in pillar_items
assert pillar_items["new"] == "additional" assert pillar_items["new"] == "additional"
@ -166,16 +166,16 @@ def test_pillar_get_integer_key(salt_call_cli, pillar_tree):
from pillar.items from pillar.items
""" """
ret = salt_call_cli.run("pillar.items") ret = salt_call_cli.run("pillar.items")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
pillar_items = ret.json pillar_items = ret.data
assert "12345" in pillar_items assert "12345" in pillar_items
assert pillar_items["12345"] == {"code": ["luggage"]} assert pillar_items["12345"] == {"code": ["luggage"]}
ret = salt_call_cli.run("pillar.get", key="12345") ret = salt_call_cli.run("pillar.get", key="12345")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
pillar_get = ret.json pillar_get = ret.data
assert "code" in pillar_get assert "code" in pillar_get
assert "luggage" in pillar_get["code"] assert "luggage" in pillar_get["code"]
@ -195,8 +195,8 @@ class PillarRefresh:
minion_tgt=self.minion_id, minion_tgt=self.minion_id,
_timeout=timeout, _timeout=timeout,
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
def __enter__(self): def __enter__(self):
top_file_contents = """ top_file_contents = """
@ -244,15 +244,15 @@ def test_pillar_refresh_pillar_raw(salt_cli, salt_minion, key_pillar):
# We do not expect to see the pillar because it does not exist yet # We do not expect to see the pillar because it does not exist yet
ret = salt_cli.run("pillar.raw", key, minion_tgt=salt_minion.id) ret = salt_cli.run("pillar.raw", key, minion_tgt=salt_minion.id)
assert ret.exitcode == 0 assert ret.returncode == 0
val = ret.json val = ret.data
assert val == {} assert val == {}
with key_pillar(key) as key_pillar_instance: with key_pillar(key) as key_pillar_instance:
# The pillar exists now but raw reads it from in-memory pillars # The pillar exists now but raw reads it from in-memory pillars
ret = salt_cli.run("pillar.raw", key, minion_tgt=salt_minion.id) ret = salt_cli.run("pillar.raw", key, minion_tgt=salt_minion.id)
assert ret.exitcode == 0 assert ret.returncode == 0
val = ret.json val = ret.data
assert val == {} assert val == {}
# Calling refresh_pillar to update in-memory pillars # Calling refresh_pillar to update in-memory pillars
@ -260,8 +260,8 @@ def test_pillar_refresh_pillar_raw(salt_cli, salt_minion, key_pillar):
# The pillar can now be read from in-memory pillars # The pillar can now be read from in-memory pillars
ret = salt_cli.run("pillar.raw", key, minion_tgt=salt_minion.id) ret = salt_cli.run("pillar.raw", key, minion_tgt=salt_minion.id)
assert ret.exitcode == 0 assert ret.returncode == 0
val = ret.json val = ret.data
assert val is True, repr(val) assert val is True, repr(val)
@ -274,16 +274,16 @@ def test_pillar_refresh_pillar_get(salt_cli, salt_minion, key_pillar):
# We do not expect to see the pillar because it does not exist yet # We do not expect to see the pillar because it does not exist yet
ret = salt_cli.run("pillar.get", key, minion_tgt=salt_minion.id) ret = salt_cli.run("pillar.get", key, minion_tgt=salt_minion.id)
assert ret.exitcode == 0 assert ret.returncode == 0
val = ret.json val = ret.data
assert val == "" assert val == ""
with key_pillar(key) as key_pillar_instance: with key_pillar(key) as key_pillar_instance:
# The pillar exists now but get reads it from in-memory pillars, no # The pillar exists now but get reads it from in-memory pillars, no
# refresh happens # refresh happens
ret = salt_cli.run("pillar.get", key, minion_tgt=salt_minion.id) ret = salt_cli.run("pillar.get", key, minion_tgt=salt_minion.id)
assert ret.exitcode == 0 assert ret.returncode == 0
val = ret.json val = ret.data
assert val == "" assert val == ""
# Calling refresh_pillar to update in-memory pillars # Calling refresh_pillar to update in-memory pillars
@ -291,8 +291,8 @@ def test_pillar_refresh_pillar_get(salt_cli, salt_minion, key_pillar):
# The pillar can now be read from in-memory pillars # The pillar can now be read from in-memory pillars
ret = salt_cli.run("pillar.get", key, minion_tgt=salt_minion.id) ret = salt_cli.run("pillar.get", key, minion_tgt=salt_minion.id)
assert ret.exitcode == 0 assert ret.returncode == 0
val = ret.json val = ret.data
assert val is True, repr(val) assert val is True, repr(val)
@ -305,8 +305,8 @@ def test_pillar_refresh_pillar_item(salt_cli, salt_minion, key_pillar):
# We do not expect to see the pillar because it does not exist yet # We do not expect to see the pillar because it does not exist yet
ret = salt_cli.run("pillar.item", key, minion_tgt=salt_minion.id) ret = salt_cli.run("pillar.item", key, minion_tgt=salt_minion.id)
assert ret.exitcode == 0 assert ret.returncode == 0
val = ret.json val = ret.data
assert key in val assert key in val
assert val[key] == "" assert val[key] == ""
@ -314,8 +314,8 @@ def test_pillar_refresh_pillar_item(salt_cli, salt_minion, key_pillar):
# The pillar exists now but get reads it from in-memory pillars, no # The pillar exists now but get reads it from in-memory pillars, no
# refresh happens # refresh happens
ret = salt_cli.run("pillar.item", key, minion_tgt=salt_minion.id) ret = salt_cli.run("pillar.item", key, minion_tgt=salt_minion.id)
assert ret.exitcode == 0 assert ret.returncode == 0
val = ret.json val = ret.data
assert key in val assert key in val
assert val[key] == "" assert val[key] == ""
@ -324,8 +324,8 @@ def test_pillar_refresh_pillar_item(salt_cli, salt_minion, key_pillar):
# The pillar can now be read from in-memory pillars # The pillar can now be read from in-memory pillars
ret = salt_cli.run("pillar.item", key, minion_tgt=salt_minion.id) ret = salt_cli.run("pillar.item", key, minion_tgt=salt_minion.id)
assert ret.exitcode == 0 assert ret.returncode == 0
val = ret.json val = ret.data
assert key in val assert key in val
assert val[key] is True assert val[key] is True
@ -339,16 +339,16 @@ def test_pillar_refresh_pillar_items(salt_cli, salt_minion, key_pillar):
# We do not expect to see the pillar because it does not exist yet # We do not expect to see the pillar because it does not exist yet
ret = salt_cli.run("pillar.items", minion_tgt=salt_minion.id) ret = salt_cli.run("pillar.items", minion_tgt=salt_minion.id)
assert ret.exitcode == 0 assert ret.returncode == 0
val = ret.json val = ret.data
assert key not in val assert key not in val
with key_pillar(key) as key_pillar_instance: with key_pillar(key) as key_pillar_instance:
# A pillar.items call sees the pillar right away because a # A pillar.items call sees the pillar right away because a
# refresh_pillar event is fired. # refresh_pillar event is fired.
ret = salt_cli.run("pillar.items", minion_tgt=salt_minion.id) ret = salt_cli.run("pillar.items", minion_tgt=salt_minion.id)
assert ret.exitcode == 0 assert ret.returncode == 0
val = ret.json val = ret.data
assert key in val assert key in val
assert val[key] is True assert val[key] is True
@ -364,22 +364,22 @@ def test_pillar_refresh_pillar_ping(salt_cli, salt_minion, key_pillar):
# We do not expect to see the pillar because it does not exist yet # We do not expect to see the pillar because it does not exist yet
ret = salt_cli.run("pillar.item", key, minion_tgt=salt_minion.id) ret = salt_cli.run("pillar.item", key, minion_tgt=salt_minion.id)
assert ret.exitcode == 0 assert ret.returncode == 0
val = ret.json val = ret.data
assert key in val assert key in val
assert val[key] == "" assert val[key] == ""
with key_pillar(key) as key_pillar_instance: with key_pillar(key) as key_pillar_instance:
ret = salt_cli.run("test.ping", minion_tgt=salt_minion.id) ret = salt_cli.run("test.ping", minion_tgt=salt_minion.id)
assert ret.exitcode == 0 assert ret.returncode == 0
val = ret.json val = ret.data
assert val is True assert val is True
# The pillar exists now but get reads it from in-memory pillars, no # The pillar exists now but get reads it from in-memory pillars, no
# refresh happens # refresh happens
ret = salt_cli.run("pillar.item", key, minion_tgt=salt_minion.id) ret = salt_cli.run("pillar.item", key, minion_tgt=salt_minion.id)
assert ret.exitcode == 0 assert ret.returncode == 0
val = ret.json val = ret.data
assert key in val assert key in val
assert val[key] == "" assert val[key] == ""
@ -388,8 +388,8 @@ def test_pillar_refresh_pillar_ping(salt_cli, salt_minion, key_pillar):
# The pillar can now be read from in-memory pillars # The pillar can now be read from in-memory pillars
ret = salt_cli.run("pillar.item", key, minion_tgt=salt_minion.id) ret = salt_cli.run("pillar.item", key, minion_tgt=salt_minion.id)
assert ret.exitcode == 0 assert ret.returncode == 0
val = ret.json val = ret.data
assert key in val assert key in val
assert val[key] is True assert val[key] is True
@ -440,8 +440,8 @@ def test_pillar_refresh_pillar_scheduler(salt_master, salt_cli, salt_minion):
ret = salt_cli.run( ret = salt_cli.run(
"schedule.job_status", name="first_test_ping", minion_tgt=salt_minion.id "schedule.job_status", name="first_test_ping", minion_tgt=salt_minion.id
) )
assert "_next_fire_time" in ret.json assert "_next_fire_time" in ret.data
_next_fire_time = ret.json["_next_fire_time"] _next_fire_time = ret.data["_next_fire_time"]
# Refresh pillar # Refresh pillar
salt_cli.run( salt_cli.run(
@ -452,7 +452,7 @@ def test_pillar_refresh_pillar_scheduler(salt_master, salt_cli, salt_minion):
ret = salt_cli.run( ret = salt_cli.run(
"schedule.job_status", name="first_test_ping", minion_tgt=salt_minion.id "schedule.job_status", name="first_test_ping", minion_tgt=salt_minion.id
) )
assert ret.json["_next_fire_time"] == _next_fire_time assert ret.data["_next_fire_time"] == _next_fire_time
# Ensure job was replaced when seconds changes # Ensure job was replaced when seconds changes
with salt_master.pillar_tree.base.temp_file( with salt_master.pillar_tree.base.temp_file(
@ -469,8 +469,8 @@ def test_pillar_refresh_pillar_scheduler(salt_master, salt_cli, salt_minion):
ret = salt_cli.run( ret = salt_cli.run(
"schedule.job_status", name="first_test_ping", minion_tgt=salt_minion.id "schedule.job_status", name="first_test_ping", minion_tgt=salt_minion.id
) )
assert "_next_fire_time" in ret.json assert "_next_fire_time" in ret.data
_next_fire_time = ret.json["_next_fire_time"] _next_fire_time = ret.data["_next_fire_time"]
salt_cli.run( salt_cli.run(
"saltutil.refresh_pillar", wait=True, minion_tgt=salt_minion.id "saltutil.refresh_pillar", wait=True, minion_tgt=salt_minion.id
@ -479,7 +479,7 @@ def test_pillar_refresh_pillar_scheduler(salt_master, salt_cli, salt_minion):
ret = salt_cli.run( ret = salt_cli.run(
"schedule.job_status", name="first_test_ping", minion_tgt=salt_minion.id "schedule.job_status", name="first_test_ping", minion_tgt=salt_minion.id
) )
assert ret.json["_next_fire_time"] == _next_fire_time assert ret.data["_next_fire_time"] == _next_fire_time
# Refresh pillar once we're done # Refresh pillar once we're done
salt_cli.run("saltutil.refresh_pillar", wait=True, minion_tgt=salt_minion.id) salt_cli.run("saltutil.refresh_pillar", wait=True, minion_tgt=salt_minion.id)
@ -563,19 +563,19 @@ def test_pillar_match_filter_by_minion_id(
# Get the Minion's Pillar # Get the Minion's Pillar
ret = salt_cli.run("pillar.get", "roles", minion_tgt=salt_minion.id) ret = salt_cli.run("pillar.get", "roles", minion_tgt=salt_minion.id)
if app: if app:
assert "app" in ret.json assert "app" in ret.data
else: else:
assert "app" not in ret.json assert "app" not in ret.data
if caching: if caching:
assert "caching" in ret.json assert "caching" in ret.data
else: else:
assert "caching" not in ret.json assert "caching" not in ret.data
if db: if db:
assert "db" in ret.json assert "db" in ret.data
else: else:
assert "db" not in ret.json assert "db" not in ret.data
# Refresh pillar once we're done # Refresh pillar once we're done
salt_cli.run("saltutil.refresh_pillar", wait=True, minion_tgt=salt_minion.id) salt_cli.run("saltutil.refresh_pillar", wait=True, minion_tgt=salt_minion.id)
@ -587,4 +587,4 @@ def test_pillar_ext_59975(salt_call_cli):
pillar.ext returns result. Issue #59975 pillar.ext returns result. Issue #59975
""" """
ret = salt_call_cli.run("pillar.ext", '{"libvert": _}') ret = salt_call_cli.run("pillar.ext", '{"libvert": _}')
assert "ext_pillar_opts" in ret.json assert "ext_pillar_opts" in ret.data

View file

@ -187,14 +187,14 @@ def pillar_tree(base_env_pillar_tree_root_dir, salt_minion, salt_call_cli):
try: try:
with top_tempfile, packaging_tempfile: with top_tempfile, packaging_tempfile:
ret = salt_call_cli.run("saltutil.refresh_pillar", wait=True) ret = salt_call_cli.run("saltutil.refresh_pillar", wait=True)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
yield yield
finally: finally:
# Refresh pillar again to cleaup the temp pillar # Refresh pillar again to cleaup the temp pillar
ret = salt_call_cli.run("saltutil.refresh_pillar", wait=True) ret = salt_call_cli.run("saltutil.refresh_pillar", wait=True)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
def _testrpm_signed(abs_path_named_rpm): def _testrpm_signed(abs_path_named_rpm):
@ -360,9 +360,9 @@ def test_make_repo(grains, gpghome, repodir, gpg_agent, salt_call_cli, pillar_tr
) )
ret = salt_call_cli.run("pillar.data") ret = salt_call_cli.run("pillar.data")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
pillar = ret.json pillar = ret.data
assert pillar["gpg_passphrase"] == GPG_TEST_KEY_PASSPHRASE assert pillar["gpg_passphrase"] == GPG_TEST_KEY_PASSPHRASE
assert pillar["gpg_pkg_pub_keyname"] == "gpg_pkg_key.pub" assert pillar["gpg_pkg_pub_keyname"] == "gpg_pkg_key.pub"
@ -377,8 +377,8 @@ def test_make_repo(grains, gpghome, repodir, gpg_agent, salt_call_cli, pillar_tr
runas="root", runas="root",
timeout=15.0, timeout=15.0,
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
test_rpm_path = repodir / REPO_NAMED_RPM test_rpm_path = repodir / REPO_NAMED_RPM
assert _testrpm_signed(test_rpm_path) assert _testrpm_signed(test_rpm_path)

View file

@ -2,7 +2,8 @@
Integration tests for modules/useradd.py and modules/win_useradd.py Integration tests for modules/useradd.py and modules/win_useradd.py
""" """
import pytest import pytest
from tests.support.helpers import random_string, requires_system_grains from saltfactories.utils import random_string
from tests.support.helpers import requires_system_grains
pytestmark = [ pytestmark = [
pytest.mark.windows_whitelisted, pytest.mark.windows_whitelisted,
@ -31,7 +32,7 @@ def test_groups_includes_primary(setup_teardown_vars, grains, salt_call_cli):
# name # name
uname = random_string("RS-", lowercase=False) uname = random_string("RS-", lowercase=False)
ret = salt_call_cli.run("user.add", uname) ret = salt_call_cli.run("user.add", uname)
if ret.json is False: if ret.data is False:
# Skip because creating is not what we're testing here # Skip because creating is not what we're testing here
salt_call_cli.run("user.delete", [uname, True, True]) salt_call_cli.run("user.delete", [uname, True, True])
pytest.skip("Failed to create user") pytest.skip("Failed to create user")
@ -39,34 +40,34 @@ def test_groups_includes_primary(setup_teardown_vars, grains, salt_call_cli):
try: try:
uinfo = salt_call_cli.run("user.info", uname) uinfo = salt_call_cli.run("user.info", uname)
if grains["os_family"] in ("Suse",): if grains["os_family"] in ("Suse",):
assert "users" in uinfo.json["groups"] assert "users" in uinfo.data["groups"]
else: else:
assert uname in uinfo.json["groups"] assert uname in uinfo.data["groups"]
# This uid is available, store it # This uid is available, store it
uid = uinfo.json["uid"] uid = uinfo.data["uid"]
salt_call_cli.run("user.delete", uname, True, True) salt_call_cli.run("user.delete", uname, True, True)
# Now, a weird group id # Now, a weird group id
gname = random_string("RS-", lowercase=False) gname = random_string("RS-", lowercase=False)
ret = salt_call_cli.run("group.add", gname) ret = salt_call_cli.run("group.add", gname)
if ret.json is False: if ret.data is False:
salt_call_cli.run("group.delete", gname, True, True) salt_call_cli.run("group.delete", gname, True, True)
pytest.skip("Failed to create group") pytest.skip("Failed to create group")
ginfo = salt_call_cli.run("group.info", gname) ginfo = salt_call_cli.run("group.info", gname)
ginfo = ginfo.json ginfo = ginfo.data
# And create the user with that gid # And create the user with that gid
ret = salt_call_cli.run("user.add", uname, uid, ginfo["gid"]) ret = salt_call_cli.run("user.add", uname, uid, ginfo["gid"])
if ret.json is False: if ret.data is False:
# Skip because creating is not what we're testing here # Skip because creating is not what we're testing here
salt_call_cli.run("user.delete", [uname, True, True]) salt_call_cli.run("user.delete", [uname, True, True])
pytest.skip("Failed to create user") pytest.skip("Failed to create user")
uinfo = salt_call_cli.run("user.info", uname) uinfo = salt_call_cli.run("user.info", uname)
assert gname in uinfo.json["groups"] assert gname in uinfo.data["groups"]
except AssertionError: except AssertionError:
pytest.raises(salt_call_cli.run("user.delete", [uname, True, True])) pytest.raises(salt_call_cli.run("user.delete", [uname, True, True]))
@ -83,14 +84,14 @@ def test_user_primary_group(setup_teardown_vars, salt_call_cli):
# Create a user to test primary group function # Create a user to test primary group function
ret = salt_call_cli.run("user.add", name) ret = salt_call_cli.run("user.add", name)
if ret.json is False: if ret.data is False:
salt_call_cli.run("user.delete", name) salt_call_cli.run("user.delete", name)
pytest.skip("Failed to create a user") pytest.skip("Failed to create a user")
# Test useradd.primary_group # Test useradd.primary_group
primary_group = salt_call_cli.run("user.primary_group", name) primary_group = salt_call_cli.run("user.primary_group", name)
uid_info = salt_call_cli.run("user.info", name) uid_info = salt_call_cli.run("user.info", name)
assert primary_group.json in uid_info.json["groups"] assert primary_group.data in uid_info.data["groups"]
@pytest.mark.skip_unless_on_windows(reason="Test is only applicable to Windows.") @pytest.mark.skip_unless_on_windows(reason="Test is only applicable to Windows.")
@ -102,7 +103,7 @@ def test_add_user(setup_teardown_vars, salt_call_cli):
user_name = setup_teardown_vars[0] user_name = setup_teardown_vars[0]
salt_call_cli.run("user.add", user_name) salt_call_cli.run("user.add", user_name)
user_add = salt_call_cli.run("user.list_users") user_add = salt_call_cli.run("user.list_users")
assert user_name in user_add.json assert user_name in user_add.data
@pytest.mark.skip_unless_on_windows(reason="Test is only applicable to Windows.") @pytest.mark.skip_unless_on_windows(reason="Test is only applicable to Windows.")
@ -114,7 +115,7 @@ def test_add_group(setup_teardown_vars, salt_call_cli):
group_name = setup_teardown_vars[1] group_name = setup_teardown_vars[1]
salt_call_cli.run("group.add", group_name) salt_call_cli.run("group.add", group_name)
group_list = salt_call_cli.run("group.list_groups") group_list = salt_call_cli.run("group.list_groups")
assert group_name in group_list.json assert group_name in group_list.data
@pytest.mark.skip_unless_on_windows(reason="Test is only applicable to Windows.") @pytest.mark.skip_unless_on_windows(reason="Test is only applicable to Windows.")
@ -131,7 +132,7 @@ def test_add_user_to_group(setup_teardown_vars, salt_call_cli):
salt_call_cli.run("user.add", user_name, groups=group_name) salt_call_cli.run("user.add", user_name, groups=group_name)
user_info = salt_call_cli.run("user.info", user_name) user_info = salt_call_cli.run("user.info", user_name)
assert group_name in user_info.json["groups"] assert group_name in user_info.data["groups"]
@pytest.mark.skip_unless_on_windows(reason="Test is only applicable to Windows.") @pytest.mark.skip_unless_on_windows(reason="Test is only applicable to Windows.")
@ -148,7 +149,7 @@ def test_add_user_addgroup(setup_teardown_vars, salt_call_cli):
salt_call_cli.run("user.addgroup", user_name, group_name) salt_call_cli.run("user.addgroup", user_name, group_name)
info = salt_call_cli.run("user.info", user_name) info = salt_call_cli.run("user.info", user_name)
assert [group_name] == info.json["groups"] assert [group_name] == info.data["groups"]
@pytest.mark.skip_unless_on_windows(reason="Test is only applicable to Windows.") @pytest.mark.skip_unless_on_windows(reason="Test is only applicable to Windows.")
@ -163,7 +164,7 @@ def test_user_chhome(setup_teardown_vars, salt_call_cli):
salt_call_cli.run("user.chhome", user_name, user_dir) salt_call_cli.run("user.chhome", user_name, user_dir)
info = salt_call_cli.run("user.info", user_name) info = salt_call_cli.run("user.info", user_name)
assert user_dir == info.json["home"] assert user_dir == info.data["home"]
@pytest.mark.skip_unless_on_windows(reason="Test is only applicable to Windows.") @pytest.mark.skip_unless_on_windows(reason="Test is only applicable to Windows.")
@ -178,7 +179,7 @@ def test_user_chprofile(setup_teardown_vars, salt_call_cli):
salt_call_cli.run("user.chprofile", user_name, config) salt_call_cli.run("user.chprofile", user_name, config)
info = salt_call_cli.run("user.info", user_name) info = salt_call_cli.run("user.info", user_name)
assert config == info.json["profile"] assert config == info.data["profile"]
@pytest.mark.skip_unless_on_windows(reason="Test is only applicable to Windows.") @pytest.mark.skip_unless_on_windows(reason="Test is only applicable to Windows.")
@ -193,7 +194,7 @@ def test_user_chfullname(setup_teardown_vars, salt_call_cli):
salt_call_cli.run("user.chfullname", user_name, name) salt_call_cli.run("user.chfullname", user_name, name)
info = salt_call_cli.run("user.info", user_name) info = salt_call_cli.run("user.info", user_name)
assert name == info.json["fullname"] assert name == info.data["fullname"]
@pytest.mark.skip_unless_on_windows(reason="Test is only applicable to Windows.") @pytest.mark.skip_unless_on_windows(reason="Test is only applicable to Windows.")
@ -206,7 +207,7 @@ def test_user_delete(setup_teardown_vars, salt_call_cli):
salt_call_cli.run("user.add", user_name) salt_call_cli.run("user.add", user_name)
salt_call_cli.run("user.delete", user_name) salt_call_cli.run("user.delete", user_name)
ret = salt_call_cli.run("user.info", user_name) ret = salt_call_cli.run("user.info", user_name)
assert {} == ret.json assert {} == ret.data
@pytest.mark.skip_unless_on_windows(reason="Test is only applicable to Windows.") @pytest.mark.skip_unless_on_windows(reason="Test is only applicable to Windows.")
@ -223,11 +224,11 @@ def test_user_removegroup(setup_teardown_vars, salt_call_cli):
salt_call_cli.run("user.addgroup", user_name, group_name) salt_call_cli.run("user.addgroup", user_name, group_name)
ret = salt_call_cli.run("user.list_groups", user_name) ret = salt_call_cli.run("user.list_groups", user_name)
assert [group_name] == ret.json assert [group_name] == ret.data
salt_call_cli.run("user.removegroup", user_name, group_name) salt_call_cli.run("user.removegroup", user_name, group_name)
ret = salt_call_cli.run("user.list_groups", user_name) ret = salt_call_cli.run("user.list_groups", user_name)
assert [group_name] not in ret.json assert [group_name] not in ret.data
@pytest.mark.skip_unless_on_windows(reason="Test is only applicable to Windows.") @pytest.mark.skip_unless_on_windows(reason="Test is only applicable to Windows.")
@ -243,7 +244,7 @@ def test_user_rename(setup_teardown_vars, salt_call_cli):
salt_call_cli.run("user.rename", user_name, name) salt_call_cli.run("user.rename", user_name, name)
info = salt_call_cli.run("user.info", name) info = salt_call_cli.run("user.info", name)
assert info.json["active"] is True assert info.data["active"] is True
@pytest.mark.skip_unless_on_windows(reason="Test is only applicable to Windows.") @pytest.mark.skip_unless_on_windows(reason="Test is only applicable to Windows.")
@ -257,7 +258,7 @@ def test_user_setpassword(setup_teardown_vars, salt_call_cli):
salt_call_cli.run("user.add", user_name) salt_call_cli.run("user.add", user_name)
ret = salt_call_cli.run("user.setpassword", user_name, passwd) ret = salt_call_cli.run("user.setpassword", user_name, passwd)
assert ret.json is True assert ret.data is True
@pytest.mark.skip_unless_on_windows(reason="Test is only applicable to Windows.") @pytest.mark.skip_unless_on_windows(reason="Test is only applicable to Windows.")
@ -276,7 +277,7 @@ def test_user_setpassword_policy(setup_teardown_vars, salt_call_cli):
# fix the policy and store the previous strerror in ret to cleanup # fix the policy and store the previous strerror in ret to cleanup
salt_call_cli.run("lgpo.set", "computer_policy={'Minimum Password Length': 0}") salt_call_cli.run("lgpo.set", "computer_policy={'Minimum Password Length': 0}")
assert ( assert (
ret.json == "The password does not meet the password policy requirements." ret.data == "The password does not meet the password policy requirements."
" Check the minimum password length, password complexity and" " Check the minimum password length, password complexity and"
" password history requirements." " password history requirements."
) )

View file

@ -183,8 +183,8 @@ class TestVirtTest:
Test virt.get_profiles with the KVM profile Test virt.get_profiles with the KVM profile
""" """
ret = salt_cli.run("virt.get_profiles", "kvm", minion_tgt=virt_minion_0.id) ret = salt_cli.run("virt.get_profiles", "kvm", minion_tgt=virt_minion_0.id)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
profiles = ret.json profiles = ret.data
assert isinstance(profiles, dict) assert isinstance(profiles, dict)
nic = profiles["nic"]["default"][0] nic = profiles["nic"]["default"][0]
disk = profiles["disk"]["default"][0] disk = profiles["disk"]["default"][0]
@ -203,8 +203,8 @@ class TestVirtTest:
Test virt.get_profiles with the VMware profile Test virt.get_profiles with the VMware profile
""" """
ret = salt_cli.run("virt.get_profiles", "vmware", minion_tgt=virt_minion_0.id) ret = salt_cli.run("virt.get_profiles", "vmware", minion_tgt=virt_minion_0.id)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
profiles = ret.json profiles = ret.data
assert isinstance(profiles, dict) assert isinstance(profiles, dict)
nic = profiles["nic"]["default"][0] nic = profiles["nic"]["default"][0]
disk = profiles["disk"]["default"][0] disk = profiles["disk"]["default"][0]
@ -224,8 +224,8 @@ class TestVirtTest:
Test virt.get_profiles with the XEN profile Test virt.get_profiles with the XEN profile
""" """
ret = salt_cli.run("virt.get_profiles", "xen", minion_tgt=virt_minion_0.id) ret = salt_cli.run("virt.get_profiles", "xen", minion_tgt=virt_minion_0.id)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
profiles = ret.json profiles = ret.data
assert isinstance(profiles, dict) assert isinstance(profiles, dict)
nic = profiles["nic"]["default"][0] nic = profiles["nic"]["default"][0]
disk = profiles["disk"]["default"][0] disk = profiles["disk"]["default"][0]
@ -244,8 +244,8 @@ class TestVirtTest:
Test virt.get_profiles with the Bhyve profile Test virt.get_profiles with the Bhyve profile
""" """
ret = salt_cli.run("virt.get_profiles", "bhyve", minion_tgt=virt_minion_0.id) ret = salt_cli.run("virt.get_profiles", "bhyve", minion_tgt=virt_minion_0.id)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
profiles = ret.json profiles = ret.data
assert isinstance(profiles, dict) assert isinstance(profiles, dict)
nic = profiles["nic"]["default"][0] nic = profiles["nic"]["default"][0]
disk = profiles["disk"]["default"][0] disk = profiles["disk"]["default"][0]
@ -266,8 +266,8 @@ class TestVirtTest:
Test virt.all_capabilities Test virt.all_capabilities
""" """
ret = salt_cli.run("virt.all_capabilities", minion_tgt=virt_minion_0.id) ret = salt_cli.run("virt.all_capabilities", minion_tgt=virt_minion_0.id)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
caps = ret.json caps = ret.data
assert isinstance(caps, dict) assert isinstance(caps, dict)
assert isinstance(caps["host"]["host"]["uuid"], str) assert isinstance(caps["host"]["host"]["uuid"], str)
assert len(caps["host"]["host"]["uuid"]) == 36 assert len(caps["host"]["host"]["uuid"]) == 36
@ -278,8 +278,8 @@ class TestVirtTest:
Test virt.capabilities Test virt.capabilities
""" """
ret = salt_cli.run("virt.capabilities", minion_tgt=virt_minion_0.id) ret = salt_cli.run("virt.capabilities", minion_tgt=virt_minion_0.id)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
caps = ret.json caps = ret.data
assert isinstance(caps, dict) assert isinstance(caps, dict)
assert isinstance(caps["host"]["uuid"], str) assert isinstance(caps["host"]["uuid"], str)
assert len(caps["host"]["uuid"]) == 36 assert len(caps["host"]["uuid"]) == 36
@ -294,15 +294,15 @@ class TestVirtTest:
ret = salt_cli.run( ret = salt_cli.run(
"virt.cpu_baseline", out="libvirt", minion_tgt=virt_minion_0.id "virt.cpu_baseline", out="libvirt", minion_tgt=virt_minion_0.id
) )
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
cpu_baseline = ret.json cpu_baseline = ret.data
assert isinstance(cpu_baseline, str) assert isinstance(cpu_baseline, str)
cpu_baseline = ElementTree.fromstring(cpu_baseline) cpu_baseline = ElementTree.fromstring(cpu_baseline)
assert cpu_baseline.find("vendor").text in vendors assert cpu_baseline.find("vendor").text in vendors
ret = salt_cli.run("virt.cpu_baseline", out="salt", minion_tgt=virt_minion_0.id) ret = salt_cli.run("virt.cpu_baseline", out="salt", minion_tgt=virt_minion_0.id)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
cpu_baseline = ret.json cpu_baseline = ret.data
assert isinstance(cpu_baseline, dict) assert isinstance(cpu_baseline, dict)
assert cpu_baseline["vendor"] in vendors assert cpu_baseline["vendor"] in vendors
@ -311,8 +311,8 @@ class TestVirtTest:
Test virt.freemem Test virt.freemem
""" """
ret = salt_cli.run("virt.freemem", minion_tgt=virt_minion_0.id) ret = salt_cli.run("virt.freemem", minion_tgt=virt_minion_0.id)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
available_memory = ret.json available_memory = ret.data
assert isinstance(available_memory, Number) assert isinstance(available_memory, Number)
assert available_memory > 0 assert available_memory > 0
@ -321,8 +321,8 @@ class TestVirtTest:
Test virt.freecpu Test virt.freecpu
""" """
ret = salt_cli.run("virt.freecpu", minion_tgt=virt_minion_0.id) ret = salt_cli.run("virt.freecpu", minion_tgt=virt_minion_0.id)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
available_cpus = ret.json available_cpus = ret.data
assert isinstance(available_cpus, Number) assert isinstance(available_cpus, Number)
assert available_cpus > 0 assert available_cpus > 0
@ -331,8 +331,8 @@ class TestVirtTest:
Test virt.full_info Test virt.full_info
""" """
ret = salt_cli.run("virt.full_info", minion_tgt=virt_minion_0.id) ret = salt_cli.run("virt.full_info", minion_tgt=virt_minion_0.id)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
info = ret.json info = ret.data
assert isinstance(info, dict) assert isinstance(info, dict)
assert isinstance(info["vm_info"], dict) assert isinstance(info["vm_info"], dict)
@ -355,8 +355,8 @@ class TestVirtTest:
Test virt.node_info Test virt.node_info
""" """
ret = salt_cli.run("virt.node_info", minion_tgt=virt_minion_0.id) ret = salt_cli.run("virt.node_info", minion_tgt=virt_minion_0.id)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
info = ret.json info = ret.data
assert isinstance(info, dict) assert isinstance(info, dict)
assert isinstance(info["cpucores"], Number) assert isinstance(info["cpucores"], Number)
assert isinstance(info["cpumhz"], Number) assert isinstance(info["cpumhz"], Number)
@ -377,14 +377,14 @@ def virt_domain():
def prep_virt(salt_cli, virt_minion_0, virt_minion_1, virt_domain): def prep_virt(salt_cli, virt_minion_0, virt_minion_1, virt_domain):
try: try:
ret = salt_cli.run("virt.list_domains", minion_tgt=virt_minion_0.id) ret = salt_cli.run("virt.list_domains", minion_tgt=virt_minion_0.id)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
domains = ret.json domains = ret.data
for domain in domains: for domain in domains:
salt_cli.run("virt.stop", virt_domain, minion_tgt=virt_minion_0.id) salt_cli.run("virt.stop", virt_domain, minion_tgt=virt_minion_0.id)
salt_cli.run("virt.undefine", virt_domain, minion_tgt=virt_minion_0.id) salt_cli.run("virt.undefine", virt_domain, minion_tgt=virt_minion_0.id)
ret = salt_cli.run("virt.list_domains", minion_tgt=virt_minion_1.id) ret = salt_cli.run("virt.list_domains", minion_tgt=virt_minion_1.id)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
domains = ret.json domains = ret.data
for domain in domains: for domain in domains:
salt_cli.run("virt.stop", virt_domain, minion_tgt=virt_minion_1.id) salt_cli.run("virt.stop", virt_domain, minion_tgt=virt_minion_1.id)
salt_cli.run("virt.undefine", virt_domain, minion_tgt=virt_minion_1.id) salt_cli.run("virt.undefine", virt_domain, minion_tgt=virt_minion_1.id)
@ -393,21 +393,21 @@ def prep_virt(salt_cli, virt_minion_0, virt_minion_1, virt_domain):
"/{}.xml".format(virt_domain), "/{}.xml".format(virt_domain),
minion_tgt=virt_minion_0.id, minion_tgt=virt_minion_0.id,
) )
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
ret = salt_cli.run("virt.start", virt_domain, minion_tgt=virt_minion_0.id) ret = salt_cli.run("virt.start", virt_domain, minion_tgt=virt_minion_0.id)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
# Run tests # Run tests
yield yield
finally: finally:
ret = salt_cli.run("virt.list_domains", minion_tgt=virt_minion_0.id) ret = salt_cli.run("virt.list_domains", minion_tgt=virt_minion_0.id)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
domains = ret.json domains = ret.data
for domain in domains: for domain in domains:
salt_cli.run("virt.stop", virt_domain, minion_tgt=virt_minion_0.id) salt_cli.run("virt.stop", virt_domain, minion_tgt=virt_minion_0.id)
salt_cli.run("virt.undefine", virt_domain, minion_tgt=virt_minion_0.id) salt_cli.run("virt.undefine", virt_domain, minion_tgt=virt_minion_0.id)
ret = salt_cli.run("virt.list_domains", minion_tgt=virt_minion_1.id) ret = salt_cli.run("virt.list_domains", minion_tgt=virt_minion_1.id)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
domains = ret.json domains = ret.data
for domain in domains: for domain in domains:
salt_cli.run("virt.stop", virt_domain, minion_tgt=virt_minion_1.id) salt_cli.run("virt.stop", virt_domain, minion_tgt=virt_minion_1.id)
salt_cli.run("virt.undefine", virt_domain, minion_tgt=virt_minion_1.id) salt_cli.run("virt.undefine", virt_domain, minion_tgt=virt_minion_1.id)
@ -428,26 +428,26 @@ class TestVirtMigrateTest:
"/{}.xml".format(virt_domain), "/{}.xml".format(virt_domain),
minion_tgt=virt_minion_0.id, minion_tgt=virt_minion_0.id,
) )
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
result = ret.json result = ret.data
assert isinstance(result, bool), result assert isinstance(result, bool), result
assert result is True, result assert result is True, result
ret = salt_cli.run("virt.list_domains", minion_tgt=virt_minion_0.id) ret = salt_cli.run("virt.list_domains", minion_tgt=virt_minion_0.id)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
domains = ret.json domains = ret.data
assert isinstance(domains, list) assert isinstance(domains, list)
assert domains == [virt_domain] assert domains == [virt_domain]
ret = salt_cli.run("virt.undefine", virt_domain, minion_tgt=virt_minion_0.id) ret = salt_cli.run("virt.undefine", virt_domain, minion_tgt=virt_minion_0.id)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
result = ret.json result = ret.data
assert isinstance(result, bool) assert isinstance(result, bool)
assert result is True assert result is True
ret = salt_cli.run("virt.list_domains", minion_tgt=virt_minion_0.id) ret = salt_cli.run("virt.list_domains", minion_tgt=virt_minion_0.id)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
domains = ret.json domains = ret.data
assert isinstance(domains, list) assert isinstance(domains, list)
assert domains == [] assert domains == []
@ -458,23 +458,23 @@ class TestVirtMigrateTest:
Test domain migration over SSH, TCP and TLS transport protocol Test domain migration over SSH, TCP and TLS transport protocol
""" """
ret = salt_cli.run("virt.list_active_vms", minion_tgt=virt_minion_0.id) ret = salt_cli.run("virt.list_active_vms", minion_tgt=virt_minion_0.id)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
ret = salt_cli.run("virt.list_active_vms", minion_tgt=virt_minion_1.id) ret = salt_cli.run("virt.list_active_vms", minion_tgt=virt_minion_1.id)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
ret = salt_cli.run("virt.vm_info", virt_domain, minion_tgt=virt_minion_0.id) ret = salt_cli.run("virt.vm_info", virt_domain, minion_tgt=virt_minion_0.id)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
# Verify that the VM has been created # Verify that the VM has been created
ret = salt_cli.run("virt.list_domains", minion_tgt=virt_minion_0.id) ret = salt_cli.run("virt.list_domains", minion_tgt=virt_minion_0.id)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
domains = ret.json domains = ret.data
assert isinstance(domains, list) assert isinstance(domains, list)
assert domains == [virt_domain] assert domains == [virt_domain]
ret = salt_cli.run("virt.list_domains", minion_tgt=virt_minion_1.id) ret = salt_cli.run("virt.list_domains", minion_tgt=virt_minion_1.id)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
domains = ret.json domains = ret.data
assert isinstance(domains, list) assert isinstance(domains, list)
assert domains == [] assert domains == []
@ -484,21 +484,21 @@ class TestVirtMigrateTest:
"qemu+ssh://{}/system".format(virt_minion_1.uri), "qemu+ssh://{}/system".format(virt_minion_1.uri),
minion_tgt=virt_minion_0.id, minion_tgt=virt_minion_0.id,
) )
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
result = ret.json result = ret.data
assert isinstance(result, bool) assert isinstance(result, bool)
assert result is True assert result is True
# Verify that the VM has been migrated # Verify that the VM has been migrated
ret = salt_cli.run("virt.list_domains", minion_tgt=virt_minion_0.id) ret = salt_cli.run("virt.list_domains", minion_tgt=virt_minion_0.id)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
domains = ret.json domains = ret.data
assert isinstance(domains, list) assert isinstance(domains, list)
assert domains == [], "Failed to migrate VM" assert domains == [], "Failed to migrate VM"
ret = salt_cli.run("virt.list_domains", minion_tgt=virt_minion_1.id) ret = salt_cli.run("virt.list_domains", minion_tgt=virt_minion_1.id)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
domains = ret.json domains = ret.data
assert isinstance(domains, list) assert isinstance(domains, list)
assert domains == [virt_domain], "Failed to migrate VM" assert domains == [virt_domain], "Failed to migrate VM"
@ -510,14 +510,14 @@ class TestVirtMigrateTest:
""" """
# Verify that the VM has been created # Verify that the VM has been created
ret = salt_cli.run("virt.list_domains", minion_tgt=virt_minion_0.id) ret = salt_cli.run("virt.list_domains", minion_tgt=virt_minion_0.id)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
domains = ret.json domains = ret.data
assert isinstance(domains, list) assert isinstance(domains, list)
assert domains == [virt_domain] assert domains == [virt_domain]
ret = salt_cli.run("virt.list_domains", minion_tgt=virt_minion_1.id) ret = salt_cli.run("virt.list_domains", minion_tgt=virt_minion_1.id)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
domains = ret.json domains = ret.data
assert isinstance(domains, list) assert isinstance(domains, list)
assert domains == [] assert domains == []
@ -527,21 +527,21 @@ class TestVirtMigrateTest:
virt_minion_1.tcp_uri, virt_minion_1.tcp_uri,
minion_tgt=virt_minion_0.id, minion_tgt=virt_minion_0.id,
) )
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
result = ret.json result = ret.data
assert isinstance(result, bool) assert isinstance(result, bool)
assert result is True assert result is True
# Verify that the VM has been migrated # Verify that the VM has been migrated
ret = salt_cli.run("virt.list_domains", minion_tgt=virt_minion_0.id) ret = salt_cli.run("virt.list_domains", minion_tgt=virt_minion_0.id)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
domains = ret.json domains = ret.data
assert isinstance(domains, list) assert isinstance(domains, list)
assert domains == [], "Failed to migrate VM" assert domains == [], "Failed to migrate VM"
ret = salt_cli.run("virt.list_domains", minion_tgt=virt_minion_1.id) ret = salt_cli.run("virt.list_domains", minion_tgt=virt_minion_1.id)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
domains = ret.json domains = ret.data
assert isinstance(domains, list) assert isinstance(domains, list)
assert domains == [virt_domain], "Failed to migrate VM" assert domains == [virt_domain], "Failed to migrate VM"
@ -553,14 +553,14 @@ class TestVirtMigrateTest:
""" """
# Verify that the VM has been created # Verify that the VM has been created
ret = salt_cli.run("virt.list_domains", minion_tgt=virt_minion_0.id) ret = salt_cli.run("virt.list_domains", minion_tgt=virt_minion_0.id)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
domains = ret.json domains = ret.data
assert isinstance(domains, list) assert isinstance(domains, list)
assert domains == [virt_domain] assert domains == [virt_domain]
ret = salt_cli.run("virt.list_domains", minion_tgt=virt_minion_1.id) ret = salt_cli.run("virt.list_domains", minion_tgt=virt_minion_1.id)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
domains = ret.json domains = ret.data
assert isinstance(domains, list) assert isinstance(domains, list)
assert domains == [] assert domains == []
@ -570,20 +570,20 @@ class TestVirtMigrateTest:
virt_minion_1.tls_uri, virt_minion_1.tls_uri,
minion_tgt=virt_minion_0.id, minion_tgt=virt_minion_0.id,
) )
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
result = ret.json result = ret.data
assert isinstance(result, bool) assert isinstance(result, bool)
assert result is True assert result is True
# Verify that the VM has been migrated # Verify that the VM has been migrated
ret = salt_cli.run("virt.list_domains", minion_tgt=virt_minion_0.id) ret = salt_cli.run("virt.list_domains", minion_tgt=virt_minion_0.id)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
domains = ret.json domains = ret.data
assert isinstance(domains, list) assert isinstance(domains, list)
assert domains == [], "Failed to migrate VM" assert domains == [], "Failed to migrate VM"
ret = salt_cli.run("virt.list_domains", minion_tgt=virt_minion_1.id) ret = salt_cli.run("virt.list_domains", minion_tgt=virt_minion_1.id)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
domains = ret.json domains = ret.data
assert isinstance(domains, list) assert isinstance(domains, list)
assert domains == [virt_domain], "Failed to migrate VM" assert domains == [virt_domain], "Failed to migrate VM"

View file

@ -36,7 +36,7 @@ def pillar_salt_minion(pillar_salt_master):
# Sync All # Sync All
salt_call_cli = factory.salt_call_cli() salt_call_cli = factory.salt_call_cli()
ret = salt_call_cli.run("saltutil.sync_all", _timeout=120) ret = salt_call_cli.run("saltutil.sync_all", _timeout=120)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
yield factory yield factory

View file

@ -24,14 +24,14 @@ def pillar_cache_tree(pillar_state_tree, pillar_salt_minion, pillar_salt_call_cl
try: try:
with top_tempfile, pillar_tempfile: with top_tempfile, pillar_tempfile:
ret = pillar_salt_call_cli.run("saltutil.refresh_pillar", wait=True) ret = pillar_salt_call_cli.run("saltutil.refresh_pillar", wait=True)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
yield yield
finally: finally:
# Refresh pillar again to cleaup the temp pillar # Refresh pillar again to cleaup the temp pillar
ret = pillar_salt_call_cli.run("saltutil.refresh_pillar", wait=True) ret = pillar_salt_call_cli.run("saltutil.refresh_pillar", wait=True)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
@pytest.fixture() @pytest.fixture()
@ -68,8 +68,8 @@ def pillar_cache_tree_no_refresh(
finally: finally:
# Refresh pillar again to cleaup the temp pillar # Refresh pillar again to cleaup the temp pillar
ret = pillar_salt_call_cli.run("saltutil.refresh_pillar", wait=True) ret = pillar_salt_call_cli.run("saltutil.refresh_pillar", wait=True)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
def test_pillar_cache_refresh(pillar_cache_tree, pillar_salt_call_cli): def test_pillar_cache_refresh(pillar_cache_tree, pillar_salt_call_cli):
@ -77,10 +77,10 @@ def test_pillar_cache_refresh(pillar_cache_tree, pillar_salt_call_cli):
Test pillar cache updates after a refresh_pillar Test pillar cache updates after a refresh_pillar
""" """
ret = pillar_salt_call_cli.run("pillar.items") ret = pillar_salt_call_cli.run("pillar.items")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert "test" in ret.json assert "test" in ret.data
assert "test2" in ret.json assert "test2" in ret.data
def test_pillar_cache_items(pillar_cache_tree_no_refresh, pillar_salt_call_cli): def test_pillar_cache_items(pillar_cache_tree_no_refresh, pillar_salt_call_cli):
@ -88,11 +88,11 @@ def test_pillar_cache_items(pillar_cache_tree_no_refresh, pillar_salt_call_cli):
Test pillar cache does not refresh pillar when using pillar.items Test pillar cache does not refresh pillar when using pillar.items
""" """
# pillar.items should be empty # pillar.items should be empty
assert not pillar_salt_call_cli.run("pillar.items").json assert not pillar_salt_call_cli.run("pillar.items").data
pillar_salt_call_cli.run("saltutil.refresh_pillar", wait=True) pillar_salt_call_cli.run("saltutil.refresh_pillar", wait=True)
# pillar.items should contain the new pillar data # pillar.items should contain the new pillar data
ret = pillar_salt_call_cli.run("pillar.items") ret = pillar_salt_call_cli.run("pillar.items")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert "test" in ret.json assert "test" in ret.data
assert "test2" in ret.json assert "test2" in ret.data

View file

@ -86,14 +86,14 @@ def pillar_include_tree(base_env_pillar_tree_root_dir, salt_minion, salt_call_cl
with top_tempfile, include_tempfile, include_a_tempfile, include_b_tempfile, include_c_tempfile, include_d_tempfile: with top_tempfile, include_tempfile, include_a_tempfile, include_b_tempfile, include_c_tempfile, include_d_tempfile:
with glob_include_tempfile, glob_include_a_tempfile, glob_include_b_tempfile: with glob_include_tempfile, glob_include_a_tempfile, glob_include_b_tempfile:
ret = salt_call_cli.run("saltutil.refresh_pillar", wait=True) ret = salt_call_cli.run("saltutil.refresh_pillar", wait=True)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
yield yield
finally: finally:
# Refresh pillar again to cleaup the temp pillar # Refresh pillar again to cleaup the temp pillar
ret = salt_call_cli.run("saltutil.refresh_pillar", wait=True) ret = salt_call_cli.run("saltutil.refresh_pillar", wait=True)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
def test_pillar_include(pillar_include_tree, salt_call_cli): def test_pillar_include(pillar_include_tree, salt_call_cli):
@ -101,13 +101,13 @@ def test_pillar_include(pillar_include_tree, salt_call_cli):
Test pillar include Test pillar include
""" """
ret = salt_call_cli.run("pillar.items") ret = salt_call_cli.run("pillar.items")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert "element" in ret.json assert "element" in ret.data
assert "a" in ret.json["element"] assert "a" in ret.data["element"]
assert ret.json["element"]["a"] == {"a": ["Entry A"]} assert ret.data["element"]["a"] == {"a": ["Entry A"]}
assert "b" in ret.json["element"] assert "b" in ret.data["element"]
assert ret.json["element"]["b"] == {"b": ["Entry B"]} assert ret.data["element"]["b"] == {"b": ["Entry B"]}
def test_pillar_glob_include(pillar_include_tree, salt_call_cli): def test_pillar_glob_include(pillar_include_tree, salt_call_cli):
@ -115,12 +115,12 @@ def test_pillar_glob_include(pillar_include_tree, salt_call_cli):
Test pillar include via glob pattern Test pillar include via glob pattern
""" """
ret = salt_call_cli.run("pillar.items") ret = salt_call_cli.run("pillar.items")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert "glob-a" in ret.json assert "glob-a" in ret.data
assert ret.json["glob-a"] == ["Entry A"] assert ret.data["glob-a"] == ["Entry A"]
assert "glob-b" in ret.json assert "glob-b" in ret.data
assert ret.json["glob-b"] == ["Entry B"] assert ret.data["glob-b"] == ["Entry B"]
def test_pillar_include_already_included(pillar_include_tree, salt_call_cli): def test_pillar_include_already_included(pillar_include_tree, salt_call_cli):
@ -129,8 +129,8 @@ def test_pillar_include_already_included(pillar_include_tree, salt_call_cli):
has already been included. has already been included.
""" """
ret = salt_call_cli.run("pillar.items") ret = salt_call_cli.run("pillar.items")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert "element" in ret.json assert "element" in ret.data
assert "d" in ret.json["element"] assert "d" in ret.data["element"]
assert ret.json["element"]["d"] == {"c": ["Entry C"]} assert ret.data["element"]["d"] == {"c": ["Entry C"]}

View file

@ -4,13 +4,11 @@ Simple Smoke Tests for Connected Proxy Minion
import logging import logging
import pytest import pytest
import salt.utils.platform
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
pytestmark = [ pytestmark = [
pytest.mark.skipif( pytest.mark.skip_on_spawning_platform(
salt.utils.platform.spawning_platform(),
reason="Deltaproxy minions do not currently work on spawning platforms.", reason="Deltaproxy minions do not currently work on spawning platforms.",
) )
] ]
@ -32,7 +30,7 @@ def test_can_it_ping(salt_cli, proxy_id):
Ensure the proxy can ping Ensure the proxy can ping
""" """
ret = salt_cli.run("test.ping", minion_tgt=proxy_id) ret = salt_cli.run("test.ping", minion_tgt=proxy_id)
assert ret.json is True assert ret.data is True
def test_list_pkgs(salt_cli, proxy_id): def test_list_pkgs(salt_cli, proxy_id):
@ -41,9 +39,9 @@ def test_list_pkgs(salt_cli, proxy_id):
is working OK. is working OK.
""" """
ret = salt_cli.run("pkg.list_pkgs", minion_tgt=proxy_id) ret = salt_cli.run("pkg.list_pkgs", minion_tgt=proxy_id)
assert "coreutils" in ret.json assert "coreutils" in ret.data
assert "apache" in ret.json assert "apache" in ret.data
assert "redbull" in ret.json assert "redbull" in ret.data
def test_install_pkgs(salt_cli, proxy_id): def test_install_pkgs(salt_cli, proxy_id):
@ -53,53 +51,53 @@ def test_install_pkgs(salt_cli, proxy_id):
""" """
ret = salt_cli.run("pkg.install", "thispkg", minion_tgt=proxy_id) ret = salt_cli.run("pkg.install", "thispkg", minion_tgt=proxy_id)
assert ret.json["thispkg"] == "1.0" assert ret.data["thispkg"] == "1.0"
ret = salt_cli.run("pkg.list_pkgs", minion_tgt=proxy_id) ret = salt_cli.run("pkg.list_pkgs", minion_tgt=proxy_id)
assert ret.json["apache"] == "2.4" assert ret.data["apache"] == "2.4"
assert ret.json["redbull"] == "999.99" assert ret.data["redbull"] == "999.99"
assert ret.json["thispkg"] == "1.0" assert ret.data["thispkg"] == "1.0"
def test_remove_pkgs(salt_cli, proxy_id): def test_remove_pkgs(salt_cli, proxy_id):
ret = salt_cli.run("pkg.remove", "apache", minion_tgt=proxy_id) ret = salt_cli.run("pkg.remove", "apache", minion_tgt=proxy_id)
assert "apache" not in ret.json assert "apache" not in ret.data
def test_upgrade(salt_cli, proxy_id): def test_upgrade(salt_cli, proxy_id):
ret = salt_cli.run("pkg.upgrade", minion_tgt=proxy_id) ret = salt_cli.run("pkg.upgrade", minion_tgt=proxy_id)
assert ret.json["coreutils"]["new"] == "2.0" assert ret.data["coreutils"]["new"] == "2.0"
assert ret.json["redbull"]["new"] == "1000.99" assert ret.data["redbull"]["new"] == "1000.99"
def test_service_list(salt_cli, proxy_id): def test_service_list(salt_cli, proxy_id):
ret = salt_cli.run("service.list", minion_tgt=proxy_id) ret = salt_cli.run("service.list", minion_tgt=proxy_id)
assert "ntp" in ret.json assert "ntp" in ret.data
def test_service_stop(salt_cli, proxy_id): def test_service_stop(salt_cli, proxy_id):
ret = salt_cli.run("service.stop", "ntp", minion_tgt=proxy_id) ret = salt_cli.run("service.stop", "ntp", minion_tgt=proxy_id)
ret = salt_cli.run("service.status", "ntp", minion_tgt=proxy_id) ret = salt_cli.run("service.status", "ntp", minion_tgt=proxy_id)
assert ret.json is False assert ret.data is False
def test_service_start(salt_cli, proxy_id): def test_service_start(salt_cli, proxy_id):
ret = salt_cli.run("service.start", "samba", minion_tgt=proxy_id) ret = salt_cli.run("service.start", "samba", minion_tgt=proxy_id)
ret = salt_cli.run("service.status", "samba", minion_tgt=proxy_id) ret = salt_cli.run("service.status", "samba", minion_tgt=proxy_id)
assert ret.json is True assert ret.data is True
def test_service_get_all(salt_cli, proxy_id): def test_service_get_all(salt_cli, proxy_id):
ret = salt_cli.run("service.get_all", minion_tgt=proxy_id) ret = salt_cli.run("service.get_all", minion_tgt=proxy_id)
assert ret.json assert ret.data
assert "samba" in ret.json assert "samba" in ret.data
def test_grains_items(salt_cli, proxy_id): def test_grains_items(salt_cli, proxy_id):
ret = salt_cli.run("grains.items", minion_tgt=proxy_id) ret = salt_cli.run("grains.items", minion_tgt=proxy_id)
assert ret.json["kernel"] == "proxy" assert ret.data["kernel"] == "proxy"
assert ret.json["kernelrelease"] == "proxy" assert ret.data["kernelrelease"] == "proxy"
def test_state_apply(salt_master, salt_cli, tmp_path, proxy_id): def test_state_apply(salt_master, salt_cli, tmp_path, proxy_id):
@ -116,7 +114,7 @@ def test_state_apply(salt_master, salt_cli, tmp_path, proxy_id):
with salt_master.state_tree.base.temp_file("core.sls", core_state): with salt_master.state_tree.base.temp_file("core.sls", core_state):
ret = salt_cli.run("state.apply", "core", minion_tgt=proxy_id) ret = salt_cli.run("state.apply", "core", minion_tgt=proxy_id)
for value in ret.json.values(): for value in ret.data.values():
assert value["result"] is True assert value["result"] is True
@ -143,7 +141,7 @@ def test_state_highstate(salt_master, salt_cli, tmp_path, proxy_id):
"top.sls", top_sls "top.sls", top_sls
), salt_master.state_tree.base.temp_file("core.sls", core_state): ), salt_master.state_tree.base.temp_file("core.sls", core_state):
ret = salt_cli.run("state.highstate", minion_tgt=proxy_id) ret = salt_cli.run("state.highstate", minion_tgt=proxy_id)
for value in ret.json.values(): for value in ret.data.values():
assert value["result"] is True assert value["result"] is True

View file

@ -23,8 +23,8 @@ def test_can_it_ping(salt_call_cli):
Ensure the proxy can ping Ensure the proxy can ping
""" """
ret = salt_call_cli.run("test.ping") ret = salt_call_cli.run("test.ping")
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
assert ret.json is True assert ret.data is True
@pytest.mark.slow_test @pytest.mark.slow_test
@ -34,19 +34,19 @@ def test_list_pkgs(salt_call_cli):
is working OK. is working OK.
""" """
ret = salt_call_cli.run("pkg.list_pkgs") ret = salt_call_cli.run("pkg.list_pkgs")
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
for package_name in salt.proxy.dummy._initial_state()["packages"]: for package_name in salt.proxy.dummy._initial_state()["packages"]:
assert package_name in ret.json assert package_name in ret.data
@pytest.mark.slow_test @pytest.mark.slow_test
def test_upgrade(salt_call_cli): def test_upgrade(salt_call_cli):
ret = salt_call_cli.run("pkg.upgrade") ret = salt_call_cli.run("pkg.upgrade")
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
# Assert that something got upgraded # Assert that something got upgraded
assert ret.json assert ret.data
assert ret.json["coreutils"]["new"] == "2.0" assert ret.data["coreutils"]["new"] == "2.0"
assert ret.json["redbull"]["new"], "1000.99" assert ret.data["redbull"]["new"], "1000.99"
@pytest.fixture @pytest.fixture
@ -57,29 +57,29 @@ def service_name():
@pytest.mark.slow_test @pytest.mark.slow_test
def test_service_list(salt_call_cli, service_name): def test_service_list(salt_call_cli, service_name):
ret = salt_call_cli.run("service.list") ret = salt_call_cli.run("service.list")
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
assert service_name in ret.json assert service_name in ret.data
@pytest.mark.slow_test @pytest.mark.slow_test
def test_service_start(salt_call_cli): def test_service_start(salt_call_cli):
ret = salt_call_cli.run("service.start", "samba") ret = salt_call_cli.run("service.start", "samba")
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
ret = salt_call_cli.run("service.status", "samba") ret = salt_call_cli.run("service.status", "samba")
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
assert ret.json is True assert ret.data is True
@pytest.mark.slow_test @pytest.mark.slow_test
def test_service_get_all(salt_call_cli, service_name): def test_service_get_all(salt_call_cli, service_name):
ret = salt_call_cli.run("service.get_all") ret = salt_call_cli.run("service.get_all")
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
assert service_name in ret.json assert service_name in ret.data
@pytest.mark.slow_test @pytest.mark.slow_test
def test_grains_items(salt_call_cli): def test_grains_items(salt_call_cli):
ret = salt_call_cli.run("grains.items") ret = salt_call_cli.run("grains.items")
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
assert ret.json["kernel"] == "proxy" assert ret.data["kernel"] == "proxy"
assert ret.json["kernelrelease"] == "proxy" assert ret.data["kernelrelease"] == "proxy"

View file

@ -13,7 +13,7 @@ def test_can_it_ping(salt_cli, salt_proxy):
Ensure the proxy can ping Ensure the proxy can ping
""" """
ret = salt_cli.run("test.ping", minion_tgt=salt_proxy.id) ret = salt_cli.run("test.ping", minion_tgt=salt_proxy.id)
assert ret.json is True assert ret.data is True
def test_list_pkgs(salt_cli, salt_proxy): def test_list_pkgs(salt_cli, salt_proxy):
@ -22,9 +22,9 @@ def test_list_pkgs(salt_cli, salt_proxy):
is working OK. is working OK.
""" """
ret = salt_cli.run("pkg.list_pkgs", minion_tgt=salt_proxy.id) ret = salt_cli.run("pkg.list_pkgs", minion_tgt=salt_proxy.id)
assert "coreutils" in ret.json assert "coreutils" in ret.data
assert "apache" in ret.json assert "apache" in ret.data
assert "redbull" in ret.json assert "redbull" in ret.data
def test_install_pkgs(salt_cli, salt_proxy): def test_install_pkgs(salt_cli, salt_proxy):
@ -33,53 +33,53 @@ def test_install_pkgs(salt_cli, salt_proxy):
is working OK. is working OK.
""" """
ret = salt_cli.run("pkg.install", "thispkg", minion_tgt=salt_proxy.id) ret = salt_cli.run("pkg.install", "thispkg", minion_tgt=salt_proxy.id)
assert ret.json["thispkg"] == "1.0" assert ret.data["thispkg"] == "1.0"
ret = salt_cli.run("pkg.list_pkgs", minion_tgt=salt_proxy.id) ret = salt_cli.run("pkg.list_pkgs", minion_tgt=salt_proxy.id)
assert ret.json["apache"] == "2.4" assert ret.data["apache"] == "2.4"
assert ret.json["redbull"] == "999.99" assert ret.data["redbull"] == "999.99"
assert ret.json["thispkg"] == "1.0" assert ret.data["thispkg"] == "1.0"
def test_remove_pkgs(salt_cli, salt_proxy): def test_remove_pkgs(salt_cli, salt_proxy):
ret = salt_cli.run("pkg.remove", "apache", minion_tgt=salt_proxy.id) ret = salt_cli.run("pkg.remove", "apache", minion_tgt=salt_proxy.id)
assert "apache" not in ret.json assert "apache" not in ret.data
def test_upgrade(salt_cli, salt_proxy): def test_upgrade(salt_cli, salt_proxy):
ret = salt_cli.run("pkg.upgrade", minion_tgt=salt_proxy.id) ret = salt_cli.run("pkg.upgrade", minion_tgt=salt_proxy.id)
assert ret.json["coreutils"]["new"] == "2.0" assert ret.data["coreutils"]["new"] == "2.0"
assert ret.json["redbull"]["new"] == "1000.99" assert ret.data["redbull"]["new"] == "1000.99"
def test_service_list(salt_cli, salt_proxy): def test_service_list(salt_cli, salt_proxy):
ret = salt_cli.run("service.list", minion_tgt=salt_proxy.id) ret = salt_cli.run("service.list", minion_tgt=salt_proxy.id)
assert "ntp" in ret.json assert "ntp" in ret.data
def test_service_stop(salt_cli, salt_proxy): def test_service_stop(salt_cli, salt_proxy):
ret = salt_cli.run("service.stop", "ntp", minion_tgt=salt_proxy.id) ret = salt_cli.run("service.stop", "ntp", minion_tgt=salt_proxy.id)
ret = salt_cli.run("service.status", "ntp", minion_tgt=salt_proxy.id) ret = salt_cli.run("service.status", "ntp", minion_tgt=salt_proxy.id)
assert ret.json is False assert ret.data is False
def test_service_start(salt_cli, salt_proxy): def test_service_start(salt_cli, salt_proxy):
ret = salt_cli.run("service.start", "samba", minion_tgt=salt_proxy.id) ret = salt_cli.run("service.start", "samba", minion_tgt=salt_proxy.id)
ret = salt_cli.run("service.status", "samba", minion_tgt=salt_proxy.id) ret = salt_cli.run("service.status", "samba", minion_tgt=salt_proxy.id)
assert ret.json is True assert ret.data is True
def test_service_get_all(salt_cli, salt_proxy): def test_service_get_all(salt_cli, salt_proxy):
ret = salt_cli.run("service.get_all", minion_tgt=salt_proxy.id) ret = salt_cli.run("service.get_all", minion_tgt=salt_proxy.id)
assert ret.json assert ret.data
assert "samba" in ret.json assert "samba" in ret.data
def test_grains_items(salt_cli, salt_proxy): def test_grains_items(salt_cli, salt_proxy):
ret = salt_cli.run("grains.items", minion_tgt=salt_proxy.id) ret = salt_cli.run("grains.items", minion_tgt=salt_proxy.id)
assert ret.json["kernel"] == "proxy" assert ret.data["kernel"] == "proxy"
assert ret.json["kernelrelease"] == "proxy" assert ret.data["kernelrelease"] == "proxy"
def test_state_apply(salt_master, salt_cli, salt_proxy, tmp_path): def test_state_apply(salt_master, salt_cli, salt_proxy, tmp_path):
@ -96,7 +96,7 @@ def test_state_apply(salt_master, salt_cli, salt_proxy, tmp_path):
with salt_master.state_tree.base.temp_file("core.sls", core_state): with salt_master.state_tree.base.temp_file("core.sls", core_state):
ret = salt_cli.run("state.apply", "core", minion_tgt=salt_proxy.id) ret = salt_cli.run("state.apply", "core", minion_tgt=salt_proxy.id)
for value in ret.json.values(): for value in ret.data.values():
assert value["result"] is True assert value["result"] is True
@ -123,5 +123,5 @@ def test_state_highstate(salt_master, salt_cli, salt_proxy, tmp_path):
"top.sls", top_sls "top.sls", top_sls
), salt_master.state_tree.base.temp_file("core.sls", core_state): ), salt_master.state_tree.base.temp_file("core.sls", core_state):
ret = salt_cli.run("state.highstate", minion_tgt=salt_proxy.id) ret = salt_cli.run("state.highstate", minion_tgt=salt_proxy.id)
for value in ret.json.values(): for value in ret.data.values():
assert value["result"] is True assert value["result"] is True

View file

@ -118,21 +118,21 @@ def test_reactor_is_leader(
When leader is set to false reactor should timeout/not do anything. When leader is set to false reactor should timeout/not do anything.
""" """
ret = salt_run_cli.run("reactor.is_leader") ret = salt_run_cli.run("reactor.is_leader")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ( assert (
"salt.exceptions.CommandExecutionError: Reactor system is not running." "salt.exceptions.CommandExecutionError: Reactor system is not running."
in ret.stdout in ret.stdout
) )
ret = salt_run_cli.run("reactor.set_leader", value=True) ret = salt_run_cli.run("reactor.set_leader", value=True)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ( assert (
"salt.exceptions.CommandExecutionError: Reactor system is not running." "salt.exceptions.CommandExecutionError: Reactor system is not running."
in ret.stdout in ret.stdout
) )
ret = salt_run_cli.run("reactor.is_leader") ret = salt_run_cli.run("reactor.is_leader")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ( assert (
"salt.exceptions.CommandExecutionError: Reactor system is not running." "salt.exceptions.CommandExecutionError: Reactor system is not running."
in ret.stdout in ret.stdout
@ -163,20 +163,20 @@ def test_reactor_is_leader(
# Now, with the temp config in place, ensure the reactor engine is running # Now, with the temp config in place, ensure the reactor engine is running
with pytest.helpers.temp_file("reactor-test.conf", config_overrides, confd_dir): with pytest.helpers.temp_file("reactor-test.conf", config_overrides, confd_dir):
ret = salt_run_cli.run("reactor.set_leader", value=True) ret = salt_run_cli.run("reactor.set_leader", value=True)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ( assert (
"CommandExecutionError" not in ret.stdout "CommandExecutionError" not in ret.stdout
), "reactor engine is not running" ), "reactor engine is not running"
ret = salt_run_cli.run("reactor.is_leader") ret = salt_run_cli.run("reactor.is_leader")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.stdout.rstrip().splitlines()[-1] == "true" assert ret.stdout.rstrip().splitlines()[-1] == "true"
ret = salt_run_cli.run("reactor.set_leader", value=False) ret = salt_run_cli.run("reactor.set_leader", value=False)
assert ret.exitcode == 0 assert ret.returncode == 0
ret = salt_run_cli.run("reactor.is_leader") ret = salt_run_cli.run("reactor.is_leader")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.stdout.rstrip().splitlines()[-1] == "false" assert ret.stdout.rstrip().splitlines()[-1] == "false"
start_time = time.time() start_time = time.time()
@ -199,9 +199,9 @@ def test_reactor_is_leader(
# make reactor the leader again; ensure reactor engine is available # make reactor the leader again; ensure reactor engine is available
ret = salt_run_cli.run("reactor.set_leader", value=True) ret = salt_run_cli.run("reactor.set_leader", value=True)
assert ret.exitcode == 0 assert ret.returncode == 0
ret = salt_run_cli.run("reactor.is_leader") ret = salt_run_cli.run("reactor.is_leader")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.stdout.rstrip().splitlines()[-1] == "true" assert ret.stdout.rstrip().splitlines()[-1] == "true"
# trigger a reaction # trigger a reaction
@ -219,7 +219,7 @@ def test_reactor_is_leader(
# Let's just confirm the engine is not running once again(because the config file is deleted by now) # Let's just confirm the engine is not running once again(because the config file is deleted by now)
ret = salt_run_cli.run("reactor.is_leader") ret = salt_run_cli.run("reactor.is_leader")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ( assert (
"salt.exceptions.CommandExecutionError: Reactor system is not running." "salt.exceptions.CommandExecutionError: Reactor system is not running."
in ret.stdout in ret.stdout

View file

@ -26,7 +26,7 @@ def test_toml_renderer(salt_call_cli, tmp_path, base_env_state_tree_root_dir):
"issue-58822.sls", state_file, base_env_state_tree_root_dir "issue-58822.sls", state_file, base_env_state_tree_root_dir
): ):
ret = salt_call_cli.run("state.apply", "issue-58822", pillar=pillar) ret = salt_call_cli.run("state.apply", "issue-58822", pillar=pillar)
assert ret.exitcode == 0 assert ret.returncode == 0
contents = config_file_path.read_text() contents = config_file_path.read_text()
expected = ( expected = (
'[tool.black]\nexclude = "foobar"\n\n[tool.isort]\ninclude_trailing_comma =' '[tool.black]\nexclude = "foobar"\n\n[tool.isort]\ninclude_trailing_comma ='

View file

@ -29,15 +29,15 @@ def test_state_event(salt_run_cli, salt_cli, salt_minion):
while not runner_future.done(): while not runner_future.done():
ret = salt_cli.run("--static", "test.ping", minion_tgt=salt_minion.id) ret = salt_cli.run("--static", "test.ping", minion_tgt=salt_minion.id)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
# Wait for the runner command which should now have data to return to us # Wait for the runner command which should now have data to return to us
exc = runner_future.exception() exc = runner_future.exception()
if exc: if exc:
raise exc raise exc
ret = runner_future.result() ret = runner_future.result()
assert ret.exitcode == 0 assert ret.returncode == 0
# We have to parse the JSON ourselves since we have regular output mixed with JSON output # We have to parse the JSON ourselves since we have regular output mixed with JSON output
data = None data = None
for line in ret.stdout.splitlines(): for line in ret.stdout.splitlines():
@ -90,8 +90,8 @@ def test_jid_in_ret_event(
jid = salt.utils.jid.gen_jid(salt_master.config) jid = salt.utils.jid.gen_jid(salt_master.config)
ret = salt_run_cli.run("--jid", jid, "state.orchestrate", "test-orch") ret = salt_run_cli.run("--jid", jid, "state.orchestrate", "test-orch")
assert ret.exitcode == 0 assert ret.returncode == 0
orch_job_data = ret.json orch_job_data = ret.data
for step_data in orch_job_data["data"][salt_master.id].values(): for step_data in orch_job_data["data"][salt_master.id].values():
assert "__jid__" in step_data assert "__jid__" in step_data
@ -147,8 +147,8 @@ def test_parallel_orchestrations(
jid = salt.utils.jid.gen_jid(salt_master.config) jid = salt.utils.jid.gen_jid(salt_master.config)
ret = salt_run_cli.run("--jid", jid, "state.orchestrate", "test-orch") ret = salt_run_cli.run("--jid", jid, "state.orchestrate", "test-orch")
assert ret.exitcode == 0 assert ret.returncode == 0
orch_job_data = ret.json orch_job_data = ret.data
for step_data in orch_job_data["data"][salt_master.id].values(): for step_data in orch_job_data["data"][salt_master.id].values():
# we expect each duration to be greater than 10s # we expect each duration to be greater than 10s
assert step_data["duration"] > 10 * 1000 assert step_data["duration"] > 10 * 1000
@ -201,8 +201,8 @@ def test_orchestration_soft_kill(
# Without soft kill, the orchestration will fail because stage_two is set to fail # Without soft kill, the orchestration will fail because stage_two is set to fail
ret = salt_run_cli.run("--jid", jid, "state.orchestrate", "test-orch") ret = salt_run_cli.run("--jid", jid, "state.orchestrate", "test-orch")
assert ret.exitcode == 1 assert ret.returncode == 1
for state_data in ret.json["data"][salt_master.id].values(): for state_data in ret.data["data"][salt_master.id].values():
if state_data["__id__"] == "stage_two": if state_data["__id__"] == "stage_two":
assert state_data["result"] is False assert state_data["result"] is False
else: else:
@ -212,10 +212,10 @@ def test_orchestration_soft_kill(
# and 'stage_two' will not be present in the returned data # and 'stage_two' will not be present in the returned data
jid = salt.utils.jid.gen_jid(salt_master.config) jid = salt.utils.jid.gen_jid(salt_master.config)
ret = salt_run_cli.run("state.soft_kill", jid, "stage_two") ret = salt_run_cli.run("state.soft_kill", jid, "stage_two")
assert ret.exitcode == 0 assert ret.returncode == 0
ret = salt_run_cli.run("--jid", jid, "state.orchestrate", "test-orch") ret = salt_run_cli.run("--jid", jid, "state.orchestrate", "test-orch")
assert ret.exitcode == 0 assert ret.returncode == 0
for state_data in ret.json["data"][salt_master.id].values(): for state_data in ret.data["data"][salt_master.id].values():
if state_data["__id__"] == "stage_two": if state_data["__id__"] == "stage_two":
pytest.fail("'stage_two' was present in the ochestration return data") pytest.fail("'stage_two' was present in the ochestration return data")
else: else:
@ -262,8 +262,8 @@ def test_orchestration_with_pillar_dot_items(
jid = salt.utils.jid.gen_jid(salt_master.config) jid = salt.utils.jid.gen_jid(salt_master.config)
ret = salt_run_cli.run("--jid", jid, "state.orchestrate", "test-orch") ret = salt_run_cli.run("--jid", jid, "state.orchestrate", "test-orch")
assert ret.exitcode == 0 assert ret.returncode == 0
for state_data in ret.json["data"][salt_master.id].values(): for state_data in ret.data["data"][salt_master.id].values():
# Each state should be successful # Each state should be successful
assert state_data["result"] is True assert state_data["result"] is True
@ -315,20 +315,20 @@ def test_orchestration_onchanges_and_prereq(
ret = salt_run_cli.run( ret = salt_run_cli.run(
"--jid", jid1, "state.orchestrate", "test-orch", test=True "--jid", jid1, "state.orchestrate", "test-orch", test=True
) )
assert ret.exitcode == 0 assert ret.returncode == 0
ret1 = ret.json ret1 = ret.data
# Now run without test mode to actually create the file # Now run without test mode to actually create the file
ret = salt_run_cli.run("state.orchestrate", "test-orch") ret = salt_run_cli.run("state.orchestrate", "test-orch")
assert ret.exitcode == 0 assert ret.returncode == 0
# Run again in test mode. Since there were no changes, the requisites should not fire. # Run again in test mode. Since there were no changes, the requisites should not fire.
jid2 = salt.utils.jid.gen_jid(salt_master.config) jid2 = salt.utils.jid.gen_jid(salt_master.config)
ret = salt_run_cli.run( ret = salt_run_cli.run(
"--jid", jid2, "state.orchestrate", "test-orch", test=True "--jid", jid2, "state.orchestrate", "test-orch", test=True
) )
assert ret.exitcode == 0 assert ret.returncode == 0
ret2 = ret.json ret2 = ret.data
# The first time through, all three states should have a None result # The first time through, all three states should have a None result
for state_data in ret1["data"][salt_master.id].values(): for state_data in ret1["data"][salt_master.id].values():

View file

@ -46,7 +46,7 @@ def test_orchestrate_output(salt_run_cli, salt_minion, base_env_state_tree_root_
"simple-ping.sls", simple_ping_sls, base_env_state_tree_root_dir "simple-ping.sls", simple_ping_sls, base_env_state_tree_root_dir
): ):
ret = salt_run_cli.run("--out=highstate", "state.orchestrate", "orch-test") ret = salt_run_cli.run("--out=highstate", "state.orchestrate", "orch-test")
assert ret.exitcode == 0 assert ret.returncode == 0
ret_output = ret.stdout.splitlines() ret_output = ret.stdout.splitlines()
# First, check that we don't have the "bad" output that was displaying in # First, check that we don't have the "bad" output that was displaying in
@ -93,7 +93,7 @@ def test_orchestrate_state_output_with_salt_function(
ret = salt_run_cli.run( ret = salt_run_cli.run(
"--out=highstate", "state.orchestrate", "orch-function-test" "--out=highstate", "state.orchestrate", "orch-function-test"
) )
assert ret.exitcode == 0 assert ret.returncode == 0
ret_output = [line.strip() for line in ret.stdout.splitlines()] ret_output = [line.strip() for line in ret.stdout.splitlines()]
assert "args:" in ret_output assert "args:" in ret_output
@ -140,7 +140,7 @@ def test_orchestrate_nested(
"nested/outer.sls", outer_sls, base_env_state_tree_root_dir "nested/outer.sls", outer_sls, base_env_state_tree_root_dir
): ):
ret = salt_run_cli.run("state.orchestrate", "nested.outer") ret = salt_run_cli.run("state.orchestrate", "nested.outer")
assert ret.exitcode != 0 assert ret.returncode != 0
assert testfile.exists() is False assert testfile.exists() is False
@ -165,16 +165,16 @@ def test_orchestrate_with_mine(
""" """
) )
ret = salt_run_cli.run("mine.update", salt_minion.id) ret = salt_run_cli.run("mine.update", salt_minion.id)
assert ret.exitcode == 0 assert ret.returncode == 0
with pytest.helpers.temp_file( with pytest.helpers.temp_file(
"orch/mine.sls", sls_contents, base_env_state_tree_root_dir "orch/mine.sls", sls_contents, base_env_state_tree_root_dir
): ):
ret = salt_run_cli.run("state.orchestrate", "orch.mine") ret = salt_run_cli.run("state.orchestrate", "orch.mine")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json["data"][salt_master.id] assert ret.data["data"][salt_master.id]
for state_data in ret.json["data"][salt_master.id].values(): for state_data in ret.data["data"][salt_master.id].values():
assert state_data["changes"]["ret"] assert state_data["changes"]["ret"]
assert state_data["changes"]["ret"][salt_minion.id] is True assert state_data["changes"]["ret"][salt_minion.id] is True
@ -213,13 +213,13 @@ def test_orchestrate_state_and_function_failure(
"orch/issue43204/fail_with_changes.sls", fail_sls, base_env_state_tree_root_dir "orch/issue43204/fail_with_changes.sls", fail_sls, base_env_state_tree_root_dir
): ):
ret = salt_run_cli.run("saltutil.sync_modules") ret = salt_run_cli.run("saltutil.sync_modules")
assert ret.exitcode == 0 assert ret.returncode == 0
ret = salt_run_cli.run("state.orchestrate", "orch.issue43204") ret = salt_run_cli.run("state.orchestrate", "orch.issue43204")
assert ret.exitcode != 0 assert ret.returncode != 0
# Drill down to the changes dict # Drill down to the changes dict
data = ret.json["data"][salt_master.id] data = ret.data["data"][salt_master.id]
state_ret = data["salt_|-Step01_|-Step01_|-state"]["changes"] state_ret = data["salt_|-Step01_|-Step01_|-state"]["changes"]
func_ret = data[ func_ret = data[
"salt_|-Step02_|-runtests_helpers.nonzero_retcode_return_false_|-function" "salt_|-Step02_|-runtests_helpers.nonzero_retcode_return_false_|-function"
@ -278,13 +278,13 @@ def test_orchestrate_salt_function_return_false_failure(
"orch/issue30367.sls", sls_contents, base_env_state_tree_root_dir "orch/issue30367.sls", sls_contents, base_env_state_tree_root_dir
): ):
ret = salt_run_cli.run("saltutil.sync_modules") ret = salt_run_cli.run("saltutil.sync_modules")
assert ret.exitcode == 0 assert ret.returncode == 0
ret = salt_run_cli.run("state.orchestrate", "orch.issue30367") ret = salt_run_cli.run("state.orchestrate", "orch.issue30367")
assert ret.exitcode != 0 assert ret.returncode != 0
# Drill down to the changes dict # Drill down to the changes dict
data = ret.json["data"][salt_master.id] data = ret.data["data"][salt_master.id]
state_result = data["salt_|-deploy_check_|-test.false_|-function"]["result"] state_result = data["salt_|-deploy_check_|-test.false_|-function"]["result"]
func_ret = data["salt_|-deploy_check_|-test.false_|-function"]["changes"] func_ret = data["salt_|-deploy_check_|-test.false_|-function"]["changes"]
@ -331,10 +331,10 @@ def test_orchestrate_target_exists(
"core.sls", target_test_sls, base_env_state_tree_root_dir "core.sls", target_test_sls, base_env_state_tree_root_dir
): ):
ret = salt_run_cli.run("state.orchestrate", "orch.target-exists") ret = salt_run_cli.run("state.orchestrate", "orch.target-exists")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
data = ret.json["data"][salt_master.id] data = ret.data["data"][salt_master.id]
to_check = {"core", "test-state", "cmd.run"} to_check = {"core", "test-state", "cmd.run"}
for state_data in data.values(): for state_data in data.values():
if state_data["name"] == "core": if state_data["name"] == "core":
@ -391,10 +391,10 @@ def test_orchestrate_target_does_not_exist(
"core.sls", target_test_sls, base_env_state_tree_root_dir "core.sls", target_test_sls, base_env_state_tree_root_dir
): ):
ret = salt_run_cli.run("state.orchestrate", "orch.target-does-not-exist") ret = salt_run_cli.run("state.orchestrate", "orch.target-does-not-exist")
assert ret.exitcode != 0 assert ret.returncode != 0
assert ret.json assert ret.data
data = ret.json["data"][salt_master.id] data = ret.data["data"][salt_master.id]
to_check = {"core", "test-state", "cmd.run"} to_check = {"core", "test-state", "cmd.run"}
for state_data in data.values(): for state_data in data.values():
if state_data["name"] == "core": if state_data["name"] == "core":
@ -438,15 +438,15 @@ def test_orchestrate_retcode(salt_run_cli, salt_master, base_env_state_tree_root
"orch/retcode.sls", sls_contents, base_env_state_tree_root_dir "orch/retcode.sls", sls_contents, base_env_state_tree_root_dir
): ):
ret = salt_run_cli.run("saltutil.sync_runners") ret = salt_run_cli.run("saltutil.sync_runners")
assert ret.exitcode == 0 assert ret.returncode == 0
ret = salt_run_cli.run("saltutil.sync_wheel") ret = salt_run_cli.run("saltutil.sync_wheel")
assert ret.exitcode == 0 assert ret.returncode == 0
ret = salt_run_cli.run("state.orchestrate", "orch.retcode") ret = salt_run_cli.run("state.orchestrate", "orch.retcode")
assert ret.exitcode != 0 assert ret.returncode != 0
assert ret.json assert ret.data
data = ret.json["data"][salt_master.id] data = ret.data["data"][salt_master.id]
to_check = { to_check = {
"test_runner_success", "test_runner_success",
"test_runner_failure", "test_runner_failure",
@ -493,9 +493,9 @@ def test_orchestrate_batch_with_failhard_error(
"orch/batch.sls", sls_contents, base_env_state_tree_root_dir "orch/batch.sls", sls_contents, base_env_state_tree_root_dir
), pytest.helpers.temp_file("fail.sls", fail_sls, base_env_state_tree_root_dir): ), pytest.helpers.temp_file("fail.sls", fail_sls, base_env_state_tree_root_dir):
ret = salt_run_cli.run("state.orchestrate", "orch.batch") ret = salt_run_cli.run("state.orchestrate", "orch.batch")
assert ret.exitcode != 0 assert ret.returncode != 0
data = ret.json["data"][salt_master.id] data = ret.data["data"][salt_master.id]
result = data["salt_|-call_fail_state_|-call_fail_state_|-state"]["result"] result = data["salt_|-call_fail_state_|-call_fail_state_|-state"]["result"]
changes = data["salt_|-call_fail_state_|-call_fail_state_|-state"]["changes"] changes = data["salt_|-call_fail_state_|-call_fail_state_|-state"]["changes"]
@ -530,9 +530,9 @@ def test_orchestrate_subset(
"orch/subset.sls", sls_contents, base_env_state_tree_root_dir "orch/subset.sls", sls_contents, base_env_state_tree_root_dir
), pytest.helpers.temp_file("test.sls", test_sls, base_env_state_tree_root_dir): ), pytest.helpers.temp_file("test.sls", test_sls, base_env_state_tree_root_dir):
ret = salt_run_cli.run("state.orchestrate", "orch.subset") ret = salt_run_cli.run("state.orchestrate", "orch.subset")
assert ret.exitcode == 0 assert ret.returncode == 0
for state_data in ret.json["data"][salt_master.id].values(): for state_data in ret.data["data"][salt_master.id].values():
# Should only run in one of the minions # Should only run in one of the minions
comment = state_data["comment"] comment = state_data["comment"]
if salt_minion.id in comment: if salt_minion.id in comment:

View file

@ -36,20 +36,20 @@ def pillar_tree(base_env_pillar_tree_root_dir, salt_minion, salt_sub_minion, sal
try: try:
with top_tempfile, basic_tempfile: with top_tempfile, basic_tempfile:
ret = salt_cli.run("saltutil.refresh_pillar", wait=True, minion_tgt="*") ret = salt_cli.run("saltutil.refresh_pillar", wait=True, minion_tgt="*")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert ret.json[salt_minion.id] is True assert ret.data[salt_minion.id] is True
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
assert ret.json[salt_sub_minion.id] is True assert ret.data[salt_sub_minion.id] is True
yield yield
finally: finally:
# Refresh pillar again to cleaup the temp pillar # Refresh pillar again to cleaup the temp pillar
ret = salt_cli.run("saltutil.refresh_pillar", wait=True, minion_tgt="*") ret = salt_cli.run("saltutil.refresh_pillar", wait=True, minion_tgt="*")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert ret.json[salt_minion.id] is True assert ret.data[salt_minion.id] is True
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
assert ret.json[salt_sub_minion.id] is True assert ret.data[salt_sub_minion.id] is True
def test_cache(salt_run_cli): def test_cache(salt_run_cli):
@ -63,24 +63,24 @@ def test_cache(salt_run_cli):
key="test_cache", key="test_cache",
data="The time has come the walrus said", data="The time has come the walrus said",
) )
assert ret.exitcode == 0 assert ret.returncode == 0
# Make sure we can see the new key # Make sure we can see the new key
ret = salt_run_cli.run("cache.list", bank="cachetest/runner") ret = salt_run_cli.run("cache.list", bank="cachetest/runner")
assert ret.exitcode == 0 assert ret.returncode == 0
assert "test_cache" in ret.json assert "test_cache" in ret.data
# Make sure we can see the new data # Make sure we can see the new data
ret = salt_run_cli.run("cache.fetch", bank="cachetest/runner", key="test_cache") ret = salt_run_cli.run("cache.fetch", bank="cachetest/runner", key="test_cache")
assert ret.exitcode == 0 assert ret.returncode == 0
assert "The time has come the walrus said" in ret.stdout assert "The time has come the walrus said" in ret.stdout
# Make sure we can delete the data # Make sure we can delete the data
ret = salt_run_cli.run("cache.flush", bank="cachetest/runner", key="test_cache") ret = salt_run_cli.run("cache.flush", bank="cachetest/runner", key="test_cache")
assert ret.exitcode == 0 assert ret.returncode == 0
ret = salt_run_cli.run("cache.list", bank="cachetest/runner") ret = salt_run_cli.run("cache.list", bank="cachetest/runner")
assert ret.exitcode == 0 assert ret.returncode == 0
assert "test_cache" not in ret.json assert "test_cache" not in ret.data
def test_cache_invalid(salt_run_cli): def test_cache_invalid(salt_run_cli):
@ -88,7 +88,7 @@ def test_cache_invalid(salt_run_cli):
Store, list, fetch, then flush data Store, list, fetch, then flush data
""" """
ret = salt_run_cli.run("cache.store") ret = salt_run_cli.run("cache.store")
assert ret.exitcode == 0 assert ret.returncode == 0
# Make sure we can see the new key # Make sure we can see the new key
assert "Passed invalid arguments:" in ret.stdout assert "Passed invalid arguments:" in ret.stdout
@ -98,8 +98,8 @@ def test_grains(salt_run_cli, pillar_tree, salt_minion):
Test cache.grains Test cache.grains
""" """
ret = salt_run_cli.run("cache.grains", tgt=salt_minion.id) ret = salt_run_cli.run("cache.grains", tgt=salt_minion.id)
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
def test_pillar(salt_run_cli, pillar_tree, salt_minion, salt_sub_minion): def test_pillar(salt_run_cli, pillar_tree, salt_minion, salt_sub_minion):
@ -107,9 +107,9 @@ def test_pillar(salt_run_cli, pillar_tree, salt_minion, salt_sub_minion):
Test cache.pillar Test cache.pillar
""" """
ret = salt_run_cli.run("cache.pillar", tgt=salt_minion.id) ret = salt_run_cli.run("cache.pillar", tgt=salt_minion.id)
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id not in ret.json assert salt_sub_minion.id not in ret.data
def test_pillar_no_tgt(salt_run_cli, pillar_tree, salt_minion, salt_sub_minion): def test_pillar_no_tgt(salt_run_cli, pillar_tree, salt_minion, salt_sub_minion):
@ -119,9 +119,9 @@ def test_pillar_no_tgt(salt_run_cli, pillar_tree, salt_minion, salt_sub_minion):
data for all minions data for all minions
""" """
ret = salt_run_cli.run("cache.pillar") ret = salt_run_cli.run("cache.pillar")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
def test_pillar_minion_noexist(salt_run_cli, pillar_tree, salt_minion, salt_sub_minion): def test_pillar_minion_noexist(salt_run_cli, pillar_tree, salt_minion, salt_sub_minion):
@ -129,9 +129,9 @@ def test_pillar_minion_noexist(salt_run_cli, pillar_tree, salt_minion, salt_sub_
Test cache.pillar when the target does not exist Test cache.pillar when the target does not exist
""" """
ret = salt_run_cli.run("cache.pillar", tgt="non-exiting-minion") ret = salt_run_cli.run("cache.pillar", tgt="non-exiting-minion")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id not in ret.json assert salt_minion.id not in ret.data
assert salt_sub_minion.id not in ret.json assert salt_sub_minion.id not in ret.data
def test_pillar_minion_tgt_type_pillar( def test_pillar_minion_tgt_type_pillar(
@ -142,9 +142,9 @@ def test_pillar_minion_tgt_type_pillar(
and tgt_type is pillar and tgt_type is pillar
""" """
ret = salt_run_cli.run("cache.pillar", tgt="monty:python", tgt_type="pillar") ret = salt_run_cli.run("cache.pillar", tgt="monty:python", tgt_type="pillar")
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data
assert salt_sub_minion.id in ret.json assert salt_sub_minion.id in ret.data
def test_mine(salt_run_cli, salt_minion): def test_mine(salt_run_cli, salt_minion):
@ -152,5 +152,5 @@ def test_mine(salt_run_cli, salt_minion):
Test cache.mine Test cache.mine
""" """
ret = salt_run_cli.run("cache.mine", tgt=salt_minion.id) ret = salt_run_cli.run("cache.mine", tgt=salt_minion.id)
assert ret.exitcode == 0 assert ret.returncode == 0
assert salt_minion.id in ret.json assert salt_minion.id in ret.data

View file

@ -20,9 +20,9 @@ def etc_docker_container(salt_call_cli, sdb_etcd_port):
ret = salt_call_cli.run( ret = salt_call_cli.run(
"state.single", "docker_image.present", name="bitnami/etcd", tag="latest" "state.single", "docker_image.present", name="bitnami/etcd", tag="latest"
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
state_run = next(iter(ret.json.values())) state_run = next(iter(ret.data.values()))
assert state_run["result"] is True assert state_run["result"] is True
ret = salt_call_cli.run( ret = salt_call_cli.run(
"state.single", "state.single",
@ -33,9 +33,9 @@ def etc_docker_container(salt_call_cli, sdb_etcd_port):
environment={"ALLOW_NONE_AUTHENTICATION": "yes", "ETCD_ENABLE_V2": "true"}, environment={"ALLOW_NONE_AUTHENTICATION": "yes", "ETCD_ENABLE_V2": "true"},
cap_add="IPC_LOCK", cap_add="IPC_LOCK",
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
state_run = next(iter(ret.json.values())) state_run = next(iter(ret.data.values()))
assert state_run["result"] is True assert state_run["result"] is True
container_started = True container_started = True
tries_left = 10 tries_left = 10
@ -44,7 +44,7 @@ def etc_docker_container(salt_call_cli, sdb_etcd_port):
ret = salt_call_cli.run( ret = salt_call_cli.run(
"sdb.set", uri="sdb://sdbetcd/secret/test/test_sdb/fnord", value="bar" "sdb.set", uri="sdb://sdbetcd/secret/test/test_sdb/fnord", value="bar"
) )
if ret.exitcode == 0: if ret.returncode == 0:
break break
else: else:
pytest.skip( pytest.skip(
@ -56,16 +56,16 @@ def etc_docker_container(salt_call_cli, sdb_etcd_port):
ret = salt_call_cli.run( ret = salt_call_cli.run(
"state.single", "docker_container.stopped", name="etcd" "state.single", "docker_container.stopped", name="etcd"
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
state_run = next(iter(ret.json.values())) state_run = next(iter(ret.data.values()))
assert state_run["result"] is True assert state_run["result"] is True
ret = salt_call_cli.run( ret = salt_call_cli.run(
"state.single", "docker_container.absent", name="etcd" "state.single", "docker_container.absent", name="etcd"
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
state_run = next(iter(ret.json.values())) state_run = next(iter(ret.data.values()))
assert state_run["result"] is True assert state_run["result"] is True
@ -98,14 +98,14 @@ def test_sdb(salt_call_cli):
ret = salt_call_cli.run( ret = salt_call_cli.run(
"sdb.set", uri="sdb://sdbetcd/secret/test/test_sdb/foo", value="bar" "sdb.set", uri="sdb://sdbetcd/secret/test/test_sdb/foo", value="bar"
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json == "bar" assert ret.data == "bar"
ret = salt_call_cli.run("sdb.get", uri="sdb://sdbetcd/secret/test/test_sdb/foo") ret = salt_call_cli.run("sdb.get", uri="sdb://sdbetcd/secret/test/test_sdb/foo")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json == "bar" assert ret.data == "bar"
@pytest.mark.slow_test @pytest.mark.slow_test
@ -113,13 +113,13 @@ def test_sdb_runner(salt_run_cli):
ret = salt_run_cli.run( ret = salt_run_cli.run(
"sdb.set", uri="sdb://sdbetcd/secret/test/test_sdb_runner/foo", value="bar" "sdb.set", uri="sdb://sdbetcd/secret/test/test_sdb_runner/foo", value="bar"
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.stdout == "bar" assert ret.stdout == "bar"
ret = salt_run_cli.run( ret = salt_run_cli.run(
"sdb.get", uri="sdb://sdbetcd/secret/test/test_sdb_runner/foo" "sdb.get", uri="sdb://sdbetcd/secret/test/test_sdb_runner/foo"
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.stdout == "bar" assert ret.stdout == "bar"
@ -128,11 +128,11 @@ def test_config(salt_call_cli, pillar_tree):
ret = salt_call_cli.run( ret = salt_call_cli.run(
"sdb.set", uri="sdb://sdbetcd/secret/test/test_pillar_sdb/foo", value="bar" "sdb.set", uri="sdb://sdbetcd/secret/test/test_pillar_sdb/foo", value="bar"
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json == "bar" assert ret.data == "bar"
ret = salt_call_cli.run("config.get", "test_etcd_pillar_sdb") ret = salt_call_cli.run("config.get", "test_etcd_pillar_sdb")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json == "bar" assert ret.data == "bar"

View file

@ -9,7 +9,7 @@ import time
import pytest import pytest
import salt.utils.path import salt.utils.path
from saltfactories.utils.processes import ProcessResult from pytestshellutils.utils.processes import ProcessResult
from tests.support.runtests import RUNTIME_VARS from tests.support.runtests import RUNTIME_VARS
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -67,9 +67,9 @@ def vault_container_version(request, salt_call_cli, vault_port):
ret = salt_call_cli.run( ret = salt_call_cli.run(
"state.single", "docker_image.present", name="vault", tag=vault_version "state.single", "docker_image.present", name="vault", tag=vault_version
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
state_run = next(iter(ret.json.values())) state_run = next(iter(ret.data.values()))
assert state_run["result"] is True assert state_run["result"] is True
container_started = True container_started = True
@ -90,9 +90,9 @@ def vault_container_version(request, salt_call_cli, vault_port):
}, },
cap_add="IPC_LOCK", cap_add="IPC_LOCK",
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
state_run = next(iter(ret.json.values())) state_run = next(iter(ret.data.values()))
assert state_run["result"] is True assert state_run["result"] is True
time.sleep(1) time.sleep(1)
@ -107,7 +107,7 @@ def vault_container_version(request, salt_call_cli, vault_port):
if proc.returncode == 0: if proc.returncode == 0:
break break
ret = ProcessResult( ret = ProcessResult(
exitcode=proc.returncode, returncode=proc.returncode,
stdout=proc.stdout, stdout=proc.stdout,
stderr=proc.stderr, stderr=proc.stderr,
cmdline=proc.args, cmdline=proc.args,
@ -133,7 +133,7 @@ def vault_container_version(request, salt_call_cli, vault_port):
) )
if proc.returncode != 0: if proc.returncode != 0:
ret = ProcessResult( ret = ProcessResult(
exitcode=proc.returncode, returncode=proc.returncode,
stdout=proc.stdout, stdout=proc.stdout,
stderr=proc.stderr, stderr=proc.stderr,
cmdline=proc.args, cmdline=proc.args,
@ -150,7 +150,7 @@ def vault_container_version(request, salt_call_cli, vault_port):
universal_newlines=True, universal_newlines=True,
) )
ret = ProcessResult( ret = ProcessResult(
exitcode=proc.returncode, returncode=proc.returncode,
stdout=proc.stdout, stdout=proc.stdout,
stderr=proc.stderr, stderr=proc.stderr,
cmdline=proc.args, cmdline=proc.args,
@ -267,16 +267,16 @@ def vault_container_version(request, salt_call_cli, vault_port):
ret = salt_call_cli.run( ret = salt_call_cli.run(
"state.single", "docker_container.stopped", name="vault" "state.single", "docker_container.stopped", name="vault"
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
state_run = next(iter(ret.json.values())) state_run = next(iter(ret.data.values()))
assert state_run["result"] is True assert state_run["result"] is True
ret = salt_call_cli.run( ret = salt_call_cli.run(
"state.single", "docker_container.absent", name="vault" "state.single", "docker_container.absent", name="vault"
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
state_run = next(iter(ret.json.values())) state_run = next(iter(ret.data.values()))
assert state_run["result"] is True assert state_run["result"] is True
@ -285,12 +285,12 @@ def test_sdb(salt_call_cli):
ret = salt_call_cli.run( ret = salt_call_cli.run(
"sdb.set", uri="sdb://sdbvault/secret/test/test_sdb/foo", value="bar" "sdb.set", uri="sdb://sdbvault/secret/test/test_sdb/foo", value="bar"
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
ret = salt_call_cli.run("sdb.get", uri="sdb://sdbvault/secret/test/test_sdb/foo") ret = salt_call_cli.run("sdb.get", uri="sdb://sdbvault/secret/test/test_sdb/foo")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json == "bar" assert ret.data == "bar"
@pytest.mark.slow_test @pytest.mark.slow_test
@ -298,12 +298,12 @@ def test_sdb_runner(salt_run_cli):
ret = salt_run_cli.run( ret = salt_run_cli.run(
"sdb.set", uri="sdb://sdbvault/secret/test/test_sdb_runner/foo", value="bar" "sdb.set", uri="sdb://sdbvault/secret/test/test_sdb_runner/foo", value="bar"
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
ret = salt_run_cli.run( ret = salt_run_cli.run(
"sdb.get", uri="sdb://sdbvault/secret/test/test_sdb_runner/foo" "sdb.get", uri="sdb://sdbvault/secret/test/test_sdb_runner/foo"
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.stdout assert ret.stdout
assert ret.stdout == "bar" assert ret.stdout == "bar"
@ -313,12 +313,12 @@ def test_config(salt_call_cli, pillar_tree):
ret = salt_call_cli.run( ret = salt_call_cli.run(
"sdb.set", uri="sdb://sdbvault/secret/test/test_pillar_sdb/foo", value="bar" "sdb.set", uri="sdb://sdbvault/secret/test/test_pillar_sdb/foo", value="bar"
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
ret = salt_call_cli.run("config.get", "test_vault_pillar_sdb") ret = salt_call_cli.run("config.get", "test_vault_pillar_sdb")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json == "bar" assert ret.data == "bar"
@pytest.mark.slow_test @pytest.mark.slow_test
@ -328,13 +328,13 @@ def test_sdb_kv2_kvv2_path_local(salt_call_cli, vault_container_version):
ret = salt_call_cli.run( ret = salt_call_cli.run(
"sdb.set", uri="sdb://sdbvault/kv-v2/test/test_sdb/foo", value="bar" "sdb.set", uri="sdb://sdbvault/kv-v2/test/test_sdb/foo", value="bar"
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
ret = salt_call_cli.run( ret = salt_call_cli.run(
"--local", "sdb.get", "sdb://sdbvault/kv-v2/test/test_sdb/foo" "--local", "sdb.get", "sdb://sdbvault/kv-v2/test/test_sdb/foo"
) )
assert ret.json assert ret.data
assert ret.json == "bar" assert ret.data == "bar"
@pytest.mark.slow_test @pytest.mark.slow_test
@ -342,5 +342,5 @@ def test_sdb_kv_dual_item(salt_call_cli, vault_container_version):
if vault_container_version not in ["latest"]: if vault_container_version not in ["latest"]:
pytest.skip("Test not applicable to vault {}".format(vault_container_version)) pytest.skip("Test not applicable to vault {}".format(vault_container_version))
ret = salt_call_cli.run("--local", "sdb.get", "sdb://sdbvault/salt/data/user1") ret = salt_call_cli.run("--local", "sdb.get", "sdb://sdbvault/salt/data/user1")
# assert ret.json assert ret.data
assert ret.json == {"desc": "test user", "password": "p4ssw0rd"} assert ret.data == {"desc": "test user", "password": "p4ssw0rd"}

View file

@ -12,8 +12,8 @@ def test_grains_id(salt_ssh_cli):
Test salt-ssh grains id work for localhost. Test salt-ssh grains id work for localhost.
""" """
ret = salt_ssh_cli.run("grains.get", "id") ret = salt_ssh_cli.run("grains.get", "id")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json == "localhost" assert ret.data == "localhost"
def test_grains_items(salt_ssh_cli): def test_grains_items(salt_ssh_cli):
@ -21,9 +21,9 @@ def test_grains_items(salt_ssh_cli):
test grains.items with salt-ssh test grains.items with salt-ssh
""" """
ret = salt_ssh_cli.run("grains.items") ret = salt_ssh_cli.run("grains.items")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert isinstance(ret.json, dict) assert isinstance(ret.data, dict)
if salt.utils.platform.is_darwin(): if salt.utils.platform.is_darwin():
grain = "Darwin" grain = "Darwin"
elif salt.utils.platform.is_aix(): elif salt.utils.platform.is_aix():
@ -32,4 +32,4 @@ def test_grains_items(salt_ssh_cli):
grain = "FreeBSD" grain = "FreeBSD"
else: else:
grain = "Linux" grain = "Linux"
assert ret.json["kernel"] == grain assert ret.data["kernel"] == grain

View file

@ -39,9 +39,9 @@ def test_pillar_items(salt_ssh_cli, pillar_tree):
test pillar.items with salt-ssh test pillar.items with salt-ssh
""" """
ret = salt_ssh_cli.run("pillar.items") ret = salt_ssh_cli.run("pillar.items")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
pillar_items = ret.json pillar_items = ret.data
assert "monty" in pillar_items assert "monty" in pillar_items
assert pillar_items["monty"] == "python" assert pillar_items["monty"] == "python"
assert "knights" in pillar_items assert "knights" in pillar_items
@ -54,9 +54,9 @@ def test_pillar_get(salt_ssh_cli, pillar_tree):
test pillar.get with salt-ssh test pillar.get with salt-ssh
""" """
ret = salt_ssh_cli.run("pillar.get", "monty") ret = salt_ssh_cli.run("pillar.get", "monty")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json == "python" assert ret.data == "python"
@pytest.mark.slow_test @pytest.mark.slow_test
@ -65,5 +65,5 @@ def test_pillar_get_doesnotexist(salt_ssh_cli, pillar_tree):
test pillar.get when pillar does not exist with salt-ssh test pillar.get when pillar does not exist with salt-ssh
""" """
ret = salt_ssh_cli.run("pillar.get", "doesnotexist") ret = salt_ssh_cli.run("pillar.get", "doesnotexist")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json == "" assert ret.data == ""

View file

@ -6,11 +6,10 @@ import shutil
import subprocess import subprocess
import pytest import pytest
from saltfactories.daemons.container import Container from pytestshellutils.utils import ports
from saltfactories.utils import random_string from saltfactories.utils import random_string
from saltfactories.utils.ports import get_unused_localhost_port
docker = pytest.importorskip("docker") pytest.importorskip("docker")
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -55,18 +54,6 @@ class Keys:
shutil.rmtree(str(self.priv_path.parent), ignore_errors=True) shutil.rmtree(str(self.priv_path.parent), ignore_errors=True)
@pytest.fixture(scope="module")
def docker_client():
try:
client = docker.from_env()
except docker.errors.DockerException:
pytest.skip("Failed to get a connection to docker running on the system")
connectable = Container.client_connectable(client)
if connectable is not True: # pragma: nocover
pytest.skip(connectable)
return client
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def ssh_keys(tmp_path_factory): def ssh_keys(tmp_path_factory):
""" """
@ -81,7 +68,7 @@ def ssh_port():
""" """
Temporary ssh port fixture Temporary ssh port fixture
""" """
return get_unused_localhost_port() return ports.get_unused_localhost_port()
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
@ -108,33 +95,25 @@ def salt_ssh_roster_file(ssh_port, ssh_keys, salt_master):
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
def docker_image_name(docker_client): def ssh_docker_container(salt_factories, ssh_port, ssh_keys):
image_name = "dwoz1/cicd"
image_tag = "ssh"
try:
docker_client.images.pull(image_name, tag=image_tag)
except docker.errors.APIError as exc:
pytest.skip(
"Failed to pull docker image '{}:{}': {}".format(image_name, image_tag, exc)
)
return "{}:{}".format(image_name, image_tag)
@pytest.fixture(scope="module")
def ssh_docker_container(
salt_factories, docker_client, ssh_port, ssh_keys, docker_image_name
):
""" """
Temporary docker container with python 3.6 and ssh enabled Temporary docker container with python 3.6 and ssh enabled
""" """
container = salt_factories.get_container( container = salt_factories.get_container(
random_string("ssh-py_versions-"), random_string("ssh-py_versions-"),
docker_image_name, "dwoz1/cicd:ssh",
docker_client=docker_client,
check_ports=[ssh_port], check_ports=[ssh_port],
pull_before_start=True,
skip_on_pull_failure=True,
skip_if_docker_client_not_connectable=True,
container_run_kwargs={ container_run_kwargs={
"ports": {"22/tcp": ssh_port}, "ports": {
"environment": {"SSH_USER": "centos", "SSH_AUTHORIZED_KEYS": ssh_keys.pub}, "22/tcp": ssh_port,
},
"environment": {
"SSH_USER": "centos",
"SSH_AUTHORIZED_KEYS": ssh_keys.pub,
},
"cap_add": "IPC_LOCK", "cap_add": "IPC_LOCK",
}, },
) )
@ -161,6 +140,6 @@ def test_py36_target(salt_ssh_cli):
Test that a python >3.6 master can salt ssh to a <3.6 target Test that a python >3.6 master can salt ssh to a <3.6 target
""" """
ret = salt_ssh_cli.run("test.ping", minion_tgt="pyvertest") ret = salt_ssh_cli.run("test.ping", minion_tgt="pyvertest")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
assert ret.json is True assert ret.data is True

View file

@ -74,8 +74,8 @@ def test_state_with_import(salt_ssh_cli, state_tree):
verify salt-ssh can use imported map files in states verify salt-ssh can use imported map files in states
""" """
ret = salt_ssh_cli.run("state.sls", "test") ret = salt_ssh_cli.run("state.sls", "test")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
@pytest.fixture @pytest.fixture
@ -121,8 +121,8 @@ def test_state_with_import_from_dir(salt_ssh_cli, nested_state_tree):
ret = salt_ssh_cli.run( ret = salt_ssh_cli.run(
"--extra-filerefs=salt://foo/map.jinja", "state.apply", "foo" "--extra-filerefs=salt://foo/map.jinja", "state.apply", "foo"
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
@pytest.mark.slow_test @pytest.mark.slow_test
@ -132,13 +132,13 @@ def test_state_opts_test(salt_ssh_cli, test_opts_state_tree):
""" """
def _verify_output(ret): def _verify_output(ret):
assert ret.exitcode == 0 assert ret.returncode == 0
assert ( assert (
ret.json["cmd_|-config.get check for is_test_|-echo 'True'_|-run"]["name"] ret.data["cmd_|-config.get check for is_test_|-echo 'True'_|-run"]["name"]
== "echo 'True'" == "echo 'True'"
) )
assert ( assert (
ret.json["cmd_|-opts.get check for test_|-echo 'True'_|-run"]["name"] ret.data["cmd_|-opts.get check for test_|-echo 'True'_|-run"]["name"]
== "echo 'True'" == "echo 'True'"
) )

View file

@ -10,7 +10,7 @@ import pytest
import salt.utils.files import salt.utils.files
import salt.utils.path import salt.utils.path
import yaml import yaml
from saltfactories.exceptions import FactoryTimeout from pytestshellutils.exceptions import FactoryTimeout
from saltfactories.utils.functional import StateResult from saltfactories.utils.functional import StateResult
from tests.support.runtests import RUNTIME_VARS from tests.support.runtests import RUNTIME_VARS
@ -118,6 +118,6 @@ def test_ansible_playbook(salt_call_cli, ansible_inventory, tmp_path):
if timeout == timeouts[-1]: if timeout == timeouts[-1]:
pytest.fail("Failed to run {}".format(name)) pytest.fail("Failed to run {}".format(name))
else: else:
assert ret.exitcode == 0 assert ret.returncode == 0
assert StateResult(ret.json).result is True assert StateResult(ret.data).result is True
break break

View file

@ -25,21 +25,21 @@ def test_present_absent(salt_master, salt_minion, salt_call_cli):
"state.apply", "state.apply",
"manage_beacons", "manage_beacons",
) )
assert ret.exitcode == 0 assert ret.returncode == 0
state_id = "beacon_|-beacon-diskusage_|-diskusage_|-present" state_id = "beacon_|-beacon-diskusage_|-diskusage_|-present"
assert state_id in ret.json assert state_id in ret.data
assert ret.json[state_id]["result"] assert ret.data[state_id]["result"]
assert ret.json[state_id]["comment"] == "Adding diskusage to beacons" assert ret.data[state_id]["comment"] == "Adding diskusage to beacons"
ret = salt_call_cli.run("beacons.list", return_yaml=False) ret = salt_call_cli.run("beacons.list", return_yaml=False)
assert "diskusage" in ret.json assert "diskusage" in ret.data
assert {"interval": 5} in ret.json["diskusage"] assert {"interval": 5} in ret.data["diskusage"]
assert {"/": "38%"} in ret.json["diskusage"] assert {"/": "38%"} in ret.data["diskusage"]
ret = salt_call_cli.run("state.single", "beacon.absent", "diskusage") ret = salt_call_cli.run("state.single", "beacon.absent", "diskusage")
assert ret.json assert ret.data
ret = salt_call_cli.run("beacons.list", return_yaml=False) ret = salt_call_cli.run("beacons.list", return_yaml=False)
assert ret.json == {} assert ret.data == {}
ret = salt_call_cli.run("beacons.reset") ret = salt_call_cli.run("beacons.reset")

View file

@ -49,8 +49,8 @@ def test_managed(cron_account, salt_cli, salt_minion, base_env_state_tree_root_d
user=cron_account.username, user=cron_account.username,
minion_tgt=salt_minion.id, minion_tgt=salt_minion.id,
) )
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
state = ret.json["cron_|-salt://issue-46881/cron_|-salt://issue-46881/cron_|-file"] state = ret.data["cron_|-salt://issue-46881/cron_|-salt://issue-46881/cron_|-file"]
assert "changes" in state assert "changes" in state
assert "diff" in state["changes"] assert "diff" in state["changes"]
assert state["changes"]["diff"] == expected assert state["changes"]["diff"] == expected

View file

@ -10,8 +10,8 @@ import textwrap
import pytest import pytest
import salt.utils.files import salt.utils.files
import salt.utils.path import salt.utils.path
from pytestshellutils.utils import ports
from salt.utils.versions import LooseVersion as _LooseVersion from salt.utils.versions import LooseVersion as _LooseVersion
from saltfactories.utils.ports import get_unused_localhost_port
from tests.support.helpers import SKIP_INITIAL_PHOTONOS_FAILURES from tests.support.helpers import SKIP_INITIAL_PHOTONOS_FAILURES
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -106,14 +106,14 @@ def pillar_tree(salt_master, salt_minion, salt_call_cli):
try: try:
with top_tempfile, basic_tempfile: with top_tempfile, basic_tempfile:
ret = salt_call_cli.run("saltutil.refresh_pillar", wait=True) ret = salt_call_cli.run("saltutil.refresh_pillar", wait=True)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
yield yield
finally: finally:
# Refresh pillar again to cleaup the temp pillar # Refresh pillar again to cleaup the temp pillar
ret = salt_call_cli.run("saltutil.refresh_pillar", wait=True) ret = salt_call_cli.run("saltutil.refresh_pillar", wait=True)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
@pytest.fixture(scope="module") @pytest.fixture(scope="module")
@ -121,8 +121,8 @@ def salt_secondary_master(request, salt_factories):
# #
# Enable a secondary Salt master so we can disable follow_symlinks # Enable a secondary Salt master so we can disable follow_symlinks
# #
publish_port = get_unused_localhost_port() publish_port = ports.get_unused_localhost_port()
ret_port = get_unused_localhost_port() ret_port = ports.get_unused_localhost_port()
config_defaults = { config_defaults = {
"open_mode": True, "open_mode": True,
@ -203,10 +203,10 @@ def test_verify_ssl_skip_verify_false(
"verify_ssl.sls", true_content "verify_ssl.sls", true_content
) as sfpath: ) as sfpath:
ret = salt_call_cli.run("--local", "state.apply", "verify_ssl") ret = salt_call_cli.run("--local", "state.apply", "verify_ssl")
assert ret.exitcode == 1 assert ret.returncode == 1
assert ( assert (
"SSL: CERTIFICATE_VERIFY_FAILED" "SSL: CERTIFICATE_VERIFY_FAILED"
in ret.json[next(iter(ret.json))]["comment"] in ret.data[next(iter(ret.data))]["comment"]
) )
# test when verify_ssl is False # test when verify_ssl is False
@ -214,8 +214,8 @@ def test_verify_ssl_skip_verify_false(
"verify_ssl.sls", false_content "verify_ssl.sls", false_content
) as sfpath: ) as sfpath:
ret = salt_call_cli.run("--local", "state.apply", "verify_ssl") ret = salt_call_cli.run("--local", "state.apply", "verify_ssl")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json[next(iter(ret.json))]["changes"] == { assert ret.data[next(iter(ret.data))]["changes"] == {
"diff": "New file", "diff": "New file",
"mode": "0644", "mode": "0644",
} }
@ -243,9 +243,9 @@ def test_contents_pillar_with_pillar_list(
) )
with sls_tempfile: with sls_tempfile:
ret = salt_call_cli.run("state.sls", sls_name) ret = salt_call_cli.run("state.sls", sls_name)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
state_run = next(iter(ret.json.values())) state_run = next(iter(ret.data.values()))
assert state_run["result"] is True assert state_run["result"] is True
# Check to make sure the file was created # Check to make sure the file was created
assert target_path.is_file() assert target_path.is_file()
@ -259,10 +259,10 @@ def test_managed_file_with_pillar_sls(
is rendered properly and file is created. is rendered properly and file is created.
""" """
ret = salt_call_cli.run("pillar.get", "monty") ret = salt_call_cli.run("pillar.get", "monty")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
target_path = tmp_path / "file-pillar-{}-target.txt".format(ret.json) target_path = tmp_path / "file-pillar-{}-target.txt".format(ret.data)
sls_name = "file-pillar-get" sls_name = "file-pillar-get"
sls_contents = ( sls_contents = (
""" """
@ -280,9 +280,9 @@ def test_managed_file_with_pillar_sls(
) )
with sls_tempfile: with sls_tempfile:
ret = salt_call_cli.run("state.sls", sls_name) ret = salt_call_cli.run("state.sls", sls_name)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
state_run = next(iter(ret.json.values())) state_run = next(iter(ret.data.values()))
assert state_run["result"] is True assert state_run["result"] is True
# Check to make sure the file was created # Check to make sure the file was created
assert target_path.is_file() assert target_path.is_file()
@ -314,16 +314,16 @@ def test_issue_50221(
) )
with sls_tempfile, issue_50221_ext_pillar_tempfile: with sls_tempfile, issue_50221_ext_pillar_tempfile:
ret = salt_call_cli.run("pillar.get", "issue-50221") ret = salt_call_cli.run("pillar.get", "issue-50221")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
# The type of new line, ie, `\n` vs `\r\n` is not important # The type of new line, ie, `\n` vs `\r\n` is not important
assert ret.json.replace("\r\n", "\n") == expected_content assert ret.data.replace("\r\n", "\n") == expected_content
ret = salt_call_cli.run( ret = salt_call_cli.run(
"state.apply", sls_name, pillar={"target-path": str(target_path)} "state.apply", sls_name, pillar={"target-path": str(target_path)}
) )
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
state_run = next(iter(ret.json.values())) state_run = next(iter(ret.data.values()))
assert state_run["result"] is True assert state_run["result"] is True
# Check to make sure the file was created # Check to make sure the file was created
assert target_path.is_file() assert target_path.is_file()
@ -376,9 +376,9 @@ def test_issue_60426(
with sls_tempfile, jinja_tempfile: with sls_tempfile, jinja_tempfile:
ret = salt_call_cli.run("state.apply", sls_name) ret = salt_call_cli.run("state.apply", sls_name)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
state_run = next(iter(ret.json.values())) state_run = next(iter(ret.data.values()))
assert state_run["result"] is True assert state_run["result"] is True
# Check to make sure the file was created # Check to make sure the file was created
assert target_path.is_file() assert target_path.is_file()
@ -417,9 +417,9 @@ def test_issue_60426(
with sls_tempfile, jinja_tempfile: with sls_tempfile, jinja_tempfile:
ret = salt_call_cli.run("state.apply", sls_name) ret = salt_call_cli.run("state.apply", sls_name)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
state_run = next(iter(ret.json.values())) state_run = next(iter(ret.data.values()))
assert state_run["result"] is True assert state_run["result"] is True
# Check to make sure the file was created # Check to make sure the file was created
assert target_path.is_file() assert target_path.is_file()
@ -447,33 +447,33 @@ def test_issue_60203(
) )
with sls_tempfile: with sls_tempfile:
ret = salt_call_cli.run("state.apply", sls_name) ret = salt_call_cli.run("state.apply", sls_name)
assert ret.exitcode == 1 assert ret.returncode == 1
assert ret.json assert ret.data
assert ( assert (
"file_|-credentials exposed via file_|-/tmp/test.tar.gz_|-managed" "file_|-credentials exposed via file_|-/tmp/test.tar.gz_|-managed"
in ret.json in ret.data
) )
assert ( assert (
"comment" "comment"
in ret.json[ in ret.data[
"file_|-credentials exposed via file_|-/tmp/test.tar.gz_|-managed" "file_|-credentials exposed via file_|-/tmp/test.tar.gz_|-managed"
] ]
) )
assert ( assert (
"Unable to manage" "Unable to manage"
in ret.json[ in ret.data[
"file_|-credentials exposed via file_|-/tmp/test.tar.gz_|-managed" "file_|-credentials exposed via file_|-/tmp/test.tar.gz_|-managed"
]["comment"] ]["comment"]
) )
assert ( assert (
"/files/test.tar.gz.sha256" "/files/test.tar.gz.sha256"
in ret.json[ in ret.data[
"file_|-credentials exposed via file_|-/tmp/test.tar.gz_|-managed" "file_|-credentials exposed via file_|-/tmp/test.tar.gz_|-managed"
]["comment"] ]["comment"]
) )
assert ( assert (
"dontshowme" "dontshowme"
not in ret.json[ not in ret.data[
"file_|-credentials exposed via file_|-/tmp/test.tar.gz_|-managed" "file_|-credentials exposed via file_|-/tmp/test.tar.gz_|-managed"
]["comment"] ]["comment"]
) )
@ -540,18 +540,18 @@ def test_patch_single_file(salt_call_cli, min_patch_ver, patch_file_dest):
# Store the original contents and make sure they change # Store the original contents and make sure they change
ret = salt_call_cli.run("state.apply", "test_patch") ret = salt_call_cli.run("state.apply", "test_patch")
# Check to make sure the patch was applied okay # Check to make sure the patch was applied okay
assert ret.exitcode == 0 assert ret.returncode == 0
state_run = next(iter(ret.json.values())) state_run = next(iter(ret.data.values()))
assert state_run["result"] is True assert state_run["result"] is True
assert state_run["comment"] == "Patch successfully applied" assert state_run["comment"] == "Patch successfully applied"
# Re-run the state, should succeed and there should be a message about # Re-run the state, should succeed and there should be a message about
# a partially-applied hunk. # a partially-applied hunk.
ret = salt_call_cli.run("state.apply", "test_patch") ret = salt_call_cli.run("state.apply", "test_patch")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
state_run = next(iter(ret.json.values())) state_run = next(iter(ret.data.values()))
assert state_run["result"] is True assert state_run["result"] is True
assert state_run["comment"] == "Patch was already applied" assert state_run["comment"] == "Patch was already applied"
assert state_run["changes"] == {} assert state_run["changes"] == {}
@ -597,19 +597,19 @@ def test_patch_directory(
with sls_tempfile, numbers_tempfile, math_tempfile: with sls_tempfile, numbers_tempfile, math_tempfile:
# Run the state file # Run the state file
ret = salt_call_cli.run("state.apply", "test_patch") ret = salt_call_cli.run("state.apply", "test_patch")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
# Check to make sure the patch was applied okay # Check to make sure the patch was applied okay
state_run = next(iter(ret.json.values())) state_run = next(iter(ret.data.values()))
assert state_run["result"] is True assert state_run["result"] is True
assert state_run["comment"] == "Patch successfully applied" assert state_run["comment"] == "Patch successfully applied"
# Re-run the state, should succeed and there should be a message about # Re-run the state, should succeed and there should be a message about
# a partially-applied hunk. # a partially-applied hunk.
ret = salt_call_cli.run("state.apply", "test_patch") ret = salt_call_cli.run("state.apply", "test_patch")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
state_run = next(iter(ret.json.values())) state_run = next(iter(ret.data.values()))
assert state_run["result"] is True assert state_run["result"] is True
assert state_run["comment"] == "Patch was already applied" assert state_run["comment"] == "Patch was already applied"
assert state_run["changes"] == {} assert state_run["changes"] == {}
@ -667,19 +667,19 @@ def test_patch_strip_parsing(
with sls_tempfile, sls_patch_tempfile, numbers_tempfile, math_tempfile: with sls_tempfile, sls_patch_tempfile, numbers_tempfile, math_tempfile:
# Run the state using -p1 # Run the state using -p1
ret = salt_call_cli.run("state.apply", "test_patch") ret = salt_call_cli.run("state.apply", "test_patch")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
# Check to make sure the patch was applied okay # Check to make sure the patch was applied okay
state_run = next(iter(ret.json.values())) state_run = next(iter(ret.data.values()))
assert state_run["result"] is True assert state_run["result"] is True
assert state_run["comment"] == "Patch successfully applied" assert state_run["comment"] == "Patch successfully applied"
# Re-run the state using --strip=1 # Re-run the state using --strip=1
ret = salt_call_cli.run("state.apply", "test_patch_strip") ret = salt_call_cli.run("state.apply", "test_patch_strip")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
state_run = next(iter(ret.json.values())) state_run = next(iter(ret.data.values()))
assert state_run["result"] is True assert state_run["result"] is True
assert state_run["comment"] == "Patch was already applied" assert state_run["comment"] == "Patch was already applied"
assert state_run["changes"] == {} assert state_run["changes"] == {}
@ -721,11 +721,11 @@ def test_patch_saltenv(
with sls_tempfile, math_tempfile: with sls_tempfile, math_tempfile:
ret = salt_call_cli.run("state.apply", "test_patch") ret = salt_call_cli.run("state.apply", "test_patch")
assert ret.exitcode == 1 assert ret.returncode == 1
assert ret.json assert ret.data
# Check to make sure the patch was applied okay # Check to make sure the patch was applied okay
state_run = next(iter(ret.json.values())) state_run = next(iter(ret.data.values()))
assert state_run["result"] is False assert state_run["result"] is False
assert state_run[ assert state_run[
"comment" "comment"
@ -791,20 +791,20 @@ def test_patch_single_file_failure(
pass pass
ret = salt_call_cli.run("state.apply", "test_patch") ret = salt_call_cli.run("state.apply", "test_patch")
assert ret.exitcode == 1 assert ret.returncode == 1
assert ret.json assert ret.data
# Check to make sure the patch was applied okay # Check to make sure the patch was applied okay
state_run = next(iter(ret.json.values())) state_run = next(iter(ret.data.values()))
assert state_run["result"] is False assert state_run["result"] is False
assert "Patch would not apply cleanly" in state_run["comment"] assert "Patch would not apply cleanly" in state_run["comment"]
# Test the reject_file option and ensure that the rejects are written # Test the reject_file option and ensure that the rejects are written
# to the path specified. # to the path specified.
ret = salt_call_cli.run("state.apply", "test_patch_reject") ret = salt_call_cli.run("state.apply", "test_patch_reject")
assert ret.exitcode == 1 assert ret.returncode == 1
assert ret.json assert ret.data
state_run = next(iter(ret.json.values())) state_run = next(iter(ret.data.values()))
assert "Patch would not apply cleanly" in state_run["comment"] assert "Patch would not apply cleanly" in state_run["comment"]
assert ( assert (
re.match( re.match(
@ -872,20 +872,20 @@ def test_patch_directory_failure(
pass pass
ret = salt_call_cli.run("state.apply", "test_patch") ret = salt_call_cli.run("state.apply", "test_patch")
assert ret.exitcode == 1 assert ret.returncode == 1
assert ret.json assert ret.data
# Check to make sure the patch was applied okay # Check to make sure the patch was applied okay
state_run = next(iter(ret.json.values())) state_run = next(iter(ret.data.values()))
assert state_run["result"] is False assert state_run["result"] is False
assert "Patch would not apply cleanly" in state_run["comment"] assert "Patch would not apply cleanly" in state_run["comment"]
# Test the reject_file option and ensure that the rejects are written # Test the reject_file option and ensure that the rejects are written
# to the path specified. # to the path specified.
ret = salt_call_cli.run("state.apply", "test_patch_reject") ret = salt_call_cli.run("state.apply", "test_patch_reject")
assert ret.exitcode == 1 assert ret.returncode == 1
assert ret.json assert ret.data
state_run = next(iter(ret.json.values())) state_run = next(iter(ret.data.values()))
assert "Patch would not apply cleanly" in state_run["comment"] assert "Patch would not apply cleanly" in state_run["comment"]
assert ( assert (
re.match( re.match(
@ -937,20 +937,20 @@ def test_patch_single_file_template(
with sls_tempfile, numbers_tempfile: with sls_tempfile, numbers_tempfile:
ret = salt_call_cli.run("state.apply", "test_patch") ret = salt_call_cli.run("state.apply", "test_patch")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
# Check to make sure the patch was applied okay # Check to make sure the patch was applied okay
state_run = next(iter(ret.json.values())) state_run = next(iter(ret.data.values()))
assert state_run["result"] is True assert state_run["result"] is True
assert state_run["comment"] == "Patch successfully applied" assert state_run["comment"] == "Patch successfully applied"
# Re-run the state, should succeed and there should be a message about # Re-run the state, should succeed and there should be a message about
# a partially-applied hunk. # a partially-applied hunk.
ret = salt_call_cli.run("state.apply", "test_patch") ret = salt_call_cli.run("state.apply", "test_patch")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
state_run = next(iter(ret.json.values())) state_run = next(iter(ret.data.values()))
assert state_run["result"] is True assert state_run["result"] is True
assert state_run["comment"] == "Patch was already applied" assert state_run["comment"] == "Patch was already applied"
assert state_run["changes"] == {} assert state_run["changes"] == {}
@ -998,20 +998,20 @@ def test_patch_directory_template(
with sls_tempfile, numbers_tempfile, math_tempfile: with sls_tempfile, numbers_tempfile, math_tempfile:
ret = salt_call_cli.run("state.apply", "test_patch") ret = salt_call_cli.run("state.apply", "test_patch")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
# Check to make sure the patch was applied okay # Check to make sure the patch was applied okay
state_run = next(iter(ret.json.values())) state_run = next(iter(ret.data.values()))
assert state_run["result"] is True assert state_run["result"] is True
assert state_run["comment"] == "Patch was already applied" assert state_run["comment"] == "Patch was already applied"
# Re-run the state, should succeed and there should be a message about # Re-run the state, should succeed and there should be a message about
# a partially-applied hunk. # a partially-applied hunk.
ret = salt_call_cli.run("state.apply", "test_patch") ret = salt_call_cli.run("state.apply", "test_patch")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
state_run = next(iter(ret.json.values())) state_run = next(iter(ret.data.values()))
assert state_run["result"] is True assert state_run["result"] is True
assert state_run["comment"] == "Patch was already applied" assert state_run["comment"] == "Patch was already applied"
assert state_run["changes"] == {} assert state_run["changes"] == {}
@ -1053,9 +1053,9 @@ def test_patch_test_mode(
with sls_patch_tempfile, numbers_tempfile: with sls_patch_tempfile, numbers_tempfile:
# Test application with test=True mode # Test application with test=True mode
ret = salt_call_cli.run("state.apply", "test_patch", test=True) ret = salt_call_cli.run("state.apply", "test_patch", test=True)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
state_run = next(iter(ret.json.values())) state_run = next(iter(ret.data.values()))
assert state_run["result"] is None assert state_run["result"] is None
assert state_run["comment"] == "The patch would be applied" assert state_run["comment"] == "The patch would be applied"
@ -1063,11 +1063,11 @@ def test_patch_test_mode(
# exit with a True rather than a None result if test=True is used on an # exit with a True rather than a None result if test=True is used on an
# already-applied patch. # already-applied patch.
ret = salt_call_cli.run("state.apply", "test_patch") ret = salt_call_cli.run("state.apply", "test_patch")
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
# Check to make sure the patch was applied okay # Check to make sure the patch was applied okay
state_run = next(iter(ret.json.values())) state_run = next(iter(ret.data.values()))
assert state_run["result"] is True assert state_run["result"] is True
assert state_run["comment"] == "Patch successfully applied" assert state_run["comment"] == "Patch successfully applied"
@ -1076,11 +1076,11 @@ def test_patch_test_mode(
# the same as if we try to run this state on an already-patched file # the same as if we try to run this state on an already-patched file
# *without* test=True. # *without* test=True.
ret = salt_call_cli.run("state.apply", "test_patch", test=True) ret = salt_call_cli.run("state.apply", "test_patch", test=True)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
# Check to make sure the patch was applied okay # Check to make sure the patch was applied okay
state_run = next(iter(ret.json.values())) state_run = next(iter(ret.data.values()))
assert state_run["result"] is True assert state_run["result"] is True
assert state_run["comment"] == "Patch was already applied" assert state_run["comment"] == "Patch was already applied"
@ -1093,11 +1093,11 @@ def test_patch_test_mode(
# case we should return a False result because we should already know # case we should return a False result because we should already know
# by this point that the patch will not apply cleanly. # by this point that the patch will not apply cleanly.
ret = salt_call_cli.run("state.apply", "test_patch", test=True) ret = salt_call_cli.run("state.apply", "test_patch", test=True)
assert ret.exitcode == 1 assert ret.returncode == 1
assert ret.json assert ret.data
# Check to make sure the patch was applied okay # Check to make sure the patch was applied okay
state_run = next(iter(ret.json.values())) state_run = next(iter(ret.data.values()))
assert state_run["result"] is False assert state_run["result"] is False
assert "Patch would not apply cleanly" in state_run["comment"] assert "Patch would not apply cleanly" in state_run["comment"]
@ -1136,9 +1136,9 @@ def test_recurse(
test_tempdir.joinpath(_dir, str(_file)).touch() test_tempdir.joinpath(_dir, str(_file)).touch()
ret = salt_call_cli.run("state.apply", sls_name) ret = salt_call_cli.run("state.apply", sls_name)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
state_run = next(iter(ret.json.values())) state_run = next(iter(ret.data.values()))
assert state_run["result"] is True assert state_run["result"] is True
# Check to make sure the directories and files were created # Check to make sure the directories and files were created
@ -1188,9 +1188,9 @@ def test_recurse_keep_symlinks_in_fileserver_root(
os.chdir(str(cwd)) os.chdir(str(cwd))
ret = salt_call_cli.run("state.apply", sls_name) ret = salt_call_cli.run("state.apply", sls_name)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
state_run = next(iter(ret.json.values())) state_run = next(iter(ret.data.values()))
assert state_run["result"] is True assert state_run["result"] is True
# Check to make sure the directories and files were created # Check to make sure the directories and files were created
@ -1245,9 +1245,9 @@ def test_recurse_keep_symlinks_outside_fileserver_root(
os.chdir(str(cwd)) os.chdir(str(cwd))
ret = salt_cli_secondary_wrapper("state.apply", sls_name) ret = salt_cli_secondary_wrapper("state.apply", sls_name)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json assert ret.data
state_run = next(iter(ret.json.values())) state_run = next(iter(ret.data.values()))
assert state_run["result"] is True assert state_run["result"] is True
# Check to make sure the directories and files were created # Check to make sure the directories and files were created

View file

@ -31,7 +31,7 @@ def test_state(salt_call_cli):
) )
state_id = "idem_|-idem_test_|-idem_test_|-state" state_id = "idem_|-idem_test_|-idem_test_|-state"
parent = ret.json[state_id] parent = ret.data[state_id]
assert parent["result"] is True, parent["comment"] assert parent["result"] is True, parent["comment"]
sub_state_ret = parent["sub_state_run"][0] sub_state_ret = parent["sub_state_run"][0]
assert sub_state_ret["result"] is True assert sub_state_ret["result"] is True
@ -44,7 +44,7 @@ def test_state(salt_call_cli):
chunk_ret = state_obj.call_chunk( chunk_ret = state_obj.call_chunk(
{"state": "state", "name": "name", "fun": "fun", "__id__": "__id__"}, {"state": "state", "name": "name", "fun": "fun", "__id__": "__id__"},
ret.json, ret.data,
{}, {},
) )
# Verify that the sub_state_run looks like a normal salt state # Verify that the sub_state_run looks like a normal salt state
@ -58,7 +58,7 @@ def test_bad_state(salt_call_cli):
ret = salt_call_cli.run( ret = salt_call_cli.run(
"--local", "state.single", "idem.state", sls=bad_sls, name="idem_bad_test" "--local", "state.single", "idem.state", sls=bad_sls, name="idem_bad_test"
) )
parent = ret.json["idem_|-idem_bad_test_|-idem_bad_test_|-state"] parent = ret.data["idem_|-idem_bad_test_|-idem_bad_test_|-state"]
assert parent["result"] is False assert parent["result"] is False
assert "SLS ref {} did not resolve to a file".format(bad_sls) == parent["comment"] assert "SLS ref {} did not resolve to a file".format(bad_sls) == parent["comment"]

View file

@ -27,7 +27,7 @@ def test_options_present(salt_master, salt_call_cli):
with salt_master.state_tree.base.temp_file("manage_ini.sls", content): with salt_master.state_tree.base.temp_file("manage_ini.sls", content):
ret = salt_call_cli.run("--local", "state.apply", "manage_ini") ret = salt_call_cli.run("--local", "state.apply", "manage_ini")
assert ret.json[next(iter(ret.json))]["changes"] == { assert ret.data[next(iter(ret.data))]["changes"] == {
"general": { "general": {
"before": None, "before": None,
"after": {"server_hostname": "foo.com", "server_port": "1234"}, "after": {"server_hostname": "foo.com", "server_port": "1234"},
@ -50,10 +50,10 @@ def test_options_present(salt_master, salt_call_cli):
with salt_master.state_tree.base.temp_file("manage_ini.sls", content): with salt_master.state_tree.base.temp_file("manage_ini.sls", content):
# check to see adding a new section works # check to see adding a new section works
ret = salt_call_cli.run("--local", "state.apply", "manage_ini") ret = salt_call_cli.run("--local", "state.apply", "manage_ini")
assert ret.json[next(iter(ret.json))]["changes"] == { assert ret.data[next(iter(ret.data))]["changes"] == {
"general": {"server_user": {"before": None, "after": "saltfoo"}} "general": {"server_user": {"before": None, "after": "saltfoo"}}
} }
# check when no changes are expected # check when no changes are expected
ret = salt_call_cli.run("--local", "state.apply", "manage_ini") ret = salt_call_cli.run("--local", "state.apply", "manage_ini")
assert ret.json[next(iter(ret.json))]["changes"] == {} assert ret.data[next(iter(ret.data))]["changes"] == {}

View file

@ -55,8 +55,8 @@ def test_database_present_absent(salt_cli_wrapper):
"mysql_database.present", "mysql_database.present",
name="test_database", name="test_database",
) )
state = ret.json["mysql_database_|-test_database_|-test_database_|-present"] state = ret.data["mysql_database_|-test_database_|-test_database_|-present"]
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
assert "changes" in state assert "changes" in state
assert state["changes"] == {"test_database": "Present"} assert state["changes"] == {"test_database": "Present"}
@ -69,9 +69,9 @@ def test_database_present_absent(salt_cli_wrapper):
"mysql_database.absent", "mysql_database.absent",
name="test_database", name="test_database",
) )
state = ret.json["mysql_database_|-test_database_|-test_database_|-absent"] state = ret.data["mysql_database_|-test_database_|-test_database_|-absent"]
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
assert "changes" in state assert "changes" in state
assert state["changes"] == {"test_database": "Absent"} assert state["changes"] == {"test_database": "Absent"}
@ -84,7 +84,7 @@ def test_grants_present_absent(salt_cli_wrapper, salt_call_cli_wrapper):
# Create the database # Create the database
ret = salt_call_cli_wrapper("mysql.db_create", "salt") ret = salt_call_cli_wrapper("mysql.db_create", "salt")
assert ret.json assert ret.data
# Create a user # Create a user
ret = salt_call_cli_wrapper( ret = salt_call_cli_wrapper(
@ -93,7 +93,7 @@ def test_grants_present_absent(salt_cli_wrapper, salt_call_cli_wrapper):
host="localhost", host="localhost",
password="badpassword", password="badpassword",
) )
assert ret.json assert ret.data
ret = salt_cli_wrapper( ret = salt_cli_wrapper(
"state.single", "state.single",
@ -104,8 +104,8 @@ def test_grants_present_absent(salt_cli_wrapper, salt_call_cli_wrapper):
user="george", user="george",
host="localhost", host="localhost",
) )
state = ret.json["mysql_grants_|-add_salt_grants_|-add_salt_grants_|-present"] state = ret.data["mysql_grants_|-add_salt_grants_|-add_salt_grants_|-present"]
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
assert "changes" in state assert "changes" in state
assert state["changes"] == {"add_salt_grants": "Present"} assert state["changes"] == {"add_salt_grants": "Present"}
@ -125,8 +125,8 @@ def test_grants_present_absent(salt_cli_wrapper, salt_call_cli_wrapper):
user="george", user="george",
host="localhost", host="localhost",
) )
state = ret.json["mysql_grants_|-delete_salt_grants_|-delete_salt_grants_|-absent"] state = ret.data["mysql_grants_|-delete_salt_grants_|-delete_salt_grants_|-absent"]
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
assert "changes" in state assert "changes" in state
assert state["changes"] == {"delete_salt_grants": "Absent"} assert state["changes"] == {"delete_salt_grants": "Absent"}
@ -139,11 +139,11 @@ def test_grants_present_absent(salt_cli_wrapper, salt_call_cli_wrapper):
# Remove the user # Remove the user
ret = salt_call_cli_wrapper("mysql.user_remove", "george", host="localhost") ret = salt_call_cli_wrapper("mysql.user_remove", "george", host="localhost")
assert ret.json assert ret.data
# Remove the database # Remove the database
ret = salt_call_cli_wrapper("mysql.db_remove", "salt") ret = salt_call_cli_wrapper("mysql.db_remove", "salt")
assert ret.json assert ret.data
def test_user_present_absent(salt_cli_wrapper): def test_user_present_absent(salt_cli_wrapper):
@ -155,8 +155,8 @@ def test_user_present_absent(salt_cli_wrapper):
host="localhost", host="localhost",
password="password", password="password",
) )
state = ret.json["mysql_user_|-george_|-george_|-present"] state = ret.data["mysql_user_|-george_|-george_|-present"]
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
assert "changes" in state assert "changes" in state
assert state["changes"] == {"george": "Present"} assert state["changes"] == {"george": "Present"}
@ -170,8 +170,8 @@ def test_user_present_absent(salt_cli_wrapper):
name="george", name="george",
host="localhost", host="localhost",
) )
state = ret.json["mysql_user_|-george_|-george_|-absent"] state = ret.data["mysql_user_|-george_|-george_|-absent"]
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
assert "changes" in state assert "changes" in state
assert state["changes"] == {"george": "Absent"} assert state["changes"] == {"george": "Absent"}
@ -189,8 +189,8 @@ def test_user_present_absent_passwordless(salt_cli_wrapper):
host="localhost", host="localhost",
allow_passwordless=True, allow_passwordless=True,
) )
state = ret.json["mysql_user_|-george_|-george_|-present"] state = ret.data["mysql_user_|-george_|-george_|-present"]
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
assert "changes" in state assert "changes" in state
assert state["changes"] == {"george": "Present"} assert state["changes"] == {"george": "Present"}
@ -208,8 +208,8 @@ def test_user_present_absent_passwordless(salt_cli_wrapper):
name="george", name="george",
host="localhost", host="localhost",
) )
state = ret.json["mysql_user_|-george_|-george_|-absent"] state = ret.data["mysql_user_|-george_|-george_|-absent"]
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
assert "changes" in state assert "changes" in state
assert state["changes"] == {"george": "Absent"} assert state["changes"] == {"george": "Absent"}
@ -235,7 +235,7 @@ def test_user_present_absent_unixsocket(salt_cli_wrapper, mysql_container):
# already enabled on MariaDB > 10.3 # already enabled on MariaDB > 10.3
if "mariadb" not in mysql_container.mysql_name: if "mariadb" not in mysql_container.mysql_name:
ret = salt_cli_wrapper("mysql.plugin_add", "auth_socket") ret = salt_cli_wrapper("mysql.plugin_add", "auth_socket")
assert ret.json assert ret.data
ret = salt_cli_wrapper( ret = salt_cli_wrapper(
"state.single", "state.single",
@ -245,8 +245,8 @@ def test_user_present_absent_unixsocket(salt_cli_wrapper, mysql_container):
unix_socket=True, unix_socket=True,
allow_passwordless=False, allow_passwordless=False,
) )
state = ret.json["mysql_user_|-george_|-george_|-present"] state = ret.data["mysql_user_|-george_|-george_|-present"]
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
assert "changes" in state assert "changes" in state
assert state["changes"] == {"george": "Present"} assert state["changes"] == {"george": "Present"}
@ -262,8 +262,8 @@ def test_user_present_absent_unixsocket(salt_cli_wrapper, mysql_container):
name="george", name="george",
host="localhost", host="localhost",
) )
state = ret.json["mysql_user_|-george_|-george_|-absent"] state = ret.data["mysql_user_|-george_|-george_|-absent"]
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
assert "changes" in state assert "changes" in state
assert state["changes"] == {"george": "Absent"} assert state["changes"] == {"george": "Absent"}
@ -273,4 +273,4 @@ def test_user_present_absent_unixsocket(salt_cli_wrapper, mysql_container):
if "mariadb" not in mysql_container.mysql_name: if "mariadb" not in mysql_container.mysql_name:
ret = salt_cli_wrapper("mysql.plugin_remove", "auth_socket") ret = salt_cli_wrapper("mysql.plugin_remove", "auth_socket")
assert ret.json assert ret.data

View file

@ -32,8 +32,8 @@ def test_issue_60083(
"state.apply", sls_name, pillar={"target-path": str(target_path)} "state.apply", sls_name, pillar={"target-path": str(target_path)}
) )
assert ret.stdout.find("Jinja error") == -1 assert ret.stdout.find("Jinja error") == -1
assert ret.json assert ret.data
keys = list(ret.json.keys()) keys = list(ret.data.keys())
assert len(keys) == 1 assert len(keys) == 1
key = keys[0] key = keys[0]
assert ret.json[key]["changes"]["diff"] == "New file" assert ret.data[key]["changes"]["diff"] == "New file"

View file

@ -56,9 +56,9 @@ class BlackoutPillar:
def refresh_pillar(self, timeout=60, sleep=0.5, exiting_blackout=None): def refresh_pillar(self, timeout=60, sleep=0.5, exiting_blackout=None):
ret = self.salt_cli.run("saltutil.refresh_pillar", wait=True, minion_tgt="*") ret = self.salt_cli.run("saltutil.refresh_pillar", wait=True, minion_tgt="*")
assert ret.exitcode == 0 assert ret.returncode == 0
assert self.minion_1_id in ret.json assert self.minion_1_id in ret.data
assert self.minion_2_id in ret.json assert self.minion_2_id in ret.data
stop_at = time.time() + timeout stop_at = time.time() + timeout
while True: while True:
if time.time() > stop_at: if time.time() > stop_at:
@ -82,23 +82,23 @@ class BlackoutPillar:
time.sleep(sleep) time.sleep(sleep)
ret = self.salt_cli.run("pillar.get", "minion_blackout", minion_tgt="*") ret = self.salt_cli.run("pillar.get", "minion_blackout", minion_tgt="*")
if not ret.json: if not ret.data:
# Something is wrong here. Try again # Something is wrong here. Try again
continue continue
assert self.minion_1_id in ret.json assert self.minion_1_id in ret.data
assert self.minion_2_id in ret.json assert self.minion_2_id in ret.data
if ret.json[self.minion_1_id] == "" or ret.json[self.minion_2_id] == "": if ret.data[self.minion_1_id] == "" or ret.data[self.minion_2_id] == "":
# Pillar not found # Pillar not found
continue continue
# Minion 2 must NEVER enter blackout # Minion 2 must NEVER enter blackout
assert ret.json[self.minion_2_id] is False assert ret.data[self.minion_2_id] is False
if exiting_blackout is True and ret.json[self.minion_1_id] is not False: if exiting_blackout is True and ret.data[self.minion_1_id] is not False:
continue continue
elif ( elif (
exiting_blackout is False exiting_blackout is False
and "Minion in blackout mode" not in ret.json[self.minion_1_id] and "Minion in blackout mode" not in ret.data[self.minion_1_id]
): ):
continue continue
# We got the pillar we're after, break out of the loop # We got the pillar we're after, break out of the loop

View file

@ -20,15 +20,15 @@ def test_blackout(salt_cli, blackout, salt_minion_1):
Test that basic minion blackout functionality works Test that basic minion blackout functionality works
""" """
ret = salt_cli.run("test.ping", minion_tgt=salt_minion_1.id) ret = salt_cli.run("test.ping", minion_tgt=salt_minion_1.id)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
with blackout.enter_blackout("minion_blackout: true"): with blackout.enter_blackout("minion_blackout: true"):
ret = salt_cli.run("test.ping", minion_tgt=salt_minion_1.id) ret = salt_cli.run("test.ping", minion_tgt=salt_minion_1.id)
assert ret.exitcode == 1 assert ret.returncode == 1
assert "Minion in blackout mode." in ret.stdout assert "Minion in blackout mode." in ret.stdout
ret = salt_cli.run("test.ping", minion_tgt=salt_minion_1.id) ret = salt_cli.run("test.ping", minion_tgt=salt_minion_1.id)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
@pytest.mark.slow_test @pytest.mark.slow_test
@ -43,16 +43,16 @@ def test_blackout_whitelist(salt_cli, blackout, salt_minion_1):
- test.fib - test.fib
""" """
ret = salt_cli.run("test.ping", minion_tgt=salt_minion_1.id) ret = salt_cli.run("test.ping", minion_tgt=salt_minion_1.id)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
with blackout.enter_blackout(blackout_contents): with blackout.enter_blackout(blackout_contents):
ret = salt_cli.run("test.ping", minion_tgt=salt_minion_1.id) ret = salt_cli.run("test.ping", minion_tgt=salt_minion_1.id)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
ret = salt_cli.run("test.fib", "7", minion_tgt=salt_minion_1.id) ret = salt_cli.run("test.fib", "7", minion_tgt=salt_minion_1.id)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json[0] == 13 assert ret.data[0] == 13
@pytest.mark.slow_test @pytest.mark.slow_test
@ -68,22 +68,22 @@ def test_blackout_nonwhitelist(salt_cli, blackout, salt_minion_1):
- test.fib - test.fib
""" """
ret = salt_cli.run("test.ping", minion_tgt=salt_minion_1.id) ret = salt_cli.run("test.ping", minion_tgt=salt_minion_1.id)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
with blackout.enter_blackout(blackout_contents): with blackout.enter_blackout(blackout_contents):
ret = salt_cli.run("test.ping", minion_tgt=salt_minion_1.id) ret = salt_cli.run("test.ping", minion_tgt=salt_minion_1.id)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True
ret = salt_cli.run("state.apply", minion_tgt=salt_minion_1.id) ret = salt_cli.run("state.apply", minion_tgt=salt_minion_1.id)
assert ret.exitcode == 1 assert ret.returncode == 1
assert "Minion in blackout mode." in ret.stdout assert "Minion in blackout mode." in ret.stdout
ret = salt_cli.run( ret = salt_cli.run(
"cloud.query", "list_nodes_full", minion_tgt=salt_minion_1.id "cloud.query", "list_nodes_full", minion_tgt=salt_minion_1.id
) )
assert ret.exitcode == 1 assert ret.returncode == 1
assert "Minion in blackout mode." in ret.stdout assert "Minion in blackout mode." in ret.stdout
ret = salt_cli.run("test.ping", minion_tgt=salt_minion_1.id) ret = salt_cli.run("test.ping", minion_tgt=salt_minion_1.id)
assert ret.exitcode == 0 assert ret.returncode == 0
assert ret.json is True assert ret.data is True

View file

@ -119,6 +119,8 @@ def salt_minion(
image=minion_image, image=minion_image,
docker_client=docker_client, docker_client=docker_client,
start_timeout=120, start_timeout=120,
pull_before_start=False,
skip_if_docker_client_not_connectable=True,
container_run_kwargs={ container_run_kwargs={
"volumes": {str(artifacts_path): {"bind": "/artifacts", "mode": "z"}} "volumes": {str(artifacts_path): {"bind": "/artifacts", "mode": "z"}}
}, },
@ -172,8 +174,8 @@ def populated_state_tree(minion_id, package_name, state_tree):
def test_ping(salt_cli, salt_minion): def test_ping(salt_cli, salt_minion):
ret = salt_cli.run("test.ping", minion_tgt=salt_minion.id) ret = salt_cli.run("test.ping", minion_tgt=salt_minion.id)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
assert ret.json is True assert ret.data is True
@pytest.mark.usefixtures("populated_state_tree") @pytest.mark.usefixtures("populated_state_tree")
@ -182,10 +184,10 @@ def test_highstate(salt_cli, salt_minion, package_name):
Assert a state.highstate with a newer master runs properly on older minions. Assert a state.highstate with a newer master runs properly on older minions.
""" """
ret = salt_cli.run("state.highstate", minion_tgt=salt_minion.id, _timeout=300) ret = salt_cli.run("state.highstate", minion_tgt=salt_minion.id, _timeout=300)
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
assert ret.json is not None assert ret.data is not None
assert isinstance(ret.json, dict), ret.json assert isinstance(ret.data, dict), ret.data
state_return = next(iter(ret.json.values())) state_return = next(iter(ret.data.values()))
assert package_name in state_return["changes"], state_return assert package_name in state_return["changes"], state_return
@ -205,9 +207,9 @@ def test_cp(salt_cp_cli, salt_minion, artifacts_path, cp_file_source):
ret = salt_cp_cli.run( ret = salt_cp_cli.run(
str(cp_file_source), remote_path, minion_tgt=salt_minion.id, _timeout=300 str(cp_file_source), remote_path, minion_tgt=salt_minion.id, _timeout=300
) )
assert ret.exitcode == 0, ret assert ret.returncode == 0, ret
assert ret.json is not None assert ret.data is not None
assert isinstance(ret.json, dict), ret.json assert isinstance(ret.data, dict), ret.data
assert ret.json == {remote_path: True} assert ret.data == {remote_path: True}
cp_file_dest = artifacts_path / "cheese" cp_file_dest = artifacts_path / "cheese"
assert cp_file_source.read_text() == cp_file_dest.read_text() assert cp_file_source.read_text() == cp_file_dest.read_text()

View file

@ -6,7 +6,7 @@ import time
import pytest import pytest
import salt.utils.platform import salt.utils.platform
from saltfactories.exceptions import FactoryNotStarted, FactoryTimeout from pytestshellutils.exceptions import FactoryNotStarted, FactoryTimeout
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -177,7 +177,7 @@ def run_salt_cmds():
"test.ping", "test.ping",
minion_tgt=minion, minion_tgt=minion,
) )
if ret.exitcode == 0 and ret.json is True: if ret.returncode == 0 and ret.data is True:
returned_minions.append((cli, minions_to_check[minion])) returned_minions.append((cli, minions_to_check[minion]))
minions_to_check.pop(minion) minions_to_check.pop(minion)
except FactoryTimeout: except FactoryTimeout:

View file

@ -46,32 +46,32 @@ def setup_beacons(mm_master_1_salt_cli, salt_mm_minion_1, inotify_test_path):
beacon_data=[{"files": {str(inotify_test_path): {"mask": ["create"]}}}], beacon_data=[{"files": {str(inotify_test_path): {"mask": ["create"]}}}],
minion_tgt=salt_mm_minion_1.id, minion_tgt=salt_mm_minion_1.id,
) )
assert ret.exitcode == 0 assert ret.returncode == 0
log.debug("Inotify beacon add returned: %s", ret.json or ret.stdout) log.debug("Inotify beacon add returned: %s", ret.data or ret.stdout)
assert ret.json assert ret.data
assert ret.json["result"] is True assert ret.data["result"] is True
ret = mm_master_1_salt_cli.run( ret = mm_master_1_salt_cli.run(
"beacons.add", "beacons.add",
"status", "status",
beacon_data=[{"time": ["all"]}], beacon_data=[{"time": ["all"]}],
minion_tgt=salt_mm_minion_1.id, minion_tgt=salt_mm_minion_1.id,
) )
assert ret.exitcode == 0 assert ret.returncode == 0
log.debug("Status beacon add returned: %s", ret.json or ret.stdout) log.debug("Status beacon add returned: %s", ret.data or ret.stdout)
assert ret.json assert ret.data
assert ret.json["result"] is True assert ret.data["result"] is True
ret = mm_master_1_salt_cli.run( ret = mm_master_1_salt_cli.run(
"beacons.list", return_yaml=False, minion_tgt=salt_mm_minion_1.id "beacons.list", return_yaml=False, minion_tgt=salt_mm_minion_1.id
) )
assert ret.exitcode == 0 assert ret.returncode == 0
log.debug("Beacons list: %s", ret.json or ret.stdout) log.debug("Beacons list: %s", ret.data or ret.stdout)
assert ret.json assert ret.data
assert "inotify" in ret.json assert "inotify" in ret.data
assert ret.json["inotify"] == [ assert ret.data["inotify"] == [
{"files": {str(inotify_test_path): {"mask": ["create"]}}} {"files": {str(inotify_test_path): {"mask": ["create"]}}}
] ]
assert "status" in ret.json assert "status" in ret.data
assert ret.json["status"] == [{"time": ["all"]}] assert ret.data["status"] == [{"time": ["all"]}]
yield start_time yield start_time
finally: finally:
# Remove the added beacons # Remove the added beacons

View file

@ -6,7 +6,7 @@ import time
import pytest import pytest
import salt.utils.platform import salt.utils.platform
from saltfactories.exceptions import FactoryTimeout from pytestshellutils.exceptions import FactoryTimeout
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -160,7 +160,7 @@ def run_salt_cmds():
"test.ping", "test.ping",
minion_tgt=minion, minion_tgt=minion,
) )
if ret.exitcode == 0 and ret.json is True: if ret.returncode == 0 and ret.data is True:
returned_minions.append((cli, minion_instances[minion])) returned_minions.append((cli, minion_instances[minion]))
clis_to_check[minion].remove(cli) clis_to_check[minion].remove(cli)
except FactoryTimeout: except FactoryTimeout:

Some files were not shown because too many files have changed in this diff Show more