diff options
author | Paul Vinciguerra <pvinci@vinciconsulting.com> | 2019-12-01 22:24:28 -0500 |
---|---|---|
committer | Dave Wallace <dwallacelf@gmail.com> | 2020-05-05 20:50:10 +0000 |
commit | 9beabd8afd9c9a3f302ebddaae47f7a1275faeca (patch) | |
tree | 51dc0e7982f8c8d4a26eaef0acffc0d0c8f7b5cb /test/util.py | |
parent | 03ec134bc8f7a0180742c768bbd7dd96a81bfdfc (diff) |
tests: clean up logging
Tests currently expect the logger to be poked from run_tests.py.
The tests should run without any magic values. This change sets a default
null logger and removes the hasattr checks for the logger.
For reference, see: https://docs.python-guide.org/writing/logging/
Type: test
Change-Id: I98f953d73d12d00e74b59c94a0fb8c7a625b9c44
Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
Diffstat (limited to 'test/util.py')
-rw-r--r-- | test/util.py | 26 |
1 files changed, 8 insertions, 18 deletions
diff --git a/test/util.py b/test/util.py index c86d602d792..c7e4693e998 100644 --- a/test/util.py +++ b/test/util.py @@ -2,6 +2,7 @@ import abc import ipaddress +import logging import socket from socket import AF_INET6 import six @@ -20,6 +21,10 @@ from scapy.utils6 import in6_mactoifaceid from io import BytesIO from vpp_papi import mac_pton +# Set up an empty logger for the testcase that can be overridden as necessary +null_logger = logging.getLogger('VppTestCase.util') +null_logger.addHandler(logging.NullHandler()) + def ppp(headline, packet): """ Return string containing the output of scapy packet.show() call. """ @@ -272,20 +277,7 @@ class L4_CONN_SIDE: L4_CONN_SIDE_ONE = 1 -class LoggerWrapper(object): - def __init__(self, logger=None): - self._logger = logger - - def debug(self, *args, **kwargs): - if self._logger: - self._logger.debug(*args, **kwargs) - - def error(self, *args, **kwargs): - if self._logger: - self._logger.error(*args, **kwargs) - - -def fragment_rfc791(packet, fragsize, _logger=None): +def fragment_rfc791(packet, fragsize, logger=null_logger): """ Fragment an IPv4 packet per RFC 791 :param packet: packet to fragment @@ -293,7 +285,6 @@ def fragment_rfc791(packet, fragsize, _logger=None): :note: IP options are not supported :returns: list of fragments """ - logger = LoggerWrapper(_logger) logger.debug(ppp("Fragmenting packet:", packet)) packet = packet.__class__(scapy.compat.raw(packet)) # recalc. all values if len(packet[IP].options) > 0: @@ -325,13 +316,13 @@ def fragment_rfc791(packet, fragsize, _logger=None): p[IP].frag = fo + nfb del p[IP].chksum - more_fragments = fragment_rfc791(p, fragsize, _logger) + more_fragments = fragment_rfc791(p, fragsize, logger) pkts.extend(more_fragments) return pkts -def fragment_rfc8200(packet, identification, fragsize, _logger=None): +def fragment_rfc8200(packet, identification, fragsize, logger=null_logger): """ Fragment an IPv6 packet per RFC 8200 :param packet: packet to fragment @@ -339,7 +330,6 @@ def fragment_rfc8200(packet, identification, fragsize, _logger=None): :note: IP options are not supported :returns: list of fragments """ - logger = LoggerWrapper(_logger) packet = packet.__class__(scapy.compat.raw(packet)) # recalc. all values if len(packet) <= fragsize: return [packet] |