def test_detect_connection_based_on_ifcfg_file(self): """ NM may use ifcfg files as its storage format for connections via the ifcfg-rh settings plugin. This is the default option under RHEL/Centos/Fedora. When a connection is defined, it is saved in an ifcfg file, however, the filename is not recorded in NM records. In some scenarios, it is useful look for the ifcfg filename based on a given connection or the other way around, looking for the connection given the filename. """ iface = iface_name() with dummy_devices(1) as nics: with nm_connections(iface, IPV4ADDR, slaves=nics, con_count=3, save=True): device = networkmanager.Device(iface) expected_uuids = { con.connection.uuid for con in device.connections() } actual_uuids = { networkmanager.ifcfg2connection(file)[0] for file in self._ifcfg_files() } self.assertLessEqual(expected_uuids, actual_uuids)
def test_detect_connection_based_on_ifcfg_file(self): """ NM may use ifcfg files as its storage format for connections via the ifcfg-rh settings plugin. This is the default option under RHEL/Centos/Fedora. When a connection is defined, it is saved in an ifcfg file, however, the filename is not recorded in NM records. In some scenarios, it is useful look for the ifcfg filename based on a given connection or the other way around, looking for the connection given the filename. """ iface = iface_name() with nm_connections(iface, IPV4ADDR, con_count=3, save=True): device = networkmanager.Device(iface) expected_uuids = {con.connection.uuid for con in device.connections()} actual_uuids = {networkmanager.ifcfg2connection(file)[0] for file in TestNMIfcfg2Connection._ifcfg_files()} self.assertLessEqual(expected_uuids, actual_uuids)
def _ifcfg_file_lookup(connection_uuid): for ifcfg_file in IfcfgAcquireNMonline._ifcfg_files(): uuid, _ = networkmanager.ifcfg2connection(ifcfg_file) if uuid and uuid == connection_uuid: return ifcfg_file return None