diff options
author | Paul Vinciguerra <pvinci@vinciconsulting.com> | 2019-11-12 12:11:00 -0500 |
---|---|---|
committer | Ole Trøan <otroan@employees.org> | 2019-11-13 09:43:04 +0000 |
commit | 6af62565e34f90fc0f9811c14753996a2d14ab16 (patch) | |
tree | 2cd872bdf04d953fab89134afcfc7ebc151fe5be | |
parent | 44d06916b9654f393176e9fa85d0442184decbea (diff) |
papi: enhance MACAddress() equality
Allows for comparison without needing str(MACAddress())
Traceback (most recent call last):
File "/vpp/test/test_ip6.py", line 1074, in test_icmpv6_echo
self.assertEqual(ether.dst, self.pg0.remote_mac)
AssertionError: '02:01:00:00:ff:02' != MACAddress(02:01:00:00:ff:02)
Type: feature
Change-Id: Ife1cbfc74d477695d15b33a19da7dd2fa241a348
Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
-rw-r--r-- | src/vpp-api/python/vpp_papi/macaddress.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/vpp-api/python/vpp_papi/macaddress.py b/src/vpp-api/python/vpp_papi/macaddress.py index 02c90dbce06..c3b10a3c11e 100644 --- a/src/vpp-api/python/vpp_papi/macaddress.py +++ b/src/vpp-api/python/vpp_papi/macaddress.py @@ -54,8 +54,14 @@ class MACAddress(): return '%s(%s)' % (self.__class__.__name__, self.mac_string) def __eq__(self, other): + if not isinstance(other, MACAddress): - return NotImplemented + try: + # if it looks like a mac address, we'll take it. + # (allows for equality with scapy hw-addresses) + return self.mac_binary == MACAddress(other).mac_binary + except Exception: + return NotImplemented return self.mac_binary == other.mac_binary def __ne__(self, other): |