Commit 3e5fca60 authored by Ondřej Zajíček's avatar Ondřej Zajíček

Netlab: Differentiate optional/mandatory log messages in log tests

Also fix pattern in cf-ospf-custom and some missing imports
parent 6f3b872b
......@@ -58,4 +58,4 @@ def test_bird_routes_ipv6(exp_devs: str):
@pytest.mark.parametrize("exp_devs", EXPECTED_DEVICES)
def test_logging(exp_devs: str):
"""Check the log files. There should only DBG, INFO and TRACE messages"""
tk.test_logs(exp_devs, [])
tk.test_logs(exp_devs, [], [])
......@@ -58,4 +58,4 @@ def test_bird_routes_ipv6(exp_devs: str):
@pytest.mark.parametrize("exp_devs", EXPECTED_DEVICES)
def test_logging(exp_devs: str):
"""Check the log files. There should only DBG, INFO and TRACE messages"""
tk.test_logs(exp_devs, [])
tk.test_logs(exp_devs, [], [])
......@@ -58,4 +58,4 @@ def test_bird_routes_ipv6(exp_devs: str):
@pytest.mark.parametrize("exp_devs", EXPECTED_DEVICES)
def test_logging(exp_devs: str):
"""Check the log files. There should only DBG, INFO and TRACE messages"""
tk.test_logs(exp_devs, [])
tk.test_logs(exp_devs, [], [])
......@@ -58,4 +58,4 @@ def test_bird_routes_ipv6(exp_devs: str):
@pytest.mark.parametrize("exp_devs", EXPECTED_DEVICES)
def test_logging(exp_devs: str):
"""Check the log files. There should only DBG, INFO and TRACE messages"""
tk.test_logs(exp_devs, [])
tk.test_logs(exp_devs, [], [])
......@@ -7,29 +7,28 @@ import tests.config as cf
LIMIT = 60
EXPECTED_DEVICES = ("m1", "m2", "m3", "m4", "m5", "m6", "m7", "m8")
LOG_OPT = ["<WARN> ospf.: Cannot find next hop for LSA"]
LOGS_M1 = [
"<INFO> Started",
"<AUTH> ospf4: Authentication failed for nbr 10.0.0.3 on ve2 - wrong password",
"<AUTH> ospf5: Authentication failed for nbr 10.0.0.3 on ve2 - wrong authentication code",
"<AUTH> ospf6: Authentication failed for nbr 10.0.0.3 on ve2 - wrong authentication code"
]
LOGS_M3 = [
"<INFO> Started",
"<AUTH> ospf4: Authentication failed for nbr 10.0.0.1 on ve1 - wrong password",
"<AUTH> ospf5: Authentication failed for nbr 10.0.0.1 on ve1 - wrong authentication code",
"<AUTH> ospf6: Authentication failed for nbr 10.0.0.1 on ve1 - wrong authentication code",
]
LOGS_M6 = [
"<INFO> Started",
"<AUTH> ospf4: Authentication failed for nbr 10.0.0.8 on ve2 - wrong authentication code",
"<AUTH> ospf5: Authentication failed for nbr 10.0.0.8 on ve2 - wrong authentication code",
"<AUTH> ospf6: Authentication failed for nbr 10.0.0.8 on ve2 - wrong authentication code",
]
LOGS_M8 = [
"<INFO> Started",
"<AUTH> ospf4: Authentication failed for nbr 10.0.0.6 on ve1 - wrong authentication code",
"<AUTH> ospf5: Authentication failed for nbr 10.0.0.6 on ve1 - wrong authentication code",
"<AUTH> ospf6: Authentication failed for nbr 10.0.0.6 on ve1 - wrong authentication code",
......@@ -93,4 +92,4 @@ def test_bird_routes_ipv6(exp_devs: str):
)
def test_logging(exp_devs: str, exp_messages: List[str]):
"""Check the log files. There should only DBG, INFO and TRACE messages"""
tk.test_logs(exp_devs, exp_messages)
tk.test_logs(exp_devs, LOG_OPT, exp_messages)
......@@ -6,6 +6,7 @@ import tests.config as cf
LIMIT = 60
EXPECTED_DEVICES = ("m1", "m2", "m3", "m4", "m5", "m6", "m7", "m8")
LOG_OPT = ["<WARN> ospf.: Cannot find next hop for LSA"]
@pytest.mark.skipif(cf.save == False, reason="mode: save")
......@@ -53,4 +54,4 @@ def test_bird_routes_ipv6(exp_devs: str):
@pytest.mark.parametrize("exp_devs", EXPECTED_DEVICES)
def test_logging(exp_devs: str):
"""Check the log files. There should only DBG, INFO and TRACE messages"""
tk.test_logs(exp_devs, [])
tk.test_logs(exp_devs, LOG_OPT, [])
......@@ -6,6 +6,7 @@ import tests.config as cf
LIMIT = 60
EXPECTED_DEVICES = ("m1", "m2", "m3", "m4", "m5", "m6", "m7", "m8")
LOG_OPT = ["<WARN> ospf.: Cannot find next hop for LSA"]
@pytest.mark.skipif(cf.save == False, reason="mode: save")
......@@ -53,4 +54,4 @@ def test_bird_routes_ipv6(exp_devs: str):
@pytest.mark.parametrize("exp_devs", EXPECTED_DEVICES)
def test_logging(exp_devs: str):
"""Check the log files. There should only DBG, INFO and TRACE messages"""
tk.test_logs(exp_devs, [])
tk.test_logs(exp_devs, LOG_OPT, [])
import pytest
from typing import List
import tests.kernel as tk
import tests.config as cf
......@@ -6,12 +7,13 @@ import tests.config as cf
LIMIT = 60
EXPECTED_DEVICES = ("m1", "m2", "m3", "m4", "m5", "m6", "m7", "m8")
LOG_M = ["<WARN> ospf5: Cannot find next hop for LSA"]
LOG_M5 = ["<RMT> ospf6: Bad packet from .* via ve1 - wrong TTL \(1\)"]
LOG_OPT = ["<WARN> ospf.: Cannot find next hop for LSA"]
LOG_M5 = ["<RMT> ospf6: Bad packet from .* via ve1 - wrong TTL \\(1\\)"]
LOG_M8 = [
"<RMT> ospf4: Bad packet from .* via ve1 - wrong TTL \(1\)",
"<RMT> ospf5: Bad packet from .* via ve1 - wrong TTL \(1\)",
"<RMT> ospf6: Bad packet from .* via ve1 - wrong TTL \(1\)",
"<RMT> ospf4: Bad packet from .* via ve1 - wrong TTL \\(1\\)",
"<RMT> ospf5: Bad packet from .* via ve1 - wrong TTL \\(1\\)",
"<RMT> ospf6: Bad packet from .* via ve1 - wrong TTL \\(1\\)",
]
......@@ -60,10 +62,10 @@ def test_bird_routes_ipv6(exp_devs: str):
@pytest.mark.parametrize(
"exp_devs, exp_messages",
[
pytest.param("m1", LOG_M),
pytest.param("m2", LOG_M),
pytest.param("m3", LOG_M),
pytest.param("m4", LOG_M),
pytest.param("m1", []),
pytest.param("m2", []),
pytest.param("m3", []),
pytest.param("m4", []),
pytest.param("m5", LOG_M5),
pytest.param("m6", []),
pytest.param("m7", []),
......@@ -72,4 +74,4 @@ def test_bird_routes_ipv6(exp_devs: str):
)
def test_logging(exp_devs: str, exp_messages: List[str]):
"""Check the log files. There should only DBG, INFO and TRACE messages"""
tk.test_logs(exp_devs, exp_messages)
tk.test_logs(exp_devs, LOG_OPT, exp_messages)
......@@ -6,6 +6,7 @@ import tests.config as cf
LIMIT = 60
EXPECTED_DEVICES = ("m1", "m2", "m3", "m4", "m5", "m6", "m7", "m8")
LOG_OPT = ["<WARN> ospf.: Cannot find next hop for LSA"]
@pytest.mark.skipif(cf.save == False, reason="mode: save")
......@@ -53,4 +54,4 @@ def test_bird_routes_ipv6(exp_devs: str):
@pytest.mark.parametrize("exp_devs", EXPECTED_DEVICES)
def test_logging(exp_devs: str):
"""Check the log files. There should only DBG, INFO and TRACE messages"""
tk.test_logs(exp_devs, [])
tk.test_logs(exp_devs, LOG_OPT, [])
import pytest
from typing import List
import tests.kernel as tk
import tests.config as cf
......@@ -6,12 +7,10 @@ import tests.config as cf
LIMIT = 60
EXPECTED_DEVICES = ("m1", "m2", "m3", "m4", "m5", "m6", "m7", "m8")
LOG_OPT = ["<WARN> ospf.: Cannot find next hop for LSA"]
LOG_M3 = [
"<WARN> ospf5: Configured neighbor address .* should be link-local",
"<WARN> ospf5: Configured neighbor address .* should be link-local",
"<WARN> ospf5: Configured neighbor address .* should be link-local",
"<WARN> ospf6: Configured neighbor address .* should be link-local",
"<WARN> ospf6: Configured neighbor address .* should be link-local",
"<WARN> ospf6: Configured neighbor address .* should be link-local"
]
......@@ -73,4 +72,4 @@ def test_bird_routes_ipv6(exp_devs: str):
)
def test_logging(exp_devs: str, exp_messages: List[str]):
"""Check the log files. There should only DBG, INFO and TRACE messages"""
tk.test_logs(exp_devs, exp_messages)
tk.test_logs(exp_devs, LOG_OPT, exp_messages)
......@@ -6,6 +6,7 @@ import tests.config as cf
LIMIT = 60
EXPECTED_DEVICES = ("m1", "m2", "m3", "m4", "m5", "m6", "m7", "m8")
LOG_OPT = ["<WARN> ospf.: Cannot find next hop for LSA"]
@pytest.mark.skipif(cf.save == False, reason="mode: save")
......@@ -53,4 +54,4 @@ def test_bird_routes_ipv6(exp_devs: str):
@pytest.mark.parametrize("exp_devs", EXPECTED_DEVICES)
def test_logging(exp_devs: str):
"""Check the log files. There should only DBG, INFO and TRACE messages"""
tk.test_logs(exp_devs, [])
tk.test_logs(exp_devs, LOG_OPT, [])
import pytest
from typing import List
import tests.kernel as tk
import tests.config as cf
......@@ -6,12 +7,10 @@ import tests.config as cf
LIMIT = 60
EXPECTED_DEVICES = ("m1", "m2", "m3", "m4", "m5", "m6", "m7", "m8")
LOG_OPT = ["<WARN> ospf.: Cannot find next hop for LSA"]
LOG_M = [
"<WARN> ospf5: Configured neighbor address .* should be link-local",
"<WARN> ospf5: Configured neighbor address .* should be link-local",
"<WARN> ospf5: Configured neighbor address .* should be link-local",
"<WARN> ospf6: Configured neighbor address .* should be link-local",
"<WARN> ospf6: Configured neighbor address .* should be link-local",
"<WARN> ospf6: Configured neighbor address .* should be link-local"
]
......@@ -73,4 +72,4 @@ def test_bird_routes_ipv6(exp_devs: str):
)
def test_logging(exp_devs: str, exp_messages: List[str]):
"""Check the log files. There should only DBG, INFO and TRACE messages"""
tk.test_logs(exp_devs, exp_messages)
tk.test_logs(exp_devs, LOG_OPT, exp_messages)
......@@ -5,6 +5,7 @@ import tests.config as cf
LIMIT = 60
EXPECTED_DEVICES = ("m1", "m2", "m3", "m4", "m5", "m6", "m7", "m8", "m9", "m10")
LOG_OPT = ["<WARN> ospf.: Cannot find next hop for LSA"]
@pytest.mark.skipif(cf.save == False, reason="mode: save")
......@@ -66,4 +67,4 @@ def test_bird_routes_ipv6_vrfs(tab: str):
@pytest.mark.parametrize("exp_devs", EXPECTED_DEVICES)
def test_logging(exp_devs: str):
"""Check the log files. There should only DBG, INFO and TRACE messages"""
tk.test_logs(exp_devs, [])
tk.test_logs(exp_devs, LOG_OPT, [])
......@@ -84,21 +84,20 @@ def read_file(name: str) -> None:
return txt.read().split("\n")
def test_logs(dev: str, log_messages: List[str],
def test_logs(dev: str, log_optional: List[str], log_mandatory: List[str],
filename: str = "bird.log") -> None:
pattern = "DBG|TRACE|INFO"
logfile = f"{dev}/{filename}"
if not log_messages:
if not os.system(f"egrep -v '{pattern}' {logfile}"):
assert False, "Log file contains incorrect message"
if log_optional:
pattern = f"{pattern}|{'|'.join(log_optional)}"
elif log_messages:
check_expected_logs_timeout(log_messages, logfile)
pattern = f"{pattern}|{'|'.join(log_messages)}"
if log_mandatory:
pattern = f"{pattern}|{'|'.join(log_mandatory)}"
check_expected_logs_timeout(log_mandatory, logfile)
if not os.system(f"egrep -v '{pattern}' {logfile}"):
assert False, "Log file contains incorrect message"
if not os.system(f"egrep -v '{pattern}' {logfile}"):
assert False, "Log file contains incorrect message"
def check_expected_logs_timeout(log_messages: str, logfile: str) -> None:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment