add buildbot extension for autoscaling nix builders
This commit is contained in:
parent
ea12318b88
commit
d1976a5fd8
13 changed files with 2300 additions and 8 deletions
|
|
@ -0,0 +1,59 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
import pytest
|
||||
|
||||
from buildbot_autoscale_ext.configurator import AutoscaleConfigurator
|
||||
from buildbot_autoscale_ext.settings import AutoscaleSettings
|
||||
from buildbot_autoscale_ext.steps import CapacityGateStep, CapacityReleaseStep
|
||||
|
||||
|
||||
@dataclass
|
||||
class FakeFactory:
|
||||
steps: list[object] = field(default_factory=list)
|
||||
|
||||
|
||||
@dataclass
|
||||
class FakeBuilder:
|
||||
name: str
|
||||
factory: FakeFactory
|
||||
|
||||
|
||||
def test_patches_nix_builders() -> None:
|
||||
cfg = {
|
||||
"builders": [
|
||||
FakeBuilder("proj/nix-build", FakeFactory(["original"])),
|
||||
FakeBuilder("proj/eval", FakeFactory(["eval"])),
|
||||
]
|
||||
}
|
||||
|
||||
AutoscaleConfigurator(AutoscaleSettings(daemon_socket="/tmp/daemon.sock")).configure(cfg)
|
||||
|
||||
patched_steps = cfg["builders"][0].factory.steps
|
||||
assert isinstance(patched_steps[0], CapacityGateStep)
|
||||
assert patched_steps[1] == "original"
|
||||
assert isinstance(patched_steps[-1], CapacityReleaseStep)
|
||||
|
||||
untouched_steps = cfg["builders"][1].factory.steps
|
||||
assert untouched_steps == ["eval"]
|
||||
|
||||
|
||||
def test_empty_builders_no_error() -> None:
|
||||
cfg = {"builders": []}
|
||||
AutoscaleConfigurator(AutoscaleSettings(daemon_socket="/tmp/daemon.sock")).configure(cfg)
|
||||
|
||||
|
||||
def test_startup_log_contains_patched_names(caplog: pytest.LogCaptureFixture) -> None:
|
||||
caplog.set_level(logging.INFO)
|
||||
cfg = {
|
||||
"builders": [
|
||||
FakeBuilder("one/nix-build", FakeFactory()),
|
||||
FakeBuilder("two/eval", FakeFactory()),
|
||||
]
|
||||
}
|
||||
|
||||
AutoscaleConfigurator(AutoscaleSettings(daemon_socket="/tmp/daemon.sock")).configure(cfg)
|
||||
|
||||
assert "one/nix-build" in caplog.text
|
||||
Loading…
Add table
Add a link
Reference in a new issue