def test_find_matching_iface(self, gim): # we mock-out get_interface_macaddress to return useful values for the test gim.side_effect = lambda x: '00:01:02:03:04:05' if x == 'eth1' else '00:00:00:00:00:00' match = {'name': 'e*', 'macaddress': '00:01:02:03:04:05'} iface = utils.find_matching_iface(DEVICES, match) self.assertEqual(iface, 'eth1')
def test_find_matching_iface_name_and_driver(self, gidn): # we mock-out get_interface_driver_name to return useful values for the test gidn.side_effect = lambda x: 'foo' if x == 'ens4' else 'bar' match = {'name': 'ens?', 'driver': 'f*'} iface = utils.find_matching_iface(DEVICES, match) self.assertEqual(iface, 'ens4')
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 non-critical interfaces which can be safely updated. """ changes = {} phys = dict(config_manager.physical_interfaces) composite_interfaces = [config_manager.bridges, config_manager.bonds] # Find physical interfaces which need a rename # But do not rename virtual interfaces for phy, settings in phys.items(): if not settings or not isinstance(settings, dict): continue # Skip special values, like "renderer: ..." newname = settings.get('set-name') if not newname: continue # Skip if no new name needs to be set match = settings.get('match') if not match: continue # Skip if no match for current name is given if NetplanApply.is_composite_member(composite_interfaces, phy): logging.debug('Skipping composite member {}'.format(phy)) # do not rename members of virtual devices. MAC addresses # may be the same for all interface members. continue # Find current name of the interface, according to match conditions and globs (name, mac, driver) current_iface_name = utils.find_matching_iface(interfaces, match) if not current_iface_name: logging.warning( 'Cannot find unique matching interface for {}: {}'.format( phy, match)) continue if current_iface_name == newname: # Skip interface if it already has the correct name logging.debug( 'Skipping correctly named interface: {}'.format(newname)) continue if settings.get('critical', False): # Skip interfaces defined as critical, as we should not take them down in order to rename logging.warning( 'Cannot rename {} ({} -> {}) at runtime (needs reboot), due to being critical' .format(phy, current_iface_name, newname)) continue # record the interface rename change changes[current_iface_name] = {'name': newname} logging.debug('Link changes: {}'.format(changes)) return changes
def test_find_matching_iface_too_many(self): # too many matches iface = utils.find_matching_iface(DEVICES, {'name': 'e*'}) self.assertEqual(iface, None)