Skip to content

Commit

Permalink
Skip mac2iface test for esoteric interfaces
Browse files Browse the repository at this point in the history
mac2iface takes a MAC address as argument and returns the corresponding
interface (if any).

The mac2iface tests will however invoke mac2iface with invalid MAC
addresses when esoteric network interfaces are present on the system. As
an example, armhf autopkgtest runners in Ubuntu have gre interfaces
configured. gre interfaces do not store a MAC address in the "address"
field:

 $ ip link add type gre
 $ ip -j addr show dev gre0 | jq '.[]["address"]'
    "0.0.0.0"

We now ensure that the test-suite calls mac2iface with only valid MAC
addresses. We also skip all the 00:00:00:00:00:00 addresses because they
are invalid and can be visible on multiple interfaces (not just the
loopback interface).

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
  • Loading branch information
ogayot committed Dec 5, 2023
1 parent 7eb10fd commit 544b438
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions test/test-iputil.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,32 @@ def test_get_interface(self):
self.assertEqual('', iputil.get_interface(ifaces, ''))
self.assertEqual('', iputil.get_interface(ifaces, None))

@staticmethod
def _is_ok_for_mac2iface(iface) -> bool:
''' mac2iface can only work with interfaces that have a proper MAC
address. One can use this function to filter out other interfaces
configured on the system. '''
if iface['link_type'] != 'ether':
# Some esoteric interface types (e.g., gre) use the address
# field to store something that is not a MAC address. Skip
# them.
return False
if 'address' not in iface:
return False
if iface['address'] == '00:00:00:00:00:00':
# All 0's is an invalid MAC address so do not bother.
# In practice, it often appears as the address of the loopback
# interface but it can also appear for other things like a gretap
# or erspan interface.
return False
return True

def test_mac2iface(self):
for iface in self.ifaces:
address = iface.get('address', None)
if address:
self.assertEqual(iface['ifname'], iputil.mac2iface(address))
# We only test the interfaces that have a MAC address, and a valid one.
candidate_ifaces = [iface for iface in self.ifaces if self._is_ok_for_mac2iface(iface)]

for iface in candidate_ifaces:
self.assertEqual(iface['ifname'], iputil.mac2iface(iface['address']))

def test_remove_invalid_addresses(self):
good_tcp = trid.TID({'transport': 'tcp', 'traddr': '1.1.1.1', 'subsysnqn': '', 'trsvcid': '8009'})
Expand Down

0 comments on commit 544b438

Please sign in to comment.