Skip to content

Commit 9ad2d77

Browse files
committed
feat: Add custom_allowlist to verify_messages function
Signed-off_by: Kacper Tokarzewski <kacper.tokarzewski@intel.com>
1 parent 571d6fd commit 9ad2d77

3 files changed

Lines changed: 79 additions & 4 deletions

File tree

mfd_dmesg/base.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import datetime
66
import logging
77
import re
8-
from typing import Iterable, Optional, Union, List, Tuple, TYPE_CHECKING
8+
from typing import Iterable, Optional, Union, List, Tuple, TYPE_CHECKING, Any
99

1010
from mfd_common_libs import add_logging_level, log_levels, os_supported
1111
from mfd_connect.exceptions import ConnectionCalledProcessError
@@ -220,9 +220,11 @@ def _check_specific_errors(self, error_msg: str) -> bool:
220220
else:
221221
return True
222222

223-
def verify_messages(self) -> dict:
223+
def verify_messages(self, custom_allowlist: list[str | Any] = DMESG_WHITELIST) -> dict:
224224
"""Verify if there are err level messages in dmesg output.
225225
226+
:param custom_allowlist: list of error messages to ignore in the dmesg output, if any.
227+
By default, it uses DMESG_WHITELIST which contains known benign errors.
226228
:return: dictionary indicating success or failure and the error messages if present.
227229
"""
228230
logger.log(level=log_levels.MODULE_DEBUG, msg="Verify Dmesg Errors.")
@@ -233,7 +235,7 @@ def verify_messages(self) -> dict:
233235
for error in out.splitlines():
234236
is_error = True
235237
if self._check_specific_errors(error):
236-
for benign_message in DMESG_WHITELIST:
238+
for benign_message in custom_allowlist:
237239
if benign_message in error:
238240
is_error = False
239241
logger.log(

mfd_dmesg/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from dataclasses import dataclass
66
from typing import Optional
7-
from .enums import DmesgLevelOptions # noqa: F401
7+
from .enums import DmesgLevelOptions # noqa: F401
88

99

1010
@dataclass

tests/unit/test_mfd_dmesg/test_base.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,50 @@ def test_verify_messages_no_errors(self, dmesg):
386386
)
387387
assert dmesg.verify_messages()["successful"]
388388

389+
def test_verify_messages_with_custom_allowlist(self, dmesg):
390+
output = dedent(
391+
"""
392+
[ 4.660616] Couldn't get size: 0x800000000000000e
393+
[ 4.694322] MODSIGN: Couldn't get UEFI db list
394+
[ 4.728454] Couldn't get size: 0x800000000000000e
395+
[ 33.580364] cdc_ether 1-1.1.2:1.0 enp0s29u1u1u2: CDC: unexpected notification 20!"""
396+
)
397+
custom_allowlist = ["Couldn't get size", "MODSIGN", "unexpected notification"]
398+
dmesg._connection.execute_command.return_value = ConnectionCompletedProcess(
399+
return_code=0, args="command", stdout=output, stderr="stderr"
400+
)
401+
result = dmesg.verify_messages(custom_allowlist=custom_allowlist)
402+
assert result["successful"]
403+
assert result["error"] == ""
404+
405+
def test_verify_messages_with_custom_allowlist_partial_match(self, dmesg):
406+
output = dedent(
407+
"""
408+
[ 4.660616] Couldn't get size: 0x800000000000000e
409+
[ 4.694322] MODSIGN: Couldn't get UEFI db list
410+
[ 33.580364] cdc_ether 1-1.1.2:1.0 enp0s29u1u1u2: CDC: unexpected notification 20!"""
411+
)
412+
custom_allowlist = ["Couldn't get size"]
413+
dmesg._connection.execute_command.return_value = ConnectionCompletedProcess(
414+
return_code=0, args="command", stdout=output, stderr="stderr"
415+
)
416+
result = dmesg.verify_messages(custom_allowlist=custom_allowlist)
417+
assert not result["successful"]
418+
assert "MODSIGN" in result["error"]
419+
assert "unexpected notification" in result["error"]
420+
421+
def test_verify_messages_with_empty_custom_allowlist(self, dmesg):
422+
output = dedent(
423+
"""
424+
[ 4.660616] Couldn't get size: 0x800000000000000e"""
425+
)
426+
dmesg._connection.execute_command.return_value = ConnectionCompletedProcess(
427+
return_code=0, args="command", stdout=output, stderr="stderr"
428+
)
429+
result = dmesg.verify_messages(custom_allowlist=[])
430+
assert not result["successful"]
431+
assert "Couldn't get size" in result["error"]
432+
389433
def test_check_errors(self, dmesg):
390434
output = dedent(
391435
"""
@@ -841,6 +885,35 @@ def test_verify_messages_no_errors(self, dmesg):
841885
)
842886
assert dmesg.verify_messages()["successful"]
843887

888+
def test_verify_messages_with_custom_allowlist(self, dmesg):
889+
output = dedent(
890+
"""
891+
[ 4.660616] Couldn't get size error: 0x800000000000000e
892+
[ 4.694322] MODSIGN ERROR: Couldn't get UEFI db list
893+
[ 4.728454] Couldn't get size ERROR: 0x800000000000000e"""
894+
)
895+
custom_allowlist = ["Couldn't get size", "MODSIGN"]
896+
dmesg._connection.execute_command.return_value = ConnectionCompletedProcess(
897+
return_code=0, args="command", stdout=output, stderr="stderr"
898+
)
899+
result = dmesg.verify_messages(custom_allowlist=custom_allowlist)
900+
assert result["successful"]
901+
assert result["error"] == ""
902+
903+
def test_verify_messages_with_custom_allowlist_partial_match(self, dmesg):
904+
output = dedent(
905+
"""
906+
[ 4.660616] Couldn't get size error: 0x800000000000000e
907+
[ 4.694322] MODSIGN ERROR: Couldn't get UEFI db list"""
908+
)
909+
custom_allowlist = ["Couldn't get size"]
910+
dmesg._connection.execute_command.return_value = ConnectionCompletedProcess(
911+
return_code=0, args="command", stdout=output, stderr="stderr"
912+
)
913+
result = dmesg.verify_messages(custom_allowlist=custom_allowlist)
914+
assert not result["successful"]
915+
assert "MODSIGN ERROR" in result["error"]
916+
844917
def test_check_errors(self, dmesg):
845918
output = dedent(
846919
"""

0 commit comments

Comments
 (0)