[PATCH rhel7-branch] network: apply ks configuration to devices activated in initramfs (#1037605)

Radek Vykydal rvykydal at redhat.com
Fri Mar 7 12:05:31 UTC 2014


Resolves: rhbz#1037605
---
 pyanaconda/network.py | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/pyanaconda/network.py b/pyanaconda/network.py
index 1b74fb3..a296536 100644
--- a/pyanaconda/network.py
+++ b/pyanaconda/network.py
@@ -1118,10 +1118,10 @@ def setOnboot(ksdata):
             log.debug("setOnboot: %s" % e)
     return updated_devices
 
-def apply_kickstart_from_pre_section(ksdata):
+def apply_kickstart(ksdata):
     applied_devices = []
 
-    for network_data in ksdata.network.network:
+    for i, network_data in enumerate(ksdata.network.network):
 
         # TODO: wireless not supported yet
         if network_data.essid:
@@ -1129,16 +1129,33 @@ def apply_kickstart_from_pre_section(ksdata):
 
         dev_name = get_device_name(network_data)
         if not dev_name:
-            log.warning("network: pre kickstart: --device %s does not exist" % network_data.device)
+            log.warning("network: apply kickstart: --device %s does not exist" % network_data.device)
             continue
 
         ifcfg_path = find_ifcfg_file_of_device(dev_name)
-        # if the device was already configured in intramfs by kickstart ignore it
         if ifcfg_path:
             with open(ifcfg_path, 'r') as f:
+                # If we have kickstart ifcfg from initramfs
                 if "Generated by parse-kickstart" in f.read():
+                    # and we should activate the device
+                    if i == 0 or network_data.activate:
+                        ifcfg = IfcfgFile(ifcfg_path)
+                        ifcfg.read()
+                        con_uuid = ifcfg.get("UUID")
+                        # and the ifcfg had not been already applied to device by NM
+                        if con_uuid != nm.nm_device_active_con_uuid(dev_name):
+                            # apply it overriding configuration generated by NM
+                            # taking over connection activated in initramfs
+                            log.debug("network: kickstart - reactivating device %s with %s" % (dev_name, con_uuid))
+                            try:
+                                nm.nm_activate_device_connection(dev_name, con_uuid)
+                            except nm.UnknownConnectionError:
+                                log.warning("network: pre kickstart: can't activate connection %s on %s" %
+                                            (con_uuid, dev_name))
                     continue
 
+        # If we don't have kickstart ifcfg from initramfs the command was added
+        # in %pre section after switch root, so apply it now
         applied_devices.append(dev_name)
         if ifcfg_path:
             # if the device was already configured in initramfs update the settings
@@ -1162,7 +1179,7 @@ def networkInitialize(ksdata):
     logIfcfgFiles("network initialization")
 
     if not flags.imageInstall:
-        devnames = apply_kickstart_from_pre_section(ksdata)
+        devnames = apply_kickstart(ksdata)
         if devnames:
             msg = "kickstart pre section applied for devices %s" % devnames
             log.debug("network: %s" % msg)
-- 
1.7.11.7



More information about the anaconda-patches mailing list