0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-12-22 17:51:53 +00:00

Flock tests: BIRDInstance class for MinimalistMachines running BIRD

This commit is contained in:
Maria Matejka 2024-07-11 23:06:14 +02:00
parent 971a1e2792
commit ca431d04d9
2 changed files with 34 additions and 22 deletions

View File

@ -12,22 +12,16 @@ name = selfpath.parent.stem
sys.path.insert(0, str(selfpath.parent.parent / "lib")) sys.path.insert(0, str(selfpath.parent.parent / "lib"))
from BIRD.CLI import CLI, Transport from BIRD.Test import Test, BIRDInstance
from BIRD.Test import Test
os.chdir(pathlib.Path(__file__).parent) os.chdir(pathlib.Path(__file__).parent)
class MinimalistTransport(Transport):
def __init__(self, socket, machine):
self.sock = socket
self.machine = machine
async def send_cmd(self, *args):
return await self.sock.send_cmd("run_in", self.machine, "./birdc", "-l", *args)
class ThisTest(Test): class ThisTest(Test):
async def start(self): async def start(self):
self.src, self.dest = await self.machines("src", "dest") self.src, self.dest = await self.machines(
"src", "dest",
t=BIRDInstance,
)
async def main(): async def main():
t = ThisTest(name) t = ThisTest(name)
@ -89,23 +83,20 @@ async def main():
await asyncio.sleep(5) await asyncio.sleep(5)
src_cli = CLI(MinimalistTransport(h.control_socket, "src"))
dest_cli = CLI(MinimalistTransport(h.control_socket, "dest"))
print(await asyncio.gather(*[ print(await asyncio.gather(*[
where.show_route() where.show_route()
for where in (src_cli, dest_cli) for where in (t.src, t.dest)
])) ]))
await asyncio.sleep(1) await asyncio.sleep(1)
for p in ("p170", "p180", "p190", "p200"): for p in ("p170", "p180", "p190", "p200"):
await src_cli.enable(p) await t.src.enable(p)
await asyncio.sleep(1) await asyncio.sleep(1)
shr = await asyncio.gather(*[ shr = await asyncio.gather(*[
where.show_route() where.show_route()
for where in (src_cli, dest_cli) for where in (t.src, t.dest)
]) ])
print(shr[0]["out"].decode(), shr[1]["out"].decode()) print(shr[0]["out"].decode(), shr[1]["out"].decode())
@ -114,12 +105,12 @@ async def main():
print(await asyncio.gather(*[ print(await asyncio.gather(*[
where.show_route() where.show_route()
for where in (src_cli, dest_cli) for where in (t.src, t.dest)
])) ]))
print(await asyncio.gather(*[ print(await asyncio.gather(*[
c.down() c.down()
for c in (src_cli, dest_cli) for c in (t.src, t.dest)
])) ]))
await asyncio.sleep(5) await asyncio.sleep(5)

View File

@ -7,6 +7,27 @@ sys.path.insert(0, "/home/maria/flock")
from flock.Hypervisor import Hypervisor from flock.Hypervisor import Hypervisor
from flock.Machine import Machine from flock.Machine import Machine
from .CLI import CLI, Transport
class MinimalistTransport(Transport):
def __init__(self, socket, machine):
self.sock = socket
self.machine = machine
async def send_cmd(self, *args):
return await self.sock.send_cmd("run_in", self.machine, "./birdc", "-l", *args)
class BIRDInstance(CLI):
def __init__(self, mach: Machine):
self.mach = mach
self.workdir = self.mach.workdir
super().__init__(
transport=MinimalistTransport(
socket=mach.hypervisor.control_socket,
machine=self.mach.name
)
)
class Test: class Test:
machines_start = {} machines_start = {}
@ -34,17 +55,17 @@ class Test:
return await self.hypervisor.control_socket.send_cmd_early(*args) return await self.hypervisor.control_socket.send_cmd_early(*args)
async def machines(self, *names): async def machines(self, *names, t: type):
info = await asyncio.gather(*[ info = await asyncio.gather(*[
self.hcom("machine", name, { "type": "minimalist" }) self.hcom("machine", name, { "type": "minimalist" })
for name in names for name in names
]) ])
return [ return [
Machine.new( t(mach=Machine.new(
name=n, name=n,
hypervisor=self.hypervisor, hypervisor=self.hypervisor,
**i **i
) for n,i in zip(names, info) )) for n,i in zip(names, info)
] ]