diff --git a/pyanaconda/modules/network/initialization.py b/pyanaconda/modules/network/initialization.py index 1e3454c352d..5679ad26939 100644 --- a/pyanaconda/modules/network/initialization.py +++ b/pyanaconda/modules/network/initialization.py @@ -240,89 +240,102 @@ def _run(self, nm_client): continue iface = device.get_iface() + if get_config_file_connection_of_device(nm_client, iface): continue - cons = device.get_available_connections() + available_cons = device.get_available_connections() log.debug("%s: %s connections found for device %s", self.name, - [con.get_uuid() for con in cons], iface) - n_cons = len(cons) - con = None + [con.get_uuid() for con in available_cons], iface) + initramfs_cons = [con for con in available_cons + if self._is_initramfs_connection(con, iface)] + log.debug("%s: %s initramfs connections found for device %s", self.name, + [con.get_uuid() for con in initramfs_cons], iface) - device_is_port = any(con.get_setting_connection().get_master() for con in cons) + dumped_con = None + + device_is_port = any(con.get_setting_connection().get_master() + for con in available_cons) if device_is_port: # We have to dump persistent ifcfg files for ports created in initramfs # Filter out potenital connection created for BOOTIF option rhbz#2175664 - port_cons = [c for c in cons if not is_bootif_connection(c)] - if len(port_cons) == 1 and self._is_initramfs_connection(port_cons[0], iface): - log.debug("%s: device %s has an initramfs port connection", - self.name, iface) - con = self._select_persistent_connection_for_device( - device, port_cons, allow_ports=True) + port_cons = [c for c in available_cons if not is_bootif_connection(c)] + if initramfs_cons: + if len(port_cons) == 1: + log.debug("%s: port device %s has an initramfs port connection", + self.name, iface) + dumped_con = self._select_persistent_connection_for_device( + device, port_cons, allow_ports=True) + else: + log.debug("%s: port device %s has an initramfs connection", + self.name, iface) else: - log.debug("%s: creating default connection for port device %s", + log.debug("%s: not creating default connection for port device %s", self.name, iface) + continue + + if not dumped_con: + dumped_con = self._select_persistent_connection_for_device(device, available_cons) + + if not dumped_con and len(initramfs_cons) == 1: + # Try to clone the persistent connection for the device + # from the connection which should be a generic (not bound + # to iface) connection created by NM in initramfs + dumped_con = clone_connection_sync(nm_client, initramfs_cons[0], con_id=iface) - if not con: - con = self._select_persistent_connection_for_device(device, cons) - - has_initramfs_con = any(self._is_initramfs_connection(con, iface) for con in cons) - if has_initramfs_con: - log.debug("%s: device %s has initramfs connection", self.name, iface) - if not con and n_cons == 1: - # Try to clone the persistent connection for the device - # from the connection which should be a generic (not bound - # to iface) connection created by NM in initramfs - con = clone_connection_sync(nm_client, cons[0], con_id=iface) - - if con: - self._update_connection(nm_client, con, iface) - # Update some values of connection generated in initramfs so it - # can be used as persistent configuration. - if has_initramfs_con: - update_connection_values( - con, - [ - # Make sure ONBOOT is yes - (NM.SETTING_CONNECTION_SETTING_NAME, - NM.SETTING_CONNECTION_AUTOCONNECT, - True), - # Update cloned generic connection from initramfs - (NM.SETTING_CONNECTION_SETTING_NAME, - NM.SETTING_CONNECTION_MULTI_CONNECT, - 0), - # Update cloned generic connection from initramfs - (NM.SETTING_CONNECTION_SETTING_NAME, - NM.SETTING_CONNECTION_WAIT_DEVICE_TIMEOUT, - -1) - ] - ) + if dumped_con: log.debug("%s: dumping connection %s to config file for %s", - self.name, con.get_uuid(), iface) - commit_changes_with_autoconnection_blocked(con, nm_client) + self.name, dumped_con.get_uuid(), iface) + self._dump_connection(nm_client, dumped_con, iface, bool(initramfs_cons)) else: log.debug("%s: none of the connections can be dumped as persistent", self.name) - if n_cons > 1 and not device_is_port: + if len(available_cons) > 1 and not device_is_port: log.warning("%s: unexpected number of connections, not dumping any", self.name) continue log.debug("%s: creating default connection for %s", self.name, iface) - network_data = copy.deepcopy(self._default_network_data) - if has_initramfs_con: - network_data.onboot = True - add_connection_from_ksdata( - nm_client, - network_data, - iface, - activate=False, - ifname_option_values=self._ifname_option_values - ) + self._create_default_connection(nm_client, iface, bool(initramfs_cons)) new_configs.append(iface) return new_configs + def _dump_connection(self, nm_client, dumped_con, iface, initramfs_con): + self._update_connection(nm_client, dumped_con, iface) + # Update some values of connection generated in initramfs so it + # can be used as persistent configuration. + if initramfs_con: + update_connection_values( + dumped_con, + [ + # Make sure ONBOOT is yes + (NM.SETTING_CONNECTION_SETTING_NAME, + NM.SETTING_CONNECTION_AUTOCONNECT, + True), + # Update cloned generic connection from initramfs + (NM.SETTING_CONNECTION_SETTING_NAME, + NM.SETTING_CONNECTION_MULTI_CONNECT, + 0), + # Update cloned generic connection from initramfs + (NM.SETTING_CONNECTION_SETTING_NAME, + NM.SETTING_CONNECTION_WAIT_DEVICE_TIMEOUT, + -1) + ] + ) + commit_changes_with_autoconnection_blocked(dumped_con, nm_client) + + def _create_default_connection(self, nm_client, iface, initramfs_con): + network_data = copy.deepcopy(self._default_network_data) + network_data.onboot = initramfs_con + add_connection_from_ksdata( + nm_client, + network_data, + iface, + activate=False, + ifname_option_values=self._ifname_option_values + ) + def _is_initramfs_connection(self, con, iface): con_id = con.get_id() return con_id in ["Wired Connection", iface] \