VPP-1508: Python3 tests. Explicitly specify string formatting.
[vpp.git] / test / util.py
index a3ec6e3..fc0ebd7 100644 (file)
@@ -1,33 +1,29 @@
 """ test framework utilities """
 
+import abc
 import socket
+from socket import AF_INET6
+import six
 import sys
 import os.path
-from abc import abstractmethod, ABCMeta
-from scapy.utils6 import in6_mactoifaceid
 
 from scapy.layers.l2 import Ether
-from scapy.packet import Raw
 from scapy.layers.inet import IP
 from scapy.layers.inet6 import IPv6, IPv6ExtHdrFragment, IPv6ExtHdrRouting,\
     IPv6ExtHdrHopByHop
+from scapy.packet import Raw
 from scapy.utils import hexdump
-from socket import AF_INET6
+from scapy.utils6 import in6_mactoifaceid
+
 from io import BytesIO
-from vpp_mac import mactobinary
+from vpp_papi import mac_pton
 
 
 def ppp(headline, packet):
     """ Return string containing the output of scapy packet.show() call. """
-    o = BytesIO()
-    old_stdout = sys.stdout
-    sys.stdout = o
-    print(headline)
-    hexdump(packet)
-    print("")
-    packet.show()
-    sys.stdout = old_stdout
-    return o.getvalue()
+    return '%s\n%s\n\n%s\n' % (headline,
+                               hexdump(packet, dump=True),
+                               packet.show(dump=True))
 
 
 def ppc(headline, capture, limit=10):
@@ -59,6 +55,7 @@ def ip4n_range(ip4n, s, e):
             for ip in ip4_range(ip4, s, e))
 
 
+# wrapper around scapy library function.
 def mk_ll_addr(mac):
     euid = in6_mactoifaceid(mac)
     addr = "fe80::" + euid
@@ -99,11 +96,9 @@ def check_core_path(logger, core_path):
 
 
 class NumericConstant(object):
-    __metaclass__ = ABCMeta
 
     desc_dict = {}
 
-    @abstractmethod
     def __init__(self, value):
         self._value = value
 
@@ -130,7 +125,7 @@ class Host(object):
     @property
     def bin_mac(self):
         """ MAC address """
-        return mactobinary(self._mac)
+        return mac_pton(self._mac)
 
     @property
     def ip4(self):