tests: cli wrapper should return string 53/22753/3
authorOle Troan <ot@cisco.com>
Tue, 15 Oct 2019 17:31:55 +0000 (19:31 +0200)
committerNeale Ranns <nranns@cisco.com>
Wed, 16 Oct 2019 15:00:45 +0000 (15:00 +0000)
Python3 fixes.

Type: fix
Signed-off-by: Ole Troan <ot@cisco.com>
Change-Id: I648b2142d45dfab9146a02eeb1b12de11103ff9f
Signed-off-by: Ole Troan <ot@cisco.com>
test/framework.py
test/test_ip4.py
test/util.py
test/vpp_interface.py
test/vpp_papi_provider.py

index fb14465..c1bfaa7 100644 (file)
@@ -175,14 +175,16 @@ def pump_output(testclass):
         if testclass.vpp.stderr.fileno() in readable:
             read = os.read(testclass.vpp.stderr.fileno(), 102400)
             if len(read) > 0:
-                split = read.splitlines(True)
+                split = read.decode('ascii',
+                                    errors='backslashreplace').splitlines(True)
                 if len(stderr_fragment) > 0:
                     split[0] = "%s%s" % (stderr_fragment, split[0])
-                if len(split) > 0 and split[-1].endswith(b"\n"):
+                if len(split) > 0 and split[-1].endswith("\n"):
                     limit = None
                 else:
                     limit = -1
                     stderr_fragment = split[-1]
+
                 testclass.vpp_stderr_deque.extend(split[:limit])
                 if not testclass.cache_vpp_output:
                     for line in split[:limit]:
index 60bc023..af0c319 100644 (file)
@@ -100,7 +100,7 @@ class TestIPv4(VppTestCase):
         :param int packet_size: Required packet size.
         :param Scapy pkt: Packet to be modified.
         """
-        dst_if_idx = packet_size / 10 % 2
+        dst_if_idx = int(packet_size / 10 % 2)
         dst_if = self.flows[src_if][dst_if_idx]
         info = self.create_packet_info(src_if, dst_if)
         payload = self.info_to_payload(info)
@@ -377,7 +377,7 @@ class TestICMPEcho(VppTestCase):
 
         icmp_id = 0xb
         icmp_seq = 5
-        icmp_load = '\x0a' * 18
+        icmp_load = b'\x0a' * 18
         p_echo_request = (Ether(src=self.pg0.remote_mac,
                                 dst=self.pg0.local_mac) /
                           IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) /
@@ -1938,7 +1938,7 @@ class TestIPv4Frag(VppTestCase):
         packets = self.dst_if.get_capture(3)
 
         # Assume VPP sends the fragments in order
-        payload = ''
+        payload = b''
         for p in packets:
             payload_offset = p.frag * 8
             if payload_offset > 0:
index 96d3c60..ed6c409 100644 (file)
@@ -58,7 +58,7 @@ def ip4n_range(ip4n, s, e):
 
 # wrapper around scapy library function.
 def mk_ll_addr(mac):
-    euid = in6_mactoifaceid(mac)
+    euid = in6_mactoifaceid(str(mac))
     addr = "fe80::" + euid
     return addr
 
index 1e047f5..431a03a 100644 (file)
@@ -33,7 +33,7 @@ class VppInterface(object):
     @property
     def local_mac(self):
         """MAC-address of the VPP interface."""
-        return self._local_mac
+        return str(self._local_mac)
 
     @property
     def local_addr(self):
@@ -260,9 +260,8 @@ class VppInterface(object):
         r = self.test.vapi.sw_interface_dump(sw_if_index=self.sw_if_index)
         for intf in r:
             if intf.sw_if_index == self.sw_if_index:
-                self._name = intf.interface_name.split(b'\0',
-                                                       1)[0].decode('utf8')
-                self._local_mac = bytes(intf.l2_address)
+                self._name = intf.interface_name
+                self._local_mac = intf.l2_address
                 self._dump = intf
                 break
         else:
index d80f2ed..297c159 100644 (file)
@@ -369,8 +369,7 @@ class VppPapiProvider(object):
         :param cli: CLI to execute
         :returns: CLI output
         """
-        return cli + "\n" + self.cli(cli).encode('ascii',
-                                                 errors='backslashreplace')
+        return cli + "\n" + self.cli(cli)
 
     def want_ip4_arp_events(self, enable_disable=1, ip="0.0.0.0"):
         return self.api(self.papi.want_ip4_arp_events,