vuls: init at 0.27.0
[NixPkgs.git] / nixos / tests / ulogd / ulogd.py
blob76a8d0c6e24a36af9815ba2b2c6467f0cd817bab
1 start_all()
2 machine.wait_for_unit("ulogd.service")
3 machine.systemctl("start network-online.target")
4 machine.wait_for_unit("network-online.target")
6 with subtest("Ulogd is running"):
7 machine.succeed("pgrep ulogd >&2")
9 # All packets show up twice in the logs
10 with subtest("Logs are collected"):
11 machine.succeed("ping -f 127.0.0.1 -c 5 >&2")
12 machine.succeed("sleep 2")
13 machine.wait_until_succeeds("du /var/log/ulogd.pcap")
14 _, echo_request_packets = machine.execute("tcpdump -r /var/log/ulogd.pcap icmp[0] == 8 and host 127.0.0.1")
15 expected, actual = 5 * 2, len(echo_request_packets.splitlines())
16 assert expected == actual, f"Expected {expected} ICMP request packets from pcap, got: {actual}"
17 _, echo_reply_packets = machine.execute("tcpdump -r /var/log/ulogd.pcap icmp[0] == 0 and host 127.0.0.1")
18 expected, actual = 5 * 2, len(echo_reply_packets.splitlines())
19 assert expected == actual, f"Expected {expected} ICMP reply packets from pcap, got: {actual}"
21 machine.wait_until_succeeds("du /var/log/ulogd_pkts.log")
22 _, echo_request_packets = machine.execute("grep TYPE=8 /var/log/ulogd_pkts.log")
23 expected, actual = 5 * 2, len(echo_request_packets.splitlines())
24 assert expected == actual, f"Expected {expected} ICMP request packets from logfile, got: {actual}"
25 _, echo_reply_packets = machine.execute("grep TYPE=0 /var/log/ulogd_pkts.log")
26 expected, actual = 5 * 2, len(echo_reply_packets.splitlines())
27 assert expected == actual, f"Expected {expected} ICMP reply packets from logfile, got: {actual}"
29 with subtest("Reloading service reopens log file"):
30 machine.succeed("mv /var/log/ulogd.pcap /var/log/old_ulogd.pcap")
31 machine.succeed("mv /var/log/ulogd_pkts.log /var/log/old_ulogd_pkts.log")
32 machine.succeed("systemctl reload ulogd.service")
33 machine.succeed("ping -f 127.0.0.1 -c 5 >&2")
34 machine.succeed("sleep 2")
35 machine.wait_until_succeeds("du /var/log/ulogd.pcap")
36 _, echo_request_packets = machine.execute("tcpdump -r /var/log/ulogd.pcap icmp[0] == 8 and host 127.0.0.1")
37 expected, actual = 5 * 2, len(echo_request_packets.splitlines())
38 assert expected == actual, f"Expected {expected} packets, got: {actual}"
39 _, echo_reply_packets = machine.execute("tcpdump -r /var/log/ulogd.pcap icmp[0] == 0 and host 127.0.0.1")
40 expected, actual = 5 * 2, len(echo_reply_packets.splitlines())
41 assert expected == actual, f"Expected {expected} packets, got: {actual}"
43 machine.wait_until_succeeds("du /var/log/ulogd_pkts.log")
44 _, echo_request_packets = machine.execute("grep TYPE=8 /var/log/ulogd_pkts.log")
45 expected, actual = 5 * 2, len(echo_request_packets.splitlines())
46 assert expected == actual, f"Expected {expected} ICMP request packets from logfile, got: {actual}"
47 _, echo_reply_packets = machine.execute("grep TYPE=0 /var/log/ulogd_pkts.log")
48 expected, actual = 5 * 2, len(echo_reply_packets.splitlines())
49 assert expected == actual, f"Expected {expected} ICMP reply packets from logfile, got: {actual}"