Beispiel #1
0
    def display(chroot=None):
        command = "%s pvdisplay --units b 2>/dev/null" % \
                  LVM_PHYSICAL_VOLUME.prog
        log.debug1(command)
        (status, rusage, msg) = runScript(script=command, chroot=chroot)
        if msg and msg != "":
            log.debug1(msg, nofmt=1)
        if status != 0:
            log.error("Failed to get general physical volume information.")
            return None

        dict = {}
        device = None
        for line in msg.split("\n"):
            line = line.strip()
            if len(line) < 1 or line[0] == '#':
                continue
            if line[:7] == "PV Name":
                device = line[7:].strip()
                dict[device] = {}
                d = dict[device]
            if not device:
                continue
            try:
                if line[:7] == "VG Name":
                    d["vgname"] = line[7:].strip()
                elif line[:7] == "PV UUID":
                    d["pvuuid"] = line[7:].strip()
            except:
                log.error("pvdisplay output malformed.")
                return None
        return dict
Beispiel #2
0
    def display(chroot=None):
        command = "%s pvdisplay --units b 2>/dev/null" % \
                  LVM_PHYSICAL_VOLUME.prog
        log.debug1(command)
        (status, rusage, msg) = runScript(script=command, chroot=chroot)
        if msg and msg != "":
            log.debug1(msg, nofmt=1)
        if status != 0:
            log.error("Failed to get general physical volume information.")
            return None

        dict = { }
        device = None
        for line in msg.split("\n"):
            line = line.strip()
            if len(line) < 1 or line[0] == '#':
                continue
            if line[:7] == "PV Name":
                device = line[7:].strip()
                dict[device] = { }
                d = dict[device]
            if not device:
                continue
            try:
                if line[:7] == "VG Name":
                    d["vgname"] = line[7:].strip()
                elif line[:7] == "PV UUID":
                    d["pvuuid"] = line[7:].strip()
            except:
                log.error("pvdisplay output malformed.")
                return None
        return dict
Beispiel #3
0
def run_script(command, chroot='', logging=flog):
    if chroot != '':
        logging.debug1("'%s' in '%s'", command, chroot, nofmt=1)
    else:
        logging.debug1(command, nofmt=1)
    (status, rusage, msg) = runScript(script=command, chroot=chroot)
    if msg and msg != "":
        logging.info1(msg, nofmt=1)
    return status
Beispiel #4
0
def run_script(command, chroot='', logging=flog):
    if chroot != '':
        logging.debug1("'%s' in '%s'", command, chroot, nofmt=1)
    else:
        logging.debug1(command, nofmt=1)
    (status, rusage, msg) = runScript(script=command, chroot=chroot)
    if msg and msg != "":
        logging.info1(msg, nofmt=1)
    return status
Beispiel #5
0
def run_ks_script(dict, chroot):
    interpreter = "/bin/sh"
    if dict.has_key("interpreter"):
        interpreter = dict["interpreter"]
    (status, rusage, msg) = runScript(interpreter, dict["script"],
                                      chroot=chroot)
    if msg and msg != "":
        flog.info1(msg, nofmt=1)
    if status != 0:
        if dict.has_key("erroronfail"):
            log.error("Script failed, aborting.")
            return 0
        else:
            log.warning("Script failed.")

    return 1
Beispiel #6
0
def run_ks_script(dict, chroot):
    interpreter = "/bin/sh"
    if dict.has_key("interpreter"):
        interpreter = dict["interpreter"]
    (status, rusage, msg) = runScript(interpreter,
                                      dict["script"],
                                      chroot=chroot)
    if msg and msg != "":
        flog.info1(msg, nofmt=1)
    if status != 0:
        if dict.has_key("erroronfail"):
            log.error("Script failed, aborting.")
            return 0
        else:
            log.warning("Script failed.")

    return 1
Beispiel #7
0
    def scan(chroot=None):
        command = "%s pvscan 2>/dev/null" % LVM_PHYSICAL_VOLUME.prog
        log.debug1(command)
        (status, rusage, msg) = runScript(script=command, chroot=chroot)
        if msg and msg != "":
            log.debug1(msg, nofmt=1)
        if status != 0:
            log.error("Failed to scan for physical volumes.")
            return None

        dict = { }
        for line in msg.split("\n"):
            line = line.strip()
            if len(line) < 1 or line[0] == '#':
                continue
            splits = line.split()
            if len(splits) < 4 or splits[0] != "PV" or splits[2] != "VG":
                continue
            # set <volgroup>: <device>, ..
            dict.setdefault(splits[3], [ ]).append(splits[1])
        return dict
Beispiel #8
0
    def scan(chroot=None):
        command = "%s pvscan 2>/dev/null" % LVM_PHYSICAL_VOLUME.prog
        log.debug1(command)
        (status, rusage, msg) = runScript(script=command, chroot=chroot)
        if msg and msg != "":
            log.debug1(msg, nofmt=1)
        if status != 0:
            log.error("Failed to scan for physical volumes.")
            return None

        dict = {}
        for line in msg.split("\n"):
            line = line.strip()
            if len(line) < 1 or line[0] == '#':
                continue
            splits = line.split()
            if len(splits) < 4 or splits[0] != "PV" or splits[2] != "VG":
                continue
            # set <volgroup>: <device>, ..
            dict.setdefault(splits[3], []).append(splits[1])
        return dict
Beispiel #9
0
    def display(chroot=None):
        command = "%s lvdisplay --units b 2>/dev/null" % \
                  LVM_LOGICAL_VOLUME.prog
        log.debug1(command)
        (status, rusage, msg) = runScript(script=command, chroot=chroot)
        if msg and msg != "":
            log.debug1(msg, nofmt=1)
        if status != 0:
            log.error("Failed to get volume group information.")
            return None

        dict = { }
        volume = None
        for line in msg.split("\n"):
            line = line.strip()
            if len(line) < 1 or line[0] == '#':
                continue
            if line[:7] == "LV Name":
                volume = line[7:].strip()
                dict[volume] = { }
                d = dict[volume]
            if not volume:
                continue
            try:
                if line[:6] == "VG Name":
                    d["vgname"] = line[7:].strip()
                elif line[:6] == "LV UUID":
                    d["lvuuid"] = line[7:].strip()
                elif line[:7] == "LV Size":
                    if line[-2:] == " B":
                        d["lvsize"] = long(line[7:-1].strip())
                elif line[:7] == "Block device":
                    d["device"] = line[12:].strip()
            except:
                log.error("lvdisplay output malformed.")
                return None
        return dict
Beispiel #10
0
    def display(chroot=None):
        command = "%s vgdisplay --units b 2>/dev/null" % LVM_VOLGROUP.prog
        log.debug1(command)
        (status, rusage, msg) = runScript(script=command, chroot=chroot)
        if msg and msg != "":
            log.debug1(msg, nofmt=1)
        if status != 0:
            log.error("Failed to get volume group information.")
            return None

        dict = { }
        group = None
        for line in msg.split("\n"):
            line = line.strip()
            if len(line) < 1 or line[0] == '#':
                continue
            if line[:7] == "VG Name":
                group = line[7:].strip()
                dict[group] = { }
                d = dict[group]
            if not group:
                continue
            try:
                if line[:6] == "Format":
                    d["format"] = line[7:].strip()
                elif line[:7] == "VG Size":
                    if line[-2:] == " B":
                        d["vgsize"] = long(line[7:-1].strip())
                elif line[:7] == "PE Size":
                    if line[-2:] == " B":
                        d["pesize"] = long(line[7:-1].strip())
                elif line[:8] == "Total PE":
                    d["pe"] = long(line[8:].strip())
            except:
                log.error("vgdisplay output malformed.")
                return None
        return dict
Beispiel #11
0
    def display(chroot=None):
        command = "%s lvdisplay --units b 2>/dev/null" % \
                  LVM_LOGICAL_VOLUME.prog
        log.debug1(command)
        (status, rusage, msg) = runScript(script=command, chroot=chroot)
        if msg and msg != "":
            log.debug1(msg, nofmt=1)
        if status != 0:
            log.error("Failed to get volume group information.")
            return None

        dict = {}
        volume = None
        for line in msg.split("\n"):
            line = line.strip()
            if len(line) < 1 or line[0] == '#':
                continue
            if line[:7] == "LV Name":
                volume = line[7:].strip()
                dict[volume] = {}
                d = dict[volume]
            if not volume:
                continue
            try:
                if line[:6] == "VG Name":
                    d["vgname"] = line[7:].strip()
                elif line[:6] == "LV UUID":
                    d["lvuuid"] = line[7:].strip()
                elif line[:7] == "LV Size":
                    if line[-2:] == " B":
                        d["lvsize"] = long(line[7:-1].strip())
                elif line[:7] == "Block device":
                    d["device"] = line[12:].strip()
            except:
                log.error("lvdisplay output malformed.")
                return None
        return dict
Beispiel #12
0
    def display(chroot=None):
        command = "%s vgdisplay --units b 2>/dev/null" % LVM_VOLGROUP.prog
        log.debug1(command)
        (status, rusage, msg) = runScript(script=command, chroot=chroot)
        if msg and msg != "":
            log.debug1(msg, nofmt=1)
        if status != 0:
            log.error("Failed to get volume group information.")
            return None

        dict = {}
        group = None
        for line in msg.split("\n"):
            line = line.strip()
            if len(line) < 1 or line[0] == '#':
                continue
            if line[:7] == "VG Name":
                group = line[7:].strip()
                dict[group] = {}
                d = dict[group]
            if not group:
                continue
            try:
                if line[:6] == "Format":
                    d["format"] = line[7:].strip()
                elif line[:7] == "VG Size":
                    if line[-2:] == " B":
                        d["vgsize"] = long(line[7:-1].strip())
                elif line[:7] == "PE Size":
                    if line[-2:] == " B":
                        d["pesize"] = long(line[7:-1].strip())
                elif line[:8] == "Total PE":
                    d["pe"] = long(line[8:].strip())
            except:
                log.error("vgdisplay output malformed.")
                return None
        return dict
Beispiel #13
0
    def scan(chroot=None):
        command = "%s lvscan 2>/dev/null" % LVM_LOGICAL_VOLUME.prog
        log.debug1(command)
        (status, rusage, msg) = runScript(script=command, chroot=chroot)
        if msg and msg != "":
            log.debug1(msg, nofmt=1)
        if status != 0:
            log.error("Failed to scan for logical volumes.")
            return None

        dict = { }
        for line in msg.split("\n"):
            line = line.strip()
            if len(line) < 1 or line[0] == '#':
                continue
            splits = line.split("'")
            if len(splits) < 3:
                continue
            # set <volgroup>: <device>, ..
            d = splits[1].split("/")
            if len(d) != 3 or d[0] != "dev":
                continue
            dict[splits[1]] = d[1]
        return dict
Beispiel #14
0
    def scan(chroot=None):
        command = "%s lvscan 2>/dev/null" % LVM_LOGICAL_VOLUME.prog
        log.debug1(command)
        (status, rusage, msg) = runScript(script=command, chroot=chroot)
        if msg and msg != "":
            log.debug1(msg, nofmt=1)
        if status != 0:
            log.error("Failed to scan for logical volumes.")
            return None

        dict = {}
        for line in msg.split("\n"):
            line = line.strip()
            if len(line) < 1 or line[0] == '#':
                continue
            splits = line.split("'")
            if len(splits) < 3:
                continue
            # set <volgroup>: <device>, ..
            d = splits[1].split("/")
            if len(d) != 3 or d[0] != "dev":
                continue
            dict[splits[1]] = d[1]
        return dict
Beispiel #15
0
    def runOperations(self, operations):
        """Perform (operation, RpmPackage) from list operation.

        Return 1 on success, 0 on error (after warning the user)."""
        result = 1
        if operations == []:
            log.error("No updates are necessary.")
            return 1
        # Cache the packages
        if not self.config.nocache:
            log.info2("Caching network packages")
        new_operations = []
        for (op, pkg) in operations:
            if op in (OP_UPDATE, OP_INSTALL, OP_FRESHEN):
                source = pkg.source
                # cache remote pkgs to disk
                if not self.config.nocache and \
                   (pkg.source.startswith("http://") or \
                    pkg.source.startswith("https://") or \
                    pkg.yumrepo != None):
                    log.info3("Caching network package %s", pkg.getNEVRA())
                    source = pkg.nc.cache(pkg.source)
                    if source is None:
                        log.error("Error downloading %s", pkg.source)
                        return 0
                pkg.source = source

                # check signature
                if not self.config.nosignature:
                    try:
                        pkg.reread()
                    except Exception, e:
                        log.error("Error rereading package: %s", e)
                        return 0
                    # Check packages if we have turned on signature checking
                    if pkg.verifyOneSignature() == -1:
                        log.error(
                            "Signature verification failed for "
                            "package %s", pkg.getNEVRA())
                        raise ValueError
                    else:
                        log.info3("Signature of package %s correct",
                                  pkg.getNEVRA())
                    pkg.close()
                    pkg.clear(ntags=self.config.nevratags)
            new_operations.append((op, pkg))
            if pkg["pretransprog"] != None and not self.config.noscripts:
                try:
                    (status, rusage, output) = functions.runScript(
                        pkg["pretransprog"],
                        pkg["pretrans"], [0],
                        rusage=self.config.rusage,
                        prefixes=pkg["prefixes"],
                        chroot=self.config.buildroot)
                except (IOError, OSError), e:
                    log.error("\n%s: Error running pre transaction script: %s",
                              pkg.getNEVRA(), e)
                else:
                    if rusage != None and len(rusage):
                        sys.stderr.write("\nRUSAGE, %s_%s, %s, %s\n" %
                                         (pkg.getNEVRA(), "pretrans",
                                          str(rusage[0]), str(rusage[1])))
                    if output or status != 0:
                        log.error(
                            "Output running pre transaction script for "
                            "package %s", pkg.getNEVRA())
                        log.error(output, nofmt=1)
Beispiel #16
0
                    result = 0
                    break
                # update DB
                if self.__erasePkgFromDB(pkg) == 0:
                    log.error("Couldn't erase package %s from database.",
                              pkg.getNEVRA())
                    result = 0
                    break

        # Start all posttrans scripts:
        for (posttransprog, posttransscript, nevra, prefixes) in posttrans:
            try:
                (status, rusage,
                 output) = functions.runScript(posttransprog,
                                               posttransscript, [0],
                                               rusage=self.config.rusage,
                                               prefixes=prefixes,
                                               chroot=self.config.buildroot)
            except (IOError, OSError), e:
                log.error("\n%s: Error running post transaction script: %s",
                          nevra, e)
            else:
                if rusage != None and len(rusage):
                    sys.stderr.write(
                        "\nRUSAGE, %s_%s, %s, %s\n" %
                        (nevra, "posttrans", str(rusage[0]), str(rusage[1])))
                if output or status != 0:
                    log.error(
                        "Output running post transaction script for "
                        "package %s", nevra)
                    log.error(output, nofmt=1)
Beispiel #17
0
    def runOperations(self, operations):
        """Perform (operation, RpmPackage) from list operation.

        Return 1 on success, 0 on error (after warning the user)."""
        result = 1
        if operations == []:
            log.error("No updates are necessary.")
            return 1
        # Cache the packages
        if not self.config.nocache:
            log.info2("Caching network packages")
        new_operations = []
        for (op, pkg) in operations:
            if op in (OP_UPDATE, OP_INSTALL, OP_FRESHEN):
                source = pkg.source
                # cache remote pkgs to disk
                if not self.config.nocache and \
                   (pkg.source.startswith("http://") or \
                    pkg.source.startswith("https://") or \
                    pkg.yumrepo != None):
                    log.info3("Caching network package %s", pkg.getNEVRA())
                    source = pkg.nc.cache(pkg.source)
                    if source is None:
                        log.error("Error downloading %s", pkg.source)
                        return 0
                pkg.source = source

                # check signature
                if not self.config.nosignature:
                    try:
                        pkg.reread()
                    except Exception, e:
                        log.error("Error rereading package: %s", e)
                        return 0
                    # Check packages if we have turned on signature checking
                    if pkg.verifyOneSignature() == -1:
                        log.error("Signature verification failed for "
                                  "package %s", pkg.getNEVRA())
                        raise ValueError
                    else:
                        log.info3("Signature of package %s correct",
                                  pkg.getNEVRA())
                    pkg.close()
                    pkg.clear(ntags=self.config.nevratags)
            new_operations.append((op, pkg))
            if pkg["pretransprog"] != None and not self.config.noscripts:
                try:
                    (status, rusage, output) = functions.runScript(
                        pkg["pretransprog"], pkg["pretrans"], [0],
                        rusage=self.config.rusage, prefixes=pkg["prefixes"],
                        chroot=self.config.buildroot)
                except (IOError, OSError), e:
                    log.error("\n%s: Error running pre transaction script: %s",
                              pkg.getNEVRA(), e)
                else:
                    if rusage != None and len(rusage):
                        sys.stderr.write("\nRUSAGE, %s_%s, %s, %s\n" % (pkg.getNEVRA(), "pretrans", str(rusage[0]), str(rusage[1])))
                    if output or status != 0:
                        log.error("Output running pre transaction script for "
                                  "package %s", pkg.getNEVRA())
                        log.error(output, nofmt=1)
