hive-egress: the lease hook's lines reach the journal at info under egress-lease
dnsmasq relays the hook's stderr at LOG_DEBUG as dnsmasq-script, and the field log shipper's journald receiver keeps info and above, so no lease add or renewal was visible in the field. The hook now also writes each line to /dev/log at info priority with identifier egress-lease. The stderr print stays. The VM test reads the lines back with journalctl -t egress-lease -p info.
This commit is contained in:
parent
7efa8c8ea7
commit
d9551415bf
1 changed files with 122 additions and 9 deletions
|
|
@ -288,8 +288,14 @@ pkgs.testers.runNixOSTest {
|
|||
def acks_of(mac_addr):
|
||||
return int(host.succeed("echo " + acks_of_cmd(mac_addr)).strip())
|
||||
|
||||
# What `hive-priv egress-lease` leaves in the journal: one line per lease event, under its
|
||||
# own identifier at info priority, which is as low as the log shipper reads. `-u dnsmasq`
|
||||
# would also match dnsmasq's debug-priority copy of the same stderr line, which the shipper
|
||||
# drops and which would count each event twice.
|
||||
LEASE_LOG = "journalctl -t egress-lease -p info -o cat --no-pager"
|
||||
|
||||
def stale_dels():
|
||||
return host.succeed("journalctl -u dnsmasq -o cat --no-pager | grep -c 'egress-lease: del .* skipped (stale)' || true").strip()
|
||||
return host.succeed(LEASE_LOG + " | grep -c 'egress-lease: del .* skipped (stale)' || true").strip()
|
||||
|
||||
def applied_dels(who=""):
|
||||
"""How many deletes the lease script applied so far, all or `mac=<mac> ` only.
|
||||
|
|
@ -297,7 +303,7 @@ pkgs.testers.runNixOSTest {
|
|||
A count is taken before the step under test and compared after: the
|
||||
journal holds the lines of every earlier subtest.
|
||||
"""
|
||||
return int(host.succeed(f"journalctl -u dnsmasq -o cat --no-pager | grep -c 'egress-lease: del {who}.* applied' || true").strip())
|
||||
return int(host.succeed(f"{LEASE_LOG} | grep -c 'egress-lease: del {who}.* applied' || true").strip())
|
||||
|
||||
host.start()
|
||||
host.wait_for_unit("multi-user.target")
|
||||
|
|
@ -336,6 +342,10 @@ pkgs.testers.runNixOSTest {
|
|||
port = found.group(1)
|
||||
print(f"tolerated start-up refusal, {(stamp - QUIET_AFTER_US[port]) / 1e6:+.3f}s from the end of {port}'s settle: {message}")
|
||||
assert not spoof_lines(), spoof_lines()
|
||||
# Each lease left its line in the journal where the shipper can read it, with the
|
||||
# container's MAC and address in it.
|
||||
for mac_addr, ip_addr in ((MAC_A, IP_A), (MAC_B, IP_B)):
|
||||
host.wait_until_succeeds(f"{LEASE_LOG} | grep -E 'egress-lease: (add|old) mac={mac_addr} ip={ip_addr} '")
|
||||
|
||||
with subtest("a container sending from its own address reaches the host and the other container"):
|
||||
assert ct_ok("a", "ping -c1 -W2 ${gateway}")
|
||||
|
|
@ -509,7 +519,7 @@ pkgs.testers.runNixOSTest {
|
|||
host.succeed("date -s @$(( $(date +%s) + 7200 ))")
|
||||
# Any DHCP packet makes dnsmasq prune: a DISCOVER with a's own chaddr.
|
||||
ct("a", "perl ${bootp} " + MAC_A)
|
||||
host.wait_until_succeeds("test $(journalctl -u dnsmasq -o cat --no-pager | grep -c 'egress-lease: del .* skipped (stale)') -ge " + str(skipped + 2), timeout=60)
|
||||
host.wait_until_succeeds("test $(" + LEASE_LOG + " | grep -c 'egress-lease: del .* skipped (stale)') -ge " + str(skipped + 2), timeout=60)
|
||||
host.succeed(f"nft list set {TABLE} lease_v4 | grep -q '{MAC_A} . {IP_A}'")
|
||||
host.succeed(f"nft list set {TABLE} lease_v4 | grep -q '{MAC_B} . {IP_B}'")
|
||||
assert ct_ok("a", "ping -c1 -W2 ${gateway}"), "a reaches the host after dnsmasq forgot its lease"
|
||||
|
|
@ -537,7 +547,7 @@ pkgs.testers.runNixOSTest {
|
|||
host.wait_until_fails(f"nft list set {TABLE} lease_v4 | grep -q '{MAC_A} . {IP_A}'", timeout=30)
|
||||
host.succeed(f"nft list set {TABLE} lease_v4 | grep -q '{MAC_B} . {IP_B}'")
|
||||
host.wait_until_succeeds(
|
||||
"test $(journalctl -u dnsmasq -o cat --no-pager | grep -c 'egress-lease: del mac=" + MAC_A + " .* applied') -gt " + str(released),
|
||||
"test $(" + LEASE_LOG + " | grep -c 'egress-lease: del mac=" + MAC_A + " .* applied') -gt " + str(released),
|
||||
timeout=30,
|
||||
)
|
||||
# a asks again, as its container would after a restart.
|
||||
|
|
|
|||
Loading…
Reference in a new issue