testutils: add inspect_packet() and use it when receive_pkt_verify() fails
diff --git a/src/python/oftest/testutils.py b/src/python/oftest/testutils.py
index 76d55f8..8b0b3b6 100644
--- a/src/python/oftest/testutils.py
+++ b/src/python/oftest/testutils.py
@@ -109,9 +109,6 @@
                 scapy.TCP(sport=tcp_sport, dport=tcp_dport)
 
     pkt = pkt/("D" * (pktlen - len(pkt)))
-    
-    #print pkt.show()
-    #print scapy.Ether(str(pkt)).show()
 
     return pkt
 
@@ -374,6 +371,8 @@
                                 + str(exp_pkt).encode('hex'))
             logging.debug("Received len " + str(len(rcv_pkt)) + ": "
                                 + str(rcv_pkt).encode('hex'))
+            logging.debug("Expected packet: " + inspect_packet(scapy.Ether(str(exp_pkt))))
+            logging.debug("Received packet: " + inspect_packet(scapy.Ether(str(rcv_pkt))))
         parent.assertEqual(str(exp_pkt), str(rcv_pkt),
                            "Packet match error on port " + str(check_port))
 
@@ -902,3 +901,20 @@
 def format_packet(pkt):
     return "Packet length %d \n%s" % (len(str(pkt)), 
                                       hex_dump_buffer(str(pkt)))
+
+def inspect_packet(pkt):
+    """
+    Wrapper around scapy's show() method.
+    @returns A string showing the dissected packet.
+    """
+    from cStringIO import StringIO
+    out = None
+    backup = sys.stdout
+    try:
+        sys.stdout = StringIO()
+        pkt.show2()
+        out = sys.stdout.getvalue()
+        sys.stdout.close()
+    finally:
+        sys.stdout = backup
+    return out
diff --git a/tests/pktact.py b/tests/pktact.py
index 97c5113..25ea9cd 100644
--- a/tests/pktact.py
+++ b/tests/pktact.py
@@ -1991,16 +1991,6 @@
         # - VLAN?
         # - action
 
-    def pktToStr(self, pkt):
-        from cStringIO import StringIO
-        backup = sys.stdout
-        sys.stdout = StringIO()
-        pkt.show2()
-        out = sys.stdout.getvalue() 
-        sys.stdout.close() 
-        sys.stdout = backup
-        return out
-
     def createMatch(self, **kwargs):
         match = ofp.ofp_match()
         match.wildcards = ofp.OFPFW_ALL
@@ -2044,7 +2034,7 @@
         logging.info("Ingress %s to egress %s" % 
                        (str(ingress_port), str(egress_port)))
         logging.info("Packet:")
-        logging.info(self.pktToStr(pkt))
+        logging.info(inspect_packet(pkt))
 
         match.in_port = ingress_port
 
@@ -2108,7 +2098,7 @@
             if str_pkt != str_rcv_pkt:
                 logging.error("Response packet does not match send packet")
                 logging.info("Response:")
-                logging.info(self.pktToStr(scapy.Ether(rcv_pkt)))
+                logging.info(inspect_packet(scapy.Ether(rcv_pkt)))
             self.assertEqual(str_pkt, str_rcv_pkt,
                              'Response packet does not match send packet')
         elif expected_result == self.RESULT_NOMATCH: