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

Flock tests: encapsulated config and cleanup

This commit is contained in:
Maria Matejka 2024-07-12 19:56:04 +02:00
parent db8d849756
commit 62145d087b
4 changed files with 30 additions and 34 deletions

View File

@ -14,8 +14,8 @@ protocol kernel kernel6 {
} }
protocol bgp LINK { protocol bgp LINK {
local {{ links["L"]["dest"]["ipv6"].ip }} as 2; local {{ t.links["L"]["dest"]["ipv6"].ip }} as 2;
neighbor {{ links["L"]["src"]["ipv6"].ip }} as 1; neighbor {{ t.links["L"]["src"]["ipv6"].ip }} as 1;
ipv6 { ipv6 {
import all; import all;
export none; export none;

View File

@ -89,8 +89,8 @@ function CHECK() -> bool {
} }
protocol bgp LINK { protocol bgp LINK {
local {{ links["L"]["src"]["ipv6"].ip }} as 1; local {{ t.links["L"]["src"]["ipv6"].ip }} as 1;
neighbor {{ links["L"]["dest"]["ipv6"].ip }} as 2; neighbor {{ t.links["L"]["dest"]["ipv6"].ip }} as 2;
ipv6 { ipv6 {
import none; import none;
export where CHECK(); export where CHECK();

View File

@ -1,8 +1,6 @@
#!/usr/bin/python3 #!/usr/bin/python3
import asyncio import asyncio
import ipaddress
import jinja2
import os import os
import pathlib import pathlib
import sys import sys
@ -26,30 +24,17 @@ class ThisTest(Test):
"L": await self.link("L", "src", "dest") "L": await self.link("L", "src", "dest")
} }
await super().start()
async def main(): async def main():
t = ThisTest(name) t = ThisTest(name)
await t.start() await t.start()
h = t.hypervisor h = t.hypervisor
print(t.links, t.src, t.dest) print(t.links, t.src, t.dest)
env = jinja2.Environment()
src_conf = open("bird_src.conf", "r").read()
jt = env.from_string(src_conf)
with open(t.src.workdir / "bird.conf", "w") as f:
f.write(jt.render( links=t.links ))
dest_conf = open("bird_dest.conf", "r").read()
jt = env.from_string(dest_conf)
with open(t.dest.workdir / "bird.conf", "w") as f:
f.write(jt.render( links=t.links ))
print(await asyncio.gather(*[
h.control_socket.send_cmd("run_in", where, "./bird", "-l")
for where in ("src", "dest")
]))
await asyncio.sleep(5) await asyncio.sleep(5)
print(await asyncio.gather(*[ print(await asyncio.gather(*[
@ -77,17 +62,7 @@ async def main():
for where in (t.src, t.dest) for where in (t.src, t.dest)
])) ]))
print(await asyncio.gather(*[
c.down()
for c in (t.src, t.dest)
]))
await asyncio.sleep(5)
await t.cleanup() await t.cleanup()
for q in (t.dest, t.src):
for f in ("bird.conf", "bird.log"):
(q.workdir / f).unlink()
await h.control_socket.send_cmd("stop", True) await h.control_socket.send_cmd("stop", True)
assert(__name__ == "__main__") assert(__name__ == "__main__")

View File

@ -1,5 +1,6 @@
import asyncio import asyncio
import ipaddress import ipaddress
import jinja2
import os import os
import pathlib import pathlib
import sys import sys
@ -65,10 +66,11 @@ class BIRDBinDir:
default_bindir = BIRDBinDir.get("..") default_bindir = BIRDBinDir.get("..")
class BIRDInstance(CLI): class BIRDInstance(CLI):
def __init__(self, mach: Machine, bindir=None): def __init__(self, mach: Machine, bindir=None, conf=None):
self.mach = mach self.mach = mach
self.workdir = self.mach.workdir self.workdir = self.mach.workdir
self.bindir = BIRDBinDir.get(bindir) if bindir is not None else default_bindir self.bindir = BIRDBinDir.get(bindir) if bindir is not None else default_bindir
self.conf = conf if conf is not None else f"bird_{mach.name}.conf"
super().__init__( super().__init__(
transport=MinimalistTransport( transport=MinimalistTransport(
@ -77,9 +79,24 @@ class BIRDInstance(CLI):
) )
) )
async def start(self, test):
self.bindir.copy(self.workdir) self.bindir.copy(self.workdir)
with (open(self.conf, "r") as s, open(self.workdir / "bird.conf", "w") as f):
f.write(jinja2.Environment().from_string(s.read()).render(t=test))
await test.hcom("run_in", self.mach.name, "./bird", "-l")
async def cleanup(self): async def cleanup(self):
# Send down command and wait for BIRD to actually finish
await self.down()
while (self.workdir / "bird.ctl").exists():
await asyncio.sleep(0.1)
# Remove known files
for f in ("bird.conf", "bird.log"):
(self.workdir / f).unlink()
self.bindir.cleanup(self.workdir) self.bindir.cleanup(self.workdir)
class Test: class Test:
@ -133,7 +150,8 @@ class Test:
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)
] ]
for n,i in zip(names, inst): for n,i in zip(names, inst):
@ -162,5 +180,8 @@ class Test:
case _: case _:
raise NotImplementedError("virtual bridge") raise NotImplementedError("virtual bridge")
async def start(self):
await asyncio.gather(*[ v.start(test=self) for v in self.machine_index.values() ])
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() ])