fix(pyright): resolve type errors introduced by lifecycle refactor
- Remove unused INFRA_IMAGE import from test_orchestrator_lifecycle - Update integration test to use new single-container OrchestratorService API (infra_name/image replaces orchestrator_name/gateway_name/gateway_image) - Move type: ignore to the lambda line in gateway_init SIGHUP handler - Break two long lines in test_orchestrator_lifecycle
This commit is contained in:
@@ -378,8 +378,9 @@ def main(argv: Sequence[str] | None = None) -> int:
|
|||||||
# --signal HUP <bundle>` after writing routes.yaml. The kernel
|
# --signal HUP <bundle>` after writing routes.yaml. The kernel
|
||||||
# delivers SIGHUP to PID 1 (this supervisor); forward it to
|
# delivers SIGHUP to PID 1 (this supervisor); forward it to
|
||||||
# mitmdump so it reloads its addon.
|
# mitmdump so it reloads its addon.
|
||||||
signal.signal( # type: ignore
|
signal.signal(
|
||||||
signal.SIGHUP, lambda *_: sup.forward_signal(signal.SIGHUP, "egress")
|
signal.SIGHUP,
|
||||||
|
lambda *_: sup.forward_signal(signal.SIGHUP, "egress"), # type: ignore[misc]
|
||||||
)
|
)
|
||||||
|
|
||||||
while not sup.tick():
|
while not sup.tick():
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ from tests._docker import skip_unless_docker
|
|||||||
# image instead of leaking a new dangling tag on every invocation.
|
# image instead of leaking a new dangling tag on every invocation.
|
||||||
_TEST_ORCHESTRATOR_IMAGE = "bot-bottle-orchestrator:itest"
|
_TEST_ORCHESTRATOR_IMAGE = "bot-bottle-orchestrator:itest"
|
||||||
_TEST_GATEWAY_IMAGE = "bot-bottle-gateway:itest"
|
_TEST_GATEWAY_IMAGE = "bot-bottle-gateway:itest"
|
||||||
|
_TEST_INFRA_IMAGE = "bot-bottle-infra:itest"
|
||||||
|
|
||||||
|
|
||||||
@skip_unless_docker()
|
@skip_unless_docker()
|
||||||
@@ -69,20 +70,17 @@ class TestDockerControlPlaneAuthIntegration(unittest.TestCase):
|
|||||||
os.environ["BOT_BOTTLE_ROOT"] = cls._tmp.name
|
os.environ["BOT_BOTTLE_ROOT"] = cls._tmp.name
|
||||||
cls.addClassCleanup(_restore_root)
|
cls.addClassCleanup(_restore_root)
|
||||||
|
|
||||||
orchestrator_name = f"bot-bottle-orch-itest-{suffix}"
|
infra_name = f"bot-bottle-infra-itest-{suffix}"
|
||||||
gateway_name = f"bot-bottle-gw-itest-{suffix}"
|
|
||||||
network = f"bot-bottle-net-itest-{suffix}"
|
network = f"bot-bottle-net-itest-{suffix}"
|
||||||
host_root = Path(cls._tmp.name)
|
host_root = Path(cls._tmp.name)
|
||||||
cls.addClassCleanup(
|
cls.addClassCleanup(
|
||||||
cls._teardown_docker, orchestrator_name, gateway_name, network, host_root
|
cls._teardown_docker, infra_name, network, host_root
|
||||||
)
|
)
|
||||||
|
|
||||||
cls.svc = OrchestratorService(
|
cls.svc = OrchestratorService(
|
||||||
orchestrator_name=orchestrator_name,
|
infra_name=infra_name,
|
||||||
gateway_name=gateway_name,
|
|
||||||
network=network,
|
network=network,
|
||||||
image=_TEST_ORCHESTRATOR_IMAGE,
|
image=_TEST_INFRA_IMAGE,
|
||||||
gateway_image=_TEST_GATEWAY_IMAGE,
|
|
||||||
port=20000 + secrets.randbelow(10000),
|
port=20000 + secrets.randbelow(10000),
|
||||||
host_root=host_root,
|
host_root=host_root,
|
||||||
)
|
)
|
||||||
@@ -91,23 +89,23 @@ class TestDockerControlPlaneAuthIntegration(unittest.TestCase):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _teardown_docker(
|
def _teardown_docker(
|
||||||
orchestrator_name: str, gateway_name: str, network: str, host_root: Path
|
infra_name: str, network: str, host_root: Path
|
||||||
) -> None:
|
) -> None:
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
["docker", "rm", "--force", orchestrator_name, gateway_name],
|
["docker", "rm", "--force", infra_name],
|
||||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=False,
|
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=False,
|
||||||
)
|
)
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
["docker", "network", "rm", network],
|
["docker", "network", "rm", network],
|
||||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=False,
|
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=False,
|
||||||
)
|
)
|
||||||
# The orchestrator container (no USER directive) wrote the registry
|
# The infra container (no USER directive) wrote the registry
|
||||||
# DB as root into the throwaway host_root; chown it back so the
|
# DB as root into the throwaway host_root; chown it back so the
|
||||||
# (non-root) tempdir cleanup can remove it. Same workaround
|
# (non-root) tempdir cleanup can remove it. Same workaround
|
||||||
# test_multitenant_isolation.py uses for the identical bind mount.
|
# test_multitenant_isolation.py uses for the identical bind mount.
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
["docker", "run", "--rm", "-v", f"{host_root}:/r",
|
["docker", "run", "--rm", "-v", f"{host_root}:/r",
|
||||||
"--entrypoint", "chown", _TEST_GATEWAY_IMAGE, "-R",
|
"--entrypoint", "chown", _TEST_INFRA_IMAGE, "-R",
|
||||||
f"{os.getuid()}:{os.getgid()}", "/r"],
|
f"{os.getuid()}:{os.getgid()}", "/r"],
|
||||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=False,
|
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=False,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ from unittest.mock import MagicMock, Mock, patch
|
|||||||
|
|
||||||
from bot_bottle.orchestrator.lifecycle import (
|
from bot_bottle.orchestrator.lifecycle import (
|
||||||
INFRA_NAME,
|
INFRA_NAME,
|
||||||
INFRA_IMAGE,
|
|
||||||
INFRA_SOURCE_HASH_LABEL,
|
INFRA_SOURCE_HASH_LABEL,
|
||||||
OrchestratorService,
|
OrchestratorService,
|
||||||
OrchestratorStartError,
|
OrchestratorStartError,
|
||||||
@@ -113,7 +112,8 @@ class TestOrchestratorService(unittest.TestCase):
|
|||||||
# Both processes in one container — no separate entrypoint override.
|
# Both processes in one container — no separate entrypoint override.
|
||||||
self.assertNotIn("--entrypoint", argv)
|
self.assertNotIn("--entrypoint", argv)
|
||||||
# Gateway daemons + orchestrator explicitly opted in.
|
# Gateway daemons + orchestrator explicitly opted in.
|
||||||
self.assertIn("orchestrator", argv[argv.index("BOT_BOTTLE_GATEWAY_DAEMONS=egress,git-http,supervise,orchestrator")])
|
daemons_flag = "BOT_BOTTLE_GATEWAY_DAEMONS=egress,git-http,supervise,orchestrator"
|
||||||
|
self.assertIn("orchestrator", argv[argv.index(daemons_flag)])
|
||||||
|
|
||||||
def test_ensure_running_builds_both_images(self) -> None:
|
def test_ensure_running_builds_both_images(self) -> None:
|
||||||
calls: list[list[str]] = []
|
calls: list[list[str]] = []
|
||||||
@@ -147,7 +147,10 @@ class TestOrchestratorService(unittest.TestCase):
|
|||||||
def test_stop_removes_infra_container(self) -> None:
|
def test_stop_removes_infra_container(self) -> None:
|
||||||
with patch(_RUN) as run:
|
with patch(_RUN) as run:
|
||||||
self.svc.stop()
|
self.svc.stop()
|
||||||
rms = [c.args[0] for c in run.call_args_list if c.args[0][:3] == ["docker", "rm", "--force"]]
|
rms = [
|
||||||
|
c.args[0] for c in run.call_args_list
|
||||||
|
if c.args[0][:3] == ["docker", "rm", "--force"]
|
||||||
|
]
|
||||||
self.assertTrue(any(INFRA_NAME in a for a in rms))
|
self.assertTrue(any(INFRA_NAME in a for a in rms))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user