91 lines
3.0 KiB
Python
91 lines
3.0 KiB
Python
from __future__ import annotations
|
|
|
|
import importlib.util
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
PROFILES_PATH = ROOT / "ops" / "gitea-deploy-broker" / "runner_profiles.py"
|
|
|
|
|
|
def _profiles_module():
|
|
spec = importlib.util.spec_from_file_location("appops_runner_profiles_test", PROFILES_PATH)
|
|
assert spec and spec.loader
|
|
module = importlib.util.module_from_spec(spec)
|
|
sys.modules[spec.name] = module
|
|
spec.loader.exec_module(module)
|
|
return module
|
|
|
|
|
|
def test_fixed_profiles_expose_stable_names_labels_and_resource_envelopes():
|
|
profiles = _profiles_module()
|
|
|
|
assert tuple(profiles.RUNNER_PROFILES) == (
|
|
"checks",
|
|
"backend",
|
|
"frontend",
|
|
"security",
|
|
"browser",
|
|
"build",
|
|
)
|
|
assert [profile.display_name for profile in profiles.RUNNER_PROFILES.values()] == [
|
|
"ITWorx CI · Checks",
|
|
"ITWorx CI · Backend",
|
|
"ITWorx CI · Frontend",
|
|
"ITWorx CI · Security",
|
|
"ITWorx CI · Browser",
|
|
"ITWorx CI · Build",
|
|
]
|
|
assert [profile.container_name for profile in profiles.RUNNER_PROFILES.values()] == [
|
|
"itworx-ci-checks",
|
|
"itworx-ci-backend",
|
|
"itworx-ci-frontend",
|
|
"itworx-ci-security",
|
|
"itworx-ci-browser",
|
|
"itworx-ci-build",
|
|
]
|
|
assert [
|
|
(profile.cpu_milli, profile.memory_mib, profile.heavy)
|
|
for profile in profiles.RUNNER_PROFILES.values()
|
|
] == [
|
|
(1000, 1536, False),
|
|
(3000, 5120, False),
|
|
(3000, 5120, False),
|
|
(1000, 2048, False),
|
|
(3000, 6144, True),
|
|
(4000, 6144, True),
|
|
]
|
|
assert (profiles.BASE_OVERHEAD_CPU_MILLI, profiles.BASE_OVERHEAD_MEMORY_MIB) == (
|
|
1000,
|
|
2048,
|
|
)
|
|
assert (profiles.HOST_CPU_BUDGET_MILLI, profiles.HOST_MEMORY_BUDGET_MIB) == (
|
|
8000,
|
|
16384,
|
|
)
|
|
assert (profiles.MAX_ACTIVE_CLAIMS, profiles.MAX_HEAVY_ACTIVE) == (2, 1)
|
|
|
|
|
|
def test_shared_legacy_labels_only_admit_backend_and_frontend_profiles():
|
|
profiles = _profiles_module()
|
|
|
|
assert [
|
|
profile.id for profile in profiles.profiles_for_labels(["linux-validation"])
|
|
] == ["backend", "frontend"]
|
|
assert [
|
|
profile.id for profile in profiles.profiles_for_labels(["ubuntu-latest"])
|
|
] == ["backend", "frontend"]
|
|
assert profiles.profiles_for_labels(["itworx-ci-security"])[0].id == "security"
|
|
assert profiles.profiles_for_labels(["linux-validation", "itworx-ci-security"]) == ()
|
|
assert profiles.profile_for_container("itworx-ci-browser").id == "browser"
|
|
assert profiles.profile_for_container("itworx-ci-unknown") is None
|
|
|
|
|
|
def test_legacy_docker_jobs_use_only_the_fixed_heavy_build_profile():
|
|
profiles = _profiles_module()
|
|
assert [profile.id for profile in profiles.profiles_for_labels(["docker-validation"])] == ["build"]
|
|
assert profiles.RUNNER_PROFILES['build'].heavy
|
|
assert profiles.profiles_for_labels(["docker-validation", "linux-validation"]) == ()
|
|
assert profiles.profiles_for_labels(["docker-validation", "unraid-deploy"]) == ()
|