Publish curated Unraid-AppOps-Gateway source from 451646fee806a47e3256731766980a05a262dcdd
This commit is contained in:
1 parent
532f3d9f26
commit
0a82153d95
43 files changed
+17722
-93
No files matched your search
@@ -2,13 +2,13 @@ from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
import io
|
||||
import json
|
||||
import sys
|
||||
import types
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
CONTROLLER_ROOT = ROOT / "ops" / "gitea-deploy-broker"
|
||||
CONTROLLER_PATH = CONTROLLER_ROOT / "runner_capacity_controller.py"
|
||||
@@ -123,8 +123,18 @@ def test_host_snapshot_handles_absent_load_tuple(capacity_module, monkeypatch):
|
||||
assert result["host"] is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize("raw", ["", "pswpin 1\n", "pswpin -1\npswpout 2\n",
|
||||
"pswpin 1\npswpin 2\npswpout 3\n", "pswpin invalid\npswpout 2\n", "x" * 65537])
|
||||
@pytest.mark.parametrize(
|
||||
"raw",
|
||||
[
|
||||
"",
|
||||
"pswpin 1\n",
|
||||
"pswpin -1\npswpout 2\n",
|
||||
"pswpin 1\npswpin 2\npswpout 3\n",
|
||||
"pswpin invalid\npswpout 2\n",
|
||||
"x" * 65537,
|
||||
],
|
||||
ids=["empty", "missing-counter", "negative", "duplicate", "invalid", "oversized"],
|
||||
)
|
||||
def test_strict_swap_reader_rejects_missing_or_invalid_counters(capacity_module, monkeypatch, raw):
|
||||
monkeypatch.setattr(capacity_module, "Path", lambda _path: types.SimpleNamespace(
|
||||
open=lambda **_kwargs: io.StringIO(raw)
|
||||
@@ -161,6 +171,96 @@ def test_host_snapshot_rejects_invalid_global_metrics(capacity_module, monkeypat
|
||||
assert result["host"] is None
|
||||
|
||||
|
||||
def test_snapshot_and_cycle_treat_empty_optional_burst_inspect_as_not_configured(
|
||||
capacity_module, monkeypatch
|
||||
):
|
||||
service = capacity_module.RunnerCapacityController()
|
||||
commands = []
|
||||
state_reads = []
|
||||
|
||||
def inspect_only(arguments, **kwargs):
|
||||
commands.append((arguments, kwargs))
|
||||
assert arguments == ["docker", "inspect", capacity_module.BURST_RUNNER_NAME]
|
||||
assert kwargs == {"check": False}
|
||||
return "[]"
|
||||
|
||||
def unexpected(*_args, **_kwargs):
|
||||
pytest.fail("an absent optional burst runner must not reach registration, state, or mutation")
|
||||
|
||||
monkeypatch.setattr(service, "_run", inspect_only)
|
||||
monkeypatch.setattr(service, "_read_state", lambda: state_reads.append("read") or {})
|
||||
for name in ("_runner_registration", "_gitea_request", "_write_state", "_record", "_set_disabled"):
|
||||
monkeypatch.setattr(service, name, unexpected)
|
||||
|
||||
snapshot = service.snapshot()
|
||||
result = service.cycle()
|
||||
|
||||
assert snapshot["status"] == "not_configured"
|
||||
assert snapshot["runner"] == capacity_module.BURST_RUNNER_NAME
|
||||
assert result["status"] == "not_configured"
|
||||
assert result["runner"] == capacity_module.BURST_RUNNER_NAME
|
||||
assert state_reads == ["read"]
|
||||
assert commands == [
|
||||
(["docker", "inspect", capacity_module.BURST_RUNNER_NAME], {"check": False}),
|
||||
(["docker", "inspect", capacity_module.BURST_RUNNER_NAME], {"check": False}),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("raw", "reason"),
|
||||
[
|
||||
("not-json", "runner_capacity_container_invalid"),
|
||||
("{}", "runner_capacity_container_invalid"),
|
||||
(
|
||||
json.dumps([
|
||||
{"Config": {"Labels": {
|
||||
"com.docker.compose.project": "gitea-deploy-runners",
|
||||
"tech.itworx.role": "gitea-actions-burst-runner",
|
||||
}}, "State": {}},
|
||||
{"Config": {"Labels": {
|
||||
"com.docker.compose.project": "gitea-deploy-runners",
|
||||
"tech.itworx.role": "gitea-actions-burst-runner",
|
||||
}}, "State": {}},
|
||||
]),
|
||||
"runner_capacity_container_invalid",
|
||||
),
|
||||
(
|
||||
json.dumps([{
|
||||
"Config": {"Labels": {
|
||||
"com.docker.compose.project": "foreign-project",
|
||||
"tech.itworx.role": "gitea-actions-burst-runner",
|
||||
}},
|
||||
"State": {},
|
||||
}]),
|
||||
"runner_capacity_container_identity_invalid",
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_cycle_still_refuses_malformed_foreign_or_multiple_burst_inspect_results(
|
||||
capacity_module, monkeypatch, raw, reason
|
||||
):
|
||||
service = capacity_module.RunnerCapacityController()
|
||||
commands = []
|
||||
|
||||
def inspect_only(arguments, **kwargs):
|
||||
commands.append((arguments, kwargs))
|
||||
return raw
|
||||
|
||||
def unexpected(*_args, **_kwargs):
|
||||
pytest.fail("invalid burst inventory must stop before registration or mutation")
|
||||
|
||||
monkeypatch.setattr(service, "_run", inspect_only)
|
||||
for name in ("_runner_registration", "_gitea_request", "_write_state", "_record", "_set_disabled"):
|
||||
monkeypatch.setattr(service, name, unexpected)
|
||||
|
||||
with pytest.raises(capacity_module.RunnerCapacityError, match=reason):
|
||||
service.cycle()
|
||||
|
||||
assert commands == [
|
||||
(["docker", "inspect", capacity_module.BURST_RUNNER_NAME], {"check": False})
|
||||
]
|
||||
|
||||
|
||||
def _wire_common(service, monkeypatch, *, running=False, busy=False, disabled=True):
|
||||
monkeypatch.setattr(
|
||||
service,
|
||||
@@ -183,7 +283,7 @@ def _wire_common(service, monkeypatch, *, running=False, busy=False, disabled=Tr
|
||||
"labels": ["linux-validation", "ubuntu-latest"],
|
||||
},
|
||||
)
|
||||
monkeypatch.setattr(service, "_read_state", lambda: {})
|
||||
monkeypatch.setattr(service, "_read_state", dict)
|
||||
monkeypatch.setattr(service, "_write_state", lambda _state: None)
|
||||
monkeypatch.setattr(service, "_record", lambda _event: None)
|
||||
monkeypatch.setattr(service, "_host_guard_state", lambda: ("clear", ""))
|
||||
|
||||
Reference in new issue
Block a user