mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
add minion swarm test using saltfactories
This commit is contained in:
parent
0555d65725
commit
68d4f52cf7
3 changed files with 90 additions and 0 deletions
0
tests/pytests/scenarios/swarm/__init__.py
Normal file
0
tests/pytests/scenarios/swarm/__init__.py
Normal file
71
tests/pytests/scenarios/swarm/conftest.py
Normal file
71
tests/pytests/scenarios/swarm/conftest.py
Normal file
|
@ -0,0 +1,71 @@
|
|||
from contextlib import ExitStack
|
||||
|
||||
import pytest
|
||||
from saltfactories.utils import random_string
|
||||
|
||||
|
||||
@pytest.fixture(scope="package")
|
||||
def salt_master_factory(salt_factories):
|
||||
factory = salt_factories.salt_master_daemon(
|
||||
random_string("swarm-master-"),
|
||||
extra_cli_arguments_after_first_start_failure=["--log-level=debug"],
|
||||
)
|
||||
return factory
|
||||
|
||||
|
||||
@pytest.fixture(scope="package")
|
||||
def salt_master(salt_master_factory):
|
||||
with salt_master_factory.started():
|
||||
yield salt_master_factory
|
||||
|
||||
|
||||
@pytest.fixture(scope="package")
|
||||
def salt_minion(salt_minion_factory):
|
||||
with salt_minion_factory.started():
|
||||
yield salt_minion_factory
|
||||
|
||||
|
||||
@pytest.fixture(scope="package")
|
||||
def salt_key_cli(salt_master):
|
||||
assert salt_master.is_running()
|
||||
return salt_master.salt_key_cli()
|
||||
|
||||
|
||||
@pytest.fixture(scope="package")
|
||||
def salt_cli(salt_master):
|
||||
assert salt_master.is_running()
|
||||
return salt_master.salt_cli()
|
||||
|
||||
|
||||
@pytest.fixture(scope="package")
|
||||
def pki_dir(tmp_path_factory, salt_key_cli):
|
||||
pki_dir = tmp_path_factory.mktemp("swarm") / "pki"
|
||||
key_ret = salt_key_cli.run("--gen-keys", "minion", "--gen-keys-dir", str(pki_dir))
|
||||
assert key_ret.returncode == 0
|
||||
return pki_dir
|
||||
|
||||
|
||||
@pytest.fixture(scope="package")
|
||||
def minion_count():
|
||||
return 20
|
||||
|
||||
|
||||
@pytest.fixture(scope="package")
|
||||
def minion_swarm(salt_master, minion_count):
|
||||
assert salt_master.is_running()
|
||||
minions = []
|
||||
# We create and arbitrarily tall context stack to register the
|
||||
# minions stop mechanism callback
|
||||
with ExitStack() as stack:
|
||||
for idx in range(minion_count):
|
||||
minion_factory = salt_master.salt_minion_daemon(
|
||||
random_string("swarm-minion-{}-".format(idx)),
|
||||
extra_cli_arguments_after_first_start_failure=["--log-level=debug"],
|
||||
)
|
||||
stack.enter_context(minion_factory.started())
|
||||
minions.append(minion_factory)
|
||||
for minion in minions:
|
||||
assert minion.is_running()
|
||||
yield minions
|
||||
for minion in minions:
|
||||
assert not minion.is_running()
|
19
tests/pytests/scenarios/swarm/test_minion_swarm.py
Normal file
19
tests/pytests/scenarios/swarm/test_minion_swarm.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
import random
|
||||
|
||||
import pytest
|
||||
|
||||
pytestmark = [pytest.mark.slow_test]
|
||||
|
||||
|
||||
def test_ping(minion_swarm, salt_cli):
|
||||
ret = salt_cli.run("test.ping", minion_tgt="*")
|
||||
assert ret.data
|
||||
for minion in minion_swarm:
|
||||
assert minion.id in ret.data
|
||||
assert ret.data[minion.id] is True
|
||||
|
||||
|
||||
def test_ping_one(minion_swarm, salt_cli):
|
||||
minion = random.choice(minion_swarm)
|
||||
ret = salt_cli.run("test.ping", minion_tgt=minion.id)
|
||||
assert ret.data is True
|
Loading…
Add table
Reference in a new issue