571030b8e8
test / stage-firecracker-inputs (pull_request) Successful in 5s
tracker-policy-pr / check-pr (pull_request) Successful in 12s
test / integration-docker (pull_request) Successful in 33s
test / unit (pull_request) Successful in 39s
lint / lint (push) Successful in 49s
test / build-infra (pull_request) Successful in 3m23s
test / integration-firecracker (pull_request) Successful in 1m42s
test / coverage (pull_request) Failing after 1m26s
test / publish-infra (pull_request) Has been skipped
A failed container list or a partial per-container inspect were previously indistinguishable from a legitimately empty/partial live set, so reconciliation could silently unregister healthy bottles. - enumerate_active() now raises EnumerationError instead of returning [] when `container list` fails - Add inspect_container_network_ip() to util, which returns None on inspect failure (vs "" for "no DHCP address yet"), so live_source_ips can tell the two apart - live_source_ips() raises EnumerationError on either failure mode; register_agent() catches it and skips reconciliation, same as OrchestratorClientError - Update tests: rename test_empty_when_the_cli_fails to test_raises_when_the_cli_fails, update patching to the new function, add coverage for list failure, per-container inspect failure, and the launch-not-blocked path
77 lines
2.9 KiB
Python
77 lines
2.9 KiB
Python
"""Unit: Apple Container cleanup/enumeration helpers."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
from bot_bottle.backend.macos_container import cleanup, enumerate as enum_mod
|
|
from bot_bottle.backend.macos_container.bottle_cleanup_plan import (
|
|
MacosContainerBottleCleanupPlan,
|
|
)
|
|
|
|
|
|
class TestMacosContainerCleanup(unittest.TestCase):
|
|
def test_lists_prefixed_containers(self):
|
|
completed = cleanup.subprocess.CompletedProcess(
|
|
args=[],
|
|
returncode=0,
|
|
stdout="bot-bottle-a\nbot-bottle-b\nother\n",
|
|
stderr="",
|
|
)
|
|
with patch.object(cleanup.subprocess, "run", return_value=completed):
|
|
self.assertEqual(
|
|
["bot-bottle-a", "bot-bottle-b"],
|
|
cleanup._list_prefixed_containers(),
|
|
)
|
|
|
|
def test_cleanup_deletes_containers_and_networks(self):
|
|
plan = MacosContainerBottleCleanupPlan(
|
|
containers=("bot-bottle-a",),
|
|
networks=("bot-bottle-net-a",),
|
|
)
|
|
with patch.object(cleanup.subprocess, "run") as run:
|
|
cleanup.cleanup(plan)
|
|
self.assertEqual(
|
|
["container", "delete", "--force", "bot-bottle-a"],
|
|
run.call_args_list[0].args[0],
|
|
)
|
|
self.assertEqual(
|
|
["container", "network", "delete", "bot-bottle-net-a"],
|
|
run.call_args_list[1].args[0],
|
|
)
|
|
|
|
|
|
class TestMacosContainerEnumerate(unittest.TestCase):
|
|
"""The backend launches bottles again (PRD 0070), so enumeration is real
|
|
rather than the disabled-era stub. These must not shell out: `container`
|
|
does not exist on the Linux CI host."""
|
|
|
|
def _enumerate(self, stdout: str, returncode: int = 0):
|
|
completed = enum_mod.subprocess.CompletedProcess(
|
|
args=[], returncode=returncode, stdout=stdout, stderr="",
|
|
)
|
|
with patch.object(enum_mod.subprocess, "run", return_value=completed), \
|
|
patch.object(enum_mod, "read_metadata", return_value=None):
|
|
return enum_mod.enumerate_active()
|
|
|
|
def test_lists_agent_containers_by_slug(self):
|
|
agents = self._enumerate("bot-bottle-dev-abc\nunrelated\n")
|
|
self.assertEqual(["dev-abc"], [a.slug for a in agents])
|
|
self.assertEqual(["macos-container"], [a.backend_name for a in agents])
|
|
|
|
def test_excludes_the_infra_singleton(self):
|
|
"""The infra container shares the bot-bottle- prefix but is
|
|
infrastructure — listing it would invent an agent per host."""
|
|
agents = self._enumerate("bot-bottle-mac-infra\nbot-bottle-dev-abc\n")
|
|
self.assertEqual(["dev-abc"], [a.slug for a in agents])
|
|
|
|
def test_raises_when_the_cli_fails(self):
|
|
from bot_bottle.backend.macos_container.enumerate import EnumerationError
|
|
with self.assertRaises(EnumerationError):
|
|
self._enumerate("", returncode=1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|