From 9f55cf1838b4be47c303ce3742aacf76136d8d1c Mon Sep 17 00:00:00 2001 From: Jane Fan Date: Tue, 5 Jun 2018 15:28:05 +0000 Subject: [PATCH] Add the vlan_mask fixture --- lab/network/macvlan.py | 8 +++++--- pytest_lab/network.py | 8 +++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lab/network/macvlan.py b/lab/network/macvlan.py index 5d1636b..3ed9a23 100644 --- a/lab/network/macvlan.py +++ b/lab/network/macvlan.py @@ -84,9 +84,11 @@ def addresses(self): if addr.is_link_local: continue elif addr.version == 4: - data.setdefault(socket.AF_INET, []).append(addr) + values = data.setdefault(socket.AF_INET, []) + values.append(addr), values.append(prefix) elif addr.version == 6: - data.setdefault(socket.AF_INET6, []).append(addr) + values = data.setdefault(socket.AF_INET6, []) + values.append(addr), values.append(prefix) return data @@ -98,7 +100,7 @@ def get_address(self, family, timeout=10): # again in a bit addrs = self.addresses.get(family, None) if addrs: - return addrs[0] + return addrs time.sleep(1) family_name = 'ipv4' if family == socket.AF_INET else 'ipv6' diff --git a/pytest_lab/network.py b/pytest_lab/network.py index e2882da..c203434 100644 --- a/pytest_lab/network.py +++ b/pytest_lab/network.py @@ -94,4 +94,10 @@ def inner(count): @pytest.fixture(scope='class') def vlan_addr(vlan, addr_family): '''Return the correct ip address for the macvlan interface''' - return vlan.get_address(addr_family).compressed + return vlan.get_address(addr_family)[0].compressed + + +@pytest.fixture(scope='class') +def vlan_mask(vlan, addr_family): + '''Return the correct network mask for the macvlan interface''' + return vlan.get_address(addr_family)[1]