Пример #1
0
 def get_BMC_host(self):
     try:
         bmc_ip = settings.get_value('BMCER', 'host', type=str)
         port = settings.get_value('BMCER', 'port', type=int)
         user = settings.get_value('BMCER', 'user', type=str)
         passwd = settings.get_value('BMCER', 'password', type=str)
         command = settings.get_value('BMCER', 'command', type=str)
     except Exception as e:
         raise error.ServRunError(e.args[0], e.args[1])
     else:
         self.command = command
         try:
             bmc_host = host_factory.create_host(bmc_ip, user, passwd, port)
         except Exception as e:
             raise error.ServRunError(e.args[0], e.args[1])
         else:
             self.host = bmc_host
Пример #2
0
    def send_file(self,
                  source,
                  dest,
                  delete_dest=False,
                  preserve_symlinks=False):
        """
        Copy files from a local path to the remote host.
        """
        self.start_master_ssh()

        if isinstance(source, basestring):
            source_is_dir = os.path.isdir(source)
            source = [source]
        remote_dest = self._encode_remote_paths([dest])

        # if rsync is diabled or fails, try scp
        try_scp = True

        if try_scp:
            # scp has no equivalent to --delete, just drop the entire dest dir
            if delete_dest:
                dest_exists = False
                try:
                    self.run("test -x %s" % dest)
                    dest_exists = True
                except error.ServRunError:
                    pass

                dest_is_dir = False
                if dest_exists:
                    try:
                        self.run("test -d %s" % dest)
                        dest_is_dir = True
                    except error.ServRunError:
                        pass

                # if there is a list of more than one path, destination *has*
                # to be a dir.It therr's a single path being transferred and
                # it is a dir, the destination also has to be a dir
                if len(source) > 1 and source_is_dir:
                    dest_is_dir = True

                if dest_exists and dest_is_dir:
                    cmd = "rm -fr %s && mkdir %s" % (dest, dest)
                elif not dest_exists and dest_is_dir:
                    cmd = "mkdir %s" % dest
                    self.run(cmd)

            local_sources = self._make_rsync_compatible_source(source, True)
            if local_sources:
                scp = self._make_scp_cmd(local_sources, remote_dest)
                try:
                    utils.run(scp)  # utils.run
                except error.CmdError, e:
                    raise error.ServRunError(e.args[0], e.args[1])
Пример #3
0
    def remote_BMC_operate(self):
        returncode = -1

        try:
            self.get_BMC_host()
        except Exception as e:
            return returncode

        if not self.host or not self.command:
            return returncode

        try:
            result = self.host.run(self.command)
        except error.CmdError, e:
            raise error.ServRunError(e.args[0], e.args[1])
Пример #4
0
 def run_commands(self, bench_name, cmd_sec_name):
     returncode = -1
     output = ''
     pwd = os.getcwd()
     try:
         # the commands is multiple lines, and was included by Quotation
         try:
             logging.debug("the actual commands running in local is: %s" %
                           cmd_sec_name)
             test_case_dir = os.path.join(caliper_path.BENCHS_DIR,
                                          bench_name, 'tests')
             cmd_sec_name_tmp_file = os.path.join(Folder.workspace,
                                                  Folder.name,
                                                  cmd_sec_name + '_tmp.log')
             subprocess.call("echo '$$ %s RUN START' >> %s" %
                             (cmd_sec_name, cmd_sec_name_tmp_file),
                             shell=True)
             os.chdir(test_case_dir)
             result = subprocess.call(
                 'ansible-playbook -i %s %s.yml --extra-vars "hosts=%s" -u %s>> %s 2>&1'
                 % (Folder.project_config, cmd_sec_name, self.host,
                    getpass.getuser(), cmd_sec_name_tmp_file),
                 stdout=subprocess.PIPE,
                 shell=True)
             subprocess.call("echo '$$ %s RUN STOP' >> %s" %
                             (cmd_sec_name, cmd_sec_name_tmp_file),
                             shell=True)
             subprocess.call(
                 "echo '==================================' >> %s" %
                 (cmd_sec_name_tmp_file),
                 shell=True)
             server_utils.file_copy(Folder.caliper_run_log_file,
                                    cmd_sec_name_tmp_file, 'a+')
             if os.path.exists(cmd_sec_name_tmp_file):
                 os.remove(cmd_sec_name_tmp_file)
         except error.CmdError, e:
             raise error.ServRunError(e.args[0], e.args[1])
     except Exception, e:
         logging.debug(e)
