From d40cac403fd178fc8b1e056b58d1986011f9ae48 Mon Sep 17 00:00:00 2001 From: James Prestwood Date: Thu, 10 Dec 2020 09:45:22 -0800 Subject: [PATCH] auto-t: support IP match with no IP set This allows an interface with no IP set to be checked for by passing None in as the address. This will generate an exception by ioctl which we catch. --- autotests/util/testutil.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/autotests/util/testutil.py b/autotests/util/testutil.py index 94f8ef32..f50223b1 100644 --- a/autotests/util/testutil.py +++ b/autotests/util/testutil.py @@ -146,9 +146,15 @@ def test_iface_operstate(intf=None): sock.close() def test_ip_address_match(intf, ip): - s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - addr = fcntl.ioctl(s.fileno(), SIOCGIFADDR, struct.pack('256s', intf.encode('utf-8'))) - addr = socket.inet_ntoa(addr[20:24]) + try: + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + addr = fcntl.ioctl(s.fileno(), SIOCGIFADDR, struct.pack('256s', intf.encode('utf-8'))) + addr = socket.inet_ntoa(addr[20:24]) + except OSError as e: + if e.errno != 99 or ip != None: + raise Exception('SIOCGIFADDR failed with %d' % e.errno) + + return if ip != addr: raise Exception('IP for %s did not match %s (was %s)' % (intf, ip, addr))