VPP-1508 Python3 abstract classes
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>
diff --git a/test/template_bd.py b/test/template_bd.py
index 291f468..b0d508f 100644
--- a/test/template_bd.py
+++ b/test/template_bd.py
@@ -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 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 @@
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
diff --git a/test/test_lisp.py b/test/test_lisp.py
index b6272dc..f66fcf7 100644
--- a/test/test_lisp.py
+++ b/test/test_lisp.py
@@ -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, Ether, next_proto=3)
+@six.add_metaclass(abc.ABCMeta)
class Driver(object):
config_order = ['locator-sets',
@@ -61,7 +65,7 @@
Raw(payload))
return packet
- @abstractmethod
+ @abc.abstractmethod
def run(self):
""" testing procedure """
pass
diff --git a/test/util.py b/test/util.py
index cf45c85..5ce8407 100644
--- a/test/util.py
+++ b/test/util.py
@@ -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 @@
class NumericConstant(object):
- __metaclass__ = ABCMeta
desc_dict = {}
- @abstractmethod
def __init__(self, value):
self._value = value
diff --git a/test/vpp_interface.py b/test/vpp_interface.py
index 58384d2..2dcf149 100644
--- a/test/vpp_interface.py
+++ b/test/vpp_interface.py
@@ -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 @@
self._hosts_by_ip4[ip4] = host
self._hosts_by_ip6[ip6] = host
- @abstractmethod
+ @abc.abstractmethod
def __init__(self, test):
self._test = test
diff --git a/test/vpp_object.py b/test/vpp_object.py
index 1b0fada..a0b9fe3 100644
--- a/test/vpp_object.py
+++ b/test/vpp_object.py
@@ -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
diff --git a/test/vpp_sub_interface.py b/test/vpp_sub_interface.py
index 255cfff..63a0f54 100644
--- a/test/vpp_sub_interface.py
+++ b/test/vpp_sub_interface.py
@@ -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 @@
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 @@
def resolve_ndp(self):
super(VppSubInterface, self).resolve_ndp(self.parent)
- @abstractmethod
+ @abc.abstractmethod
def add_dot1_layer(self, pkt):
pass
diff --git a/test/vpp_tunnel_interface.py b/test/vpp_tunnel_interface.py
index c74f585..e55486e 100644
--- a/test/vpp_tunnel_interface.py
+++ b/test/vpp_tunnel_interface.py
@@ -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