Beispiel #1
0
 def generateOne(self, kver, rdPath):
     log.info("Rebuilding initrd for kernel %s", kver)
     args = ['/usr/sbin/chroot', self.image_root, '/sbin/mkinitrd',
             '-f', '--allow-missing']
     for driver in self.MODULES:
         args.append('--with=' + driver)
     if is_RH(self.image_root):
         args.append('--preload=xenblk')
     args.extend([rdPath, kver])
     logCall(args)
Beispiel #2
0
    def postTagScripts(self):
        # misc. stuff that needs to run after tag handlers have finished
        dhcp = self.filePath("etc/sysconfig/network/dhcp")
        if os.path.isfile(dhcp):
            # tell SUSE to set the hostname via DHCP
            cmd = r"""/bin/sed -e 's/DHCLIENT_SET_HOSTNAME=.*/DHCLIENT_SET_HOSTNAME="yes"/g' -i %s""" % dhcp
            logCall(cmd)

        logCall("rm -rf %s/var/lib/conarydb/rollbacks/*" % self.root)

        # set up shadow passwords/md5 passwords
        authConfigCmd = "chroot %s %%s --kickstart --enablemd5 --enableshadow" " --disablecache" % self.root
        if self.fileExists("/usr/sbin/authconfig"):
            logCall(authConfigCmd % "/usr/sbin/authconfig")
        elif self.fileExists("/usr/bin/authconfig"):
            logCall(authConfigCmd % "/usr/bin/authconfig")
        elif self.fileExists("/usr/sbin/pwconv"):
            logCall("chroot %s /usr/sbin/pwconv" % self.root)

        # allow empty password to log in for virtual appliance
        fn = self.filePath("etc/pam.d/common-auth")
        if os.path.exists(fn):
            f = open(fn)
            lines = []
            for line in f:
                line = line.strip()
                if "pam_unix2.so" in line and "nullok" not in line:
                    line += " nullok"
                lines.append(line)
            lines.append("")
            f = open(fn, "w")
            f.write("\n".join(lines))
            f.close()

        # Unlock the root account by blanking its password, unless a valid
        # password is already set.
        if self.fileExists("usr/sbin/usermod") and not hasRootPassword(self.root):
            log.info("Blanking root password.")
            logCall("chroot %s /usr/sbin/usermod -p '' root" % self.root, ignoreErrors=True)
        else:
            log.info("Not changing root password.")

        # Set up selinux autorelabel if appropriate
        selinux = self.filePath("etc/selinux/config")
        if os.path.exists(selinux):
            selinuxLines = [x.strip() for x in file(selinux).readlines()]
            if not "SELINUX=disabled" in selinuxLines:
                self.createFile(".autorelabel")

        # write an appropriate SLES inittab for XenServer
        # and update /etc/securetty so that logins work.
        if is_SUSE(self.root):
            if self.jobData["buildType"] == buildtypes.XEN_OVA:
                cmd = r"/bin/sed -e 's/^#cons:/cons:/' -e 's/^\([1-6]\):/#\1:/' -i %s" % self.filePath("/etc/inittab")
                logCall(cmd)
                cmd = r"echo -e 'console\nxvc0' >> %s" % self.filePath("/etc/securetty")
                logCall(cmd)
            elif self.jobData["buildType"] == buildtypes.AMI:
                cmd = r"/bin/sed -i 's/^#\(l4\)/\1/g' %s" % self.filePath("/etc/inittab")
                logCall(cmd)
                # This returns a non-zero exit code
                try:
                    if is_SUSE(self.root, version=10):
                        cmd = r"chroot %s /sbin/chkconfig --levels 2345 network on" % self.root
                    else:
                        cmd = r"chroot %s /sbin/chkconfig -s network 2345" % self.root
                    logCall(cmd)
                except:
                    pass

        # RedHat needs a config to tell it it's okay to upgrade the kernel
        if is_RH(self.root) and not self.fileExists("etc/sysconfig/kernel"):
            self.createFile("etc/sysconfig/kernel", "UPDATEDEFAULT=yes\n" "DEFAULTKERNEL=kernel\n")

        # Finish installation of bootloader
        if not self.fileExists("boot/boot"):
            # So /boot/blah in grub conf still works if /boot is separate
            os.symlink(".", self.filePath("boot/boot"))
        self.bootloader.install()