VPP-1508 Python3 abstract classes 60/16160/10
authorPaul Vinciguerra <pvinci@vinciconsulting.com>
Sun, 25 Nov 2018 05:46:05 +0000 (21:46 -0800)
committerDamjan Marion <dmarion@me.com>
Tue, 26 Feb 2019 11:31:42 +0000 (11:31 +0000)
Update the syntax to support abstract classes in python 2 and python 3.

Depends on: new style classes -- https://gerrit.fd.io/r/16166

Change-Id: Iad2c1240149f38b3faca1b37ab95d3d210e1daee
Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
test/template_bd.py
test/test_lisp.py
test/util.py
test/vpp_interface.py
test/vpp_object.py
test/vpp_sub_interface.py
test/vpp_tunnel_interface.py

index 291f468..b0d508f 100644 (file)
@@ -1,6 +1,7 @@
 #!/usr/bin/env python
 
-from abc import abstractmethod, ABCMeta
+import abc
+import six
 
 from scapy.layers.l2 import Ether, Raw
 from scapy.layers.inet import IP, UDP
@@ -8,9 +9,9 @@ from scapy.layers.inet import IP, UDP
 from util import ip4_range
 
 
+@six.add_metaclass(abc.ABCMeta)
 class BridgeDomain(object):
     """ Bridge domain abstraction """
-    __metaclass__ = ABCMeta
 
     @property
     def frame_request(self):
@@ -28,27 +29,27 @@ class BridgeDomain(object):
                 UDP(sport=20000, dport=10000) /
                 Raw('\xa5' * 100))
 
-    @abstractmethod
+    @abc.abstractmethod
     def ip_range(self, start, end):
         """ range of remote ip's """
         pass
 
-    @abstractmethod
+    @abc.abstractmethod
     def encap_mcast(self, pkt, src_ip, src_mac, vni):
         """ Encapsulate mcast packet """
         pass
 
-    @abstractmethod
+    @abc.abstractmethod
     def encapsulate(self, pkt, vni):
         """ Encapsulate packet """
         pass
 
-    @abstractmethod
+    @abc.abstractmethod
     def decapsulate(self, pkt):
         """ Decapsulate packet """
         pass
 
-    @abstractmethod
+    @abc.abstractmethod
     def check_encapsulation(self, pkt, vni, local_only=False):
         """ Verify the encapsulation """
         pass
index b6272dc..f66fcf7 100644 (file)
@@ -1,4 +1,7 @@
 #!/usr/bin/env python
+
+import abc
+import six
 import unittest
 
 from scapy.fields import BitField, ByteField, FlagsField, IntField
@@ -28,6 +31,7 @@ bind_layers(LISP_GPE_Header, IPv6, next_proto=2)
 bind_layers(LISP_GPE_Header, Ether, next_proto=3)
 
 
+@six.add_metaclass(abc.ABCMeta)
 class Driver(object):
 
     config_order = ['locator-sets',
@@ -61,7 +65,7 @@ class Driver(object):
                   Raw(payload))
         return packet
 
-    @abstractmethod
+    @abc.abstractmethod
     def run(self):
         """ testing procedure """
         pass
index cf45c85..5ce8407 100644 (file)
@@ -1,9 +1,10 @@
 """ test framework utilities """
 
+import abc
 import socket
+import six
 import sys
 import os.path
-from abc import abstractmethod, ABCMeta
 from scapy.utils6 import in6_mactoifaceid
 
 from scapy.layers.l2 import Ether
@@ -93,11 +94,9 @@ def check_core_path(logger, core_path):
 
 
 class NumericConstant(object):
-    __metaclass__ = ABCMeta
 
     desc_dict = {}
 
-    @abstractmethod
     def __init__(self, value):
         self._value = value
 
index 58384d2..2dcf149 100644 (file)
@@ -1,16 +1,17 @@
 import binascii
 import socket
-from abc import abstractmethod, ABCMeta
+import abc
 
+import six
 from six import moves
 
 from util import Host, mk_ll_addr
 from vpp_papi import mac_ntop
 
 
+@six.add_metaclass(abc.ABCMeta)
 class VppInterface(object):
     """Generic VPP interface."""
-    __metaclass__ = ABCMeta
 
     @property
     def sw_if_index(self):
@@ -181,7 +182,7 @@ class VppInterface(object):
             self._hosts_by_ip4[ip4] = host
             self._hosts_by_ip6[ip6] = host
 
-    @abstractmethod
+    @abc.abstractmethod
     def __init__(self, test):
         self._test = test
 
index 1b0fada..a0b9fe3 100644 (file)
@@ -1,32 +1,33 @@
 """ abstract vpp object and object registry """
 
-from abc import ABCMeta, abstractmethod
+import abc
+import six
 
 from six import moves
 
 
+@six.add_metaclass(abc.ABCMeta)
 class VppObject(object):
     """ Abstract vpp object """
-    __metaclass__ = ABCMeta
 
-    @abstractmethod
+    @abc.abstractmethod
     def add_vpp_config(self):
         """ Add the configuration for this object to vpp. """
         pass
 
-    @abstractmethod
+    @abc.abstractmethod
     def query_vpp_config(self):
         """Query the vpp configuration.
 
         :return: True if the object is configured"""
         pass
 
-    @abstractmethod
+    @abc.abstractmethod
     def remove_vpp_config(self):
         """ Remove the configuration for this object from vpp. """
         pass
 
-    @abstractmethod
+    @abc.abstractmethod
     def object_id(self):
         """ Return a unique string representing this object. """
         pass
index 255cfff..63a0f54 100644 (file)
@@ -1,12 +1,13 @@
 from scapy.layers.l2 import Dot1Q
-from abc import abstractmethod, ABCMeta
+import abc
+import six
 from vpp_pg_interface import VppPGInterface
 from vpp_papi_provider import L2_VTR_OP
 from vpp_interface import VppInterface
 
 
+@six.add_metaclass(abc.ABCMeta)
 class VppSubInterface(VppPGInterface):
-    __metaclass__ = ABCMeta
 
     @property
     def parent(self):
@@ -42,11 +43,11 @@ class VppSubInterface(VppPGInterface):
         super(VppSubInterface, self).set_sw_if_index(sw_if_index)
         self.set_vtr(L2_VTR_OP.L2_DISABLED)
 
-    @abstractmethod
+    @abc.abstractmethod
     def create_arp_req(self):
         pass
 
-    @abstractmethod
+    @abc.abstractmethod
     def create_ndp_req(self):
         pass
 
@@ -56,7 +57,7 @@ class VppSubInterface(VppPGInterface):
     def resolve_ndp(self):
         super(VppSubInterface, self).resolve_ndp(self.parent)
 
-    @abstractmethod
+    @abc.abstractmethod
     def add_dot1_layer(self, pkt):
         pass
 
index c74f585..e55486e 100644 (file)
@@ -1,13 +1,13 @@
-from abc import abstractmethod, ABCMeta
+import abc
+import six
 from vpp_pg_interface import is_ipv6_misc
 from vpp_interface import VppInterface
 
 
+@six.add_metaclass(abc.ABCMeta)
 class VppTunnelInterface(VppInterface):
-    """ VPP tunnel interface abstration """
-    __metaclass__ = ABCMeta
+    """ VPP tunnel interface abstraction """
 
-    @abstractmethod
     def __init__(self, test, parent_if):
         super(VppTunnelInterface, self).__init__(test)
         self.parent_if = parent_if