How to use the aexpect.ShellProcessTerminatedError 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 / utils_test / libvirt.py View on Github external
:param vm: the vm object
    :param vm_state: the given vm state string "shut off", "running"
                     "paused", "halt" or "pm_suspend"
    """
    # reset domain state
    if vm.is_alive():
        vm.destroy(gracefully=False)
    if not vm_state == "shut off":
        vm.start()
        session = vm.wait_for_login()
    if vm_state == "paused":
        vm.pause()
    elif vm_state == "halt":
        try:
            session.cmd("halt")
        except (aexpect.ShellProcessTerminatedError, aexpect.ShellStatusError):
            # The halt command always gets these errors, but execution is OK,
            # skip these errors
            pass
    elif vm_state == "pm_suspend":
        # Execute "pm-suspend-hybrid" command directly will get Timeout error,
        # so here execute it in background, and wait for 3s manually
        if session.cmd_status("which pm-suspend-hybrid"):
            raise exceptions.TestSkipError("Cannot execute this test for domain"
                                           " doesn't have pm-suspend-hybrid command!")
        session.cmd("pm-suspend-hybrid &")
        time.sleep(3)
github avocado-framework / avocado-vt / virttest / virt_admin.py View on Github external
def close_session(self):
        """
        If a persistent session exists, close it down.
        """
        try:
            session_id = self.__dict_get__('session_id')
            if session_id:
                try:
                    existing = VirtadminSession(a_id=session_id)
                    if existing.is_alive():
                        self.counter_decrease()
                except (aexpect.ShellStatusError,
                        aexpect.ShellProcessTerminatedError):
                    # session was already closed
                    pass  # don't check is_alive or update counter
                self.__dict_del__("session_id")
        except KeyError:
            # Allow other exceptions to be raised
            pass  # session was closed already
github autotest / autotest / client / virt / virt_test_utils.py View on Github external
session.cmd_output("./autotest control", timeout=timeout,
                                   print_func=logging.info)
        finally:
            logging.info("------------- End of test output ------------")
            if migrate_background and bg:
                bg.join()
    except aexpect.ShellTimeoutError:
        if vm.is_alive():
            get_results(destination_autotest_path)
            get_results_summary()
            raise error.TestError("Timeout elapsed while waiting for job to "
                                  "complete")
        else:
            raise error.TestError("Autotest job on guest failed "
                                  "(VM terminated during job)")
    except aexpect.ShellProcessTerminatedError:
        get_results(destination_autotest_path)
        raise error.TestError("Autotest job on guest failed "
                              "(Remote session terminated during job)")

    get_results(destination_autotest_path)
    results = get_results_summary()

    # Make a list of FAIL/ERROR/ABORT results (make sure FAIL results appear
    # before ERROR results, and ERROR results appear before ABORT results)
    bad_results = [r[0] for r in results if r[1] == "FAIL"]
    bad_results += [r[0] for r in results if r[1] == "ERROR"]
    bad_results += [r[0] for r in results if r[1] == "ABORT"]

    # Fail the test if necessary
    if not results:
        raise error.TestFail("Autotest control file run did not produce any "
github avocado-framework / avocado-vt / virttest / utils_test / __init__.py View on Github external
if os.path.isdir(server_result):
                    utils_misc.safe_rmdir(server_result)
                # Remove the control file for server.
                if os.path.exists(server_control_path):
                    os.remove(server_control_path)

    except aexpect.ShellTimeoutError:
        if vm.is_alive():
            get_results(destination_autotest_path)
            get_results_summary()
            raise exceptions.TestError("Timeout elapsed while waiting for job to "
                                       "complete")
        else:
            raise exceptions.TestError("Autotest job on guest failed "
                                       "(VM terminated during job)")
    except aexpect.ShellProcessTerminatedError:
        if ignore_session_terminated:
            try:
                vm.verify_alive()
            except Exception:
                get_results(destination_autotest_path)
                raise exceptions.TestError("Autotest job on guest failed "
                                           "(VM terminated during job)")
            logging.debug("Wait for autotest job finished on guest.")
            session.close()
            session = vm.wait_for_login()
            while time.time() < start_time + timeout:
                ps_cmd = "ps ax"
                _, processes = session.cmd_status_output(ps_cmd)
                if "autotest-local" not in processes:
                    logging.debug("Autotest job finished on guest")
                    break
github avocado-framework / avocado-vt / virttest / virsh.py View on Github external
def close_session(self):
        """
        If a persistent session exists, close it down.
        """
        try:
            session_id = self.__dict_get__('session_id')
            if session_id:
                try:
                    existing = VirshSession(a_id=session_id)
                    if existing.is_alive():
                        self.counter_decrease()
                except (aexpect.ShellStatusError,
                        aexpect.ShellProcessTerminatedError):
                    # session was already closed
                    pass  # don't check is_alive or update counter
                self.__dict_del__("session_id")
        except KeyError:
            # Allow other exceptions to be raised
            pass  # session was closed already
github avocado-framework / avocado-vt / virttest / utils_test / __init__.py View on Github external
if os.path.isdir(server_result):
                    utils_misc.safe_rmdir(server_result)
                # Remove the control file for server.
                if os.path.exists(server_control_path):
                    os.remove(server_control_path)

    except aexpect.ShellTimeoutError:
        if vm.is_alive():
            get_results(destination_autotest_path)
            get_results_summary()
            raise exceptions.TestError("Timeout elapsed while waiting "
                                       "for job to complete")
        else:
            raise exceptions.TestError("Autotest job on guest failed "
                                       "(VM terminated during job)")
    except aexpect.ShellProcessTerminatedError:
        if ignore_session_terminated:
            try:
                vm.verify_alive()
            except Exception:
                get_results(destination_autotest_path)
                raise exceptions.TestError("Autotest job on guest failed "
                                           "(VM terminated during job)")
            logging.debug("Wait for autotest job finished on guest.")
            session.close()
            session = vm.wait_for_login()
            while time.time() < start_time + timeout:
                ps_cmd = "ps ax"
                _, processes = session.cmd_status_output(ps_cmd)
                if "autotest-local" not in processes:
                    logging.debug("Autotest job finished on guest")
                    break
github avocado-framework / avocado-vt / virttest / utils_libguestfs.py View on Github external
def close_session(self):
        """
        If a persistent session exists, close it down.
        """
        try:
            run_mode = self.get('run_mode')
            existing = self.open_session()
            # except clause exits function
            # Try to end session with inner command 'quit'
            try:
                existing.cmd("quit")
            # It should jump to exception followed normally
            except aexpect.ShellProcessTerminatedError:
                self.__class__.SESSION_COUNTER -= 1
                self.__dict_del__('session_id')
                return  # guestfish session was closed normally
            # Close with 'quit' did not respond
            # So close with aexpect functions
            if run_mode != "remote":
                if existing.is_alive():
                    # try nicely first
                    existing.close()
                    if existing.is_alive():
                        # Be mean, incase it's hung
                        existing.close(sig=signal.SIGTERM)
                    # Keep count:
                    self.__class__.SESSION_COUNTER -= 1
                    self.__dict_del__('session_id')
        except LibguestfsCmdError: