コード例 #1
0
ファイル: test_env.py プロジェクト: tmishina/content
 def scp_transfer_file(self, source, destination, log_file, error_msg=None):
     if not error_msg:
         error_msg = (
             "Failed to copy {source} to {destination}"
             .format(source=source, destination=destination))
     try:
         common.run_with_stdout_logging(
             "scp", tuple(self.ssh_additional_options) + (source, destination), log_file)
     except Exception as exc:
         error_msg = error_msg + ": " + str(exc)
         logging.error(error_msg)
         raise RuntimeError(error_msg)
コード例 #2
0
 def _change_variable_value(self, varname, value):
     _, xslt_filename = tempfile.mkstemp(prefix="xslt-change-value", dir="/tmp")
     template = generate_xslt_change_value_template(varname, value)
     with open(xslt_filename, "w") as fp:
         fp.write(template)
     _, temp_datastream = tempfile.mkstemp(prefix="ds-temp", dir="/tmp")
     log_file_name = os.path.join(LogHelper.LOG_DIR, "env-preparation.log")
     with open(log_file_name, "a") as log_file:
         common.run_with_stdout_logging(
                 "xsltproc", ("--output", temp_datastream, xslt_filename, self.datastream),
                 log_file)
     os.rename(temp_datastream, self.datastream)
     os.unlink(xslt_filename)
コード例 #3
0
ファイル: rule.py プロジェクト: liveaverage/content
def _apply_script(rule_dir, domain_ip, script):
    """Run particular test script on VM and log it's output."""
    machine = "{0}@{1}".format(common.REMOTE_USER, domain_ip)
    logging.debug("Applying script {0}".format(script))
    rule_name = os.path.basename(rule_dir)
    log_file_name = os.path.join(
        LogHelper.LOG_DIR, rule_name + ".prescripts.log")

    with open(log_file_name, 'a') as log_file:
        log_file.write('##### {0} / {1} #####\n'.format(rule_name, script))
        shared_dir = os.path.join(common.REMOTE_TEST_SCENARIOS_DIRECTORY, "shared")
        command = "cd {0}; SHARED={1} bash -x {2}".format(rule_dir, shared_dir, script)
        args = common.SSH_ADDITIONAL_OPTS + (machine, command)

        try:
            common.run_with_stdout_logging("ssh", args, log_file)
        except subprocess.CalledProcessError as exc:
            logging.error("Rule testing script {script} failed with exit code {rc}"
                          .format(script=script, rc=exc.returncode))
            return False
    return True
コード例 #4
0
ファイル: test_env.py プロジェクト: tmishina/content
 def execute_ssh_command(self, command, log_file, error_msg=None):
     remote_dest = "root@{ip}".format(ip=self.domain_ip)
     if not error_msg:
         error_msg = (
             "Failed to execute '{command}' on {remote_dest}"
             .format(command=command, remote_dest=remote_dest))
     try:
         stdout = common.run_with_stdout_logging(
             "ssh", tuple(self.ssh_additional_options) + (remote_dest, command), log_file)
     except Exception as exc:
         logging.error(error_msg + ": " + str(exc))
         raise RuntimeError(error_msg)
     return stdout
コード例 #5
0
 def _change_variable_value(self, varname, value):
     _, xslt_filename = tempfile.mkstemp(prefix="xslt-change-value",
                                         dir="/tmp")
     template = generate_xslt_change_value_template(varname, value)
     with open(xslt_filename, "w") as fp:
         fp.write(template)
     descriptor, temp_datastream = tempfile.mkstemp(prefix="ds-temp",
                                                    dir="/tmp")
     os.close(descriptor)
     log_file_name = os.path.join(LogHelper.LOG_DIR, "env-preparation.log")
     with open(log_file_name, "a") as log_file:
         result = common.run_with_stdout_logging(
             "xsltproc",
             ("--output", temp_datastream, xslt_filename, self.datastream),
             log_file)
         if result.returncode:
             msg = ("Error changing value of '{varname}': {stdout}".format(
                 varname=varname, stderr=result.stderr))
             raise RuntimeError(msg)
     os.rename(temp_datastream, self.datastream)
     os.unlink(xslt_filename)
コード例 #6
0
 def execute_ssh_command(self, command, log_file, error_msg_template=None):
     """
     Args:
         - command: Command to execute remotely as a single string
         - log_file
         - error_msg_template: A string that can contain references to:
             ``command``, ``remote_dest``, ``rc``, and ``stderr``
     """
     if not error_msg_template:
         error_msg_template = "Return code of '{command}' on {remote_dest} is {rc}: {stderr}"
     remote_dest = "root@{ip}".format(ip=self.domain_ip)
     result = common.run_with_stdout_logging(
         "ssh",
         tuple(self.ssh_additional_options) + (remote_dest, command),
         log_file)
     if result.returncode:
         error_msg = error_msg_template.format(command=command,
                                               remote_dest=remote_dest,
                                               rc=result.returncode,
                                               stderr=result.stderr)
         raise RuntimeError(error_msg)
     return result.stdout