예제 #1
0
    def _install_start_webserver(cls, ip_address, ssh_key, start_id):
        local_file = pkg_resources.resource_filename(
            'octavia_tempest_plugin.contrib.httpd', 'httpd.bin')
        dest_file = '/dev/shm/httpd.bin'

        linux_client = remote_client.RemoteClient(
            ip_address, CONF.validation.image_ssh_user, pkey=ssh_key)
        linux_client.validate_authentication()

        with tempfile.NamedTemporaryFile() as key:
            key.write(ssh_key.encode('utf-8'))
            key.flush()
            cmd = ("scp -v -o UserKnownHostsFile=/dev/null "
                   "-o StrictHostKeyChecking=no "
                   "-o ConnectTimeout={0} -o ConnectionAttempts={1} "
                   "-i {2} {3} {4}@{5}:{6}").format(
                       CONF.load_balancer.scp_connection_timeout,
                       CONF.load_balancer.scp_connection_attempts, key.name,
                       local_file, CONF.validation.image_ssh_user, ip_address,
                       dest_file)
            args = shlex.split(cmd)
            subprocess_args = {
                'stdout': subprocess.PIPE,
                'stderr': subprocess.STDOUT,
                'cwd': None
            }
            proc = subprocess.Popen(args, **subprocess_args)
            stdout, stderr = proc.communicate()
            if proc.returncode != 0:
                raise exceptions.CommandFailed(proc.returncode, cmd, stdout,
                                               stderr)
        linux_client.exec_command('sudo screen -d -m {0} -port 80 '
                                  '-id {1}'.format(dest_file, start_id))
        linux_client.exec_command('sudo screen -d -m {0} -port 81 '
                                  '-id {1}'.format(dest_file, start_id + 1))
예제 #2
0
def os_execute(remote, command, fail_ok=False, merge_stderr=False):
    command = '. openrc && {}'.format(command.encode('utf-8'))
    result = remote.execute(command)
    if not fail_ok and not result.is_ok:
        raise exceptions.CommandFailed(result['exit_code'],
                                       command.decode('utf-8'),
                                       result.stdout_string,
                                       result.stderr_string)
    output = Result()
    if merge_stderr:
        output += result.stderr_string
    return output + result.stdout_string
예제 #3
0
def execute(cmd, fail_ok=False, merge_stderr=False):
    """Executes specified command for the given action."""
    cmdlist = shlex.split(cmd)
    stdout = subprocess.PIPE
    stderr = subprocess.STDOUT if merge_stderr else subprocess.PIPE
    proc = subprocess.Popen(cmdlist, stdout=stdout, stderr=stderr)
    result, result_err = proc.communicate()
    result = result.decode('utf-8')
    if not fail_ok and proc.returncode != 0:
        raise exceptions.CommandFailed(proc.returncode, cmd, result,
                                       result_err)
    return result
예제 #4
0
 def test_command_failed_exception(self):
     returncode = 1
     cmd = "foo"
     stdout = "output"
     stderr = "error"
     try:
         raise exceptions.CommandFailed(returncode, cmd, stdout, stderr)
     except exceptions.CommandFailed as e:
         self.assertIn(str(returncode), str(e))
         self.assertIn(cmd, str(e))
         self.assertIn(stdout, str(e))
         self.assertIn(stderr, str(e))
