mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Add tests for the ansible roster docs
This commit is contained in:
parent
692447efeb
commit
6ea70ae3f9
1 changed files with 99 additions and 4 deletions
|
@ -62,6 +62,28 @@ def expected_targets_return():
|
|||
}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def expected_docs_targets_return():
|
||||
return {
|
||||
"home": {
|
||||
"passwd": "password",
|
||||
"sudo": "password",
|
||||
"host": "12.34.56.78",
|
||||
"port": 23,
|
||||
"user": "gtmanfred",
|
||||
"minion_opts": {"http_port": 80},
|
||||
},
|
||||
"salt.gtmanfred.com": {
|
||||
"passwd": "password",
|
||||
"sudo": "password",
|
||||
"host": "127.0.0.1",
|
||||
"port": 22,
|
||||
"user": "gtmanfred",
|
||||
"minion_opts": {"http_port": 80},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def roster_dir(tmp_path_factory):
|
||||
dpath = tmp_path_factory.mktemp("roster")
|
||||
|
@ -136,6 +158,59 @@ def roster_dir(tmp_path_factory):
|
|||
children:
|
||||
southeast:
|
||||
"""
|
||||
docs_ini_contents = """
|
||||
[servers]
|
||||
salt.gtmanfred.com ansible_ssh_user=gtmanfred ansible_ssh_host=127.0.0.1 ansible_ssh_port=22 ansible_ssh_pass='password' ansible_sudo_pass='password'
|
||||
|
||||
[desktop]
|
||||
home ansible_ssh_user=gtmanfred ansible_ssh_host=12.34.56.78 ansible_ssh_port=23 ansible_ssh_pass='password' ansible_sudo_pass='password'
|
||||
|
||||
[computers:children]
|
||||
desktop
|
||||
servers
|
||||
|
||||
[computers:vars]
|
||||
http_port=80
|
||||
"""
|
||||
docs_script_contents = """
|
||||
#!/bin/bash
|
||||
echo '{
|
||||
"servers": [
|
||||
"salt.gtmanfred.com"
|
||||
],
|
||||
"desktop": [
|
||||
"home"
|
||||
],
|
||||
"computers": {
|
||||
"hosts": [],
|
||||
"children": [
|
||||
"desktop",
|
||||
"servers"
|
||||
],
|
||||
"vars": {
|
||||
"http_port": 80
|
||||
}
|
||||
},
|
||||
"_meta": {
|
||||
"hostvars": {
|
||||
"salt.gtmanfred.com": {
|
||||
"ansible_ssh_user": "gtmanfred",
|
||||
"ansible_ssh_host": "127.0.0.1",
|
||||
"ansible_sudo_pass": "password",
|
||||
"ansible_ssh_pass": "password",
|
||||
"ansible_ssh_port": 22
|
||||
},
|
||||
"home": {
|
||||
"ansible_ssh_user": "gtmanfred",
|
||||
"ansible_ssh_host": "12.34.56.78",
|
||||
"ansible_sudo_pass": "password",
|
||||
"ansible_ssh_pass": "password",
|
||||
"ansible_ssh_port": 23
|
||||
}
|
||||
}
|
||||
}
|
||||
}'
|
||||
"""
|
||||
with pytest.helpers.temp_file(
|
||||
"roster.py", roster_py_contents, directory=dpath
|
||||
) as py_roster:
|
||||
|
@ -144,11 +219,17 @@ def roster_dir(tmp_path_factory):
|
|||
"roster.ini", roster_ini_contents, directory=dpath
|
||||
), pytest.helpers.temp_file(
|
||||
"roster.yml", roster_yaml_contents, directory=dpath
|
||||
), pytest.helpers.temp_file(
|
||||
"roster-docs.ini", docs_ini_contents, directory=dpath
|
||||
):
|
||||
try:
|
||||
yield dpath
|
||||
finally:
|
||||
shutil.rmtree(str(dpath), ignore_errors=True)
|
||||
with pytest.helpers.temp_file(
|
||||
"roster-docs.sh", docs_script_contents, directory=dpath
|
||||
) as script_roster:
|
||||
script_roster.chmod(0o755)
|
||||
try:
|
||||
yield dpath
|
||||
finally:
|
||||
shutil.rmtree(str(dpath), ignore_errors=True)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
@ -179,3 +260,17 @@ def test_script(roster_opts, roster_dir, expected_targets_return):
|
|||
with patch.dict(ansible.__opts__, roster_opts):
|
||||
ret = ansible.targets("*")
|
||||
assert ret == expected_targets_return
|
||||
|
||||
|
||||
def test_docs_ini(roster_opts, roster_dir, expected_docs_targets_return):
|
||||
roster_opts["roster_file"] = str(roster_dir / "roster-docs.ini")
|
||||
with patch.dict(ansible.__opts__, roster_opts):
|
||||
ret = ansible.targets("*")
|
||||
assert ret == expected_docs_targets_return
|
||||
|
||||
|
||||
def test_docs_script(roster_opts, roster_dir, expected_docs_targets_return):
|
||||
roster_opts["roster_file"] = str(roster_dir / "roster-docs.sh")
|
||||
with patch.dict(ansible.__opts__, roster_opts):
|
||||
ret = ansible.targets("*")
|
||||
assert ret == expected_docs_targets_return
|
||||
|
|
Loading…
Add table
Reference in a new issue