diff --git a/flock/bgp-secondary/test.py b/flock/bgp-secondary/test.py index 33fc2c9d..3c4ea919 100644 --- a/flock/bgp-secondary/test.py +++ b/flock/bgp-secondary/test.py @@ -57,25 +57,6 @@ async def main(): with open(t.dest.workdir / "bird.conf", "w") as f: f.write(jt.render( link=link )) - with open(pathlib.Path.cwd() / ".." / ".." / "bird", "rb") as b: - with open(t.dest.workdir / "bird", "wb") as d: - d.write(dta := b.read()) - - with open(t.src.workdir / "bird", "wb") as d: - d.write(dta) - - with open(pathlib.Path.cwd() / ".." / ".." / "birdc", "rb") as b: - with open(t.dest.workdir / "birdc", "wb") as d: - d.write(dta := b.read()) - - with open(t.src.workdir / "birdc", "wb") as d: - d.write(dta) - - os.chmod(t.dest.workdir / "bird", 0o755) - os.chmod(t.src.workdir / "bird", 0o755) - os.chmod(t.dest.workdir / "birdc", 0o755) - os.chmod(t.src.workdir / "birdc", 0o755) - print(await asyncio.gather(*[ h.control_socket.send_cmd("run_in", where, "./bird", "-l") for where in ("src", "dest") diff --git a/flock/lib/BIRD/Test.py b/flock/lib/BIRD/Test.py index 58d01960..cd8b2515 100644 --- a/flock/lib/BIRD/Test.py +++ b/flock/lib/BIRD/Test.py @@ -17,10 +17,53 @@ class MinimalistTransport(Transport): async def send_cmd(self, *args): return await self.sock.send_cmd("run_in", self.machine, "./birdc", "-l", *args) +class BIRDBinDir: + index = {} + + def __init__(self, path): + self.path = path + + f = [ "bird", "birdc", "birdcl", ] + + self.files = { k: None for k in f } + self.mod = { k: None for k in f } + self.loaded = False + + @classmethod + def get(cls, where): + w = pathlib.Path(where).absolute() + try: + return cls.index[s := str(w)] + except KeyError: + cls.index[s] = (b := cls(w)) + return b + + def load(self): + for bn,v in self.files.items(): + if v is None: + with open(self.path / bn, "rb") as b: + self.files[bn] = b.read() + self.mod[bn] = (self.path / bn).stat().st_mode + + self.loaded = True + + def copy(self, target): + if not self.loaded: + self.load() + + for bn,v in self.files.items(): + if v is not None: + with open(target / bn, "wb") as b: + b.write(v) + (target / bn).chmod(self.mod[bn]) + +default_bindir = BIRDBinDir.get("..") + class BIRDInstance(CLI): - def __init__(self, mach: Machine): + def __init__(self, mach: Machine, bindir=None): self.mach = mach self.workdir = self.mach.workdir + self.bindir = BIRDBinDir.get(bindir) if bindir is not None else default_bindir super().__init__( transport=MinimalistTransport( @@ -29,6 +72,8 @@ class BIRDInstance(CLI): ) ) + self.bindir.copy(self.workdir) + class Test: machines_start = {}