Compare commits
No commits in common. "09b7d329bd7ccf7a0ec0cf0d290640204fac5843" and "071e2958f015d7c5b529bef39c813a7cec352129" have entirely different histories.
09b7d329bd
...
071e2958f0
2 changed files with 9 additions and 29 deletions
30
app.py
30
app.py
|
|
@ -11,7 +11,7 @@ from fastapi.responses import JSONResponse, RedirectResponse
|
||||||
from contextlib import asynccontextmanager
|
from contextlib import asynccontextmanager
|
||||||
|
|
||||||
log = logging.getLogger("butler")
|
log = logging.getLogger("butler")
|
||||||
VERSION = "2.3.5"
|
VERSION = "2.3.4"
|
||||||
|
|
||||||
API_DIR = os.environ.get("API_KEY_DIR", "/data/api")
|
API_DIR = os.environ.get("API_KEY_DIR", "/data/api")
|
||||||
VAULT_CACHE_DIR = os.environ.get("VAULT_CACHE_DIR", "/data/vault-cache")
|
VAULT_CACHE_DIR = os.environ.get("VAULT_CACHE_DIR", "/data/vault-cache")
|
||||||
|
|
@ -1574,29 +1574,11 @@ async def ansible_run(request: Request, _=Depends(_verify)):
|
||||||
return JSONResponse({"error": "action must be setup, tune or pvetune"}, status_code=400)
|
return JSONResponse({"error": "action must be setup, tune or pvetune"}, status_code=400)
|
||||||
if not re.fullmatch(r"[a-zA-Z0-9_.:-]+", hostname):
|
if not re.fullmatch(r"[a-zA-Z0-9_.:-]+", hostname):
|
||||||
return JSONResponse({"error": "invalid hostname/limit"}, status_code=400)
|
return JSONResponse({"error": "invalid hostname/limit"}, status_code=400)
|
||||||
if action in {"tune", "pvetune"}:
|
command = (
|
||||||
approved_files = (
|
"cd /app-config/ansible && "
|
||||||
"roles/sysctl/defaults/main.yml",
|
"git pull --ff-only origin master && "
|
||||||
"roles/sysctl/tasks/main.yml",
|
f"bash pfannkuchen.sh {action} {hostname}"
|
||||||
"group_vars/vps/sysctl.yml",
|
)
|
||||||
"sysctl-proxmox.yaml",
|
|
||||||
"roles/sysctl_proxmox/tasks/main.yml",
|
|
||||||
)
|
|
||||||
file_sync = " && ".join(
|
|
||||||
f"git show origin/master:{path} > {path}" for path in approved_files
|
|
||||||
)
|
|
||||||
command = (
|
|
||||||
"cd /app-config/ansible && "
|
|
||||||
"git fetch origin master && "
|
|
||||||
f"{file_sync} && "
|
|
||||||
f"bash pfannkuchen.sh {action} {hostname}"
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
command = (
|
|
||||||
"cd /app-config/ansible && "
|
|
||||||
"git pull --ff-only origin master && "
|
|
||||||
f"bash pfannkuchen.sh {action} {hostname}"
|
|
||||||
)
|
|
||||||
rc, out, err = _ssh(AUTOMATION1, command, timeout=600)
|
rc, out, err = _ssh(AUTOMATION1, command, timeout=600)
|
||||||
_audit("/ansible/run", "POST", 200 if rc == 0 else 502, f"{action} {hostname}")
|
_audit("/ansible/run", "POST", 200 if rc == 0 else 502, f"{action} {hostname}")
|
||||||
if action != "setup":
|
if action != "setup":
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ def test_health_exposes_current_version():
|
||||||
with TestClient(app.app) as client:
|
with TestClient(app.app) as client:
|
||||||
response = client.get("/health")
|
response = client.get("/health")
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json()["version"] == app.VERSION == "2.3.5"
|
assert response.json()["version"] == app.VERSION == "2.3.4"
|
||||||
|
|
||||||
|
|
||||||
def test_sysctl_audit_reads_fixed_keys_from_inventory_host(monkeypatch):
|
def test_sysctl_audit_reads_fixed_keys_from_inventory_host(monkeypatch):
|
||||||
|
|
@ -108,7 +108,7 @@ def test_inventory_upsert_uses_base64_script(monkeypatch):
|
||||||
assert "\\nname =" not in calls[0][1]
|
assert "\\nname =" not in calls[0][1]
|
||||||
|
|
||||||
|
|
||||||
def test_ansible_run_supports_safe_tune_action_and_syncs_approved_files(monkeypatch):
|
def test_ansible_run_supports_safe_tune_action_and_syncs_git(monkeypatch):
|
||||||
calls = []
|
calls = []
|
||||||
|
|
||||||
def fake_ssh(host, command, timeout=600):
|
def fake_ssh(host, command, timeout=600):
|
||||||
|
|
@ -124,9 +124,7 @@ def test_ansible_run_supports_safe_tune_action_and_syncs_approved_files(monkeypa
|
||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json()["action"] == "tune"
|
assert response.json()["action"] == "tune"
|
||||||
assert "git fetch origin master" in calls[0][1]
|
assert "git pull --ff-only origin master" in calls[0][1]
|
||||||
assert "git show origin/master:roles/sysctl/tasks/main.yml" in calls[0][1]
|
|
||||||
assert "git pull --ff-only" not in calls[0][1]
|
|
||||||
assert "bash pfannkuchen.sh tune emby-sascha" in calls[0][1]
|
assert "bash pfannkuchen.sh tune emby-sascha" in calls[0][1]
|
||||||
assert len(calls) == 1
|
assert len(calls) == 1
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue