mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Initial commit of formula tests
This commit is contained in:
parent
17abfb480e
commit
9c755a02ad
4 changed files with 285 additions and 0 deletions
82
tests/pytests/functional/formulas/test_docker.py
Normal file
82
tests/pytests/functional/formulas/test_docker.py
Normal file
|
@ -0,0 +1,82 @@
|
|||
"""
|
||||
Tests using docker formula
|
||||
"""
|
||||
import json
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
from zipfile import ZipFile
|
||||
|
||||
import pytest
|
||||
import requests
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def formula_tag():
|
||||
return "2.4.2"
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def repo_url(formula_tag):
|
||||
return f"https://github.com/saltstack-formulas/docker-formula/archive/refs/tags/v{formula_tag}.zip"
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def docker_repo(state_tree, base_env_state_tree_root_dir, formula_tag, repo_url):
|
||||
local_filename = Path(repo_url.split("/")[-1])
|
||||
zip_path = state_tree / local_filename
|
||||
with requests.get(repo_url, allow_redirects=True, stream=True) as req:
|
||||
req.raise_for_status()
|
||||
with salt.utils.files.fopen(zip_path, "wb") as fho:
|
||||
for chunk in req.iter_content(chunk_size=8192):
|
||||
fho.write(chunk)
|
||||
with ZipFile(zip_path) as zip_obj:
|
||||
zip_obj.extractall(state_tree)
|
||||
extract_path = state_tree / f"docker-formula-{formula_tag}"
|
||||
shutil.move(extract_path / "docker", base_env_state_tree_root_dir)
|
||||
return str(base_env_state_tree_root_dir)
|
||||
|
||||
|
||||
def test_docker_formula(salt_call_cli, docker_repo):
|
||||
out = salt_call_cli.run(
|
||||
"--local",
|
||||
"state.sls",
|
||||
"docker",
|
||||
"test=True",
|
||||
)
|
||||
ret = json.loads(str(out.stdout))
|
||||
state_ids = [
|
||||
"archive_|-docker-software-docker-archive-install_|-/usr/local/docker-19.03.9/bin/_|-extracted",
|
||||
"cmd_|-docker-software-docker-archive-install-managed-service_|-systemctl daemon-reload_|-run",
|
||||
"file_|-docker-compose-software-binary-install-symlink-docker-compose_|-/usr/local/bin/docker-compose_|-symlink",
|
||||
"file_|-docker-compose-software-binary-install_|-/usr/local/docker-compose-latest/bin//docker-compose_|-managed",
|
||||
"file_|-docker-software-daemon-file-managed-daemon_file_|-/etc/docker/daemon.json_|-absent",
|
||||
"file_|-docker-software-docker-archive-install-file-directory_|-/var/lib/docker_|-directory",
|
||||
"file_|-docker-software-docker-archive-install-managed-service_|-/usr/lib/systemd/system/docker.service_|-managed",
|
||||
"file_|-docker-software-docker-archive-install-symlink-containerd-shim_|-/usr/local/bin/containerd-shim_|-symlink",
|
||||
"file_|-docker-software-docker-archive-install-symlink-containerd_|-/usr/local/bin/containerd_|-symlink",
|
||||
"file_|-docker-software-docker-archive-install-symlink-ctr_|-/usr/local/bin/ctr_|-symlink",
|
||||
"file_|-docker-software-docker-archive-install-symlink-docker-init_|-/usr/local/bin/docker-init_|-symlink",
|
||||
"file_|-docker-software-docker-archive-install-symlink-docker-proxy_|-/usr/local/bin/docker-proxy_|-symlink",
|
||||
"file_|-docker-software-docker-archive-install-symlink-docker_|-/usr/local/bin/docker_|-symlink",
|
||||
"file_|-docker-software-docker-archive-install-symlink-dockerd_|-/usr/local/bin/dockerd_|-symlink",
|
||||
"file_|-docker-software-docker-archive-install-symlink-runc_|-/usr/local/bin/runc_|-symlink",
|
||||
"file_|-docker-software-docker-archive-install_|-/usr/local/docker-19.03.9/bin/_|-directory",
|
||||
"pkg_|-docker-compose-software-binary-install_|-python-docker_|-installed",
|
||||
"pkg_|-docker-compose-software-binary-install_|-python-pip_|-installed",
|
||||
"pkg_|-docker-software-docker-archive-install_|-python-docker_|-installed",
|
||||
"pkg_|-docker-software-docker-archive-install_|-python-pip_|-installed",
|
||||
"service_|-docker-software-service-running-docker_|-docker_|-running",
|
||||
"service_|-docker-software-service-running-unmasked_|-docker_|-unmasked",
|
||||
"service_|-docker-software-service-running-docker-fail-notify_|-docker_|-enabled",
|
||||
"test_|-docker-compose-package-install-other_|-docker-compose-package-install-other_|-show_notification",
|
||||
"test_|-docker-software-desktop-install-other_|-docker-software-desktop-install-other_|-show_notification",
|
||||
"test_|-docker-software-package-install-other_|-docker-software-package-install-other_|-show_notification",
|
||||
]
|
||||
for state_id in state_ids:
|
||||
assert ret["local"][state_id]["result"] is not False
|
||||
|
||||
state_ids = [
|
||||
"test_|-docker-software-service-running-docker-fail-notify_|-docker-software-service-running-docker-fail-notify_|-fail_without_changes",
|
||||
]
|
||||
for state_id in state_ids:
|
||||
assert ret["local"][state_id]["result"] is False
|
57
tests/pytests/functional/formulas/test_nginx.py
Normal file
57
tests/pytests/functional/formulas/test_nginx.py
Normal file
|
@ -0,0 +1,57 @@
|
|||
"""
|
||||
Tests using nginx formula
|
||||
"""
|
||||
import json
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
from zipfile import ZipFile
|
||||
|
||||
import pytest
|
||||
import requests
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def formula_tag():
|
||||
return "2.8.1"
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def repo_url(formula_tag):
|
||||
return f"https://github.com/saltstack-formulas/nginx-formula/archive/refs/tags/v{formula_tag}.zip"
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def nginx_repo(state_tree, base_env_state_tree_root_dir, formula_tag, repo_url):
|
||||
local_filename = Path(repo_url.split("/")[-1])
|
||||
zip_path = state_tree / local_filename
|
||||
with requests.get(repo_url, allow_redirects=True, stream=True) as req:
|
||||
req.raise_for_status()
|
||||
with salt.utils.files.fopen(zip_path, "wb") as fho:
|
||||
for chunk in req.iter_content(chunk_size=8192):
|
||||
fho.write(chunk)
|
||||
with ZipFile(zip_path) as zip_obj:
|
||||
zip_obj.extractall(state_tree)
|
||||
extract_path = state_tree / f"nginx-formula-{formula_tag}"
|
||||
shutil.move(extract_path / "nginx", base_env_state_tree_root_dir)
|
||||
return str(base_env_state_tree_root_dir)
|
||||
|
||||
|
||||
def test_formula(salt_call_cli, nginx_repo):
|
||||
out = salt_call_cli.run(
|
||||
"--local",
|
||||
"state.sls",
|
||||
"nginx",
|
||||
"test=True",
|
||||
)
|
||||
ret = json.loads(str(out.stdout))
|
||||
state_ids = [
|
||||
"file_|-nginx_config_|-/etc/nginx/nginx.conf_|-managed",
|
||||
"file_|-nginx_server_available_dir_|-/etc/nginx/sites-available_|-directory",
|
||||
"file_|-nginx_server_enabled_dir_|-/etc/nginx/sites-enabled_|-directory",
|
||||
"file_|-prepare_certificates_path_dir_|-/etc/nginx/ssl_|-directory",
|
||||
"pkg_|-nginx_install_|-nginx_|-installed",
|
||||
"service_|-listener_nginx_service_|-nginx_|-mod_watch",
|
||||
"service_|-nginx_service_|-nginx_|-running",
|
||||
]
|
||||
for state_id in state_ids:
|
||||
assert ret["local"][state_id]["result"] is not False
|
77
tests/pytests/functional/formulas/test_salt.py
Normal file
77
tests/pytests/functional/formulas/test_salt.py
Normal file
|
@ -0,0 +1,77 @@
|
|||
"""
|
||||
Tests using salt formula
|
||||
"""
|
||||
import json
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
from zipfile import ZipFile
|
||||
|
||||
import pytest
|
||||
import requests
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def formula_tag():
|
||||
return "1.12.0"
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def repo_url(formula_tag):
|
||||
return f"https://github.com/saltstack-formulas/salt-formula/archive/refs/tags/v{formula_tag}.zip"
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def salt_repo(state_tree, base_env_state_tree_root_dir, formula_tag, repo_url):
|
||||
local_filename = Path(repo_url.split("/")[-1])
|
||||
zip_path = state_tree / local_filename
|
||||
with requests.get(repo_url, allow_redirects=True, stream=True) as req:
|
||||
req.raise_for_status()
|
||||
with salt.utils.files.fopen(zip_path, "wb") as fho:
|
||||
for chunk in req.iter_content(chunk_size=8192):
|
||||
fho.write(chunk)
|
||||
with ZipFile(zip_path) as zip_obj:
|
||||
zip_obj.extractall(state_tree)
|
||||
extract_path = state_tree / f"salt-formula-{formula_tag}"
|
||||
shutil.move(extract_path / "salt", base_env_state_tree_root_dir)
|
||||
return str(base_env_state_tree_root_dir)
|
||||
|
||||
|
||||
def test_salt_formula(salt_call_cli, salt_repo):
|
||||
# Master Formula
|
||||
out = salt_call_cli.run(
|
||||
"--local",
|
||||
"state.sls",
|
||||
"salt.master",
|
||||
"test=True",
|
||||
)
|
||||
ret = json.loads(str(out.stdout))
|
||||
state_ids = [
|
||||
"pkg_|-salt-master_|-salt_|-installed",
|
||||
"file_|-salt-master_|-/etc/salt/master.d_|-recurse",
|
||||
"file_|-remove-old-master-conf-file_|-/etc/salt/master.d/_defaults.conf_|-absent",
|
||||
"service_|-salt-master_|-salt-master_|-running",
|
||||
]
|
||||
for state_id in state_ids:
|
||||
assert ret["local"][state_id]["result"] is not False
|
||||
|
||||
# Minion Formula
|
||||
out = salt_call_cli.run(
|
||||
"--local",
|
||||
"state.sls",
|
||||
"salt.minion",
|
||||
"test=True",
|
||||
)
|
||||
ret = json.loads(str(out.stdout))
|
||||
state_ids = [
|
||||
"pkg_|-salt-minion_|-salt_|-installed",
|
||||
"file_|-salt-minion_|-/etc/salt/minion.d_|-recurse",
|
||||
"file_|-remove-old-minion-conf-file_|-/etc/salt/minion.d/_defaults.conf_|-absent",
|
||||
"cmd_|-salt-minion_|-salt-call --local service.restart salt-minion --out-file /dev/null_|-run",
|
||||
"file_|-permissions-minion-config_|-/etc/salt/minion_|-managed",
|
||||
"file_|-salt-minion-pki-dir_|-/etc/salt/pki/minion_|-directory",
|
||||
"file_|-permissions-minion.pem_|-/etc/salt/pki/minion/minion.pem_|-managed",
|
||||
"file_|-permissions-minion.pub_|-/etc/salt/pki/minion/minion.pub_|-managed",
|
||||
"service_|-salt-minion_|-salt-minion_|-running",
|
||||
]
|
||||
for state_id in state_ids:
|
||||
assert ret["local"][state_id]["result"] is not False
|
69
tests/pytests/functional/formulas/test_users.py
Normal file
69
tests/pytests/functional/formulas/test_users.py
Normal file
|
@ -0,0 +1,69 @@
|
|||
"""
|
||||
Tests using users formula
|
||||
"""
|
||||
import json
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
from zipfile import ZipFile
|
||||
|
||||
import pytest
|
||||
import requests
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def formula_tag():
|
||||
return "0.48.8"
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def repo_url(formula_tag):
|
||||
return f"https://github.com/saltstack-formulas/users-formula/archive/refs/tags/v{formula_tag}.zip"
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def users_repo(state_tree, base_env_state_tree_root_dir, formula_tag, repo_url):
|
||||
local_filename = Path(repo_url.split("/")[-1])
|
||||
zip_path = state_tree / local_filename
|
||||
with requests.get(repo_url, allow_redirects=True, stream=True) as req:
|
||||
req.raise_for_status()
|
||||
with salt.utils.files.fopen(zip_path, "wb") as fho:
|
||||
for chunk in req.iter_content(chunk_size=8192):
|
||||
fho.write(chunk)
|
||||
with ZipFile(zip_path) as zip_obj:
|
||||
zip_obj.extractall(state_tree)
|
||||
extract_path = state_tree / f"users-formula-{formula_tag}"
|
||||
shutil.move(extract_path / "users", base_env_state_tree_root_dir)
|
||||
return str(base_env_state_tree_root_dir)
|
||||
|
||||
|
||||
def test_users_formula(salt_call_cli, users_repo):
|
||||
# sudo
|
||||
out = salt_call_cli.run(
|
||||
"--local",
|
||||
"state.sls",
|
||||
"users.sudo",
|
||||
"test=True",
|
||||
)
|
||||
ret = json.loads(str(out.stdout))
|
||||
state_ids = [
|
||||
"pkg_|-users_bash-package_|-bash_|-installed",
|
||||
"file_|-users_/etc/sudoers.d_|-/etc/sudoers.d_|-directory",
|
||||
"pkg_|-users_sudo-package_|-sudo_|-installed",
|
||||
]
|
||||
for state_id in state_ids:
|
||||
assert ret["local"][state_id]["result"] is not False
|
||||
# bashrc
|
||||
out = salt_call_cli.run(
|
||||
"--local",
|
||||
"state.sls",
|
||||
"users.bashrc",
|
||||
"test=True",
|
||||
"pillar=" + json.dumps({"users": {"stan": {"fullname": "Stan Lee"}}}),
|
||||
)
|
||||
ret = json.loads(str(out.stdout))
|
||||
state_ids = [
|
||||
"group_|-users_stan_user_|-stan_|-present",
|
||||
"file_|-users_/etc/sudoers.d/stan_|-/etc/sudoers.d/stan_|-absent",
|
||||
]
|
||||
for state_id in state_ids:
|
||||
assert ret["local"][state_id]["result"] is not False
|
Loading…
Add table
Reference in a new issue