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 ccd6388..69f6fb7 100755 --- a/gui.py +++ b/gui.py @@ -983,11 +983,11 @@ class InstallInterface(InstallInterfaceBase): self.anaconda.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 @@ -999,6 +999,7 @@ class InstallInterface(InstallInterfaceBase): dev_ssids = selectSSIDsDialog(dev_all_ssids) or dev_all_ssids self.anaconda.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 43d2ae4..fcd8f1c 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) @@ -312,9 +313,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): @@ -394,8 +413,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')) @@ -475,6 +498,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(): @@ -482,8 +511,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): @@ -492,8 +519,6 @@ class Network: device.set(('ONBOOT', 'no')) else: device.set(('ONBOOT', 'yes')) - device.writeIfcfgFile() - device.log_file("updateActiveDevices\n") def getOnbootIfaces(self): ifaces = [] @@ -506,8 +531,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()) @@ -650,8 +673,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) -- 1.6.0.6 _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list