def test_get_interfaces_by_mac_skips_empty_mac(self): """Ignore 00:00:00:00:00:00 addresses from get_interfaces_by_mac.""" empty_mac = '00:00:00:00:00:00' mac = 'aa:bb:cc:aa:bb:cc' write_file(os.path.join(self.sysdir, 'eth1', 'address'), empty_mac) write_file(os.path.join(self.sysdir, 'eth1', 'addr_assign_type'), '0') write_file(os.path.join(self.sysdir, 'eth2', 'addr_assign_type'), '0') write_file(os.path.join(self.sysdir, 'eth2', 'address'), mac) expected = [('eth2', 'aa:bb:cc:aa:bb:cc', None, None)] self.assertEqual(expected, net.get_interfaces())
def test_get_interfaces_by_mac_skips_missing_mac(self): """Ignore interfaces without an address from get_interfaces_by_mac.""" write_file(os.path.join(self.sysdir, 'eth1', 'addr_assign_type'), '0') address_path = os.path.join(self.sysdir, 'eth1', 'address') self.assertFalse(os.path.exists(address_path)) mac = 'aa:bb:cc:aa:bb:cc' write_file(os.path.join(self.sysdir, 'eth2', 'addr_assign_type'), '0') write_file(os.path.join(self.sysdir, 'eth2', 'address'), mac) expected = [('eth2', 'aa:bb:cc:aa:bb:cc', None, None)] self.assertEqual(expected, net.get_interfaces())
def get_interface_list(): ifaces = [] for iface in net.get_interfaces(): # Skip dummy, lo interfaces if "dummy" in iface[0]: continue if "lo" == iface[0]: continue ifaces.append(iface) # Sort alphabetically return sorted(ifaces, key=lambda i: i[0])
def get_metadata(url, timeout, retries, sec_between, agent): # Bring up interface (and try untill one works) exception = RuntimeError("Failed to DHCP") # Seek iface with DHCP for iface in net.get_interfaces(): # Skip dummy, lo interfaces if "dummy" in iface[0]: continue if "lo" == iface[0]: continue try: with EphemeralDHCPv4( iface=iface[0], connectivity_url_data={"url": url} ): # Fetch the metadata v1 = read_metadata(url, timeout, retries, sec_between, agent) return json.loads(v1) except (NoDHCPLeaseError, subp.ProcessExecutionError) as exc: LOG.error("DHCP Exception: %s", exc) exception = exc raise exception
def test_get_interfaces_empty_list_without_sys_net(self): """get_interfaces returns an empty list when missing SYS_CLASS_NET.""" self.m_sys_path.return_value = 'idontexist' self.assertEqual([], net.get_interfaces())
def get_interfaces(self) -> list: return net.get_interfaces()