make test: improve handling of packet captures
[vpp.git] / test / template_bd.py
index 6c6fb3d..d70648b 100644 (file)
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 
-from abc import abstractmethod
+from abc import abstractmethod, ABCMeta
 
 from scapy.layers.l2 import Ether, Raw
 from scapy.layers.inet import IP, UDP
@@ -8,6 +8,7 @@ from scapy.layers.inet import IP, UDP
 
 class BridgeDomain(object):
     """ Bridge domain abstraction """
+    __metaclass__ = ABCMeta
 
     @property
     def frame_pg0_to_pg1(self):
@@ -55,10 +56,7 @@ class BridgeDomain(object):
         self.pg_start()
 
         # Pick first received frame and check if it's the non-encapsulated frame
-        out = self.pg1.get_capture()
-        self.assertEqual(len(out), 1,
-                         'Invalid number of packets on '
-                         'output: {}'.format(len(out)))
+        out = self.pg1.get_capture(1)
         pkt = out[0]
 
         # TODO: add error messages
@@ -82,10 +80,7 @@ class BridgeDomain(object):
         self.pg_start()
 
         # Pick first received frame and check if it's corectly encapsulated.
-        out = self.pg0.get_capture()
-        self.assertEqual(len(out), 1,
-                         'Invalid number of packets on '
-                         'output: {}'.format(len(out)))
+        out = self.pg0.get_capture(1)
         pkt = out[0]
         self.check_encapsulation(pkt)