Publish curated Unraid-AppOps-Gateway source from a506550ef83ef2d81651e37c98a89f7ee330c730
This commit is contained in:
1 parent
2facb8de34
commit
767e66921e
68 files changed
+15924
-313
No files matched your search
@@ -1,6 +1,9 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
import sys
|
||||
import types
|
||||
from datetime import UTC, datetime
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
@@ -11,14 +14,71 @@ FLEET_PATH = ROOT / "ops" / "gitea-deploy-broker" / "runner_fleet.py"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def fleet_module():
|
||||
def fleet_module(monkeypatch):
|
||||
if sys.platform == "win32" and "fcntl" not in sys.modules:
|
||||
fcntl = types.ModuleType("fcntl")
|
||||
fcntl.LOCK_EX = 2
|
||||
fcntl.LOCK_UN = 8
|
||||
fcntl.LOCK_NB = 4
|
||||
fcntl.flock = lambda *_args, **_kwargs: None
|
||||
monkeypatch.setitem(sys.modules, "fcntl", fcntl)
|
||||
spec = importlib.util.spec_from_file_location("appops_runner_fleet_test", FLEET_PATH)
|
||||
assert spec and spec.loader
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
monkeypatch.setitem(
|
||||
sys.modules,
|
||||
"runner_fleet_specialize",
|
||||
types.SimpleNamespace(specialization_state=lambda: "legacy"),
|
||||
)
|
||||
monkeypatch.setattr(module, "_host_guard_state", lambda: ("clear", ""))
|
||||
monkeypatch.setattr(
|
||||
module.RunnerCapacityController,
|
||||
"snapshot",
|
||||
lambda _self: _healthy_capacity_snapshot(),
|
||||
)
|
||||
return module
|
||||
|
||||
|
||||
def _healthy_capacity_snapshot():
|
||||
return {
|
||||
"status": "ok",
|
||||
"decision": {"pressure": "headroom"},
|
||||
"host": {
|
||||
"swapCritical": False,
|
||||
"loadRatio": 0.1,
|
||||
"availableMemoryBytes": 12 * 1024**3,
|
||||
"cacheFreeBytes": 100 * 1024**3,
|
||||
"swapSampleAt": datetime.now(UTC).timestamp(),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def test_dind_uses_private_unix_socket_only_for_trusted_active_specialization(
|
||||
fleet_module, monkeypatch
|
||||
):
|
||||
service = fleet_module.RunnerFleetService()
|
||||
commands = []
|
||||
monkeypatch.setattr(
|
||||
service,
|
||||
"_run",
|
||||
lambda args, **_kwargs: commands.append(args) or "",
|
||||
)
|
||||
specialization = sys.modules["runner_fleet_specialize"]
|
||||
|
||||
service._dind(["info"])
|
||||
assert "DOCKER_HOST=tcp://127.0.0.1:2375" in commands[-1]
|
||||
|
||||
monkeypatch.setattr(specialization, "specialization_state", lambda: "active")
|
||||
service._dind(["info"])
|
||||
assert f"DOCKER_HOST={fleet_module.DIND_DOCKER_HOST}" in commands[-1]
|
||||
|
||||
for state in ("legacy", "blocked", "in_progress"):
|
||||
monkeypatch.setattr(specialization, "specialization_state", lambda value=state: value)
|
||||
service._dind(["info"])
|
||||
assert "DOCKER_HOST=tcp://127.0.0.1:2375" in commands[-1]
|
||||
|
||||
|
||||
def test_cleanup_candidates_exclude_unknown_attached_and_labeled_networks(
|
||||
fleet_module, monkeypatch
|
||||
):
|
||||
@@ -80,6 +140,7 @@ def test_automatic_cycle_only_deletes_exact_preview_candidates(fleet_module, mon
|
||||
}
|
||||
snapshot = {
|
||||
"status": "healthy",
|
||||
"capacity": _healthy_capacity_snapshot(),
|
||||
"networks": {"cleanupCandidates": [candidate]},
|
||||
"storage": {"status": "healthy"},
|
||||
"topology": {
|
||||
@@ -143,6 +204,7 @@ def test_automatic_cycle_starts_only_an_exited_known_runner(fleet_module, monkey
|
||||
service = fleet_module.RunnerFleetService()
|
||||
snapshot = {
|
||||
"status": "healthy",
|
||||
"capacity": _healthy_capacity_snapshot(),
|
||||
"networks": {"cleanupCandidates": []},
|
||||
"storage": {"status": "healthy"},
|
||||
"topology": {
|
||||
@@ -178,3 +240,21 @@ def test_automatic_cycle_starts_only_an_exited_known_runner(fleet_module, monkey
|
||||
|
||||
assert commands == [["docker", "start", "itworx-validation-runner-2"]]
|
||||
assert {event["action"] for event in events} == {"start", "restart.deferred"}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("specialization", ["active", "blocked"])
|
||||
def test_legacy_automatic_cycle_never_observes_or_mutates_after_specialization(
|
||||
fleet_module, monkeypatch, specialization
|
||||
):
|
||||
service = fleet_module.RunnerFleetService()
|
||||
monkeypatch.setitem(
|
||||
sys.modules,
|
||||
"runner_fleet_specialize",
|
||||
types.SimpleNamespace(specialization_state=lambda: specialization),
|
||||
)
|
||||
monkeypatch.setattr(service, "snapshot", lambda: pytest.fail("legacy snapshot ran"))
|
||||
monkeypatch.setattr(service, "_run", lambda *_args, **_kwargs: pytest.fail("legacy mutation ran"))
|
||||
result = service.automatic_cycle()
|
||||
|
||||
assert result["status"] == "deferred"
|
||||
assert result["reason"] == "runner_fleet_specialization_owns_recovery"
|
||||
Reference in new issue
Block a user