Re: [PATCH 28/29] Write out ifcfg files only when necessary (#520146)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ack.

On Wed, 12 May 2010, Radek Vykydal wrote:

Writing the files so often is not necessary, and can cause
timing issues (NM itself updates the files after we write
them out) which can result in duplicated connections nm-c-e
list.  Write the file only if some value in NetworkDevice
object has been actually changed.
---
gui.py     |    7 ++++---
network.py |   48 +++++++++++++++++++++++++++++++++++-------------
2 files changed, 39 insertions(+), 16 deletions(-)

diff --git a/gui.py b/gui.py
index 29d8810..6f0d6f9 100755
--- a/gui.py
+++ b/gui.py
@@ -982,11 +982,11 @@ class InstallInterface(InstallInterfaceBase):
                self.anaconda.id.network.updateActiveDevices([install_device])

            # we might want to do this only once
-            # NOTE: For wireless, we need supplicant to go to ready state,
-            #       that means to get the wireless device managed by NM
-            #       - we do it above in setNMControlledDevices.
            # TODORV: put into Network objects
            if network.hasWirelessDev():
+                # NOTE: For wireless, we need supplicant to go to ready state,
+                #       that means to get the wireless device managed by NM
+                self.anaconda.id.network.writeIfcfgFiles()
                w = self.anaconda.intf.waitWindow(_("Wireless setup"),
                                    _("Scanning access points for wireless devices"))
                # get available wireless APs
@@ -998,6 +998,7 @@ class InstallInterface(InstallInterfaceBase):
                dev_ssids = selectSSIDsDialog(dev_all_ssids) or dev_all_ssids
                self.anaconda.id.network.updateIfcfgsSSID(dev_ssids)

+            self.anaconda.id.network.writeIfcfgFiles()
            network.logIfcfgFiles(header="========== before nm-c-e run\n")
            runNMCE(self.anaconda)
            network.logIfcfgFiles(header="========== after nm-c-e run\n")
diff --git a/network.py b/network.py
index d3686a8..e2308e8 100644
--- a/network.py
+++ b/network.py
@@ -280,6 +280,7 @@ class NetworkDevice(IfcfgFile):
        if iface.startswith('ctc'):
            self.info["TYPE"] = "CTC"
        self.wepkey = ""
+        self._dirty = False

    def clear(self):
        IfcfgFile.clear(self)
@@ -310,9 +311,27 @@ class NetworkDevice(IfcfgFile):
    def loadIfcfgFile(self):
        self.clear()
        IfcfgFile.read(self)
-
-    def writeIfcfgFile(self, dir=None):
-        IfcfgFile.write(self, dir)
+        self.log("NetworkDevice read from %s\n" % self.path)
+        self._dirty = False
+
+    def writeIfcfgFile(self):
+        # Write out the file only if there is a key whose
+        # value has been changed since last load of ifcfg file.
+        if self._dirty:
+            IfcfgFile.write(self)
+            self.log("NetworkDevice written to %s\n" % self.path)
+            self._dirty = False
+
+    def set(self, *args):
+        # If we are changing value of a key set _dirty flag
+        # informing that ifcfg file needs to be synced.
+        for (key, data) in args:
+            if self.get(key) != data:
+                break
+        else:
+            return
+        IfcfgFile.set(self, *args)
+        self._dirty = True

    @property
    def keyfilePath(self):
@@ -392,8 +411,12 @@ class Network:
        devhash = isys.getDeviceProperties(dev=None)
        for iface in devhash.keys():
            device = NetworkDevice(netscriptsDir, iface, logfile=ifcfgLogFile)
-            device.loadIfcfgFile()
-            device.log("===== Network.update\n")
+            if os.access(device.path, os.R_OK):
+                device.loadIfcfgFile()
+            else:
+                log.info("Network.update(): %s file not found" %
+                         device.path)
+                continue

            if device.get('DOMAIN'):
                self.domains.append(device.get('DOMAIN'))
@@ -473,6 +496,12 @@ class Network:

        return ip

+    # Note that the file is written-out only if there is a value
+    # that has changed.
+    def writeIfcfgFiles(self):
+        for device in self.netdevices.values():
+            device.writeIfcfgFile()
+
    # devices == None => set for all
    def setNMControlledDevices(self, devices=None):
        for devname, device in self.netdevices.items():
@@ -480,8 +509,6 @@ class Network:
                device.set(('NM_CONTROLLED', 'no'))
            else:
                device.set(('NM_CONTROLLED', 'yes'))
-            device.writeIfcfgFile()
-            device.log_file("device set to be nm controlled\n")

    # devices == None => set for all
    def updateActiveDevices(self, devices=None):
@@ -490,8 +517,6 @@ class Network:
                device.set(('ONBOOT', 'no'))
            else:
                device.set(('ONBOOT', 'yes'))
-            device.writeIfcfgFile()
-            device.log_file("updateActiveDevices\n")

    def getOnbootIfaces(self):
        ifaces = []
@@ -504,8 +529,6 @@ class Network:
        for devname, device in self.netdevices.items():
            if devname in devssids.keys():
                device.set(('ESSID', devssids[devname][0]))
-                device.writeIfcfgFile()
-                device.log_file("updateIfcfgSSID\n")

    def getSSIDs(self):
        return getSSIDs(self.netdevices.keys())
@@ -648,8 +671,7 @@ class Network:
                        dev.set(('NM_CONTROLLED', 'no'))
                        break

-            dev.writeIfcfgFile(netscriptsDir)
-            dev.log_file("===== write\n")
+            dev.writeIfcfgFile()

            if dev.wepkey:
                dev.writeWepkeyFile(dir=netscriptsDir, overwrite=False)


- -- David Cantrell <dcantrell@xxxxxxxxxx>
Red Hat / Honolulu, HI

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (GNU/Linux)

iEYEARECAAYFAkvqxhQACgkQ5hsjjIy1VklAyQCdHUF26pumsEmxqj57K+9B+AJ8
O+8AoI/tWk8uPsnbfFphNrlyeRCMKaJv
=BHnU
-----END PGP SIGNATURE-----

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux