Re: [PATCH 25/25] Use separate method for copying network configuration to system (#520146).

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

 



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

Ack.

On Wed, 5 May 2010, Radek Vykydal wrote:


Better version of the patch adding Network.write() before
Network.copyConfigToSystem() which is needed for cases
when UI is configured/enabled neither in stage2 UI
nor in stage2 kickstart.


[PATCH] Use separate method for copying network configuration to system (#520146).

Former Network.write was used to write config both to anaconda
environment and to installed system. It became quite messy and
unreadable doing both things as writing to installed system was just
copying the file from anaconda root to system root for all files
except ifcfg-DEVICE. Using two separate methods makes clear what
we are doing.

Also there is a question if we need to copy the network config
to system twice as we are doing - first in preinstall step,
and then in writeconfig step. The latter is not necessary I think
and seem to be actually a noop.
---
__init__.py   |    3 +-
network.py | 193 +++++++++++++++++++++++++++++----------------------------
yuminstall.py |    3 +-
3 files changed, 101 insertions(+), 98 deletions(-)

diff --git a/__init__.py b/__init__.py
index b53877c..64c43e6 100644
--- a/__init__.py
+++ b/__init__.py
@@ -300,7 +300,8 @@ class Anaconda(object):
       self.instLanguage.write(self.rootPath)
.
       self.timezone.write(self.rootPath)
-        self.network.write(instPath=self.rootPath, anaconda=self)
+        self.network.write(anaconda=anaconda)
+        self.network.copyConfigToPath(instPath=self.rootPath)
       self.desktop.write(self.rootPath)
       self.users.write(self.rootPath)
       self.security.write(self.rootPath)
diff --git a/network.py b/network.py
index 9e46f00..97eb992 100644
--- a/network.py
+++ b/network.py
@@ -317,12 +317,17 @@ class NetworkDevice(IfcfgFile):
   def writeIfcfgFile(self, dir=None):
       IfcfgFile.write(self, dir)
.
+    @property
+    def keyfilePath(self):
+        return os.path.join(self.dir, "keys-%s" % self.iface)
+
   def writeWepkeyFile(self, dir=None, overwrite=True):
       if not self.wepkey:
           return False
       if not dir:
-            dir = os.path.dirname(self.path)
-        keyfile = os.path.join(dir, "keys-%s" % self.iface)
+            keyfile = self.keyfilePath
+        else:
+            keyfile = os.path.join(dir, os.path.basename(self.keyfilePath))
.
       if not overwrite and os.path.isfile(keyfile):
           return False
@@ -576,29 +581,56 @@ class Network:
.
       return False
.
-    def write(self, instPath='', anaconda=None):
+    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)):
-            # in Network object will not reflect what nm-c-e
- # could have changed (it has wider set of options like wpa, etc...)
-            # and it isn't worth to implement all this possibilities
-            # in Network object to be able to keep it updated.
           if dev.wepkey:
-                dev.writeWepkeyFile(dir=netscripts, overwrite=False)
-
-            # /etc/dhclient-DEVICE.conf
-            dhclientconf = '/etc/dhclient-' + device + '.conf'
-            if os.path.isfile(dhclientconf):
-                destdhclientconf = '%s%s' % (instPath, dhclientconf,)
-                try:
-                    shutil.copy(dhclientconf, destdhclientconf)
-                except:
- log.warning("unable to copy %s to target system" % (dhclientconf,))
+                dev.writeWepkeyFile(dir=netscriptsDir, overwrite=False)
.
.
       # TODORV: note that we use the last dev from the loop above
@@ -653,27 +668,26 @@ class Network:
       # care of this case.
.
       # /etc/sysconfig/network
- if (not instPath) or (not os.path.isfile(destnetwork)) or flags.livecdInstall:
-            newnetwork = "%s.new" % (destnetwork,)
+        newnetwork = "%s.new" % (networkConfFile)
.
-            f = open(newnetwork, "w")
-            f.write("NETWORKING=yes\n")
-            f.write("HOSTNAME=")
+        f = open(newnetwork, "w")
+        f.write("NETWORKING=yes\n")
+        f.write("HOSTNAME=")
.
-            # use instclass hostname if set(kickstart) to override
-            if self.hostname:
-                f.write(self.hostname + "\n")
-            else:
-                f.write("localhost.localdomain\n")
+        # use instclass hostname if set(kickstart) to override
+        if self.hostname:
+            f.write(self.hostname + "\n")
+        else:
+            f.write("localhost.localdomain\n")
.
-            if dev.get('GATEWAY'):
-                f.write("GATEWAY=%s\n" % (dev.get('GATEWAY'),))
+        if dev.get('GATEWAY'):
+            f.write("GATEWAY=%s\n" % (dev.get('GATEWAY'),))
.
-            if dev.get('IPV6_DEFAULTGW'):
- f.write("IPV6_DEFAULTGW=%s\n" % (dev.get('IPV6_DEFAULTGW'),))
+        if dev.get('IPV6_DEFAULTGW'):
+            f.write("IPV6_DEFAULTGW=%s\n" % (dev.get('IPV6_DEFAULTGW'),))
.
-            f.close()
-            shutil.move(newnetwork, destnetwork)
+        f.close()
+        shutil.move(newnetwork, networkConfFile)
.
       # If the hostname was not looked up, but typed in by the user,
       # domain might not be computed, so do it now.
