summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Vinciguerra <pvinci@vinciconsulting.com>2019-03-28 09:53:44 -0700
committerNeale Ranns <nranns@cisco.com>2019-03-29 16:02:27 +0000
commit3593a9174a8e9faddb8d4eb451d1b4632c1e0df1 (patch)
tree69e94c2f92662b09cef02a14167d1145a9ed575b
parent60f3e6547aa75a31fad1f78bea11c950cc30d63c (diff)
tests: refactor vpp_object.py
Move __str__ to super for all subclasses of VppObject Implement __repr__ in VppObject Implement __hash__ and __eq__ Change-Id: Ibd4ea37b84b17f499ab86630fb5b9ed9c8b4b1c2 Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
-rw-r--r--test/bfd.py6
-rw-r--r--test/test_abf.py6
-rw-r--r--test/test_gbp.py30
-rw-r--r--test/test_pipe.py3
-rw-r--r--test/vpp_bier.py15
-rw-r--r--test/vpp_gre_interface.py6
-rw-r--r--test/vpp_igmp.py3
-rw-r--r--test/vpp_ip_route.py24
-rw-r--r--test/vpp_ipsec.py12
-rw-r--r--test/vpp_ipsec_tun_interface.py3
-rw-r--r--test/vpp_l2.py15
-rw-r--r--test/vpp_memif.py6
-rw-r--r--test/vpp_mpls_tunnel_interface.py3
-rw-r--r--test/vpp_neighbor.py3
-rw-r--r--test/vpp_object.py25
-rw-r--r--test/vpp_srv6.py9
-rw-r--r--test/vpp_udp_encap.py3
-rw-r--r--test/vpp_vxlan_gbp_tunnel.py3
18 files changed, 22 insertions, 153 deletions
diff --git a/test/bfd.py b/test/bfd.py
index d99bbf6165c..84ef7b0ef4d 100644
--- a/test/bfd.py
+++ b/test/bfd.py
@@ -222,9 +222,6 @@ class VppBFDAuthKey(VppObject):
def object_id(self):
return "bfd-auth-key-%s" % self._conf_key_id
- def __str__(self):
- return self.object_id()
-
class VppBFDUDPSession(VppObject):
""" Represents BFD UDP session in VPP """
@@ -430,9 +427,6 @@ class VppBFDUDPSession(VppObject):
self.peer_addr,
self.af)
- def __str__(self):
- return self.object_id()
-
def admin_up(self):
""" set bfd session admin-up """
is_ipv6 = 1 if AF_INET6 == self._af else 0
diff --git a/test/test_abf.py b/test/test_abf.py
index ecd8c536230..e2f97452642 100644
--- a/test/test_abf.py
+++ b/test/test_abf.py
@@ -88,9 +88,6 @@ class VppAbfPolicy(VppObject):
def query_vpp_config(self):
return find_abf_policy(self._test, self.policy_id)
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return ("abf-policy-%d" % self.policy_id)
@@ -131,9 +128,6 @@ class VppAbfAttach(VppObject):
self.policy_id,
self.sw_if_index)
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return ("abf-attach-%d-%d" % (self.policy_id, self.sw_if_index))
diff --git a/test/test_gbp.py b/test/test_gbp.py
index 74eb424eb4f..c5f5192ea7e 100644
--- a/test/test_gbp.py
+++ b/test/test_gbp.py
@@ -131,9 +131,6 @@ class VppGbpEndpoint(VppObject):
def remove_vpp_config(self):
self._test.vapi.gbp_endpoint_del(self.handle)
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return "gbp-endpoint:[%d==%d:%s:%d]" % (self.handle,
self.itf.sw_if_index,
@@ -172,9 +169,6 @@ class VppGbpRecirc(VppObject):
self.epg.sclass,
self.is_ext)
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return "gbp-recirc:[%d]" % (self.recirc.sw_if_index)
@@ -212,9 +206,6 @@ class VppGbpExtItf(VppObject):
self.bd.bd_id,
self.rd.rd_id)
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return "gbp-ext-itf:[%d]" % (self.itf.sw_if_index)
@@ -256,9 +247,6 @@ class VppGbpSubnet(VppObject):
self.prefix.encode(),
self.type)
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return "gbp-subnet:[%d-%s]" % (self.rd_id, self.prefix)
@@ -314,9 +302,6 @@ class VppGbpEndpointGroup(VppObject):
def remove_vpp_config(self):
self._test.vapi.gbp_endpoint_group_del(self.sclass)
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return "gbp-endpoint-group:[%d]" % (self.vnid)
@@ -359,9 +344,6 @@ class VppGbpBridgeDomain(VppObject):
def remove_vpp_config(self):
self._test.vapi.gbp_bridge_domain_del(self.bd.bd_id)
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return "gbp-bridge-domain:[%d]" % (self.bd.bd_id)
@@ -398,9 +380,6 @@ class VppGbpRouteDomain(VppObject):
def remove_vpp_config(self):
self._test.vapi.gbp_route_domain_del(self.rd_id)
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return "gbp-route-domain:[%d]" % (self.rd_id)
@@ -483,9 +462,6 @@ class VppGbpContract(VppObject):
[],
self.allowed_ethertypes)
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return "gbp-contract:[%d:%s:%d]" % (self.sclass,
self.dclass,
@@ -525,9 +501,6 @@ class VppGbpVxlanTunnel(VppInterface):
def remove_vpp_config(self):
self._test.vapi.gbp_vxlan_tunnel_del(self.vni)
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return "gbp-vxlan:%d" % (self.sw_if_index)
@@ -576,9 +549,6 @@ class VppGbpAcl(VppObject):
def remove_vpp_config(self):
self._test.vapi.acl_del(self.acl_index)
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return "gbp-acl:[%d]" % (self.acl_index)
diff --git a/test/test_pipe.py b/test/test_pipe.py
index d2f21efd4d0..2c23bd04748 100644
--- a/test/test_pipe.py
+++ b/test/test_pipe.py
@@ -38,9 +38,6 @@ class VppPipe(VppInterface):
self._test.vapi.pipe_delete(
self.result.sw_if_index)
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return "pipe-%d" % (self._sw_if_index)
diff --git a/test/vpp_bier.py b/test/vpp_bier.py
index f389ca1b979..8e27f25d10f 100644
--- a/test/vpp_bier.py
+++ b/test/vpp_bier.py
@@ -97,9 +97,6 @@ class VppBierTable(VppObject):
self.mpls_label,
is_add=0)
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return "bier-table;[%d:%d:%d]" % (self.id.set_id,
self.id.sub_domain_id,
@@ -198,9 +195,6 @@ class VppBierRoute(VppObject):
is_replace=1)
self.paths = []
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return "bier-route;[%d:%d:%d:%d]" % (self.tbl_id.set_id,
self.tbl_id.sub_domain_id,
@@ -234,9 +228,6 @@ class VppBierImp(VppObject):
self._test.vapi.bier_imp_del(
self.bi_index)
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return "bier-imp;[%d:%d:%d:%d]" % (self.tbl_id.set_id,
self.tbl_id.sub_domain_id,
@@ -267,9 +258,6 @@ class VppBierDispTable(VppObject):
self.id,
is_add=0)
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return "bier-disp-table;[%d]" % (self.id)
@@ -316,9 +304,6 @@ class VppBierDispEntry(VppObject):
self.rpf_id,
is_add=0)
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return "bier-disp-entry;[%d:%d]" % (self.tbl_id,
self.bp)
diff --git a/test/vpp_gre_interface.py b/test/vpp_gre_interface.py
index d6f4202cf1a..46dce365a38 100644
--- a/test/vpp_gre_interface.py
+++ b/test/vpp_gre_interface.py
@@ -39,9 +39,6 @@ class VppGreInterface(VppInterface):
session_id=self.t_session,
is_add=0)
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return "gre-%d" % self.sw_if_index
@@ -84,8 +81,5 @@ class VppGre6Interface(VppInterface):
is_add=0,
is_ip6=1)
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return "gre-%d" % self._sw_if_index
diff --git a/test/vpp_igmp.py b/test/vpp_igmp.py
index 2403fbfd6ca..8f78a9b909a 100644
--- a/test/vpp_igmp.py
+++ b/test/vpp_igmp.py
@@ -68,9 +68,6 @@ class VppHostState(VppObject):
[],
self.sg.gaddr_p)
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return "%s:%d" % (self.sg, self.sw_if_index)
diff --git a/test/vpp_ip_route.py b/test/vpp_ip_route.py
index b7ceb3474d4..0bd6dd33735 100644
--- a/test/vpp_ip_route.py
+++ b/test/vpp_ip_route.py
@@ -143,9 +143,6 @@ class VppIpTable(VppObject):
self.table_id,
inet=AF_INET6 if self.is_ip6 == 1 else AF_INET)
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return ("table-%s-%d" %
("v6" if self.is_ip6 == 1 else "v4",
@@ -178,9 +175,6 @@ class VppIpInterfaceAddress(VppObject):
self.prefix.length,
self.intf.sw_if_index)
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return "interface-ip-%s-%s" % (self.intf, self.prefix)
@@ -214,9 +208,6 @@ class VppIpInterfaceBind(VppObject):
self.intf.sw_if_index,
self.table.is_ip6).vrf_id == self.table.table_id
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return "interface-bind-%s-%s" % (self.intf, self.table)
@@ -453,9 +444,6 @@ class VppIpRoute(VppObject):
self.table_id,
inet=AF_INET6 if self.is_ip6 == 1 else AF_INET)
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return ("%d:%s/%d"
% (self.table_id,
@@ -579,9 +567,6 @@ class VppIpMRoute(VppObject):
self.table_id,
inet=AF_INET6 if self.is_ip6 == 1 else AF_INET)
- def __str__(self):
- return self.object_id()
-
def object_id(self):
if self.is_ip6:
return ("%d:(%s,%s/%d)"
@@ -667,9 +652,6 @@ class VppMplsIpBind(VppObject):
return True
return False
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return ("%d:%s binds %d:%s/%d"
% (self.table_id,
@@ -705,9 +687,6 @@ class VppMplsTable(VppObject):
return True
return False
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return ("table-mpls-%d" % (self.table_id))
@@ -766,9 +745,6 @@ class VppMplsRoute(VppObject):
return find_mpls_route(self._test, self.table_id,
self.local_label, self.eos_bit)
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return ("%d:%s/%d"
% (self.table_id,
diff --git a/test/vpp_ipsec.py b/test/vpp_ipsec.py
index 5866a0bb72d..278ff36f1e4 100644
--- a/test/vpp_ipsec.py
+++ b/test/vpp_ipsec.py
@@ -24,9 +24,6 @@ class VppIpsecSpd(VppObject):
def remove_vpp_config(self):
self.test.vapi.ipsec_spd_add_del(self.id, is_add=0)
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return "ipsec-spd-%d" % self.id
@@ -59,9 +56,6 @@ class VppIpsecSpdItfBinding(VppObject):
self.itf.sw_if_index,
is_add=0)
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return "bind-%s-to-%s" % (self.spd.id, self.itf)
@@ -149,9 +143,6 @@ class VppIpsecSpdEntry(VppObject):
remote_port_stop=self.remote_port_stop,
is_add=0)
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return "spd-entry-%d-%d-%d-%d-%d-%d" % (self.spd.id,
self.priority,
@@ -241,9 +232,6 @@ class VppIpsecSA(VppObject):
flags=self.flags,
is_add=0)
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return "ipsec-sa-%d" % self.id
diff --git a/test/vpp_ipsec_tun_interface.py b/test/vpp_ipsec_tun_interface.py
index 5c014ea282b..c427936fa08 100644
--- a/test/vpp_ipsec_tun_interface.py
+++ b/test/vpp_ipsec_tun_interface.py
@@ -43,8 +43,5 @@ class VppIpsecTunInterface(VppTunnelInterface):
self.integ_alg, self.local_integ_key, self.remote_integ_key,
is_add=0)
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return "ipsec-tun-if-%d" % self._sw_if_index
diff --git a/test/vpp_l2.py b/test/vpp_l2.py
index dc73e4238f3..b606ff0077a 100644
--- a/test/vpp_l2.py
+++ b/test/vpp_l2.py
@@ -93,9 +93,6 @@ class VppBridgeDomain(VppObject):
def query_vpp_config(self):
return find_bridge_domain(self._test, self.bd_id)
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return "bridge-domain-%d" % (self.bd_id)
@@ -125,9 +122,6 @@ class VppBridgeDomainPort(VppObject):
self.bd.bd_id,
self.itf.sw_if_index)
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return "BD-Port-%s-%s" % (self.bd, self.itf)
@@ -157,9 +151,6 @@ class VppBridgeDomainArpEntry(VppObject):
self.mac.packed,
self.ip.address)
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return "BD-Arp-Entry-%s-%s-%s" % (self.bd, self.mac, self.ip.address)
@@ -203,9 +194,6 @@ class VppL2FibEntry(VppObject):
self.mac.packed,
self.itf.sw_if_index)
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return "L2-Fib-Entry-%s-%s-%s" % (self.bd, self.mac, self.itf)
@@ -232,8 +220,5 @@ class VppL2Vtr(VppObject):
return (d.vtr_op == self.op)
return False
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return "L2-vtr-%s-%d" % (str(self.itf), self.op)
diff --git a/test/vpp_memif.py b/test/vpp_memif.py
index 4ad9ffde4d7..7836dc14a09 100644
--- a/test/vpp_memif.py
+++ b/test/vpp_memif.py
@@ -64,9 +64,6 @@ class VppSocketFilename(VppObject):
def query_vpp_config(self):
return self._test.vapi.memif_socket_filename_dump()
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return "%d" % (self.socket_id)
@@ -135,9 +132,6 @@ class VppMemif(VppObject):
dump = self._test.vapi.memif_dump()
return get_if_dump(dump, self.sw_if_index)
- def __str__(self):
- return self.object_id()
-
def object_id(self):
if self.sw_if_index:
return "%d:%d:%d" % (self.role, self.if_id, self.sw_if_index)
diff --git a/test/vpp_mpls_tunnel_interface.py b/test/vpp_mpls_tunnel_interface.py
index a2ab1bf27cb..12f62fb4b51 100644
--- a/test/vpp_mpls_tunnel_interface.py
+++ b/test/vpp_mpls_tunnel_interface.py
@@ -60,9 +60,6 @@ class VppMPLSTunnelInterface(VppInterface):
return True
return False
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return ("mpls-tunnel%d-%d" % (self.tunnel_index,
self.sw_if_index))
diff --git a/test/vpp_neighbor.py b/test/vpp_neighbor.py
index 95bcc0d6057..eb9635fd603 100644
--- a/test/vpp_neighbor.py
+++ b/test/vpp_neighbor.py
@@ -77,9 +77,6 @@ class VppNeighbor(VppObject):
self.nbr_addr,
self.is_static())
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return ("%d:%s" % (self.sw_if_index, self.nbr_addr))
diff --git a/test/vpp_object.py b/test/vpp_object.py
index a0b9fe3abf2..2c07d472a65 100644
--- a/test/vpp_object.py
+++ b/test/vpp_object.py
@@ -27,10 +27,29 @@ class VppObject(object):
""" Remove the configuration for this object from vpp. """
pass
- @abc.abstractmethod
def object_id(self):
""" Return a unique string representing this object. """
- pass
+ return "Undefined. for <%s %s>" % (self.__class__.__name__, id(self))
+
+ def __str__(self):
+ return self.object_id()
+
+ def __repr__(self):
+ return '<%s>' % self.object_id()
+
+ def __hash__(self):
+ return hash(self.object_id())
+
+ def __eq__(self, other):
+ if not isinstance(other, self.__class__):
+ return NotImplemented
+ if other.object_id() == self.object_id():
+ return True
+ return False
+
+ # This can be removed when python2 support is dropped.
+ def __ne__(self, other):
+ return not self.__eq__(other)
class VppObjectRegistry(object):
@@ -84,6 +103,6 @@ class VppObjectRegistry(object):
if failed:
logger.error("REG: Couldn't remove configuration for object(s):")
for obj in failed:
- logger.error(moves.reprlib.repr(obj))
+ logger.error(repr(obj))
raise Exception("Couldn't remove configuration for object(s): %s" %
(", ".join(str(x) for x in failed)))
diff --git a/test/vpp_srv6.py b/test/vpp_srv6.py
index b84eea37bea..b6dbc014207 100644
--- a/test/vpp_srv6.py
+++ b/test/vpp_srv6.py
@@ -86,9 +86,6 @@ class VppSRv6LocalSID(VppObject):
# use _configured flag for now
return self._configured
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return ("%d;%s,%d"
% (self.fib_table,
@@ -144,9 +141,6 @@ class VppSRv6Policy(VppObject):
# use _configured flag for now
return self._configured
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return ("%d;%s-><%s>;%d"
% (self.sr_type,
@@ -219,9 +213,6 @@ class VppSRv6Steering(VppObject):
# use _configured flag for now
return self._configured
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return ("%d;%d;%s/%d->%s"
% (self.table_id,
diff --git a/test/vpp_udp_encap.py b/test/vpp_udp_encap.py
index 7534912bef9..bdca9a8ca18 100644
--- a/test/vpp_udp_encap.py
+++ b/test/vpp_udp_encap.py
@@ -54,9 +54,6 @@ class VppUdpEncap(VppObject):
def query_vpp_config(self):
return find_udp_encap(self._test, self)
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return ("udp-encap-%d" % self.id)
diff --git a/test/vpp_vxlan_gbp_tunnel.py b/test/vpp_vxlan_gbp_tunnel.py
index efeb4f960db..47817ed168f 100644
--- a/test/vpp_vxlan_gbp_tunnel.py
+++ b/test/vpp_vxlan_gbp_tunnel.py
@@ -68,9 +68,6 @@ class VppVxlanGbpTunnel(VppInterface):
self.dst,
self.vni))
- def __str__(self):
- return self.object_id()
-
def object_id(self):
return "vxlan-gbp-%d-%d-%s-%s" % (self.sw_if_index, self.vni,
self.src, self.dst)