Merging upstream version 0.15.0.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
bfebc2a0f4
commit
0a0cb7f4fd
103 changed files with 79620 additions and 742 deletions
|
@ -81,14 +81,15 @@ def test_create_inventory_from_cvp(tmp_path: Path, inventory: list[dict[str, Any
|
|||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("inventory_filename", "ansible_group", "expected_raise", "expected_inv_length"),
|
||||
("inventory_filename", "ansible_group", "expected_raise", "expected_log", "expected_inv_length"),
|
||||
[
|
||||
pytest.param("ansible_inventory.yml", None, nullcontext(), 7, id="no group"),
|
||||
pytest.param("ansible_inventory.yml", "ATD_LEAFS", nullcontext(), 4, id="group found"),
|
||||
pytest.param("ansible_inventory.yml", None, nullcontext(), None, 7, id="no group"),
|
||||
pytest.param("ansible_inventory.yml", "ATD_LEAFS", nullcontext(), None, 4, id="group found"),
|
||||
pytest.param(
|
||||
"ansible_inventory.yml",
|
||||
"DUMMY",
|
||||
pytest.raises(ValueError, match="Group DUMMY not found in Ansible inventory"),
|
||||
None,
|
||||
0,
|
||||
id="group not found",
|
||||
),
|
||||
|
@ -96,6 +97,7 @@ def test_create_inventory_from_cvp(tmp_path: Path, inventory: list[dict[str, Any
|
|||
"empty_ansible_inventory.yml",
|
||||
None,
|
||||
pytest.raises(ValueError, match="Ansible inventory .* is empty"),
|
||||
None,
|
||||
0,
|
||||
id="empty inventory",
|
||||
),
|
||||
|
@ -103,19 +105,39 @@ def test_create_inventory_from_cvp(tmp_path: Path, inventory: list[dict[str, Any
|
|||
"wrong_ansible_inventory.yml",
|
||||
None,
|
||||
pytest.raises(ValueError, match="Could not parse"),
|
||||
None,
|
||||
0,
|
||||
id="os error inventory",
|
||||
),
|
||||
pytest.param(
|
||||
"ansible_inventory_with_vault.yml",
|
||||
None,
|
||||
pytest.raises(ValueError, match="Could not parse"),
|
||||
"`anta get from-ansible` does not support inline vaulted variables",
|
||||
0,
|
||||
id="Vault variable in inventory",
|
||||
),
|
||||
pytest.param(
|
||||
"ansible_inventory_unknown_yaml_tag.yml",
|
||||
None,
|
||||
pytest.raises(ValueError, match="Could not parse"),
|
||||
None,
|
||||
0,
|
||||
id="Unknown YAML tag in inventory",
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_create_inventory_from_ansible(
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
tmp_path: Path,
|
||||
inventory_filename: Path,
|
||||
ansible_group: str | None,
|
||||
expected_raise: AbstractContextManager[Exception],
|
||||
expected_log: str | None,
|
||||
expected_inv_length: int,
|
||||
) -> None:
|
||||
"""Test anta.get.utils.create_inventory_from_ansible."""
|
||||
# pylint: disable=R0913
|
||||
target_file = tmp_path / "inventory.yml"
|
||||
inventory_file_path = DATA_DIR / inventory_filename
|
||||
|
||||
|
@ -130,3 +152,5 @@ def test_create_inventory_from_ansible(
|
|||
assert len(inv) == expected_inv_length
|
||||
if not isinstance(expected_raise, nullcontext):
|
||||
assert not target_file.exists()
|
||||
if expected_log:
|
||||
assert expected_log in caplog.text
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue