How to use the aexpect.ExpectError function in aexpect

To help you get started, we’ve selected a few aexpect examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github avocado-framework / avocado-vt / virttest / virt_admin.py View on Github external
else:
                            output_slice = output[i + 1:]
                        for j in range(len(output_slice) - 1):
                            output_slice[j] = output_slice[j] + '\n'
                        for k in range(len(output_slice)):
                            out += output_slice[k]
                        return match, out
                return match, o

        # Check if the child has terminated
        if utils_misc.wait_for(lambda: not self.is_alive(), 5, 0, 0.1):
            raise aexpect.ExpectProcessTerminatedError(patterns,
                                                       self.get_status(), o)
        else:
            # This shouldn't happen
            raise aexpect.ExpectError(patterns, o)
github autotest / autotest-client-tests / virt / virttest / kvm_virtio_port.py View on Github external
def _cmd(self, cmd, timeout=10):
        """
        Execute given command inside the script's main loop.
        @param command: Command that will be executed.
        @param timeout: Timeout used to verify expected output.
        @return: Tuple (match index, data)
        """
        logging.debug("Executing '%s' on virtio_console_guest.py,"
                      " vm: %s, timeout: %s", cmd, self.vm.name, timeout)
        self.session.sendline(cmd)
        try:
            (match, data) = self.session.read_until_last_line_matches(
                                                ["PASS:", "FAIL:"], timeout)

        except aexpect.ExpectError, inst:
            match = None
            data = "Cmd process timeout. Data in console: " + inst.output

        self.vm.verify_kernel_crash()

        return (match, data)
github avocado-framework / avocado-vt / virttest / qemu_virtio_port.py View on Github external
patterns = ("^PASS:", "^FAIL:")
        logging.debug("Executing '%s' on virtio_console_guest.py,"
                      " vm: %s, timeout: %s", cmd, self.vm.name, timeout)
        self.session.sendline(cmd)
        try:
            (match, data) = self.session.read_until_any_line_matches(patterns,
                                                                     timeout=timeout)
            if patterns[match].startswith('^PASS:'):
                match = 0
            elif patterns[match].startswith('^FAIL:'):
                match = 1
            else:
                data = ("Incorrect pattern %s. Data in console:\n%s"
                        % (patterns[match], data))
                match = None
        except aexpect.ExpectError as inst:
            match = None
            data = "Cmd process timeout. Data in console:\n" + inst.output

        self.vm.verify_kernel_crash()

        return (match, data)
github avocado-framework / avocado-vt / virttest / virsh.py View on Github external
else:
                            output_slice = output[i + 1:]
                        for j in range(len(output_slice) - 1):
                            output_slice[j] = output_slice[j] + '\n'
                        for k in range(len(output_slice)):
                            out += output_slice[k]
                        return match, out
                return match, o

        # Check if the child has terminated
        if utils_misc.wait_for(lambda: not self.is_alive(), 5, 0, 0.1):
            raise aexpect.ExpectProcessTerminatedError(patterns,
                                                       self.get_status(), o)
        else:
            # This shouldn't happen
            raise aexpect.ExpectError(patterns, o)
github avocado-framework / avocado-vt / virttest / utils_net.py View on Github external
print_func=output_func)
        except aexpect.ShellTimeoutError:
            # Send ctrl+c (SIGINT) through ssh session
            session.send("\003")
            try:
                output2 = session.read_up_to_prompt(print_func=output_func)
                output += output2
            except aexpect.ExpectTimeoutError as e:
                output += e.output
                # We also need to use this session to query the return value
                session.send("\003")

        session.sendline(session.status_test_command)
        try:
            o2 = session.read_up_to_prompt()
        except aexpect.ExpectError:
            status = -1
        else:
            try:
                status = int(re.findall("\d+", o2)[0])
            except Exception:
                status = -1

        return status, output
github avocado-framework / avocado-vt / virttest / utils_test / libvirt.py View on Github external
logging.debug("Got 'login:', sending '%s'", user)
                session.sendline(user)
            elif match == 2:
                if debug:
                    logging.debug("Got 'Password:', sending '%s'", passwd)
                session.sendline(passwd)
            elif match == 3:
                if debug:
                    logging.debug("Got Shell prompt -- logged in")
                break

        status, output = session.cmd_status_output(console_cmd)
        logging.info("output of command:\n%s", output)
        session.close()
    except (aexpect.ShellError,
            aexpect.ExpectError) as detail:
        log = session.get_output()
        logging.error("Verify virsh console failed:\n%s\n%s", detail, log)
        session.close()
        return False

    if not re.search("processor", output):
        logging.error("Verify virsh console failed: Result does not match.")
        return False

    return True
github autotest / autotest / client / virt / virt_test_utils.py View on Github external
print_func=output_func)
        except aexpect.ShellTimeoutError:
            # Send ctrl+c (SIGINT) through ssh session
            session.send("\003")
            try:
                output2 = session.read_up_to_prompt(print_func=output_func)
                output += output2
            except aexpect.ExpectTimeoutError, e:
                output += e.output
                # We also need to use this session to query the return value
                session.send("\003")

        session.sendline(session.status_test_command)
        try:
            o2 = session.read_up_to_prompt()
        except aexpect.ExpectError:
            status = -1
        else:
            try:
                status = int(re.findall("\d+", o2)[0])
            except Exception:
                status = -1

        return status, output
github libvirt / libvirt-test-API / libvirttestapi / repos / domain / send_key.py View on Github external
10, internal_timeout=1)
            if match == 0:
                logger.debug("Got '^]', sending '\\n'")
                session.sendline()
            elif match == 1:
                logger.debug("Got 'login:', sending '%s'", username)
                session.sendline(username)
            elif match == 2:
                logger.debug("Got 'Password:', sending '%s'", password)
                session.sendline(password)
            elif match == 3:
                logger.debug("Got Shell prompt -- logged in")
                break
        session.close()
    except (aexpect.ShellError,
            aexpect.ExpectError) as detail:
        if 'Shell process terminated' not in str(detail):
            logger.error('Expect shell terminated, but found %s'
                         % detail)
        log = session.get_output()
        logger.error("failed login guest: %s" % log)
        session.close()
# end test