Пример #5
0
    def _run(self, command, timeout, ignore_status, stdout, stderr,
             connect_timeout, env, options, stdin, args):
        """Helper function for run"""
        ssh_cmd = self.ssh_command(connect_timeout, options)
        if not env.strip():
            env = ""
        else:
            env = "export %s;" % env

        for arg in args:
            command += ' "%s"' % utils.sh_escape(arg)

        full_cmd = '%s "%s %s"' % (ssh_cmd, env, utils.sh_escape(command))
        result = utils.run(full_cmd,
                           timeout,
                           True,
                           stdout,
                           stderr,
                           verbose=False,
                           stdin=stdin,
                           stderr_is_expected=ignore_status)
        # the error message will show up in band(indistinguishable from stuff
        # sent through the SSH connection). so we hace the remote computer
        # echo the message "Connected." before running any command.
        if result.exit_status == 255:
            if re.search(
                    r'^ssh: connect to the host .* port .*: '
                    r'Connection timed out\r$', result.stderr):
                raise error.ServSSHTimeour("ssh timed out", result)
            if "Permission Denied." in result.stderr:
                msg = "ssh permission denied"
                raise error.ServSSHPemissionDenidError(msg, result)

        if not ignore_status and result.exit_status > 0:
            raise error.ServRunError("command execution error", result)

        return result
Пример #6
0
 def run(self,
         command,
         timeout=14400,
         ignore_status=False,
         stdout_tee=utils.TEE_TO_LOGS,
         stderr_tee=utils.TEE_TO_LOGS,
         connect_timeout=30,
         options='',
         stdin=None,
         verbose=True,
         args=()):
     """
     run a command on the remote host
     """
     if verbose:
         logging.debug("Running (ssh) '%s'" % command)
     self.start_master_ssh()
     env = " ".join("=".join(pair) for pair in self.env.iteritems())
     try:
         return self._run(command, timeout, ignore_status, stdout_tee,
                          stderr_tee, connect_timeout, env, options, stdin,
                          args)
     except error.CmdError, cmderr:
         raise error.ServRunError(cmderr.args[0], cmderr.args[1])
Пример #7
0
def nuke_pid(pid, signal_queue=(signal.SIGTERM, signal.SIGKILL)):
    for sig in signal_queue:
        if signal_pid(pid, sig):
            return
    raise error.ServRunError("Could not kill %d" % pid, None)
Пример #8
0
def get_local_machine_arch():
    try:
        arch_result = run("/bin/uname -a")
    except error.CmdError, e:
        raise error.ServRunError(e.args[0], e.args[1])
Пример #9
0
def get_host_name(host):
    try:
        arch_result = host.run("/bin/uname -a")
    except error.CmdError, e:
        raise error.ServRunError(e.args[0], e.args[1])
Пример #10
0
def get_target_exec_dir(target):
    try:
        target_arch = get_host_arch(target)
    except error.ServUnsupportedError, e:
        raise error.ServRunError(e.args[0], e.args[1])
Пример #11
0
import os
import re

from caliper.server.shared.utils import *
from caliper.server.shared import error
from caliper.server.shared import caliper_path
from caliper.server.shared.settings import settings


def get_target_exec_dir(target):
    try:
        target_arch = get_host_arch(target)
    except error.ServUnsupportedError, e:
        raise error.ServRunError(e.args[0], e.args[1])
    except error.ServRunError, e:
        raise error.ServRunError(e.args[0], e.args[1])
    target_execution_dir = os.path.abspath(
        os.path.join(caliper_path.GEN_DIR, target_arch))
    return target_execution_dir


def get_host_arch(host):
    try:
        arch_result = host.run("/bin/uname -a")
    except error.CmdError, e:
        raise error.ServRunError(e.args[0], e.args[1])

    else:
        returncode = arch_result.exit_status
        if returncode == 0:
            output = arch_result.stdout