[PATCH 05/15] remove Network(): copying configuration to target system

Radek Vykydal rvykydal at redhat.com
Thu Jul 19 10:02:38 UTC 2012


---
 pyanaconda/__init__.py                |    2 +-
 pyanaconda/network.py                 |  116 +++++++++++++++++---------------
 pyanaconda/yuminstall.py              |    2 +-
 tests/pyanaconda_test/network_test.py |   18 -----
 4 files changed, 64 insertions(+), 74 deletions(-)

diff --git a/pyanaconda/__init__.py b/pyanaconda/__init__.py
index 4a4be2a..4510a7a 100644
--- a/pyanaconda/__init__.py
+++ b/pyanaconda/__init__.py
@@ -287,7 +287,7 @@ class Anaconda(object):
         if not self.ksdata:
             self.instClass.setNetworkOnbootDefault(self.network)
         self.network.write()
-        self.network.copyConfigToPath()
+        network.copyConfigToPath(ROOT_PATH)
         self.network.disableNMForStorageDevices(self)
         self.network.autostartFCoEDevices(self)
         self.desktop.write()
diff --git a/pyanaconda/network.py b/pyanaconda/network.py
index 59ddcdd..837e437 100644
--- a/pyanaconda/network.py
+++ b/pyanaconda/network.py
@@ -524,60 +524,6 @@ class Network:
             line = "%s" % kickstartNetworkData(dev, self.hostname)
             f.write(line)
 
-    def _copyFileToPath(self, file, instPath='', overwrite=False):
-        if not os.path.isfile(file):
-            return False
-        destfile = os.path.join(instPath, file.lstrip('/'))
-        if (os.path.isfile(destfile) and not overwrite):
-            return False
-        if not os.path.isdir(os.path.dirname(destfile)):
-            iutil.mkdirChain(os.path.dirname(destfile))
-        shutil.copy(file, destfile)
-        return True
-
-    def _copyIfcfgFiles(self):
-        files = os.listdir(netscriptsDir)
-        for cfgFile in files:
-            if cfgFile.startswith(("ifcfg-","keys-")):
-                srcfile = os.path.join(netscriptsDir, cfgFile)
-                self._copyFileToPath(srcfile, ROOT_PATH)
-
-    def copyConfigToPath(self):
-        if flags.imageInstall:
-            # for image installs we only want to write out
-            # /etc/sysconfig/network
-            destfile = os.path.normpath(ROOT_PATH + networkConfFile)
-            if not os.path.isdir(os.path.dirname(destfile)):
-                iutil.mkdirChain(os.path.dirname(destfile))
-            shutil.move("/tmp/sysconfig-network", destfile)
-            return
-
-        # /etc/sysconfig/network-scripts/ifcfg-*
-        # /etc/sysconfig/network-scripts/keys-*
-        # we can copy all of them
-        self._copyIfcfgFiles()
-
-        # /etc/dhcp/dhclient-DEVICE.conf
-        # TODORV: do we really don't want overwrite on live cd?
-        for devName, device in self.netdevices.items():
-            dhclientfile = os.path.join("/etc/dhcp/dhclient-%s.conf" % devName)
-            self._copyFileToPath(dhclientfile, ROOT_PATH)
-
-        # /etc/sysconfig/network
-        self._copyFileToPath(networkConfFile, ROOT_PATH,
-                             overwrite=flags.livecdInstall)
-
-        # /etc/resolv.conf
-        self._copyFileToPath("/etc/resolv.conf", ROOT_PATH,
-                             overwrite=flags.livecdInstall)
-
-        # /etc/udev/rules.d/70-persistent-net.rules
-        self._copyFileToPath("/etc/udev/rules.d/70-persistent-net.rules",
-                             ROOT_PATH, overwrite=flags.livecdInstall)
-
-        self._copyFileToPath(ipv6ConfFile, ROOT_PATH,
-                             overwrite=flags.livecdInstall)
-
     def disableNMForStorageDevices(self, anaconda):
         for devName, device in self.netdevices.items():
             if (device.usedByFCoE(anaconda) or
@@ -607,6 +553,10 @@ class Network:
                     log.warning("autoconnectFCoEDevices: %s file not found" %
                                 device.path)
 
+    # TODO:
+    # - do not write ifcfg files
+    # - separate function for sysconfig/network
+    # - separate fnc for ipv6
     def write(self):
         ifcfglog.debug("Network.write() called")
 
@@ -693,6 +643,10 @@ class Network:
                                    networkStorageDevice.host_address,
                                    self.hostname)
 
+def getDevices():
+    # TODO: filter with existence of ifcfg file?
+    return isys.getDeviceProperties().keys()
+
 def waitForDevicesActivation(devices):
     waited_devs_props = {}
 
@@ -945,3 +899,57 @@ def setHostname(hn):
     log.info("setting installation environment hostname to %s" % hn)
     iutil.execWithRedirect("hostname", ["-v", hn ],
                            stdout="/dev/tty5", stderr="/dev/tty5")
