Exemple #1
0
    def install_local_packages(self, packages):
        def in_chroot(lst):
            return ["chroot", self.chroot] + lst

        packages = [ os.path.abspath(p) for p in packages ]
        for package in packages:
            if not os.path.isfile(package):
                raise Exception("package file %r does not exist" % package)
            if not package.startswith(self.chroot + os.path.sep):
                raise Exception("package file %r is not within the chroot" % package)

        pkgmgr, config, lock = self.grab_pm("in_chroot")
        try:
            with lock:
                # always happens in chroot
                # packages must be a list of paths to RPMs valid within the chroot
                for option, retries in options_retries:
                    logger.info("Installing packages %s: %s", option, ", ".join(packages))
                    cmd = in_chroot(
                        [pkgmgr]
                        + (['localinstall'] if pkgmgr == "yum" else ['install'])
                        + ['-y']
                        + option
                        + ['-c', config.name[len(self.chroot):]]
                        + (['--'] if pkgmgr == "yum" else [])
                    ) + [ p[len(self.chroot):] for p in packages ]
                    try:
                        out, ret = retrymod.retry(retries)(check_call_retry_rpmdberror)(cmd)
                    except RpmdbCorruptionError:
                        logger.warning("Repairing RPMDB corruption before retrying package install...")
                        cmdmod.check_call(in_chroot(["rpm", "--rebuilddb"]))
                        out, ret = retrymod.retry(retries)(check_call_retry_rpmdberror)(cmd)
                return out, ret
        finally:
            self.ungrab_pm()
Exemple #2
0
    def install_local_packages(self, packages):
        def in_chroot(lst):
            return ["chroot", self.chroot] + lst

        packages = [ os.path.abspath(p) for p in packages ]
        for package in packages:
            if not os.path.isfile(package):
                raise Exception("package file %r does not exist" % package)
            if not package.startswith(self.chroot + os.path.sep):
                raise Exception("package file %r is not within the chroot" % package)

        pkgmgr, config, lock = self.grab_pm("in_chroot")
        try:
            with lock:
                # always happens in chroot
                # packages must be a list of paths to RPMs valid within the chroot
                for option, retries in options_retries:
                    logger.info("Installing packages %s: %s", option, ", ".join(packages))
                    cmd = in_chroot(
                        [pkgmgr]
                        + (['localinstall'] if pkgmgr == "yum" else ['install'])
                        + ['-qy']
                        + option
                        + ['-c', config.name[len(self.chroot):]]
                        + (['--'] if pkgmgr == "yum" else [])
                    ) + [ p[len(self.chroot):] for p in packages ]
                    out, ret = retrymod.retry(retries)(check_call_retry_rpmdberror)(cmd)
                return out, ret
        finally:
            self.ungrab_pm()
Exemple #3
0
    def ensure_packages_installed(self, packages, method="in_chroot"):
        def in_chroot(lst):
            return ["chroot", self.chroot] + lst

        pkgmgr, config, lock = self.grab_pm(method)
        try:
            with lock:
                try:
                    cmdmod.check_call_no_output(in_chroot(["rpm", "-q"] + packages))
                    logger.info("All required packages are available")
                    return
                except subprocess.CalledProcessError:
                    pass
                for option, retries in options_retries:
                    logger.info("Installing packages %s %s: %s", option, method, ", ".join(packages))
                    cmd = (
                        ([pkgmgr] if method == "out_of_chroot" else in_chroot([pkgmgr]))
                        + ["install", "-qy", "--disableplugin=*qubes*"]
                        + (["-c", config.name if method == "out_of_chroot" else config.name[len(self.chroot):]])
                        + option
                        + (['--installroot=%s' % self.chroot,
                            '--releasever=%d' % self.releasever] if method == "out_of_chroot" else [])
                        + (['--'] if pkgmgr == "yum" else [])
                        + packages
                    )
                    out, ret = retrymod.retry(retries)(check_call_retry_rpmdberror)(cmd)
                return out, ret
        finally:
            self.ungrab_pm()
