3 """Test peer information import and export."""
7 from testlib import check, cmd
8 from testlib.log import log
9 from testlib.proc import Tinc, Script
10 from testlib.test import Test
13 def init(ctx: Test) -> T.Tuple[Tinc, Tinc, Tinc]:
14 """Initialize new test nodes."""
15 foo, bar, baz = ctx.node(), ctx.node(), ctx.node()
17 log.info("configure %s", foo.name)
26 log.info("configure %s", bar.name)
35 log.info("configure %s", baz.name)
47 def run_tests(ctx: Test) -> None:
49 foo, bar, baz = init(ctx)
52 bar, baz = Tinc('{bar}'), Tinc('{baz}')
53 bar.cmd('add', 'ConnectTo', this.name)
54 baz.cmd('add', 'ConnectTo', this.name)
56 foo.add_script(Script.TINC_UP, tinc_up)
59 log.info("run exchange")
60 cmd.exchange(foo, bar)
62 log.info("run exchange with export-all")
63 cmd.exchange(foo, baz, export_all=True)
65 log.info("run exchange-all")
66 out, err = foo.cmd("exchange-all", code=1)
67 check.is_in("No host configuration files imported", err)
69 log.info("run import")
70 bar.cmd("import", stdin=out)
72 for first, second in (
73 (foo.sub("hosts", foo.name), bar.sub("hosts", foo.name)),
74 (foo.sub("hosts", foo.name), baz.sub("hosts", foo.name)),
75 (foo.sub("hosts", bar.name), bar.sub("hosts", bar.name)),
76 (foo.sub("hosts", bar.name), baz.sub("hosts", bar.name)),
77 (foo.sub("hosts", baz.name), bar.sub("hosts", baz.name)),
78 (foo.sub("hosts", baz.name), baz.sub("hosts", baz.name)),
80 log.info("comparing configs %s and %s", first, second)
81 check.files_eq(first, second)
83 log.info("create %s scripts", foo)
84 foo.add_script(bar.script_up)
85 foo.add_script(baz.script_up)
87 log.info("start nodes")
91 log.info("wait for up scripts")
92 foo[bar.script_up].wait()
93 foo[baz.script_up].wait()
95 for tinc in foo, bar, baz:
99 with Test("import-export") as context: