57 lines
1.6 KiB
Python
57 lines
1.6 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
import yaml
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[3]
|
|
PLAYBOOK = ROOT / "infra" / "ansible" / "playbooks" / "110-backup-runtime-deploy.yml"
|
|
|
|
EXPECTED_FILES = {
|
|
"common.sh",
|
|
"backup-all.sh",
|
|
"backup-awoooi.sh",
|
|
"backup-awoooi-frequent.sh",
|
|
"backup-clawbot.sh",
|
|
"backup-sentry.sh",
|
|
}
|
|
|
|
|
|
def test_backup_runtime_deploy_is_fixed_to_host_110_and_six_files() -> None:
|
|
plays = yaml.safe_load(PLAYBOOK.read_text(encoding="utf-8"))
|
|
assert len(plays) == 1
|
|
play = plays[0]
|
|
|
|
assert play["hosts"] == "host_110"
|
|
assert play["gather_facts"] is False
|
|
assert play["become"] is True
|
|
assert play["serial"] == 1
|
|
assert play["any_errors_fatal"] is True
|
|
assert play["vars"]["backup_runtime_root"] == "/backup/scripts"
|
|
assert set(play["vars"]["backup_runtime_files"]) == EXPECTED_FILES
|
|
|
|
|
|
def test_backup_runtime_deploy_has_validation_rollback_and_identity_readback() -> None:
|
|
source = PLAYBOOK.read_text(encoding="utf-8")
|
|
|
|
assert 'inventory_hostname == "host_110"' in source
|
|
assert 'validate: "/bin/bash -n %s"' in source
|
|
assert "backup: true" in source
|
|
assert "checksum_algorithm: sha256" in source
|
|
assert "rstrip=false" in source
|
|
assert "backup_runtime_identity_failed" in source
|
|
assert "changed_when: false" in source
|
|
|
|
for forbidden in (
|
|
"ansible.builtin.service:",
|
|
"ansible.builtin.systemd:",
|
|
"ansible.builtin.cron:",
|
|
"ansible.builtin.shell:",
|
|
"ansible.builtin.command:",
|
|
"ansible.builtin.git:",
|
|
"docker_container",
|
|
"kubectl",
|
|
):
|
|
assert forbidden not in source
|