Exemple #4
0
    def ensure_packages_installed(self, packages, method="in_chroot"):
        def in_chroot(lst):
            return ["chroot", self.chroot] + lst

        pkgmgr, config, lock = self.grab_pm(method)
        try:
                try:
                    with lock:
                        cmdmod.check_call_no_output(in_chroot(["rpm", "-q"] + packages))
                    logger.info("All required packages are available")
                    return
                except subprocess.CalledProcessError:
                    pass
                for option, retries in options_retries:
                    logger.info("Installing packages %s %s: %s", option, method, ", ".join(packages))
                    cmd = (
                        ([pkgmgr] if method == "out_of_chroot" else in_chroot([pkgmgr]))
                        + ["install", "-y", "--disableplugin=*qubes*"]
                        + (["-c", config.name if method == "out_of_chroot" else config.name[len(self.chroot):]])
                        + option
                        + (['--installroot=%s' % self.chroot,
                            '--releasever=%d' % self.releasever] if method == "out_of_chroot" else [])
                        + (['--'] if pkgmgr == "yum" else [])
                        + packages
                    )
                    try:
                        with lock:
                            out, ret = retrymod.retry(retries)(check_call_retry_rpmdberror)(cmd)
                    except RpmdbCorruptionError:
                        if method == "out_of_chroot":
                            # We do not support recovery in this case.
                            raise
                        logger.warning("Repairing RPMDB corruption before retrying package install...")
                        cmdmod.check_call(in_chroot(["rpm", "--rebuilddb"]))
                        with lock:
                            out, ret = retrymod.retry(retries)(check_call_retry_rpmdberror)(cmd)
                return out, ret
        finally:
            self.ungrab_pm()
Exemple #5
0
def deploy_zfs():
    args = get_deploy_parser().parse_args()
    logging.basicConfig(level=logging.DEBUG, format=BASIC_FORMAT)
    if not test_yum():
        print >> sys.stderr, "error: could not find either yum or DNF. Please use your package manager to install yum or DNF."
        return 5
    p = lambda withinchroot: j("/", withinchroot.lstrip(os.path.sep))
    in_chroot = lambda x: x

    pkgmgr = SystemPackageManager()
    pkgmgr.ensure_packages_installed = retrymod.retry(1)(pkgmgr.ensure_packages_installed)
    pkgmgr.install_local_packages = retrymod.retry(1)(pkgmgr.install_local_packages)

    to_rmdir = []
    to_unmount = []

    def cleanup():
        for fs in reversed(to_unmount):
            umount(fs)
        for filename in to_rmdir:
            os.rmdir(filename)

    try:
        deploy_zfs_in_machine(p=p,
                              in_chroot=in_chroot,
                              pkgmgr=pkgmgr,
                              prebuilt_rpms_path=args.prebuiltrpms,
                              branch=args.branch,
                              break_before=None,
                              to_rmdir=to_rmdir,
                              to_unmount=to_unmount,)
    except BaseException, e:
        logging.exception("Unexpected error")
        if not args.nocleanup:
            logging.info("Cleaning up now")
            cleanup()
        raise
Exemple #6
0
 def ensure_packages_installed(self, packages, method="out_of_chroot"):
     logger.info("Checking packages are available: %s", packages)
     try:
         cmdmod.check_call_no_output(["rpm", "-q"] + packages)
         logger.info("All required packages are available")
         return
     except subprocess.CalledProcessError:
         pass
     for option, retries in options_retries:
         logger.info("Installing packages %s %s: %s", option, method,
                     ", ".join(packages))
         cmd = ([self.strategy, 'install', '-y'] + option +
                (['--'] if self.strategy == "yum" else []) + packages)
         out, ret = retrymod.retry(retries)(check_call_retry_rpmdberror)(
             cmd)
     return out, ret
Exemple #7
0
 def ensure_packages_installed(self, packages, method="out_of_chroot"):
     logger.info("Checking packages are available: %s", packages)
     try:
         cmdmod.check_call_no_output(["rpm", "-q"] + packages)
         logger.info("All required packages are available")
         return
     except subprocess.CalledProcessError:
         pass
     for option, retries in options_retries:
         logger.info("Installing packages %s %s: %s", option, method, ", ".join(packages))
         cmd = (
             [self.strategy, 'install', '-y']
             + option
             + (['--'] if self.strategy == "yum" else [])
             + packages
         )
         out, ret = retrymod.retry(retries)(check_call_retry_rpmdberror)(cmd)
     return out, ret
