0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-10-18 09:58:43 +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 {
local {{ links["L"]["dest"]["ipv6"].ip }} as 2;
neighbor {{ links["L"]["src"]["ipv6"].ip }} as 1;
local {{ t.links["L"]["dest"]["ipv6"].ip }} as 2;
neighbor {{ t.links["L"]["src"]["ipv6"].ip }} as 1;
ipv6 {
import all;
export none;

View File

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

View File

@ -1,8 +1,6 @@
#!/usr/bin/python3
import asyncio
import ipaddress
import jinja2
import os
import pathlib
import sys
@ -26,30 +24,17 @@ class ThisTest(Test):
"L": await self.link("L", "src", "dest")
}
await super().start()
async def main():
t = ThisTest(name)
await t.start()
h = t.hypervisor
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)
print(await asyncio.gather(*[
@ -77,17 +62,7 @@ async def main():
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()
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)
assert(__name__ == "__main__")

View File

@ -1,5 +1,6 @@
import asyncio
import ipaddress
import jinja2
import os
import pathlib
import sys
@ -65,10 +66,11 @@ class BIRDBinDir:
default_bindir = BIRDBinDir.get("..")
class BIRDInstance(CLI):
def __init__(self, mach: Machine, bindir=None):
def __init__(self, mach: Machine, bindir=None, conf=None):
self.mach = mach
self.workdir = self.mach.workdir
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__(
transport=MinimalistTransport(
@ -77,9 +79,24 @@ class BIRDInstance(CLI):
)
)
async def start(self, test):
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):
# 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)
class Test:
@ -133,7 +150,8 @@ class Test:
name=n,
hypervisor=self.hypervisor,
**i
)) for n,i in zip(names, info)
),
) for n,i in zip(names, info)
]
for n,i in zip(names, inst):
@ -162,5 +180,8 @@ class Test:
case _:
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):
await asyncio.gather(*[ v.cleanup() for v in self.machine_index.values() ])