feat: background remote agent updates survive SAC navigation (0.20.19)
This commit is contained in:
@@ -1,8 +1,24 @@
|
||||
"""Additional Linux admin API tests."""
|
||||
|
||||
import time
|
||||
from unittest.mock import patch
|
||||
|
||||
|
||||
def wait_remote_job(client, host_id, headers, timeout=5.0):
|
||||
deadline = time.monotonic() + timeout
|
||||
while time.monotonic() < deadline:
|
||||
response = client.get(
|
||||
f"/api/v1/hosts/{host_id}/actions/remote-job",
|
||||
headers=headers,
|
||||
)
|
||||
assert response.status_code == 200
|
||||
body = response.json()
|
||||
if not body.get("active") and body.get("status") != "running":
|
||||
return body
|
||||
time.sleep(0.05)
|
||||
raise AssertionError("remote job did not finish in time")
|
||||
|
||||
|
||||
def test_get_linux_admin_settings_env_default(jwt_headers, client, monkeypatch):
|
||||
monkeypatch.setenv("SAC_LINUX_ADMIN_USER", "")
|
||||
monkeypatch.setenv("SAC_LINUX_ADMIN_PASSWORD", "")
|
||||
@@ -137,7 +153,7 @@ def test_host_agent_update_success(jwt_headers, client, db_session, monkeypatch)
|
||||
db_session.commit()
|
||||
db_session.refresh(host)
|
||||
|
||||
with patch("app.api.v1.hosts.run_ssh_monitor_update") as mock_update:
|
||||
with patch("app.services.host_remote_actions.run_ssh_monitor_update") as mock_update:
|
||||
mock_update.return_value = SshCommandResult(
|
||||
ok=True,
|
||||
message="SSH OK (ubabuba), exit 0\nSUMMARY updated",
|
||||
@@ -150,9 +166,11 @@ def test_host_agent_update_success(jwt_headers, client, db_session, monkeypatch)
|
||||
headers=jwt_headers,
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.status_code == 202
|
||||
body = response.json()
|
||||
assert body["ok"] is True
|
||||
assert body["target"] == "ubabuba"
|
||||
if "product_version" in body:
|
||||
assert body["product_version"] is None or isinstance(body["product_version"], str)
|
||||
assert body["status"] == "running"
|
||||
job = wait_remote_job(client, host.id, jwt_headers)
|
||||
assert job["ok"] is True
|
||||
assert job["target"] == "ubabuba"
|
||||
if "product_version" in job:
|
||||
assert job["product_version"] is None or isinstance(job["product_version"], str)
|
||||
|
||||
Reference in New Issue
Block a user