Beispiel #1
0
 def __init__(self, logger):
     self.environ = Environment()
     self.logger = logger
     self.ch = CommandHelper(self.logger)
     self.yumloc = "/usr/bin/yum"
     self.install = self.yumloc + " install -y "
     self.remove = self.yumloc + " remove -y "
     self.search = self.yumloc + " list "
     self.checkupdates = self.search + "updates "
     self.listavail = self.search + "available "
     self.listinstalled = self.search + "installed "
     self.updatepkg = self.yumloc + " update -y --obsoletes "
     myos = self.environ.getostype().lower()
     if re.search("red hat.*?release 6", myos) or \
             re.search("^centos$", myos.strip()):
         self.rpmloc = "/bin/rpm"
     else:
         self.rpmloc = "/usr/bin/rpm"
     self.provides = self.rpmloc + " -qf "
     self.query = self.rpmloc + " -qa "
Beispiel #2
0
    def __init__(self, ptype, ecode, errmsg=""):
        '''
        class init

        @param ptype: string; package manager name; valid values:
            apt
            dnf
            yum
            zypper
        @param ecode: int; exit code
        @param errmsg: string; (OPTIONAL); include any error string you want this class to parse 
                in order to more accurately determine the success or failure of the pkg mgr action
        @return: void
        @author: Breen Malmberg
        '''

        super(repoError, self).__init__(ptype, ecode, errmsg)
        self.environ = Environment()
        self.logger = LogDispatcher(self.environ)

        # default initialization of variables
        msg = "No further information available"
        successrange = []
        self.success = True
        self.errmsgdict = {
            "Error parsing config": False,
            "Could not parse": False,
            "No repomd file": False,
            "repositories failed": False,
            "doesn't have enough cached data to continue": False,
            "Abort, retry, ignore": False,
            "System management is locked": False
        }

        try:

            if ptype == "zypper":
                msg = self.zypperCodes(ecode)
                successrange = [0, 100, 101, 102, 103, 104, 106]
            elif ptype == "yum":
                msg = self.yumCodes(ecode)
                successrange = [0, 100]
            elif ptype == "apt":
                msg = self.aptCodes(ecode)
                successrange = [0]
            elif ptype == "dnf":
                msg = self.dnfCodes(ecode)
                successrange = [0, 100]
            else:
                self.logger.log(
                    LogPriority.DEBUG,
                    "Unable to identify package manager. Cannot guarantee package manager action success!"
                )

        except (KeyboardInterrupt, SystemExit):
            raise

        try:

            # First we try to go based off of the content of the error message
            # Since that is more reliable than exit codes, when trying to determine
            # Actual success or failure of the package manager command
            if errmsg:
                # (maybe we couldn't identify the package manager and
                # as a result couldn't populate the errmsgdict)
                if self.errmsgdict:
                    for entry in self.errmsgdict:
                        if re.search(entry, errmsg, re.IGNORECASE):
                            self.success = self.errmsgdict[entry]
                            if self.success:
                                # If success then the message passed is merely informational in nature
                                self.logger.log(LogPriority.INFO, errmsg)
                            else:
                                # If not success, then the message passed indicates an actual problem
                                self.logger.log(LogPriority.WARNING, errmsg)
                            return

            else:
                # If there is no error message passed, then we do our best
                # To determine success or failure based off of what the exit
                # Code indicates
                if ecode in successrange:
                    self.logger.log(LogPriority.INFO, msg)
                else:
                    self.success = False
                    self.logger.log(LogPriority.WARNING, msg)

        except IndexError as indexE:
            self.logger.log(LogPriority.WARNING, str(indexE))

        return