Example #1
0
def verifystate(nextstate):
    e = executeCommand(nextstate.get("verify"))
    rcode = e.execute()
    if rcode == 0:
        return True
    else:
        return False
Example #2
0
 def verifystate(self, nextstate):
     e = executeCommand(nextstate.get("verify"),self.force_yes)
     rcode = e.execute()
     if rcode == 0:
         return True
     else:
         return False
Example #3
0
def verifystate(nextstate):
    e = executeCommand(nextstate.get("verify"))
    rcode = e.execute()
    if rcode == 0:
        return True
    else:
        return False
Example #4
0
def getstate(pdefn):
    logger = logging.getLogger("Maintenance.Automation")
    statelist = []
    for k in pdefn.keys():
        state, cmd = k, pdefn.get(k).get("verify")
        logger.info("Verifying state '{0}' using command '{1}'".format(state, cmd))
        e = executeCommand(cmd)
        rcode = e.execute()
        if rcode == 0:
            statelist.append(k)
    if len(statelist) > 1:
        raise Exception
    elif len(statelist) == 1:
        return statelist[0]
    else:
        raise Exception
Example #5
0
def getstate(pdefn):
    logger = logging.getLogger('Maintenance.Automation')
    statelist = []
    for k in pdefn.keys():
        state, cmd = k, pdefn.get(k).get('verify')
        logger.info("Verifying state '{0}' using command '{1}'".format(
            state, cmd))
        e = executeCommand(cmd)
        rcode = e.execute()
        if rcode == 0:
            statelist.append(k)
    if len(statelist) > 1:
        raise Exception
    elif len(statelist) == 1:
        return statelist[0]
    else:
        raise Exception
Example #6
0
 def getstate(self, pdefn):
     # iterates through each defined state
     # in the process definition and trying
     # to check at what state the object is in
     logger = logging.getLogger('Maintenance.Automation')
     statelist = []
     for k in pdefn.keys():
         state, cmd = k, pdefn.get(k).get('verify')
         logger.info("Verifying state '{0}' using command '{1}'".format(
             state, cmd))
         e = executeCommand(cmd, self.force_yes)
         rcode = e.execute()
         if rcode == 0:
             statelist.append(k)
     if len(statelist) > 1:
         raise Exception
     elif len(statelist) == 1:
         return statelist[0]
     else:
         raise Exception
Example #7
0
 def execute(self, command):
     e = executeCommand(command,self.force_yes)
     rcode = e.execute()
     return rcode
Example #8
0
    def executeCommand(self, cmdToExecute, expectedOutput, expectedErrorOutput,
                       expectedReturnCodes, timeout, skipOutputChecks):

        commandOutputObj = executeCommand(cmdToExecute, timeout)
        if commandOutputObj is None:
            raise Exception("Execute command returned None type object")

        correctReturnCode = False
        for x in expectedReturnCodes:
            if x == commandOutputObj.returncode:
                correctReturnCode = True

        if not correctReturnCode:
            print("stdOut:" + str(decode_or_none(commandOutputObj.stdout)))
            print("stdErr:" + str(decode_or_none(commandOutputObj.stderr)))
            if commandOutputObj.returncode == -1:
                self.assertFalse(True,
                                 msg="Command timeed out and didn't return")
            else:
                self.assertFalse(True,
                                 msg="Wrong return code recieved got " +
                                 str(commandOutputObj.returncode) +
                                 " expected one of " +
                                 str(expectedReturnCodes))

        if skipOutputChecks:
            return commandOutputObj

        stdoutString = None
        stdoutString = bytes_to_string(commandOutputObj.stdout)
        stderrString = None
        stderrString = bytes_to_string(commandOutputObj.stderr)

        if (stdoutString is None) and (expectedOutput is None):
            return commandOutputObj
        if stdoutString is None:
            print("Wrong Output: GOT:")
            print("<<<<NONE>>>>")
            print("--------------EXP:")
            print(expectedOutput)
            print("--------------")
            self.assertTrue(False)

        if expectedOutput is None:
            print("Wrong Output: GOT:")
            print(stdoutString)
            print("--------------EXP:")
            print("<<<<NONE>>>>")
            print("--------------")
            self.assertTrue(False)

        stdoutPro = stdoutString.strip().strip('\n')
        expectedOutPro = expectedOutput.strip().strip('\n')
        stdoutArr = stdoutPro.split("\n")
        expectedOutArr = expectedOutPro.split("\n")
        if stdoutPro != expectedOutPro:
            wrongLineNums = []
            for linNum in range(0, len(stdoutArr)):
                wrong = False
                if linNum >= len(stdoutArr):
                    wrong = True
                else:
                    if linNum >= len(expectedOutArr):
                        wrong = True
                    else:
                        if stdoutArr[linNum] != expectedOutArr[linNum]:
                            wrong = True
                if wrong:
                    wrongLineNums.append(linNum + 1)
            print("Wrong Output: " + str(wrongLineNums) + " GOT:")
            linNum = 0
            for line in stdoutArr:
                linNum += 1
                print("{:0>3d}: {}:".format(linNum, line))
            print("--------------EXP:")
            linNum = 0
            for line in expectedOutArr:
                linNum += 1
                print("{:0>3d}: {}:".format(linNum, line))
            print("--------------")
            self.assertTrue(False)

        self.assertEqual(stderrString,
                         expectedErrorOutput,
                         msg="Wrong Error Output")

        return commandOutputObj