def run(self):
        if "action_parameter" in self._config:
            if self.connection:
                with open(self.action_script, "r") as stdin_file:
                    exit_status, stdout, stderr = self.connection.execute(
                        "sudo {}".format(self.action_param), stdin=stdin_file)
            else:
                exit_status, stdout = \
                    execute_shell_command(
                        "/bin/bash {0} {1}".format(
                            self.action_script, self.action_param))
        else:
            if self.connection:
                with open(self.action_script, "r") as stdin_file:
                    exit_status, stdout, stderr = self.connection.execute(
                        "sudo /bin/sh -s ", stdin=stdin_file)
            else:
                exit_status, stdout = execute_shell_command(
                    "/bin/bash {0}".format(self.action_script))

        if exit_status == 0:
            LOG.debug("success,the operation's output is: %s", stdout)
        else:
            LOG.error("the operation's error, stdout:%s, stderr:%s", stdout,
                      stderr)
Beispiel #2
0
 def rollback(self):
     if "rollback_parameter" in self._config:
         if self.connection:
             with open(self.rollback_script, "r") as stdin_file:
                 exit_status, stdout, stderr = self.connection.execute(
                     "sudo {}".format(self.rollback_param),
                     stdin=stdin_file)
         else:
             exit_status, stdout = \
                 execute_shell_command(
                     "/bin/bash {0} {1}".format(
                         self.rollback_script, self.rollback_param))
     else:
         if self.connection:
             with open(self.rollback_script, "r") as stdin_file:
                 exit_status, stdout, stderr = self.connection.execute(
                     "sudo /bin/sh -s ", stdin=stdin_file)
         else:
             exit_status, stdout = execute_shell_command(
                 "/bin/bash {0}".format(self.rollback_script))
Beispiel #3
0
    def run(self):
        if "action_parameter" in self._config:
            self.action_param = \
                build_shell_command(
                    self.actionParameter_config,
                    True if self.connection else False,
                    self.intermediate_variables)
            if self.connection:
                with open(self.action_script, "r") as stdin_file:
                    exit_status, stdout, stderr = self.connection.execute(
                        "sudo {}".format(self.action_param), stdin=stdin_file)
            else:
                exit_status, stdout = \
                    execute_shell_command(
                        "/bin/bash {0} {1}".format(
                            self.action_script, self.action_param))
        else:
            if self.connection:
                with open(self.action_script, "r") as stdin_file:
                    exit_status, stdout, stderr = self.connection.execute(
                        "sudo /bin/sh -s ", stdin=stdin_file)
            else:
                exit_status, stdout = execute_shell_command(
                    "/bin/bash {0}".format(self.action_script))

        if exit_status == 0:
            LOG.debug("success,the operation's output is: %s", stdout)
            if "return_parameter" in self._config:
                returnParameter = self._config['return_parameter']
                for key, item in returnParameter.items():
                    value = read_stdout_item(stdout, key)
                    LOG.debug("intermediate variables %s: %s", item, value)
                    self.intermediate_variables[item] = value
        else:
            LOG.error("the operation's error, stdout:%s, stderr:%s", stdout,
                      stderr)
Beispiel #4
0
 def monitor_func(self):
     if "parameter" in self._config:
         self.cmd_param = \
             build_shell_command(
                 self.parameter_config,
                 bool(self.connection),
                 self.intermediate_variables)
         cmd_remote = "sudo {}".format(self.cmd_param)
         cmd_local = "/bin/bash {0} {1}".format(self.monitor_script, self.cmd_param)
     else:
         cmd_remote = "sudo /bin/sh -s "
         cmd_local = "/bin/bash {0}".format(self.monitor_script)
     if self.connection:
         with open(self.monitor_script, "r") as stdin_file:
             exit_status, stdout, stderr = self.connection.execute(cmd_remote, stdin=stdin_file)
     else:
         exit_status, stdout = execute_shell_command(cmd_local)
     if exit_status:
         return False
     return True
Beispiel #5
0
 def test__fun_execute_shell_command_fail_cmd_exception(
         self, mock_subprocess):
     cmd = "env"
     mock_subprocess.check_output.side_effect = RuntimeError
     exitcode, output = util.execute_shell_command(cmd)
     self.assertEqual(exitcode, -1)
Beispiel #6
0
 def test__fun_execute_shell_command_successful(self, mock_subprocess):
     cmd = "env"
     mock_subprocess.check_output.return_value = (0, 'unittest')
     exitcode, output = util.execute_shell_command(cmd)
     self.assertEqual(exitcode, 0)
    def verify(self):
        if "parameter" in self._config:
            if self.connection:
                with open(self.verify_script, "r") as stdin_file:
                    exit_status, stdout, stderr = self.connection.execute(
                        "sudo {}".format(self.shell_cmd), stdin=stdin_file)
            else:
                exit_status, stdout = \
                    execute_shell_command(
                        "/bin/bash {0} {1}".format(
                            self.verify_script,
                            self.rollback_param))

            LOG.debug("action script of the operation is: %s",
                      self.verify_script)
            LOG.debug("action parameter the of operation is: %s",
                      self.shell_cmd)
        else:
            if self.connection:
                with open(self.verify_script, "r") as stdin_file:
                    exit_status, stdout, stderr = self.connection.execute(
                        "sudo /bin/bash -s ", stdin=stdin_file)
            else:
                exit_status, stdout = execute_shell_command(
                    "/bin/bash {0}".format(self.verify_script))

            LOG.debug("action script of the operation is: %s",
                      self.verify_script)

        LOG.debug("exit_status ,stdout : %s ,%s", exit_status, stdout)
        if exit_status == 0 and stdout:
            self.actualResult = stdout
            LOG.debug("verifying resultchecker: %s", self.key)
            LOG.debug("verifying resultchecker,expected: %s",
                      self.expectedResult)
            LOG.debug("verifying resultchecker,actual: %s", self.actualResult)
            LOG.debug("verifying resultchecker,condition: %s", self.condition)
            if (type(self.expectedResult) is int):
                self.actualResult = int(self.actualResult)
            if self.condition == Condition.EQUAL:
                self.success = self.actualResult == self.expectedResult
            elif self.condition == Condition.GREATERTHAN:
                self.success = self.actualResult > self.expectedResult
            elif self.condition == Condition.GREATERTHANEQUAL:
                self.success = self.actualResult >= self.expectedResult
            elif self.condition == Condition.LESSTHANEQUAL:
                self.success = self.actualResult <= self.expectedResult
            elif self.condition == Condition.LESSTHAN:
                self.success = self.actualResult < self.expectedResult
            elif self.condition == Condition.IN:
                self.success = self.expectedResult in self.actualResult
            else:
                self.success = False
                LOG.debug(
                    "error happened when resultchecker: %s Invalid condition",
                    self.key)
        else:
            self.success = False
            LOG.debug(
                "error happened when resultchecker: %s verifying the result",
                self.key)
            LOG.error(stderr)

        LOG.debug("verifying resultchecker: %s,the result is : %s", self.key,
                  self.success)
        return self.success