def test_interface_macaddress(self, ifaddr): ifaddr.side_effect = lambda _: { netifaces.AF_LINK: [{ 'addr': '00:01:02:03:04:05' }] } self.assertEqual(utils.get_interface_macaddress('eth42'), '00:01:02:03:04:05')
def process_link_changes( interfaces, config_manager): # pragma: nocover (covered in autopkgtest) """ Go through the pending changes and pick what needs special handling. Only applies to "down" interfaces which can be safely updated. """ changes = {} phys = dict(config_manager.physical_interfaces) composite_interfaces = [config_manager.bridges, config_manager.bonds] # TODO (cyphermox): factor out some of this matching code (and make it # pretty) in its own module. matches = { 'by-driver': {}, 'by-mac': {}, } for phy, settings in phys.items(): if not settings: continue if phy == 'renderer': continue newname = settings.get('set-name') if not newname: continue match = settings.get('match') if not match: continue driver = match.get('driver') mac = match.get('macaddress') if driver: matches['by-driver'][driver] = newname if mac: matches['by-mac'][mac] = newname # /sys/class/net/ens3/device -> ../../../virtio0 # /sys/class/net/ens3/device/driver -> ../../../../bus/virtio/drivers/virtio_net for interface in interfaces: if interface not in phys: # do not rename virtual devices logging.debug('Skipping non-physical interface: %s', interface) continue if NetplanApply.is_composite_member(composite_interfaces, interface): logging.debug('Skipping composite member %s', interface) # do not rename members of virtual devices. MAC addresses # may be the same for all interface members. continue driver_name = utils.get_interface_driver_name(interface, only_down=True) macaddress = utils.get_interface_macaddress(interface) if driver_name in matches['by-driver']: new_name = matches['by-driver'][driver_name] logging.debug(new_name) logging.debug(interface) if new_name != interface: changes.update({interface: {'name': new_name}}) if macaddress in matches['by-mac']: new_name = matches['by-mac'][macaddress] if new_name != interface: changes.update({interface: {'name': new_name}}) logging.debug(changes) return changes
def test_interface_macaddress_empty(self, ifaddr): ifaddr.side_effect = lambda _: {} self.assertEqual(utils.get_interface_macaddress('eth42'), '')