Exemple #8
0
    def install_local_packages(self, packages):
        def in_chroot(lst):
            return ["chroot", self.chroot] + lst

        packages = [ os.path.abspath(p) for p in packages ]
        for package in packages:
            if not os.path.isfile(package):
                raise Exception("package file %r does not exist" % package)
        for option, retries in options_retries:
            logger.info("Installing packages %s: %s", option, ", ".join(packages))
            cmd = (
                [self.strategy]
                + (['localinstall'] if pkgmgr == "yum" else ['install'])
                + ['-qy']
                + (['--'] if pkgmgr == "yum" else [])
                + packages
            )
            out, ret = retrymod.retry(retries)(check_call_retry_rpmdberror)(cmd)
        return out, ret
Exemple #9
0
    def install_local_packages(self, packages):
        packages = [os.path.abspath(p) for p in packages]
        for package in packages:
            if not os.path.isfile(package):
                raise Exception("package file %r does not exist" % package)

        pkgmgr, config, lock = self.grab_pm("out_of_chroot")
        try:
            with lock:
                for option, retries in options_retries:
                    logger.info("Installing packages %s: %s", option,
                                ", ".join(packages))
                    cmd = ([self.strategy] +
                           (['localinstall']
                            if pkgmgr == "yum" else ['install']) + ['-y'] +
                           (['--'] if pkgmgr == "yum" else []) + packages)
                    out, ret = retrymod.retry(retries)(
                        check_call_retry_rpmdberror)(cmd)
                return out, ret
        finally:
            self.ungrab_pm()
Exemple #10
0
    def install_local_packages(self, packages):
        packages = [ os.path.abspath(p) for p in packages ]
        for package in packages:
            if not os.path.isfile(package):
                raise Exception("package file %r does not exist" % package)

        pkgmgr, config, lock = self.grab_pm("out_of_chroot")
        try:
            with lock:
                for option, retries in options_retries:
                    logger.info("Installing packages %s: %s", option, ", ".join(packages))
                    cmd = (
                        [self.strategy]
                        + (['localinstall'] if pkgmgr == "yum" else ['install'])
                        + ['-y']
                        + (['--'] if pkgmgr == "yum" else [])
                        + packages
                    )
                    out, ret = retrymod.retry(retries)(check_call_retry_rpmdberror)(cmd)
                return out, ret
        finally:
            self.ungrab_pm()
Exemple #11
0
                    randomness = file("/dev/urandom").read(4)
                    file(p(j("etc", "hostid")),"w").write(randomness)
                if not os.path.exists(p(j("etc", "locale.conf"))):
                    file(p(j("etc", "locale.conf")),"w").write("LANG=en_US.UTF-8\n")
                hostid = file(p(j("etc", "hostid"))).read().encode("hex")
                hostid = "%s%s%s%s"%(hostid[6:8],hostid[4:6],hostid[2:4],hostid[0:2])

                if lukspassword:
                    crypttab = \
'''%s UUID=%s none discard
'''%(luksuuid,rootuuid)
                    file(p(j("etc", "crypttab")),"w").write(crypttab)
                    os.chmod(p(j("etc", "crypttab")), 0600)

                pkgmgr = ChrootPackageManager(rootmountpoint, releasever, yum_cachedir_path)
                pkgmgr.ensure_packages_installed = retrymod.retry(1)(pkgmgr.ensure_packages_installed)
                pkgmgr.install_local_packages = retrymod.retry(1)(pkgmgr.install_local_packages)

                # install base packages
                packages = "basesystem rootfiles bash nano binutils rsync NetworkManager rpm vim-minimal e2fsprogs passwd pam net-tools cryptsetup kbd-misc kbd policycoreutils selinux-policy-targeted libseccomp util-linux".split()
                if releasever >= 21:
                    packages.append("dnf")
                else:
                    packages.append("yum")
                # install initial boot packages
                packages = packages + "grub2 grub2-tools grubby".split()
                pkgmgr.ensure_packages_installed(packages, method='out_of_chroot')

                # omit zfs modules when dracutting
                if not os.path.exists(p("usr/bin/dracut.real")):
                    check_call(in_chroot(["mv", "/usr/bin/dracut", "/usr/bin/dracut.real"]))