mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Upgrade to pytest-salt-factories 0.9.x
This commit is contained in:
parent
d30e09f297
commit
6405948882
2 changed files with 122 additions and 94 deletions
|
@ -854,12 +854,84 @@ def salt_master_config(request, salt_factories, salt_syndic_master_config):
|
|||
|
||||
@pytest.fixture(scope="session")
|
||||
def salt_minion_config(request, salt_factories, salt_master_config):
|
||||
return salt_factories.configure_minion(request, "minion", master_id="master")
|
||||
with salt.utils.files.fopen(os.path.join(RUNTIME_VARS.CONF_DIR, "minion")) as rfh:
|
||||
config_defaults = yaml.deserialize(rfh.read())
|
||||
config_defaults["hosts.file"] = os.path.join(RUNTIME_VARS.TMP, "hosts")
|
||||
config_defaults["aliases.file"] = os.path.join(RUNTIME_VARS.TMP, "aliases")
|
||||
config_defaults["transport"] = request.config.getoption("--transport")
|
||||
|
||||
config_overrides = {
|
||||
"file_roots": {
|
||||
"base": [
|
||||
RUNTIME_VARS.TMP_STATE_TREE,
|
||||
os.path.join(RUNTIME_VARS.FILES, "file", "base"),
|
||||
],
|
||||
# Alternate root to test __env__ choices
|
||||
"prod": [
|
||||
RUNTIME_VARS.TMP_PRODENV_STATE_TREE,
|
||||
os.path.join(RUNTIME_VARS.FILES, "file", "prod"),
|
||||
],
|
||||
},
|
||||
"pillar_roots": {
|
||||
"base": [
|
||||
RUNTIME_VARS.TMP_PILLAR_TREE,
|
||||
os.path.join(RUNTIME_VARS.FILES, "pillar", "base"),
|
||||
],
|
||||
"prod": [RUNTIME_VARS.TMP_PRODENV_PILLAR_TREE],
|
||||
},
|
||||
}
|
||||
virtualenv_binary = _get_virtualenv_binary_path()
|
||||
if virtualenv_binary:
|
||||
config_overrides["venv_bin"] = virtualenv_binary
|
||||
return salt_factories.configure_minion(
|
||||
request,
|
||||
"minion",
|
||||
master_id="master",
|
||||
config_defaults=config_defaults,
|
||||
config_overrides=config_overrides,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def salt_sub_minion_config(request, salt_factories, salt_master_config):
|
||||
return salt_factories.configure_minion(request, "sub_minion", master_id="master")
|
||||
with salt.utils.files.fopen(
|
||||
os.path.join(RUNTIME_VARS.CONF_DIR, "sub_minion")
|
||||
) as rfh:
|
||||
config_defaults = yaml.deserialize(rfh.read())
|
||||
config_defaults["hosts.file"] = os.path.join(RUNTIME_VARS.TMP, "hosts")
|
||||
config_defaults["aliases.file"] = os.path.join(RUNTIME_VARS.TMP, "aliases")
|
||||
config_defaults["transport"] = request.config.getoption("--transport")
|
||||
|
||||
config_overrides = {
|
||||
"file_roots": {
|
||||
"base": [
|
||||
RUNTIME_VARS.TMP_STATE_TREE,
|
||||
os.path.join(RUNTIME_VARS.FILES, "file", "base"),
|
||||
],
|
||||
# Alternate root to test __env__ choices
|
||||
"prod": [
|
||||
RUNTIME_VARS.TMP_PRODENV_STATE_TREE,
|
||||
os.path.join(RUNTIME_VARS.FILES, "file", "prod"),
|
||||
],
|
||||
},
|
||||
"pillar_roots": {
|
||||
"base": [
|
||||
RUNTIME_VARS.TMP_PILLAR_TREE,
|
||||
os.path.join(RUNTIME_VARS.FILES, "pillar", "base"),
|
||||
],
|
||||
"prod": [RUNTIME_VARS.TMP_PRODENV_PILLAR_TREE],
|
||||
},
|
||||
}
|
||||
virtualenv_binary = _get_virtualenv_binary_path()
|
||||
if virtualenv_binary:
|
||||
config_overrides["venv_bin"] = virtualenv_binary
|
||||
return salt_factories.configure_minion(
|
||||
request,
|
||||
"sub_minion",
|
||||
master_id="master",
|
||||
config_defaults=config_defaults,
|
||||
config_overrides=config_overrides,
|
||||
)
|
||||
|
||||
|
||||
def pytest_saltfactories_master_configuration_defaults(
|
||||
|
@ -1012,96 +1084,6 @@ def pytest_saltfactories_master_configuration_overrides(
|
|||
return opts
|
||||
|
||||
|
||||
def pytest_saltfactories_minion_configuration_defaults(
|
||||
request, factories_manager, root_dir, minion_id, master_port
|
||||
):
|
||||
"""
|
||||
Hook which should return a dictionary tailored for the provided minion_id
|
||||
|
||||
Stops at the first non None result
|
||||
"""
|
||||
if minion_id == "minion":
|
||||
with salt.utils.files.fopen(
|
||||
os.path.join(RUNTIME_VARS.CONF_DIR, "minion")
|
||||
) as rfh:
|
||||
opts = yaml.deserialize(rfh.read())
|
||||
elif minion_id == "sub_minion":
|
||||
with salt.utils.files.fopen(
|
||||
os.path.join(RUNTIME_VARS.CONF_DIR, "sub_minion")
|
||||
) as rfh:
|
||||
opts = yaml.deserialize(rfh.read())
|
||||
elif minion_id == "mm-minion":
|
||||
with salt.utils.files.fopen(
|
||||
os.path.join(RUNTIME_VARS.CONF_DIR, "mm_minion")
|
||||
) as rfh:
|
||||
opts = yaml.deserialize(rfh.read())
|
||||
elif minion_id == "mm-sub-minion":
|
||||
with salt.utils.files.fopen(
|
||||
os.path.join(RUNTIME_VARS.CONF_DIR, "mm_sub_minion")
|
||||
) as rfh:
|
||||
opts = yaml.deserialize(rfh.read())
|
||||
else:
|
||||
raise RuntimeError("Not prepared to handle minion_id '{}'".format(minion_id))
|
||||
|
||||
opts["hosts.file"] = os.path.join(RUNTIME_VARS.TMP, "hosts")
|
||||
opts["aliases.file"] = os.path.join(RUNTIME_VARS.TMP, "aliases")
|
||||
opts["transport"] = request.config.getoption("--transport")
|
||||
|
||||
return opts
|
||||
|
||||
|
||||
def pytest_saltfactories_minion_configuration_overrides(
|
||||
request, factories_manager, root_dir, minion_id, config_defaults
|
||||
):
|
||||
"""
|
||||
Hook which should return a dictionary tailored for the provided minion_id.
|
||||
This dictionary will override the default_options dictionary.
|
||||
|
||||
Stops at the first non None result
|
||||
"""
|
||||
if minion_id in ("minion", "sub_minion"):
|
||||
opts = {
|
||||
"file_roots": {
|
||||
"base": [
|
||||
RUNTIME_VARS.TMP_STATE_TREE,
|
||||
os.path.join(RUNTIME_VARS.FILES, "file", "base"),
|
||||
],
|
||||
# Alternate root to test __env__ choices
|
||||
"prod": [
|
||||
RUNTIME_VARS.TMP_PRODENV_STATE_TREE,
|
||||
os.path.join(RUNTIME_VARS.FILES, "file", "prod"),
|
||||
],
|
||||
},
|
||||
"pillar_roots": {
|
||||
"base": [
|
||||
RUNTIME_VARS.TMP_PILLAR_TREE,
|
||||
os.path.join(RUNTIME_VARS.FILES, "pillar", "base"),
|
||||
],
|
||||
"prod": [RUNTIME_VARS.TMP_PRODENV_PILLAR_TREE],
|
||||
},
|
||||
}
|
||||
virtualenv_binary = _get_virtualenv_binary_path()
|
||||
if virtualenv_binary:
|
||||
opts["venv_bin"] = virtualenv_binary
|
||||
return opts
|
||||
if minion_id in ("mm-minion", "mm-sub-minion"):
|
||||
mm_master_port = factories_manager.cache["configs"]["masters"]["mm-master"][
|
||||
"ret_port"
|
||||
]
|
||||
mm_sub_master_port = factories_manager.cache["configs"]["masters"][
|
||||
"mm-sub-master"
|
||||
]["ret_port"]
|
||||
opts = {
|
||||
"master_port": "",
|
||||
"master": [
|
||||
"localhost:{}".format(mm_master_port),
|
||||
"localhost:{}".format(mm_sub_master_port),
|
||||
],
|
||||
"test.foo": "baz",
|
||||
}
|
||||
return opts
|
||||
|
||||
|
||||
@pytest.hookspec(firstresult=True)
|
||||
def pytest_saltfactories_syndic_configuration_defaults(
|
||||
request, factories_manager, root_dir, syndic_id, syndic_master_port
|
||||
|
|
|
@ -12,6 +12,8 @@ import os
|
|||
import shutil
|
||||
|
||||
import pytest
|
||||
import salt.utils.files
|
||||
from salt.serializers import yaml
|
||||
from salt.utils.immutabletypes import freeze
|
||||
from tests.support.runtests import RUNTIME_VARS
|
||||
|
||||
|
@ -25,8 +27,30 @@ def salt_mm_master_config(request, salt_factories):
|
|||
|
||||
@pytest.fixture(scope="package")
|
||||
def salt_mm_minion_config(request, salt_factories, salt_mm_master, salt_mm_sub_master):
|
||||
with salt.utils.files.fopen(
|
||||
os.path.join(RUNTIME_VARS.CONF_DIR, "mm_minion")
|
||||
) as rfh:
|
||||
config_defaults = yaml.deserialize(rfh.read())
|
||||
config_defaults["hosts.file"] = os.path.join(RUNTIME_VARS.TMP, "hosts")
|
||||
config_defaults["aliases.file"] = os.path.join(RUNTIME_VARS.TMP, "aliases")
|
||||
config_defaults["transport"] = request.config.getoption("--transport")
|
||||
|
||||
mm_master_port = salt_mm_master.config["ret_port"]
|
||||
mm_sub_master_port = salt_mm_sub_master.config["ret_port"]
|
||||
config_overrides = {
|
||||
"master_port": "",
|
||||
"master": [
|
||||
"localhost:{}".format(mm_master_port),
|
||||
"localhost:{}".format(mm_sub_master_port),
|
||||
],
|
||||
"test.foo": "baz",
|
||||
}
|
||||
return salt_factories.configure_minion(
|
||||
request, "mm-minion", master_id=salt_mm_master.config["id"]
|
||||
request,
|
||||
"mm-minion",
|
||||
master_id=salt_mm_master.config["id"],
|
||||
config_defaults=config_defaults,
|
||||
config_overrides=config_overrides,
|
||||
)
|
||||
|
||||
|
||||
|
@ -39,8 +63,30 @@ def salt_mm_sub_master_config(request, salt_factories, salt_mm_master):
|
|||
def salt_mm_sub_minion_config(
|
||||
request, salt_factories, salt_mm_master, salt_mm_sub_master
|
||||
):
|
||||
with salt.utils.files.fopen(
|
||||
os.path.join(RUNTIME_VARS.CONF_DIR, "mm_sub_minion")
|
||||
) as rfh:
|
||||
config_defaults = yaml.deserialize(rfh.read())
|
||||
config_defaults["hosts.file"] = os.path.join(RUNTIME_VARS.TMP, "hosts")
|
||||
config_defaults["aliases.file"] = os.path.join(RUNTIME_VARS.TMP, "aliases")
|
||||
config_defaults["transport"] = request.config.getoption("--transport")
|
||||
|
||||
mm_master_port = salt_mm_master.config["ret_port"]
|
||||
mm_sub_master_port = salt_mm_sub_master.config["ret_port"]
|
||||
config_overrides = {
|
||||
"master_port": "",
|
||||
"master": [
|
||||
"localhost:{}".format(mm_master_port),
|
||||
"localhost:{}".format(mm_sub_master_port),
|
||||
],
|
||||
"test.foo": "baz",
|
||||
}
|
||||
return salt_factories.configure_minion(
|
||||
request, "mm-sub-minion", master_id=salt_mm_sub_master.config["id"]
|
||||
request,
|
||||
"mm-sub-minion",
|
||||
master_id=salt_mm_sub_master.config["id"],
|
||||
config_defaults=config_defaults,
|
||||
config_overrides=config_overrides,
|
||||
)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue