0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-12-22 09:41:54 +00:00

Flock tests: updated to Flock 0.1, converted RPC calls

This commit is contained in:
Maria Matejka 2024-07-26 14:47:26 +02:00
parent 266cadba72
commit 01552774c2
4 changed files with 25 additions and 28 deletions

2
.gitmodules vendored
View File

@ -4,4 +4,4 @@
[submodule "python/flock"] [submodule "python/flock"]
path = python/flock path = python/flock
url = https://gitlab.nic.cz/labs/flock url = https://gitlab.nic.cz/labs/flock
branch = v0.0 branch = v0.1

View File

@ -111,6 +111,3 @@ class ThisTest(Test):
# Pre-cleanup log checker # Pre-cleanup log checker
self.src.default_log_checker.append(f"{self.src.logprefix} <RMT> LINK: Received: Administrative shutdown") self.src.default_log_checker.append(f"{self.src.logprefix} <RMT> LINK: Received: Administrative shutdown")
self.dest.default_log_checker.append(f"{self.dest.logprefix} <RMT> LINK: Received: Administrative shutdown") self.dest.default_log_checker.append(f"{self.dest.logprefix} <RMT> LINK: Received: Administrative shutdown")
# Regular cleanup
await self.cleanup()

View File

@ -21,12 +21,12 @@ from .LogChecker import LogChecker, LogExpectedFuture
from .Aux import dict_gather, dict_expand, deep_sort_lists, deep_eq, Differs from .Aux import dict_gather, dict_expand, deep_sort_lists, deep_eq, Differs
class MinimalistTransport(Transport): class MinimalistTransport(Transport):
def __init__(self, socket, machine): def __init__(self, hypervisor, machine):
self.sock = socket self.hypervisor = hypervisor
self.machine = machine self.machine = machine
async def send_cmd(self, *args): async def send_cmd(self, *args):
return await self.sock.send_cmd("run_in", self.machine, "./birdc", "-l", *args) return await self.hypervisor.run_in(self.machine, "./birdc", "-l", *args)
class BIRDBinDir: class BIRDBinDir:
index = {} index = {}
@ -90,8 +90,8 @@ class BIRDInstance(CLI):
super().__init__( super().__init__(
transport=MinimalistTransport( transport=MinimalistTransport(
socket=mach.hypervisor.control_socket, hypervisor=mach.hypervisor,
machine=self.mach.name machine=self.mach.name,
) )
) )
@ -145,7 +145,7 @@ class BIRDInstance(CLI):
self.bindir.copy(self.workdir) self.bindir.copy(self.workdir)
self.write_config(test) self.write_config(test)
await test.hcom("run_in", self.mach.name, "./bird", "-l") await test.hypervisor.run_in(self.mach.name, "./bird", "-l")
exp = LogExpectedFuture(f"{self.logprefix} <INFO> Started$") exp = LogExpectedFuture(f"{self.logprefix} <INFO> Started$")
self.default_log_checker.expected.append(exp) self.default_log_checker.expected.append(exp)
@ -299,8 +299,7 @@ class DumpLinuxKRT(DumpOnMachines):
async def obtain_on_machine(self, mach): async def obtain_on_machine(self, mach):
raw = await dict_gather({ raw = await dict_gather({
fam: fam:
self.test.hypervisor.control_socket.send_cmd( self.test.hypervisor.run_in(mach.mach.name, "ip", "-j", f"-{fam}", "route", "show", *self.cmdargs)
"run_in", mach.mach.name, "ip", "-j", f"-{fam}", "route", "show", *self.cmdargs)
for fam in ("4", "6", "M") for fam in ("4", "6", "M")
}) })
@ -341,7 +340,7 @@ class Test:
self.route_dump_id = 0 self.route_dump_id = 0
async def hcom(self, *args): async def assure_running(self):
if self._stopped is not None: if self._stopped is not None:
return return
@ -349,28 +348,28 @@ class Test:
self._started = asyncio.Future() self._started = asyncio.Future()
if self._started.done(): if self._started.done():
return await self.hypervisor.control_socket.send_cmd(*args) return
if self._starting: if self._starting:
await self._started await self._started
else: return
self._starting = True
await self.hypervisor.prepare()
os.symlink(pathlib.Path(f"{self.name}.log").absolute(), self.hypervisor.basedir / "flock.log")
await self.hypervisor.start()
self._started.set_result(True) self._starting = True
self._starting = False await self.hypervisor.prepare()
os.symlink(pathlib.Path(f"{self.name}.log").absolute(), self.hypervisor.basedir / "flock.log")
await self.hypervisor.start()
return await self.hypervisor.control_socket.send_cmd_early(*args) self._started.set_result(await self.hypervisor.status(__rpc_timeout=5))
async def machines(self, *names, t: type): async def machines(self, *names, t: type):
for n in names: for n in names:
if n in self.machine_index: if n in self.machine_index:
raise Exception(f"Machine {n} duplicate") raise Exception(f"Machine {n} duplicate")
await self.assure_running()
info = await asyncio.gather(*[ info = await asyncio.gather(*[
self.hcom("machine", name, { "type": "minimalist" }) self.hypervisor.machine( name, { "type": "minimalist" })
for name in names for name in names
]) ])
@ -389,13 +388,15 @@ class Test:
return inst return inst
async def link(self, name, *machines): async def link(self, name, *machines):
await self.assure_running()
match len(machines): match len(machines):
case 0: case 0:
raise Exception("Link with no machines? HOW?!") raise Exception("Link with no machines? HOW?!")
case 1: case 1:
raise NotImplementedError("dummy link") raise NotImplementedError("dummy link")
case _: case _:
linfo = await self.hcom("link", name, { linfo = await self.hypervisor.link(name, {
"machines": { m: { "name": name } for m in machines }, "machines": { m: { "name": name } for m in machines },
"ipv6": str(next(self.ipv6_pxgen)), "ipv6": str(next(self.ipv6_pxgen)),
"ipv4": str(next(self.ipv4_pxgen)), "ipv4": str(next(self.ipv4_pxgen)),
@ -413,7 +414,7 @@ class Test:
async def cleanup(self): async def cleanup(self):
await asyncio.gather(*[ v.cleanup() for v in self.machine_index.values() ]) await asyncio.gather(*[ v.cleanup() for v in self.machine_index.values() ])
self.machine_index = {} self.machine_index = {}
await self.hcom("stop", True) await self.hypervisor.stop()
self._stopped = True self._stopped = True
async def run(self): async def run(self):
@ -453,8 +454,7 @@ class Test:
raw = await dict_gather({ raw = await dict_gather({
(mach.mach.name, fam): (mach.mach.name, fam):
mach.mach.hypervisor.control_socket.send_cmd( mach.mach.hypervisor.run_in(mach.mach.name, "ip", "-j", f"-{fam}", "route", "show", *args)
"run_in", mach.mach.name, "ip", "-j", f"-{fam}", "route", "show", *args)
for mach in machines for mach in machines
for fam in ("4", "6", "M") for fam in ("4", "6", "M")
}) })

@ -1 +1 @@
Subproject commit d30489bec7ed8fa4d2009f785fb6f53cff6625c5 Subproject commit 03a744d7eb362565a05787a93f6f0085ea53e2db