How to use the aexpect.ShellStatusError 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
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 avocado-framework / avocado-vt / virttest / utils_spice.py View on Github external
def stop_vdagent(guest_session, test_timeout):
    """
    Sending commands to stop the spice-vdagentd service

    :param guest_session: ssh session of the VM
    :param test_timeout: timeout time for the cmds
    """
    cmd = "service spice-vdagentd stop"
    try:
        guest_session.cmd(cmd, print_func=logging.info,
                          timeout=test_timeout)
    except ShellStatusError:
        logging.debug("Status code of \"%s\" was not obtained, most likely"
                      "due to a problem with colored output" % cmd)
    except ShellCmdError:
        raise exceptions.TestFail("Couldn't turn off spice vdagent process")
    except Exception:
        raise exceptions.TestFail("Guest Vdagent Daemon Check failed")

    logging.debug("------------ End of guest checking for Spice Vdagent"
                  " Daemon ------------")
    wait_timeout(3)
github avocado-framework / avocado-vt / virttest / utils_sasl.py View on Github external
self.remote_auth = True
        super(VirshSessionSASL, self).__init__(virsh_exec=self.virsh_exec,
                                               remote_ip=self.remote_ip,
                                               remote_user=self.remote_user,
                                               remote_pwd=self.remote_pwd,
                                               ssh_remote_auth=self.remote_auth,
                                               auto_close=True,
                                               check_libvirtd=False)
        self.sendline('connect')
        self.sendline(self.sasl_user)
        self.sendline(self.sasl_pwd)
        # make sure session is connected successfully
        if self.cmd_status('list', timeout=60) != 0:
            logging.debug("Persistent virsh session is not responding, "
                          "libvirtd may be dead.")
            raise aexpect.ShellStatusError(virsh.VIRSH_EXEC, 'list')
github avocado-framework / avocado-vt / virttest / virsh.py View on Github external
prompt=prompt, auto_close=auto_close)

        # Handle remote session prompts:
        # 1.remote to remote with ssh
        # 2.local to remote with "virsh -c uri"
        if ssh_remote_auth or self.uri:
            # Handle ssh / password prompts
            remote.handle_prompts(self, self.remote_user, self.remote_pwd,
                                  prompt, debug=True)

        # fail if libvirtd is not running
        if self.cmd_status('list', timeout=60) != 0:
            logging.debug("Persistent virsh session is not responding, "
                          "libvirtd may be dead.")
            self.auto_close = True
            raise aexpect.ShellStatusError(virsh_exec, 'list')
github avocado-framework / avocado-vt / virttest / virt_admin.py View on Github external
# Handle remote session prompts:
        # 1.remote to remote with ssh
        # 2.local to remote with "virtadmin -c uri"
        if ssh_remote_auth or self.uri:
            # Handle ssh / password prompts
            remote.handle_prompts(self, self.remote_user, self.remote_pwd,
                                  prompt, debug=True)

        # fail if libvirtd is not running
        if check_libvirtd:
            if self.cmd_status('uri', timeout=60) != 0:
                logging.debug("Persistent virt-admin session is not responding, "
                              "libvirtd may be dead.")
                self.auto_close = True
                raise aexpect.ShellStatusError(virtadmin_exec, 'uri')
github avocado-framework / avocado-vt / virttest / utils_libguestfs.py View on Github external
libvirt_domain, inspector,
                                                  uri, mount_options, run_mode)
        self.__dict_set__('run_mode', run_mode)

        if self.get('session_id') is None:
            # set_uri does not call when INITIALIZED = False
            # and no session_id passed to super __init__
            self.new_session()

        # Check whether guestfish session is prepared.
        guestfs_session = self.open_session()
        if run_mode != "remote":
            status, output = guestfs_session.cmd_status_output('is-config', timeout=60)
            if status != 0:
                logging.debug("Persistent guestfish session is not responding.")
                raise aexpect.ShellStatusError(self.lgf_exec, 'is-config')
github avocado-framework / avocado-vt / virttest / utils_libguestfs.py View on Github external
def open_session(self):
        """
        Return session with session_id in this class.
        """
        try:
            session_id = self.__dict_get__('session_id')
            run_mode = self.get('run_mode')
            if session_id:
                try:
                    if run_mode == "remote":
                        return GuestfishRemote(a_id=session_id)
                    else:
                        return GuestfishSession(a_id=session_id)
                except aexpect.ShellStatusError:
                    # session was already closed
                    self.__dict_del__('session_id')
                    raise LibguestfsCmdError(
                        "Open session '%s' failed." % session_id)
        except KeyError:
            raise LibguestfsCmdError("No session id.")