[PATCH 5/5] changes needed to have per-connection ifcfg files for wifi connections

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

 



---
 pyanaconda/gui.py                     |    4 +-
 pyanaconda/network.py                 |  111 +++++++++++++++++++++++---------
 tests/pyanaconda_test/network_test.py |   29 +--------
 3 files changed, 82 insertions(+), 62 deletions(-)

diff --git a/pyanaconda/gui.py b/pyanaconda/gui.py
index 135bc50..bf2fa52 100755
--- a/pyanaconda/gui.py
+++ b/pyanaconda/gui.py
@@ -933,11 +933,9 @@ class InstallInterface(InstallInterfaceBase):
                 # get available wireless APs
                 dev_all_ssids = self.anaconda.network.getSSIDs()
                 w.pop()
-                # prefer APs we already have set e.g. via kickstart or stage 1
-                self.anaconda.network.selectPreferredSSIDs(dev_all_ssids)
                 # select wireless APs
                 dev_ssids = selectSSIDsDialog(dev_all_ssids) or dev_all_ssids
-                self.anaconda.network.updateIfcfgsSSID(dev_ssids)
+                self.anaconda.network.writeSSIDifcfgs(dev_ssids)
 
             self.anaconda.network.writeIfcfgFiles()
             # Logging can race here with ifcfg-rh updating the file
diff --git a/pyanaconda/network.py b/pyanaconda/network.py
index ccfd527..b25ba23 100644
--- a/pyanaconda/network.py
+++ b/pyanaconda/network.py
@@ -34,6 +34,7 @@ import os
 import time
 import dbus
 import tempfile
+import simpleconfig
 from flags import flags
 from simpleconfig import IfcfgFile
 import urlgrabber.grabber
@@ -341,6 +342,51 @@ class NetworkDevice(IfcfgFile):
                     return True
         return False
 
+class WirelessNetworkDevice(NetworkDevice):
+
+    """
+    This class overwrites NetworkDevice's, IfcfgFile's and SimpleConfigFile's
+    methods to prevent working with per-device ifcfgfiles (which doesn't make
+    sense with wifi devices)
+    """
+
+    def __init__(self, iface):
+        self.info = dict()
+        self.iface = iface
+        self.dir = ""
+        self.description = ""
+
+    def clear(self):
+        self.info = dict()
+
+    #method __str__ can be left untouched
+
+    def loadIfcfgFile(self):
+        pass
+
+    def writeIfcfgFile(self):
+        pass
+
+    def set(self, *args):
+        msg = "".join(["%s=%s" % (key, val) for (key, val) in args])
+        for (key, val) in args:
+            self.info[simpleconfig.uppercase_ASCII_string(key)] = val
+
+    #not used, remove?
+    def fileContent(self):
+        return ""
+
+    #@property path can be left untouched (code using it skips nonexisting
+    #ifcfg files
+
+    def read(self):
+        #same return value as IfcfgFile.read()
+        return len(self.info)
+
+    def write(self):
+        pass
+
+
 class Network:
 
     def __init__(self):
@@ -348,8 +394,6 @@ class Network:
         self.hostname = socket.gethostname()
 
         self.update()
-        # We want wireless devices to be nm controlled by default
-        self.controlWireless()
 
         # Set all devices to be controlled by NM by default.
         # We can filter out storage devices only after
@@ -369,13 +413,16 @@ class Network:
         # populate self.netdevices
         devhash = isys.getDeviceProperties(dev=None)
         for iface in devhash.keys():
-            device = NetworkDevice(netscriptsDir, iface)
-            if os.access(device.path, os.R_OK):
-                device.loadIfcfgFile()
+            if isys.isWirelessDevice(iface):
+                device = WirelessNetworkDevice(iface)
             else:
-                log.info("Network.update(): %s file not found" %
-                         device.path)
-                continue
+                device = NetworkDevice(netscriptsDir, iface)
+                if os.access(device.path, os.R_OK):
+                    device.loadIfcfgFile()
+                else:
+                    log.info("Network.update(): %s file not found" %
+                             device.path)
+                    continue
 
             # TODORV - the last iface in loop wins, might be ok,
             #          not worthy of special juggling
@@ -531,26 +578,23 @@ class Network:
                 ifaces.append(iface)
         return ifaces
 
-    def updateIfcfgsSSID(self, devssids):
-        for devname, device in self.netdevices.items():
-            if devname in devssids.keys() and devssids[devname]:
-                device.set(('ESSID', devssids[devname][0]))
-                device.writeIfcfgFile()
+    def writeSSIDifcfgs(self, devssids):
+        ssids = []
+        for ssidlist in devssids.values():
+            ssids.extend(ssidlist)
+        for ssid in ssids:
+            path = "{0}/ifcfg-{1}".format(netscriptsDir, ssid)
+            ifcfgfile = open(path, "w")
+            ifcfgfile.write("NAME={0}\n".format(ssid)+
+                            "TYPE=Wireless\n"+
+                            "ESSID={0}\n".format(ssid)+
+                            "NM_CONTROLLED=yes\n")
+            ifcfgfile.close()
+
 
     def getSSIDs(self):
         return getSSIDs()
 
