0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-10-18 09:58:43 +00:00

Flock test: integrated with Makefile

This commit is contained in:
Maria Matejka 2024-07-12 21:08:42 +02:00
parent 62145d087b
commit d544213200
7 changed files with 57 additions and 46 deletions

View File

@ -76,7 +76,7 @@ cli: $(client)
$(daemon): LIBS += $(DAEMON_LIBS) $(daemon): LIBS += $(DAEMON_LIBS)
# Include directories # Include directories
dirs := client conf doc filter lib nest test $(addprefix proto/,$(protocols)) @sysdep_dirs@ dirs := client conf doc filter lib nest test flock $(addprefix proto/,$(protocols)) @sysdep_dirs@
# conf/Makefile declarations needed for all other modules # conf/Makefile declarations needed for all other modules
conf-lex-targets := $(addprefix $(objdir)/conf/,cf-lex.o) conf-lex-targets := $(addprefix $(objdir)/conf/,cf-lex.o)

10
flock/Makefile Normal file
View File

@ -0,0 +1,10 @@
flock-%:
@python3 -m python.BIRD.Test $*
FLOCK_ALL := $(addprefix flock-, \
bgp-secondary \
)
flock-all: $(FLOCK_ALL)
.PHONY: flock-all

View File

@ -1,18 +1,7 @@
#!/usr/bin/python3 #!/usr/bin/python3
import asyncio import asyncio
import os from python.BIRD.Test import Test, BIRDInstance
import pathlib
import sys
selfpath = pathlib.Path(__file__)
name = selfpath.parent.stem
sys.path.insert(0, str(selfpath.parent.parent / "lib"))
from BIRD.Test import Test, BIRDInstance
os.chdir(pathlib.Path(__file__).parent)
class ThisTest(Test): class ThisTest(Test):
async def start(self): async def start(self):
@ -26,44 +15,39 @@ class ThisTest(Test):
await super().start() await super().start()
async def main(): async def run(t):
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) await asyncio.sleep(5)
await asyncio.sleep(5) print(await asyncio.gather(*[
print(await asyncio.gather(*[
where.show_route()
for where in (t.src, t.dest)
]))
await asyncio.sleep(1)
for p in ("p170", "p180", "p190", "p200"):
await t.src.enable(p)
await asyncio.sleep(1)
shr = await asyncio.gather(*[
where.show_route() where.show_route()
for where in (t.src, t.dest) for where in (t.src, t.dest)
]) ]))
print(shr[0]["out"].decode(), shr[1]["out"].decode())
await asyncio.sleep(1) await asyncio.sleep(1)
print(await asyncio.gather(*[ for p in ("p170", "p180", "p190", "p200"):
where.show_route() await t.src.enable(p)
for where in (t.src, t.dest) await asyncio.sleep(1)
]))
await t.cleanup() shr = await asyncio.gather(*[
await h.control_socket.send_cmd("stop", True) where.show_route()
for where in (t.src, t.dest)
])
assert(__name__ == "__main__") print(shr[0]["out"].decode(), shr[1]["out"].decode())
asyncio.run(main())
await asyncio.sleep(1)
print(await asyncio.gather(*[
where.show_route()
for where in (t.src, t.dest)
]))
await t.cleanup()
await h.control_socket.send_cmd("stop", True)

View File

@ -1 +0,0 @@
print("imported", __file__)

View File

@ -63,7 +63,7 @@ class BIRDBinDir:
for bn in self.files: for bn in self.files:
(target / bn).unlink() (target / bn).unlink()
default_bindir = BIRDBinDir.get("..") default_bindir = BIRDBinDir.get(".")
class BIRDInstance(CLI): class BIRDInstance(CLI):
def __init__(self, mach: Machine, bindir=None, conf=None): def __init__(self, mach: Machine, bindir=None, conf=None):
@ -112,13 +112,16 @@ class Test:
self.name = name self.name = name
self.hypervisor = Hypervisor(name) self.hypervisor = Hypervisor(name)
self.machine_index = {} self.machine_index = {}
self._started = asyncio.Future() self._started = None
self._starting = False self._starting = False
self.ipv6_pxgen = self.ipv6_prefix.subnets(new_prefix=self.ipv6_link_pxlen) self.ipv6_pxgen = self.ipv6_prefix.subnets(new_prefix=self.ipv6_link_pxlen)
self.ipv4_pxgen = self.ipv4_prefix.subnets(new_prefix=self.ipv4_link_pxlen) self.ipv4_pxgen = self.ipv4_prefix.subnets(new_prefix=self.ipv4_link_pxlen)
async def hcom(self, *args): async def hcom(self, *args):
if self._started is None:
self._started = asyncio.Future()
if self._started.done(): if self._started.done():
return await self.hypervisor.control_socket.send_cmd(*args) return await self.hypervisor.control_socket.send_cmd(*args)
@ -185,3 +188,18 @@ 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() ])
if __name__ == "__main__":
name = sys.argv[1]
p = (pathlib.Path(__file__).parent.parent.parent / "flock" / name).absolute()
sys.path.insert(0, str(p))
if "MAKEFLAGS" in os.environ:
print(os.environ["MAKEFLAGS"])
import test
os.chdir(p)
asyncio.run(test.ThisTest(name).run())

0
python/BIRD/__init__.py Normal file
View File