+
+def _copyFileToPath(file, destPath='', overwrite=False):
+    if not os.path.isfile(file):
+        return False
+    destfile = os.path.join(destPath, file.lstrip('/'))
+    if (os.path.isfile(destfile) and not overwrite):
+        return False
+    if not os.path.isdir(os.path.dirname(destfile)):
+        iutil.mkdirChain(os.path.dirname(destfile))
+    shutil.copy(file, destfile)
+    return True
+
+def _copyIfcfgFiles(destPath):
+    files = os.listdir(netscriptsDir)
+    for cfgFile in files:
+        if cfgFile.startswith(("ifcfg-","keys-")):
+            srcfile = os.path.join(netscriptsDir, cfgFile)
+            _copyFileToPath(srcfile, destPath)
+
+def copyConfigToPath(destPath):
+    if flags.imageInstall:
+        # for image installs we only want to write out
+        # /etc/sysconfig/network
+        destfile = os.path.normpath(destPath + networkConfFile)
+        if not os.path.isdir(os.path.dirname(destfile)):
+            iutil.mkdirChain(os.path.dirname(destfile))
+        shutil.move("/tmp/sysconfig-network", destfile)
+        return
+
+    # /etc/sysconfig/network-scripts/ifcfg-*
+    # /etc/sysconfig/network-scripts/keys-*
+    # we can copy all of them
+    _copyIfcfgFiles(destPath)
+
+    # /etc/dhcp/dhclient-DEVICE.conf
+    # TODORV: do we really don't want overwrite on live cd?
+    for devName in getDevices():
+        dhclientfile = os.path.join("/etc/dhcp/dhclient-%s.conf" % devName)
+        _copyFileToPath(dhclientfile, destPath)
+
+    # /etc/sysconfig/network
+    _copyFileToPath(networkConfFile, destPath,
+                         overwrite=flags.livecdInstall)
+
+    # /etc/resolv.conf
+    _copyFileToPath("/etc/resolv.conf", destPath,
+                         overwrite=flags.livecdInstall)
+
+    # /etc/udev/rules.d/70-persistent-net.rules
+    _copyFileToPath("/etc/udev/rules.d/70-persistent-net.rules",
+                         destPath, overwrite=flags.livecdInstall)
+
+    _copyFileToPath(ipv6ConfFile, destPath,
+                         overwrite=flags.livecdInstall)
diff --git a/pyanaconda/yuminstall.py b/pyanaconda/yuminstall.py
index 0a3f292..b47f4de 100644
--- a/pyanaconda/yuminstall.py
+++ b/pyanaconda/yuminstall.py
@@ -1626,7 +1626,7 @@ reposdir=/etc/anaconda.repos.d,/tmp/updates/anaconda.repos.d,/tmp/product/anacon
             if not anaconda.ksdata:
                 anaconda.instClass.setNetworkOnbootDefault(anaconda.network)
             anaconda.network.write()
-            anaconda.network.copyConfigToPath()
+            network.copyConfigToPath(ROOT_PATH)
             anaconda.storage.write()
         else:
             # ensure that /etc/mtab is a symlink to /proc/self/mounts
diff --git a/tests/pyanaconda_test/network_test.py b/tests/pyanaconda_test/network_test.py
index 16ba066..b85bb4f 100644
--- a/tests/pyanaconda_test/network_test.py
+++ b/tests/pyanaconda_test/network_test.py
@@ -349,24 +349,6 @@ class NetworkTest(mock.TestCase):
         self.assertEqual(self.fs[TMPFILE],
             'network --device eth0 --bootproto dhcp --noipv6\n')
 
-    def network_copy_config_to_path_test(self):
-        import pyanaconda.network
-        pyanaconda.network.Network._copyFileToPath = mock.Mock()
-        pyanaconda.network.Network._copyIfcfgFiles = mock.Mock()
-
-
-        nw = pyanaconda.network.Network()
-        nw.netdevices['dev'] = mock.Mock()
-        nw.netdevices['dev'].path = self.DEV_FILE
-        nw.netdevices['dev'].keyfilePath = self.DEV_KEY_FILE
-        ret = nw.copyConfigToPath()
-        self.assertEqual(pyanaconda.network.Network._copyFileToPath.call_args_list,
-            [(('/etc/dhcp/dhclient-dev.conf', '/mnt/sysimage'), {}),
-             (('/tmp/etc/sysconfig/network', '/mnt/sysimage'), {'overwrite': 0}),
-             (('/etc/resolv.conf', '/mnt/sysimage'), {'overwrite': 0}),
-             (('/etc/udev/rules.d/70-persistent-net.rules', '/mnt/sysimage'), {'overwrite': 0})]
-        )
-
     def network_disable_nm_for_storage_devices_test(self):
         import pyanaconda.network
         pyanaconda.network.NetworkDevice = mock.Mock()
-- 
1.7.4



More information about the anaconda-patches mailing list