-    def selectPreferredSSIDs(self, dev_ssids):
-        for iface, device in self.netdevices.items():
-            preferred = device.get('ESSID')
-            if preferred and preferred in dev_ssids[iface]:
-                dev_ssids[iface] = [preferred]
-
-    def controlWireless(self):
-        for devname, device in self.netdevices.items():
-            if isys.isWirelessDevice(devname):
-                device.set(('NM_CONTROLLED', 'yes'))
-
     def writeKS(self, f):
         devNames = self.netdevices.keys()
         devNames.sort()
@@ -660,6 +704,13 @@ class Network:
         shutil.copy(file, destfile)
         return True
 
+    def _copyIfcfgFiles(self, instPath=''):
+        files = os.listdir(netscriptsDir)
+        for cfgFile in files:
+            if cfgFile.startswith(("ifcfg-","keys-")):
+                srcfile = os.path.join(netscriptsDir, cfgFile)
+                self._copyFileToPath(srcfile, instPath)
+
     def copyConfigToPath(self, instPath=''):
         if flags.imageInstall and instPath:
             # for image installs we only want to write out
@@ -670,13 +721,14 @@ class Network:
             shutil.move("/tmp/sysconfig-network", destfile)
             return
 
-        # /etc/sysconfig/network-scripts/ifcfg-DEVICE
-        # /etc/sysconfig/network-scripts/keys-DEVICE
+        # /etc/sysconfig/network-scripts/ifcfg-*
+        # /etc/sysconfig/network-scripts/keys-*
+        # we can copy all of them
+        self._copyIfcfgFiles(instPath)
+
         # /etc/dhcp/dhclient-DEVICE.conf
         # TODORV: do we really don't want overwrite on live cd?
         for devName, device in self.netdevices.items():
-            self._copyFileToPath(device.path, instPath)
-            self._copyFileToPath(device.keyfilePath, instPath)
             dhclientfile = os.path.join("/etc/dhcp/dhclient-%s.conf" % devName)
             self._copyFileToPath(dhclientfile, instPath)
 
@@ -750,9 +802,6 @@ class Network:
 
             dev.writeIfcfgFile()
 
-            if dev.wepkey:
-                dev.writeWepkeyFile(dir=netscriptsDir, overwrite=False)
-
         # /etc/resolv.conf is managed by NM
 
     def waitForDevicesActivation(self, devices):
diff --git a/tests/pyanaconda_test/network_test.py b/tests/pyanaconda_test/network_test.py
index 96717cd..6a0b324 100644
--- a/tests/pyanaconda_test/network_test.py
+++ b/tests/pyanaconda_test/network_test.py
@@ -443,34 +443,7 @@ class NetworkTest(mock.TestCase):
             ('set', (('ESSID', 'net_essid'),), {}))
         self.assertEqual(nw.netdevices['dev'].method_calls[1],
             ('writeIfcfgFile', (), {}))
-
-    def network_select_preferred_ssids_1_test(self):
-        import pyanaconda.network
-        nw = pyanaconda.network.Network()
-        nw.netdevices['dev'] = mock.Mock()
-        nw.netdevices['dev'].get.return_value = 'some_essid'
-        dev_ssid = {'dev': ['some_essid']}
-        nw.selectPreferredSSIDs(dev_ssid)
-        self.assertEqual(dev_ssid, {'dev': ['some_essid']})
-
-    def network_select_preferred_ssids_2_test(self):
-        import pyanaconda.network
-        nw = pyanaconda.network.Network()
-        nw.netdevices['dev'] = mock.Mock()
-        nw.netdevices['dev'].get.return_value = 'some_essid'
-        dev_ssid = {'dev': ['some_essid', 'other']}
-        nw.selectPreferredSSIDs(dev_ssid)
-        self.assertEqual(dev_ssid, {'dev': ['some_essid']})
-
-    def network_select_preferred_ssids_3_test(self):
-        import pyanaconda.network
-        nw = pyanaconda.network.Network()
-        nw.netdevices['dev'] = mock.Mock()
-        nw.netdevices['dev'].get.return_value = 'some_essid'
-        dev_ssid = {'dev': ['other', 'foo']}
-        nw.selectPreferredSSIDs(dev_ssid)
-        self.assertEqual(dev_ssid, {'dev': ['other', 'foo']})
-
+            
     def network_control_wireless_test(self):
         import pyanaconda.network
         pyanaconda.network.isys = mock.Mock()
-- 
1.7.4.4

_______________________________________________
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