[patch 18/20] Handle some yum errors better
by Mark McLoughlin
- Raise a sane exception if a specified package or group can't
be found
- Ditto if we fail to build the transaction
- Better handle failure in selectPackage() etc. by closing the
rpmdb so the unmount succeeds
Signed-off-by: Mark McLoughlin <markmc(a)redhat.com>
Index: livecd/creator/livecd-creator
===================================================================
--- livecd.orig/creator/livecd-creator
+++ livecd/creator/livecd-creator
@@ -193,11 +193,9 @@ class LiveCDYum(yum.YumBase):
def selectPackage(self, pkg):
"""Select a given package. Can be specified with name.arch or name*"""
try:
- mbrs = self.install(pattern = pkg)
- return len(mbrs)
- except yum.Errors.InstallError:
- print >> sys.stderr, "No package matching %s" %(pkg,)
- return 0
+ self.install(pattern = pkg)
+ except yum.Errors.InstallError, e:
+ raise InstallationError("Failed to find package '%s' : %s" % (pkg, e))
def deselectPackage(self, pkg):
"""Deselect package. Can be specified as name.arch or name*"""
@@ -217,7 +215,10 @@ class LiveCDYum(yum.YumBase):
print >> sys.stderr, "No such package %s to remove" %(pkg,)
def selectGroup(self, grp, include = pykickstart.parser.GROUP_DEFAULT):
- yum.YumBase.selectGroup(self, grp)
+ try:
+ yum.YumBase.selectGroup(self, grp)
+ except (yum.Errors.InstallError, yum.Errors.GroupsError), e:
+ raise InstallationError("Failed to find group '%s' : %s" % (grp, e))
if include == pykickstart.parser.GROUP_REQUIRED:
map(lambda p: self.deselectPackage(p), grp.default_packages.keys())
elif include == pykickstart.parser.GROUP_ALL:
@@ -244,10 +245,7 @@ class LiveCDYum(yum.YumBase):
def runInstall(self):
(res, resmsg) = self.buildTransaction()
if res != 2:
- print "Unable to build transaction"
- for m in resmsg:
- print m
- sys.exit(1)
+ raise InstallationError("Failed to build transaction : %s" % str.join("\n", resmsg))
dlpkgs = map(lambda x: x.po, filter(lambda txmbr: txmbr.ts_state in ("i", "u"), self.tsInfo.getMembers()))
self.downloadPkgs(dlpkgs)
@@ -439,11 +437,11 @@ class InstallationTarget:
def installPackages(self, packageList, excludePackageList, groupList = []):
"""install packages into target file system"""
- map(lambda pkg: self.ayum.selectPackage(pkg), packageList)
- map(lambda grp: self.ayum.selectGroup(grp[0], grp[1]), groupList)
- map(lambda pkg: self.ayum.deselectPackage(pkg), excludePackageList)
-
try:
+ map(lambda pkg: self.ayum.selectPackage(pkg), packageList)
+ map(lambda grp: self.ayum.selectGroup(grp[0], grp[1]), groupList)
+ map(lambda pkg: self.ayum.deselectPackage(pkg), excludePackageList)
+
self.ayum.runInstall()
finally:
self.ayum.closeRpmDB()
--
17 years
[patch 17/20] Raise an exception if no kernel or syslinux installed
by Mark McLoughlin
If we don't find any kernel, or if syslinux/mayflower isn't
installed, raise a sane exception
Signed-off-by: Mark McLoughlin <markmc(a)redhat.com>
Index: livecd/creator/livecd-creator
===================================================================
--- livecd.orig/creator/livecd-creator
+++ livecd/creator/livecd-creator
@@ -265,12 +265,6 @@ class LiveCDYum(yum.YumBase):
cb.filelog = False
return self.runTransaction(cb)
-def get_kernel_version(root):
- # FIXME: this doesn't handle multiple kernels being installed
- kdir = os.listdir("%s/install_root/lib/modules" %(root,))
- kver = os.path.basename(kdir[0])
- return kver
-
class InstallationTarget:
def __init__(self, repos, packages, epackages, groups, fs_label, skip_compression):
self.ayum = LiveCDYum()
@@ -556,8 +550,27 @@ class InstallationTarget:
os.unlink(path)
+ def get_kernel_version(self):
+ #
+ # FIXME: this doesn't handle multiple kernels - we should list
+ # them all in the isolinux menu
+ #
+ kernels = []
+ modules_dir = "%s/install_root/lib/modules" % self.build_dir
+
+ if os.path.isdir(modules_dir):
+ kernels = os.listdir(modules_dir)
+
+ if not kernels:
+ raise InstallationError("No kernels installed: /lib/modules is empty")
+
+ return kernels[0]
+
def createInitramfs(self):
# Create initramfs
+ if not os.path.isfile("/usr/lib/livecd-creator/mayflower"):
+ raise InstallationError("livecd-creator not correctly installed : "+
+ "/usr/lib/livecd-creator/mayflower not found")
shutil.copy("/usr/lib/livecd-creator/mayflower",
"%s/install_root/sbin/mayflower" %(self.build_dir,))
# modules needed for booting (this is butt ugly and we need to retrieve this from elsewhere, e.g. the kernel)
@@ -570,7 +583,7 @@ class InstallationTarget:
mayflowerconf.close()
subprocess.call(["/sbin/mayflower", "-f", "/boot/livecd-initramfs.img",
- get_kernel_version(self.build_dir)],
+ self.get_kernel_version()],
preexec_fn=self.run_in_root)
for f in ("/sbin/mayflower", "/etc/mayflower.conf"):
os.unlink("%s/install_root/%s" %(self.build_dir, f))
@@ -597,7 +610,7 @@ class InstallationTarget:
# - error handling
#
shutil.copyfile("%s/install_root/boot/vmlinuz-%s"
- %(self.build_dir, get_kernel_version(self.build_dir,)),
+ %(self.build_dir, self.get_kernel_version()),
"%s/out/isolinux/vmlinuz" %(self.build_dir,))
shutil.copyfile("%s/install_root/boot/livecd-initramfs.img"
@@ -606,10 +619,13 @@ class InstallationTarget:
os.unlink("%s/install_root/boot/livecd-initramfs.img"
%(self.build_dir,))
- shutil.copy("%s/install_root/usr/lib/syslinux/isolinux.bin" %(self.build_dir,),
- "%s/out/isolinux/isolinux.bin" %(self.build_dir,))
- shutil.copy("%s/install_root/usr/lib/syslinux/vesamenu.c32" %(self.build_dir,),
- "%s/out/isolinux/vesamenu.c32" %(self.build_dir,))
+ for p in ["isolinux.bin", "vesamenu.c32"]:
+ path = "%s/install_root/usr/lib/syslinux/%s" % (self.build_dir, p)
+
+ if not os.path.isfile(path):
+ raise InstallationError("syslinux not installed : %s not found" % path)
+
+ shutil.copy(path, "%s/out/isolinux/%s" % (self.build_dir, p))
if os.path.exists("%s/install_root/usr/lib/anaconda-runtime/syslinux-vesa-splash.jpg" %(self.build_dir,)):
shutil.copy("%s/install_root/usr/lib/anaconda-runtime/syslinux-vesa-splash.jpg" %(self.build_dir,),
--
17 years
[patch 16/20] Raise an exception if no packages/repos supplied
by Mark McLoughlin
Once we've parsed the kickstart file, raise an exception if
we still haven't been given any packages, groups or repos
Signed-off-by: Mark McLoughlin <markmc(a)redhat.com>
Index: livecd/creator/livecd-creator
===================================================================
--- livecd.orig/creator/livecd-creator
+++ livecd/creator/livecd-creator
@@ -312,6 +312,12 @@ class InstallationTarget:
self.ksparser.handler.packages.groupList))
self.epackages.extend(self.ksparser.handler.packages.excludedList)
+ if not self.packages and not self.groups:
+ raise InstallationError("No packages or groups specified")
+
+ if not self.repos:
+ raise InstallationError("No repositories specified")
+
def base_on_iso(self, base_on):
"""helper function to extract ext3 file system from a live CD ISO"""
--
17 years
[patch 15/20] Print an error if not run as root
by Mark McLoughlin
In main() check that the user is running us as root
Signed-off-by: Mark McLoughlin <markmc(a)redhat.com>
Index: livecd/creator/livecd-creator
===================================================================
--- livecd.orig/creator/livecd-creator 2007-03-27 15:01:14.000000000 +0100
+++ livecd.orig/creator/livecd-creator 2007-03-27 15:01:14.000000000 +0100
@@ -810,6 +810,10 @@ def main():
usage(out)
return ret
+ if os.geteuid () != 0:
+ print >> sys.stderr, "You must run livecd-creator as root"
+ return 1
+
target = InstallationTarget(options.repos,
options.packages,
options.epackages,
--
17 years
[patch 14/20] Handle kickstart parsing errors
by Mark McLoughlin
Raise an InstallationError if we fail to parse the kickstart
file
Signed-off-by: Mark McLoughlin <markmc(a)redhat.com>
Index: livecd/creator/livecd-creator
===================================================================
--- livecd.orig/creator/livecd-creator
+++ livecd/creator/livecd-creator
@@ -290,7 +290,12 @@ class InstallationTarget:
ksversion = pykickstart.version.makeVersion()
self.ksparser = pykickstart.parser.KickstartParser(ksversion)
if kscfg:
- self.ksparser.readKickstart(kscfg)
+ try:
+ self.ksparser.readKickstart(kscfg)
+ except IOError, (err, msg):
+ raise InstallationError("Failed to read kickstart file '%s' : %s" % (kscfg, msg))
+ except pykickstart.errors.KickstartError, e:
+ raise InstallationError("Failed to parse kickstart file '%s' : %s" % (kscfg, e))
for repo in self.ksparser.handler.repo.repoList:
already_given = False
--
17 years
[patch 13/20] Cleanup error handling in main()
by Mark McLoughlin
- Split the command line parsing out into a separate function
which raises an exception if there's a problem
- Check for existance of files supplied with --conf and --base-on
when parsing the command line
- Return the exit code from main() and have the caller pass it to
sys.exit()
- Print usage to stdout if we're run with --help
Signed-off-by: Mark McLoughlin <markmc(a)redhat.com>
Index: livecd/creator/livecd-creator
===================================================================
--- livecd.orig/creator/livecd-creator 2007-03-27 14:59:32.000000000 +0100
+++ livecd.orig/creator/livecd-creator 2007-03-27 14:59:32.000000000 +0100
@@ -673,8 +673,8 @@ label runfromram
self.createSquashFS()
self.createIso()
-def usage():
- print """
+def usage(out):
+ print >> out, """
usage: livecd-creator [--help]
[--config=<path-to-kickstart-file> | --repo=<name>,<url> --package=<p>]
[--repo=<name1>,<url1>] [--repo=<name2>,<url2> ...]
@@ -708,97 +708,118 @@ usage: livecd-creator [--help]
--repo=a-extras-dev,file:///home/user/extras/RPMS
"""
-def main():
-
- repos = []
- packages = []
- groups = []
- epackages = []
- fs_label = "livecd-" + time.strftime("%Y%m%d-%H%M")
- base_on = None
- kscfg = None
- skip_compression = False
- uncompressed_size = 3072
- give_shell = False
+class Usage(Exception):
+ def __init__(self, msg = None, no_error = False):
+ Exception.__init__(self, msg, no_error)
+
+class Options:
+ def __init__(self):
+ self.repos = []
+ self.packages = []
+ self.groups = []
+ self.epackages = []
+ self.fs_label = "livecd-" + time.strftime("%Y%m%d-%H%M")
+ self.base_on = None
+ self.kscfg = None
+ self.skip_compression = False
+ self.uncompressed_size = 3072
+ self.give_shell = False
+def parse_options(args):
try:
- opts, args = getopt.getopt(sys.argv[1:], "hr:b:p:e:f:c:su:l",
+ opts, args = getopt.getopt(args, "hr:b:p:e:f:c:su:l",
["help", "repo=", "base-on=", "package=",
"exclude-package=", "fslabel=", "config=",
"skip-compression", "uncompressed-size=",
"shell"])
- except getopt.GetoptError:
- usage()
- sys.exit(2)
- output = None
- verbose = False
+ except getopt.GetoptError, msg:
+ raise Usage(msg)
+
+ options = Options()
+
for o, a in opts:
if o in ("-h", "--help"):
- usage()
- sys.exit(0)
+ raise Usage(no_error = True)
if o in ("-l", "--shell"):
- give_shell = True
+ options.give_shell = True
continue
if o in ("-s", "--skip-compression"):
- skip_compression = True
+ options.skip_compression = True
continue
if o in ("-u", "--uncompressed-size"):
- uncompressed_size = int(a)
+ options.uncompressed_size = int(a)
continue
if o in ("-c", "--config"):
- kscfg = a
+ options.kscfg = a
+ if not os.path.isfile(options.kscfg):
+ raise Usage("Kickstart config '%s' does not exist" % options.kscfg)
continue
if o in ("-r", "--repo"):
(name, url) = a.split(",")
- for (n, u) in repos:
+ for (n, u) in options.repos:
if n == name:
- print "Repo name '%s' is already in use"%n
- sys.exit(2)
- repos.append((name, url))
+ raise Usage("Repo name '%s' is already in use" % n)
+ options.repos.append((name, url))
continue
if o in ("-p", "--package"):
if a.startswith("@"):
- groups.append((a[1:], pykickstart.parser.GROUP_DEFAULT))
+ options.groups.append((a[1:], pykickstart.parser.GROUP_DEFAULT))
else:
- packages.append(a)
+ options.packages.append(a)
continue
if o in ("-e", "--exclude-package"):
- epackages.append(a)
+ options.epackages.append(a)
continue
if o in ("-f", "--fslabel"):
- fs_label = a
- if len(fs_label) > 32:
- print "CD labels are limited to 32 characters"
- sys.exit(2)
+ options.fs_label = a
+ if len(options.fs_label) > 32:
+ raise Usage("CD labels are limited to 32 characters")
continue
if o in ("-b", "--base-on"):
- base_on = a
+ options.base_on = a
+ if not os.path.isfile(options.base_on):
+ raise Usage("Live CD ISO '%s' does not exist" % options.base_on)
continue
- print "Unknown option %s"%o
- sys.exit(2)
+ raise Usage("Unknown option %s" % o)
+
+ if not options.kscfg and not (options.packages or options.groups):
+ raise Usage("No packages or groups specified")
- if not kscfg and not (packages or groups):
- print "No packages or groups specified."
- print ""
- usage()
- sys.exit(1)
-
- if not kscfg and not repos:
- print "No repositories specified."
- print ""
- usage()
- sys.exit(1)
+ if not options.kscfg and not options.repos:
+ raise Usage("No repositories specified")
- target = InstallationTarget(repos, packages, epackages, groups, fs_label, skip_compression)
+ return options
+
+def main():
+ try:
+ options = parse_options(sys.argv[1:])
+ except Usage, (msg, no_error):
+ if no_error:
+ out = sys.stdout
+ ret = 0
+ else:
+ out = sys.stderr
+ ret = 2
+ if msg:
+ print >> out, msg
+ usage(out)
+ return ret
+
+ target = InstallationTarget(options.repos,
+ options.packages,
+ options.epackages,
+ options.groups,
+ options.fs_label,
+ options.skip_compression)
try:
- target.parse(kscfg)
+ target.parse(options.kscfg)
- target.setup(uncompressed_size, base_on)
+ target.setup(options.uncompressed_size, options.base_on)
target.install()
- if give_shell:
+ if options.give_shell:
print "Launching shell. Exit to continue."
print "----------------------------------"
target.launchShell()
@@ -808,9 +829,11 @@ def main():
target.package()
except InstallationError, e:
print >> sys.stderr, "Error creating Live CD : %s" % e
- sys.exit(1)
+ return 1
finally:
target.teardown()
+ return 0
+
if __name__ == "__main__":
- main()
+ sys.exit(main())
--
17 years
[patch 12/20] Add InstallationError exception and cleanup error handling
by Mark McLoughlin
Start cleaning up error handling by:
- Adding an InstallationError exception which can be raised
by InstallationTarget for user errors or expected system
errors
- Make sure we cleanup properly by wrapping all the installation
code in main in a try/finally
- Don't use sys.exit(1) as a way of raising an exception
- Remove boolean returns from various methods where we just
raise an exception if something goes wrong
- Don't randomly handle exceptions that would only happen
as a result of fairly pathological system failure (e.g.
failure to create /etc in the just created build dir)
- Avoid printing anything from InstallationTarget() - e.g.
imagine the class being used from a UI
Signed-off-by: Mark McLoughlin <markmc(a)redhat.com>
Index: livecd/creator/livecd-creator
===================================================================
--- livecd.orig/creator/livecd-creator
+++ livecd/creator/livecd-creator
@@ -28,6 +28,10 @@ import yum
import pykickstart.parser
import pykickstart.version
+class InstallationError(Exception):
+ def __init__(self, msg):
+ Exception.__init__(self, msg)
+
class BindChrootMount:
"""Represents a bind mount of a directory into a chroot."""
def __init__(self, src, chroot, dest = None):
@@ -312,25 +316,27 @@ class InstallationTarget:
"%s/base_on_squashfs" %(self.build_dir,),
"squashfs")
- success = False
try:
- if isoloop.setup() and squashloop.setup():
- # copy the ext3 fs out
- try:
- shutil.copyfile("%s/base_on_squashfs/os.img" %(self.build_dir,),
- "%s/data/os.img" %(self.build_dir,))
- success = True
- except Exception, e:
- print "Cannot copy os.img from squashfs from ISO to base on"
- traceback.print_exc(file=sys.stderr)
+ if not isoloop.setup():
+ raise InstallationError("Failed to loopback mount '%s'" % base_on)
+
+ if not os.path.exists(squashloop.lofile):
+ raise InstallationError("'%s' is not a valid live CD ISO : squashfs.img doesn't exist" % base_on)
+
+ if not squashloop.setup():
+ raise InstallationError("Failed to loopback mount squashfs.img from '%s'" % base_on)
+
+ os_image = self.build_dir + "/base_on_squashfs/os.img"
+
+ if not os.path.exists(os_image):
+ raise InstallationError("'%s' is not a valid live CD ISO : os.img doesn't exist" % base_on)
+
+ shutil.copyfile(os_image, self.build_dir + "/data/os.img")
finally:
# unmount and tear down the mount points and loop devices used
squashloop.cleanup()
isoloop.cleanup()
- return success
-
-
def write_fstab(self):
fstab = open(self.build_dir + "/install_root/etc/fstab", "w")
fstab.write("/dev/mapper/livecd-rw / ext3 defaults,noatime 0 0\n")
@@ -346,28 +352,19 @@ class InstallationTarget:
# setup temporary build dirs
try:
self.build_dir = tempfile.mkdtemp(dir="/var/tmp", prefix="livecd-creator-")
- except OSError, e:
- print "Cannot create build directory in /var/tmp: %s" % e
- return False
+ except OSError, (err, msg):
+ raise InstallationError("Failed create build directory in /var/tmp: %s" % msg)
- try:
- os.mkdir(self.build_dir + "/out")
- os.mkdir(self.build_dir + "/out/isolinux")
- os.mkdir(self.build_dir + "/out/sysroot")
- os.mkdir(self.build_dir + "/data")
- os.mkdir(self.build_dir + "/data/sysroot")
- os.mkdir(self.build_dir + "/install_root")
- os.mkdir(self.build_dir + "/yum-cache")
- except OSError:
- print "Cannot create directory"
- self.teardown()
- return False
+ os.makedirs(self.build_dir + "/out/isolinux")
+ os.makedirs(self.build_dir + "/out/sysroot")
+ os.makedirs(self.build_dir + "/data/sysroot")
+ os.makedirs(self.build_dir + "/install_root")
+ os.makedirs(self.build_dir + "/yum-cache")
if base_on:
# get backing ext3 image if we're based this build on an existing live CD ISO
- if not self.base_on_iso(base_on):
- self.teardown()
- return False
+ self.base_on_iso(base_on)
+
self.instloop = LoopbackMount("%s/data/os.img" %(self.build_dir,),
"%s/install_root" %(self.build_dir,))
else:
@@ -379,48 +376,32 @@ class InstallationTarget:
if not self.instloop.setup():
- self.teardown()
- return False
+ raise InstallationError("Failed to loopback mount '%s'" % self.instloop.lofile)
if not base_on:
# create a few directories needed if it's a new image
- try:
- os.mkdir(self.build_dir + "/install_root/etc")
- os.mkdir(self.build_dir + "/install_root/boot")
- os.mkdir(self.build_dir + "/install_root/var")
- os.mkdir(self.build_dir + "/install_root/var/log")
- os.mkdir(self.build_dir + "/install_root/var/cache")
- os.mkdir(self.build_dir + "/install_root/var/cache/yum")
- except OSError:
- print "Cannot create directory"
- self.teardown()
- return False
+ os.makedirs(self.build_dir + "/install_root/etc")
+ os.makedirs(self.build_dir + "/install_root/boot")
+ os.makedirs(self.build_dir + "/install_root/var/log")
+ os.makedirs(self.build_dir + "/install_root/var/cache/yum")
# bind mount system directories into install_root/
for (f, dest) in [("/sys", None), ("/proc", None), ("/dev", None),
("/dev/pts", None), ("/selinux", None),
(self.build_dir + "/yum-cache", "/var/cache/yum")]:
b = BindChrootMount(f, self.build_dir + "/install_root", dest)
- if b.mount():
- self.bindmounts.append(b)
- else:
- print "Cannot mount special file system %s"%f
- self.teardown()
- return False
+
+ if not b.mount():
+ raise InstallationError("Cannot mount special file system '%s'" % f)
+
+ self.bindmounts.append(b)
# make sure /etc/mtab is current inside install_root
- try:
- os.symlink("../proc/mounts", self.build_dir + "/install_root/etc/mtab")
- except OSError:
- print "Cannot create symlink %s/etc/mtab -> ../proc/mounts"%(self.build_dir)
- self.teardown()
- return False
+ os.symlink("../proc/mounts", self.build_dir + "/install_root/etc/mtab")
self.write_fstab()
self.ayum.setup("%s/install_root" %(self.build_dir,))
- return True
-
def unmount(self):
"""detaches system bind mounts and install_root for the file system and tears down loop devices used"""
@@ -459,13 +440,8 @@ class InstallationTarget:
try:
self.ayum.runInstall()
- except Exception, e:
- print "Error installing packages"
- traceback.print_exc(file=sys.stderr)
- self.ayum.closeRpmDB()
- return False
- self.ayum.closeRpmDB()
- return True
+ finally:
+ self.ayum.closeRpmDB()
def configureSystem(self):
instroot = "%s/install_root" %(self.build_dir,)
@@ -597,10 +573,7 @@ class InstallationTarget:
preexec_fn=self.run_in_root)
def launchShell(self):
- print "Launching shell. Exit to continue."
- print "----------------------------------"
subprocess.call(["/bin/bash"], preexec_fn=self.run_in_root)
- return True
def configureBootloader(self):
"""configure the boot loader"""
@@ -669,10 +642,7 @@ label runfromram
for (name, url) in self.repos:
self.ayum.addRepository(name, url)
- if not self.installPackages(self.packages, self.epackages, self.groups):
- self.teardown()
- sys.exit(1)
-
+ self.installPackages(self.packages, self.epackages, self.groups)
self.configureSystem()
self.relabelSystem()
self.createInitramfs()
@@ -821,29 +791,26 @@ def main():
target = InstallationTarget(repos, packages, epackages, groups, fs_label, skip_compression)
- target.parse(kscfg)
+ try:
+ target.parse(kscfg)
- if not target.setup(uncompressed_size, base_on):
- print "Cannot setup installation target. Aborting."
- sys.exit(1)
+ target.setup(uncompressed_size, base_on)
- try:
target.install()
- except SystemExit:
+
+ if give_shell:
+ print "Launching shell. Exit to continue."
+ print "----------------------------------"
+ target.launchShell()
+
+ target.unmount()
+
+ target.package()
+ except InstallationError, e:
+ print >> sys.stderr, "Error creating Live CD : %s" % e
sys.exit(1)
- except:
- print "\n\nERROR during installation..."
- traceback.print_exc(file=sys.stderr)
+ finally:
target.teardown()
- sys.exit(1)
-
-
- if give_shell:
- target.launchShell()
-
- target.unmount()
- target.package()
- target.teardown()
if __name__ == "__main__":
main()
--
17 years
[patch 11/20] No params to configureSystem()
by Mark McLoughlin
Just use self.ksparser in configureSystem() rather than passing
it as a param
Signed-off-by: Mark McLoughlin <markmc(a)redhat.com>
Index: livecd/creator/livecd-creator
===================================================================
--- livecd.orig/creator/livecd-creator
+++ livecd/creator/livecd-creator
@@ -467,7 +467,7 @@ class InstallationTarget:
self.ayum.closeRpmDB()
return True
- def configureSystem(self, ksparser):
+ def configureSystem(self):
instroot = "%s/install_root" %(self.build_dir,)
# FIXME: this is a bit ugly, but with the current pykickstart
@@ -475,7 +475,7 @@ class InstallationTarget:
# be able to do something different, but so it goes
# set up the language
- lang = ksparser.handler.lang.lang or "en_US.UTF-8"
+ lang = self.ksparser.handler.lang.lang or "en_US.UTF-8"
f = open("%s/etc/sysconfig/i18n" %(instroot,), "w+")
f.write("LANG=\"%s\"\n" %(lang,))
f.close()
@@ -485,13 +485,13 @@ class InstallationTarget:
# or do we want to make X be able to do this mapping
import rhpl.keyboard
k = rhpl.keyboard.Keyboard()
- if ksparser.handler.keyboard.keyboard:
- k.set(ksparser.handler.keyboard.keyboard)
+ if self.ksparser.handler.keyboard.keyboard:
+ k.set(self.ksparser.handler.keyboard.keyboard)
k.write(instroot)
# next up is timezone
- tz = ksparser.handler.timezone.timezone or "America/New_York"
- utc = ksparser.handler.timezone.isUtc
+ tz = self.ksparser.handler.timezone.timezone or "America/New_York"
+ utc = self.ksparser.handler.timezone.isUtc
f = open("%s/etc/sysconfig/clock" %(instroot,), "w+")
f.write("ZONE=\"%s\"\n" %(tz,))
f.write("UTC=%s\n" %(utc,))
@@ -508,14 +508,14 @@ class InstallationTarget:
f.close()
# do any authconfig bits
- auth = ksparser.handler.authconfig.authconfig or "--useshadow --enablemd5"
+ auth = self.ksparser.handler.authconfig.authconfig or "--useshadow --enablemd5"
if os.path.exists("%s/usr/sbin/authconfig" %(instroot,)):
args = ["/usr/sbin/authconfig", "--update", "--nostart"]
args.extend(auth.split())
subprocess.call(args, preexec_fn=self.run_in_root)
# firewall. FIXME: should handle the rest of the options
- if ksparser.handler.firewall.enabled and os.path.exists("%s/usr/sbin/lokkit" %(instroot,)):
+ if self.ksparser.handler.firewall.enabled and os.path.exists("%s/usr/sbin/lokkit" %(instroot,)):
subprocess.call(["/usr/sbin/lokkit", "-f", "--quiet",
"--nostart", "--enabled"],
preexec_fn=self.run_in_root)
@@ -523,7 +523,7 @@ class InstallationTarget:
# selinux
if os.path.exists("%s/usr/sbin/lokkit" %(instroot,)):
args = ["/usr/sbin/lokkit", "-f", "--quiet", "--nostart"]
- if ksparser.handler.selinux.selinux:
+ if self.ksparser.handler.selinux.selinux:
args.append("--selinux=enforcing")
else:
args.append("--selinux=disabled")
@@ -535,15 +535,15 @@ class InstallationTarget:
# enable/disable services appropriately
if os.path.exists("%s/sbin/chkconfig" %(instroot,)):
- for s in ksparser.handler.services.enabled:
+ for s in self.ksparser.handler.services.enabled:
subprocess.call(["/sbin/chkconfig", s, "--level", "345", "on"],
preexec_fn=self.run_in_root)
- for s in ksparser.handler.services.disabled:
+ for s in self.ksparser.handler.services.disabled:
subprocess.call(["/sbin/chkconfig", s, "--level", "345", "off"],
preexec_fn=self.run_in_root)
# x by default?
- if ksparser.handler.xconfig.startX:
+ if self.ksparser.handler.xconfig.startX:
f = open("%s/etc/inittab" %(instroot,), "rw+")
buf = f.read()
buf = buf.replace("id:3:initdefault", "id:5:initdefault")
@@ -553,7 +553,7 @@ class InstallationTarget:
# and now, for arbitrary %post scripts
for s in filter(lambda s: s.type == pykickstart.parser.KS_SCRIPT_POST,
- ksparser.handler.scripts):
+ self.ksparser.handler.scripts):
# we can only safely run scripts in the chroot
if not s.inChroot:
print >> sys.stderr, "Not running script outside of chroot"
@@ -673,7 +673,7 @@ label runfromram
self.teardown()
sys.exit(1)
- self.configureSystem(self.ksparser)
+ self.configureSystem()
self.relabelSystem()
self.createInitramfs()
self.configureBootloader()
--
17 years
[patch 10/20] Split out write_fstab() method
by Mark McLoughlin
This might look a little pointless, but I did it to make
re-factoring in subsequent patches easier
I think it makes the code marginally more readable, anyway
Signed-off-by: Mark McLoughlin <markmc(a)redhat.com>
Index: livecd/creator/livecd-creator
===================================================================
--- livecd.orig/creator/livecd-creator
+++ livecd/creator/livecd-creator
@@ -331,6 +331,15 @@ class InstallationTarget:
return success
+ def write_fstab(self):
+ fstab = open(self.build_dir + "/install_root/etc/fstab", "w")
+ fstab.write("/dev/mapper/livecd-rw / ext3 defaults,noatime 0 0\n")
+ fstab.write("devpts /dev/pts devpts gid=5,mode=620 0 0\n")
+ fstab.write("tmpfs /dev/shm tmpfs defaults 0 0\n")
+ fstab.write("proc /proc proc defaults 0 0\n")
+ fstab.write("sysfs /sys sysfs defaults 0 0\n")
+ fstab.close()
+
def setup(self, image_size, base_on = None):
"""setup target ext3 file system in preparation for an install"""
@@ -407,14 +416,7 @@ class InstallationTarget:
self.teardown()
return False
- # write an /etc/fstab file
- fstab = open(self.build_dir + "/install_root/etc/fstab", "w")
- fstab.write("/dev/mapper/livecd-rw / ext3 defaults,noatime 0 0\n")
- fstab.write("devpts /dev/pts devpts gid=5,mode=620 0 0\n")
- fstab.write("tmpfs /dev/shm tmpfs defaults 0 0\n")
- fstab.write("proc /proc proc defaults 0 0\n")
- fstab.write("sysfs /sys sysfs defaults 0 0\n")
- fstab.close()
+ self.write_fstab()
self.ayum.setup("%s/install_root" %(self.build_dir,))
return True
--
17 years
[patch 09/20] Consolidate bindmounts creation
by Mark McLoughlin
No reason why the /var/cache/yum bindmount shouldn't be
created in the same loop as the rest of the bindmounts
Signed-off-by: Mark McLoughlin <markmc(a)redhat.com>
Index: livecd/creator/livecd-creator
===================================================================
--- livecd.orig/creator/livecd-creator
+++ livecd/creator/livecd-creator
@@ -388,8 +388,10 @@ class InstallationTarget:
return False
# bind mount system directories into install_root/
- for f in ["/sys", "/proc", "/dev", "/dev/pts", "/selinux"]:
- b = BindChrootMount(f, "%s/install_root" %(self.build_dir,))
+ for (f, dest) in [("/sys", None), ("/proc", None), ("/dev", None),
+ ("/dev/pts", None), ("/selinux", None),
+ (self.build_dir + "/yum-cache", "/var/cache/yum")]:
+ b = BindChrootMount(f, self.build_dir + "/install_root", dest)
if b.mount():
self.bindmounts.append(b)
else:
@@ -414,16 +416,6 @@ class InstallationTarget:
fstab.write("sysfs /sys sysfs defaults 0 0\n")
fstab.close()
- b = BindChrootMount("%s/yum-cache" %(self.build_dir,),
- "%s/install_root" %(self.build_dir,),
- "/var/cache/yum")
- if b.mount():
- self.bindmounts.append(b)
- else:
- print "Cannot bind mount /var/cache/yum"
- self.teardown()
- return False
-
self.ayum.setup("%s/install_root" %(self.build_dir,))
return True
--
17 years