@@ -700,66 +714,53 @@ class Network:
               self.domains = [domainname]
.
       # /etc/resolv.conf
- if (not instPath) or (not os.path.isfile(instPath + '/etc/resolv.conf')) or flags.livecdInstall:
-            if os.path.isfile('/etc/resolv.conf') and instPath != '':
-                destresolv = "%s/etc/resolv.conf" % (instPath,)

-                shutil.copy('/etc/resolv.conf', destresolv)
-            elif (self.domains != ['localdomain'] and self.domains) or \
-                self.hasNameServers(dev.info):
-                resolv = "%s/etc/resolv.conf" % (instPath,)
+        if (self.domains != ['localdomain'] and self.domains) or \
+            self.hasNameServers(dev.info):
+            resolv = "/etc/resolv.conf"
.
-                f = open(resolv, "w")
+            f = open(resolv, "w")
.
-                if self.domains != ['localdomain'] and self.domains:
- f.write("search %s\n" % (string.joinfields(self.domains, ' '),))
+            if self.domains != ['localdomain'] and self.domains:
+ f.write("search %s\n" % (string.joinfields(self.domains, ' '),))
.
-                for key in dev.info.keys():
-                    if key.upper().startswith('DNS'):
-                        f.write("nameserver %s\n" % (dev.get(key),))
+            for key in dev.info.keys():
+                if key.upper().startswith('DNS'):
+                    f.write("nameserver %s\n" % (dev.get(key),))
.
-                f.close()
+            f.close()
.
       # /etc/udev/rules.d/70-persistent-net.rules
       rules = "/etc/udev/rules.d/70-persistent-net.rules"
-        destRules = instPath + rules
-        if (not instPath) or (not os.path.isfile(destRules)) or \
-           flags.livecdInstall:
-            if not os.path.isdir("%s/etc/udev/rules.d" %(instPath,)):
-                iutil.mkdirChain("%s/etc/udev/rules.d" %(instPath,))
-
-            if os.path.isfile(rules) and rules != destRules:
-                shutil.copy(rules, destRules)
-            else:
-                f = open(destRules, "w")
-                f.write("""
+        f = open(rules, "w")
+        f.write("""
# This file was automatically generated by the /lib/udev/write_net_rules
# program run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single line.
.
""")
-                for dev in self.netdevices.values():
-                    addr = dev.get("HWADDR")
-                    if not addr:
-                        continue
-                    devname = dev.get("DEVICE")
-                    basename = devname
-                    while basename != "" and basename[-1] in string.digits:
-                        basename = basename[:-1]
-
-                    # rules are case senstive for address. Lame.
-                    addr = addr.lower()
-
-                    s = ""
-                    if len(dev.description) > 0:
- s = "# %s (rule written by anaconda)\n" % (dev.description,)
-                    else:
-                        s = "# %s (rule written by anaconda)\n" % (devname,)
- s = s + 'SUBSYSTEM==\"net\", ACTION==\"add\", DRIVERS=="?*", ATTR{address}=="%s", ATTR{type}=="1", KERNEL=="%s*", NAME="%s"\n' % (addr, basename, devname,)
-
-                    f.write(s)
-
-                f.close()
+        for dev in self.netdevices.values():
+            addr = dev.get("HWADDR")
+            if not addr:
+                continue
+            devname = dev.get("DEVICE")
+            basename = devname
+            while basename != "" and basename[-1] in string.digits:
+                basename = basename[:-1]
+
+            # rules are case senstive for address. Lame.
+            addr = addr.lower()
+
+            s = ""
+            if len(dev.description) > 0:
+                s = "# %s (rule written by anaconda)\n" % (dev.description,)
+            else:
+                s = "# %s (rule written by anaconda)\n" % (devname,)
+ s = s + 'SUBSYSTEM==\"net\", ACTION==\"add\", DRIVERS=="?*", ATTR{address}=="%s", ATTR{type}=="1", KERNEL=="%s*", NAME="%s"\n' % (addr, basename, devname,)
+
+            f.write(s)
+
+        f.close()
.
   # write out current configuration state and wait for NetworkManager
   # to bring the device up, watch NM state and return to the caller
diff --git a/yuminstall.py b/yuminstall.py
index 604da7b..9ea0ab7 100644
--- a/yuminstall.py
+++ b/yuminstall.py
@@ -1588,7 +1588,8 @@ reposdir=/etc/anaconda.repos.d,/tmp/updates/anaconda.repos.d,/tmp/product/anacon
           if os.access("/etc/modprobe.d/anaconda.conf", os.R_OK):
               shutil.copyfile("/etc/modprobe.d/anaconda.conf",.
anaconda.rootPath + "/etc/modprobe.d/anaconda.conf") - anaconda.network.write(instPath=anaconda.rootPath, anaconda=anaconda)
+            anaconda.network.write(anaconda=anaconda)
+            anaconda.network.copyConfigToPath(instPath=anaconda.rootPath)
           anaconda.storage.write(anaconda.rootPath)
           if not anaconda.isHeadless:
               anaconda.keyboard.write(anaconda.rootPath)
--.
1.6.0.6


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


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

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iEYEARECAAYFAkvi2o8ACgkQ5hsjjIy1VkmBNQCfRbjoLsi/4azjx2YRm7hyx5FY
3ZEAoNZ5eBVNDX9W0XWRKLQGOBBJBd1S
=v4aA
-----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