Beispiel #18
0
                except (IOError, ValueError), e:
                    log.error("Error erasing %s: %s", pkg.getNEVRA(), e)
                    result = 0
                    break
                # update DB
                if self.__erasePkgFromDB(pkg) == 0:
                    log.error("Couldn't erase package %s from database.",
                              pkg.getNEVRA())
                    result = 0
                    break

        # Start all posttrans scripts:
        for (posttransprog, posttransscript, nevra, prefixes) in posttrans:
            try:
                (status, rusage, output) = functions.runScript(
                    posttransprog, posttransscript, [0],
                    rusage=self.config.rusage, prefixes=prefixes,
                    chroot=self.config.buildroot)
            except (IOError, OSError), e:
                log.error("\n%s: Error running post transaction script: %s",
                          nevra, e)
            else:
                if rusage != None and len(rusage):
                    sys.stderr.write("\nRUSAGE, %s_%s, %s, %s\n" % (nevra,
                        "posttrans", str(rusage[0]), str(rusage[1])))
                if output or status != 0:
                    log.error("Output running post transaction script for "
                              "package %s", nevra)
                    log.error(output, nofmt=1)

        if self.config.delayldconfig:
            self.config.delayldconfig = 0
Beispiel #19
0
def fuser(what):
    # first stage: close own files
    i = 0
    mypid = os.getpid()
    while 1:
        lsof = "/usr/sbin/lsof -Fpf +D '%s' 2>/dev/null" % what
        (status, rusage, msg) = runScript(script=lsof)
        if msg == "":
            break
        lines = msg.strip().split()
        for j in xrange(len(lines)):
            line = lines[j].strip()
            if not line or len(line) < 1 or line[0] != "p":
                continue
            if line != "p%d" % mypid:
                continue
            while j + 1 < len(lines):
                line = lines[j+1].strip()
                if not line or len(line) < 1 or line[0] != "f":
                    break
                try:
                    fd = int(line[1:])
                except:
                    pass
                else:
                    log.info2("Closing dangling fd %d", fd)
                    try:
                        os.close(fd)
                    except:
                        pass
                j += 1
        i += 1
        if i == 20:
            log.error("Failed to close open files.")
            break

    # second stage: kill programs
    i = 0
    sig = signal.SIGTERM
    while 1:
        lsof = "/usr/sbin/lsof -t +D '%s' 2>/dev/null" % what
        (status, rusage, msg) = runScript(script=lsof)
        if msg == "":
            break
        pids = msg.strip().split()
        if len(pids) == 0:
            break
        for pid in pids:
            try:
                p = int(pid)
            except:
                continue
            if p == os.getpid():
                # do not kill yourself
                continue
            try:
                os.kill(p, sig)
            except:
                continue
        i += 1
        if i == 20:
            log.error("Failed to kill processes:")
            os.system("/usr/sbin/lsof +D '%s'" % what)
            break
        if i > 15:
            time.sleep(1)
        if i > 10:
            sig = signal.SIGKILL
Beispiel #20
0
def fuser(what):
    # first stage: close own files
    i = 0
    mypid = os.getpid()
    while 1:
        lsof = "/usr/sbin/lsof -Fpf +D '%s' 2>/dev/null" % what
        (status, rusage, msg) = runScript(script=lsof)
        if msg == "":
            break
        lines = msg.strip().split()
        for j in xrange(len(lines)):
            line = lines[j].strip()
            if not line or len(line) < 1 or line[0] != "p":
                continue
            if line != "p%d" % mypid:
                continue
            while j + 1 < len(lines):
                line = lines[j + 1].strip()
                if not line or len(line) < 1 or line[0] != "f":
                    break
                try:
                    fd = int(line[1:])
                except:
                    pass
                else:
                    log.info2("Closing dangling fd %d", fd)
                    try:
                        os.close(fd)
                    except:
                        pass
                j += 1
        i += 1
        if i == 20:
            log.error("Failed to close open files.")
            break

    # second stage: kill programs
    i = 0
    sig = signal.SIGTERM
    while 1:
        lsof = "/usr/sbin/lsof -t +D '%s' 2>/dev/null" % what
        (status, rusage, msg) = runScript(script=lsof)
        if msg == "":
            break
        pids = msg.strip().split()
        if len(pids) == 0:
            break
        for pid in pids:
            try:
                p = int(pid)
            except:
                continue
            if p == os.getpid():
                # do not kill yourself
                continue
            try:
                os.kill(p, sig)
            except:
                continue
        i += 1
        if i == 20:
            log.error("Failed to kill processes:")
            os.system("/usr/sbin/lsof +D '%s'" % what)
            break
        if i > 15:
            time.sleep(1)
        if i > 10:
            sig = signal.SIGKILL