예제 #5
0
파일: base.py 프로젝트: yaochi/tempest
def execute(cmd,
            action,
            flags='',
            params='',
            fail_ok=False,
            merge_stderr=False,
            cli_dir='/usr/bin',
            prefix=''):
    """Executes specified command for the given action.

    :param cmd: command to be executed
    :type cmd: string
    :param action: string of the cli command to run
    :type action: string
    :param flags: any optional cli flags to use
    :type flags: string
    :param params: string of any optional positional args to use
    :type params: string
    :param fail_ok: boolean if True an exception is not raised when the
                    cli return code is non-zero
    :type fail_ok: boolean
    :param merge_stderr: boolean if True the stderr buffer is merged into
                         stdout
    :type merge_stderr: boolean
    :param cli_dir: The path where the cmd can be executed
    :type cli_dir: string
    :param prefix: prefix to insert before command
    :type prefix: string
    """
    cmd = ' '.join([prefix, os.path.join(cli_dir, cmd), flags, action, params])
    cmd = cmd.strip()
    LOG.info("running: '%s'", cmd)
    if six.PY2:
        cmd = cmd.encode('utf-8')
    cmd = shlex.split(cmd)
    result = ''
    result_err = ''
    stdout = subprocess.PIPE
    stderr = subprocess.STDOUT if merge_stderr else subprocess.PIPE
    proc = subprocess.Popen(cmd, stdout=stdout, stderr=stderr)
    result, result_err = proc.communicate()
    if not fail_ok and proc.returncode != 0:
        raise exceptions.CommandFailed(proc.returncode, cmd, result,
                                       result_err)
    if six.PY2:
        return result
    else:
        return os.fsdecode(result)
    def _install_start_webserver(cls, ip_address, ssh_key, start_id):
        local_file = pkg_resources.resource_filename(
            'octavia_tempest_plugin.contrib.httpd', 'httpd.bin')
        dest_file = '/dev/shm/httpd.bin'

        linux_client = remote_client.RemoteClient(
            ip_address, CONF.validation.image_ssh_user, pkey=ssh_key)
        linux_client.validate_authentication()

        with tempfile.NamedTemporaryFile() as key:
            key.write(ssh_key.encode('utf-8'))
            key.flush()
            cmd = ("scp -v -o UserKnownHostsFile=/dev/null "
                   "-o StrictHostKeyChecking=no "
                   "-o ConnectTimeout={0} -o ConnectionAttempts={1} "
                   "-i {2} {3} {4}@{5}:{6}").format(
                       CONF.load_balancer.scp_connection_timeout,
                       CONF.load_balancer.scp_connection_attempts, key.name,
                       local_file, CONF.validation.image_ssh_user, ip_address,
                       dest_file)
            args = shlex.split(cmd)
            subprocess_args = {
                'stdout': subprocess.PIPE,
                'stderr': subprocess.STDOUT,
                'cwd': None
            }
            proc = subprocess.Popen(args, **subprocess_args)
            stdout, stderr = proc.communicate()
            if proc.returncode != 0:
                raise exceptions.CommandFailed(proc.returncode, cmd, stdout,
                                               stderr)

        # Enabling memory overcommit allows to run golang static binaries
        # compiled with a recent golang toolchain (>=1.11). Those binaries
        # allocate a large amount of virtual memory at init time, and this
        # allocation fails in tempest's nano flavor (64MB of RAM)
        # (golang issue reported in https://github.com/golang/go/issues/28114,
        # follow-up: https://github.com/golang/go/issues/28081)
        # TODO(gthiemonge): Remove this call when golang issue is resolved.
        linux_client.exec_command('sudo sh -c "echo 1 > '
                                  '/proc/sys/vm/overcommit_memory"')

        linux_client.exec_command('sudo screen -d -m {0} -port 80 '
                                  '-id {1}'.format(dest_file, start_id))
        linux_client.exec_command('sudo screen -d -m {0} -port 81 '
                                  '-id {1}'.format(dest_file, start_id + 1))
예제 #7
0
 def _cmd(self, cmd, param):
     """Executes specified command."""
     cmd = ' '.join([cmd, param])
     LOG.info("running: '%s'" % cmd)
     cmd_str = cmd
     cmd = shlex.split(cmd)
     result = ''
     result_err = ''
     try:
         stdout = subprocess.PIPE
         stderr = subprocess.PIPE
         proc = subprocess.Popen(cmd, stdout=stdout, stderr=stderr)
         result, result_err = proc.communicate()
         if proc.returncode != 0:
             LOG.debug('error of %s:\n%s' % (cmd_str, result_err))
             raise exceptions.CommandFailed(proc.returncode, cmd, result)
     finally:
         LOG.debug('output of %s:\n%s' % (cmd_str, result))
     return proc.returncode
예제 #8
0
    def test_kuryr_pod_delete(self):
        # find kuryr CNI and controller pods, delete them one by one and create
        #  a regular pod just after removal
        kube_system_pods = self.get_pod_name_list(
            namespace=CONF.kuryr_kubernetes.kube_system_namespace)
        for kuryr_pod_name in kube_system_pods:
            if kuryr_pod_name.startswith('kuryr'):
                self.delete_pod(
                    pod_name=kuryr_pod_name,
                    body={"kind": "DeleteOptions",
                          "apiVersion": "v1",
                          "gracePeriodSeconds": 0},
                    namespace=CONF.kuryr_kubernetes.kube_system_namespace)

                # make sure the kuryr pod was deleted
                pod_delete_retries = 30
                while self.get_pod_status(
                        kuryr_pod_name,
                        namespace=CONF.kuryr_kubernetes.kube_system_namespace):
                    time.sleep(1)
                    pod_delete_retries -= 1
                    if pod_delete_retries == 0:
                        raise lib_exc.TimeoutException()

                # Create a new pod while kuryr CNI or kuryr controller Pods are
                # not in the running state.
                # Check once for controller kuryr pod and once for CNI pod
                pod_name, pod = self.create_pod()
                self.addCleanup(self.delete_pod, pod_name)
                pod_fip = self.assign_fip_to_pod(pod_name)
                if not self.ping_ip_address(
                        pod_fip['floatingip']['floating_ip_address']):
                    raise lib_exc.CommandFailed()

        # Check that both kuryr-pods are up and running
        # The newly created pods are running because create_pod is written
        # that way. Will be refactored in another patch
        for new_kuryr_pod in self.get_pod_name_list(
                namespace=CONF.kuryr_kubernetes.kube_system_namespace):
            self.assertEqual("Running", self.get_pod_status(
                new_kuryr_pod,
                namespace=CONF.kuryr_kubernetes.kube_system_namespace))