From db8d849756ffe0dff97561ef7fbbef9407bd19f9 Mon Sep 17 00:00:00 2001 From: Maria Matejka Date: Fri, 12 Jul 2024 19:03:17 +0200 Subject: [PATCH] Flock tests: Adding necessary cleanup routines --- flock/bgp-secondary/test.py | 3 ++- flock/lib/BIRD/Test.py | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/flock/bgp-secondary/test.py b/flock/bgp-secondary/test.py index 75474c27..857138a6 100644 --- a/flock/bgp-secondary/test.py +++ b/flock/bgp-secondary/test.py @@ -83,8 +83,9 @@ async def main(): ])) await asyncio.sleep(5) + await t.cleanup() for q in (t.dest, t.src): - for f in ("bird", "birdc", "bird.conf", "bird.log"): + for f in ("bird.conf", "bird.log"): (q.workdir / f).unlink() await h.control_socket.send_cmd("stop", True) diff --git a/flock/lib/BIRD/Test.py b/flock/lib/BIRD/Test.py index 52a48844..0b813f9d 100644 --- a/flock/lib/BIRD/Test.py +++ b/flock/lib/BIRD/Test.py @@ -58,6 +58,10 @@ class BIRDBinDir: b.write(v) (target / bn).chmod(self.mod[bn]) + def cleanup(self, target): + for bn in self.files: + (target / bn).unlink() + default_bindir = BIRDBinDir.get("..") class BIRDInstance(CLI): @@ -75,6 +79,9 @@ class BIRDInstance(CLI): self.bindir.copy(self.workdir) + async def cleanup(self): + self.bindir.cleanup(self.workdir) + class Test: ipv6_prefix = ipaddress.ip_network("2001:db8::/32") ipv4_prefix = ipaddress.ip_network("192.0.2.0/24") @@ -87,6 +94,7 @@ class Test: def __init__(self, name): self.name = name self.hypervisor = Hypervisor(name) + self.machine_index = {} self._started = asyncio.Future() self._starting = False @@ -111,12 +119,16 @@ class Test: return await self.hypervisor.control_socket.send_cmd_early(*args) async def machines(self, *names, t: type): + for n in names: + if n in self.machine_index: + raise Exception(f"Machine {n} duplicate") + info = await asyncio.gather(*[ self.hcom("machine", name, { "type": "minimalist" }) for name in names ]) - return [ + inst = [ t(mach=Machine.new( name=n, hypervisor=self.hypervisor, @@ -124,6 +136,11 @@ class Test: )) for n,i in zip(names, info) ] + for n,i in zip(names, inst): + self.machine_index[n] = i + + return inst + async def link(self, name, *machines): match len(machines): case 0: @@ -144,3 +161,6 @@ class Test: case _: raise NotImplementedError("virtual bridge") + + async def cleanup(self): + await asyncio.gather(*[ v.cleanup() for v in self.machine_index.values() ])