How to use the aexpect.ShellError 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
break
            if (patterns_list_len > 5):
                extra_len = len(patterns_extra_dict)
                index_in_extra_dict = match + extra_len
                key = patterns_extra_dict.keys()[index_in_extra_dict]
                value = patterns_extra_dict.get(key, "")
                logging.info("Matched '%s', details:<%s>", key, text)
                session.sendline(value)
                continue
            else:
                logging.error("The real prompt text: <%s>", text)
                break

        session.close()
        return True
    except (aexpect.ShellError, aexpect.ExpectError) as details:
        log = session.get_output()
        session.close()
        logging.error("Failed to connect libvirtd: %s\n%s", details, log)
        return False
github avocado-framework / avocado-vt / virttest / utils_netperf.py View on Github external
def install(self, install, compile_option):
        cmd = "which netperf"
        try:
            status, netperf = self.session.cmd_status_output(cmd)
        except aexpect.ShellError:
            status = 1
        if not status:
            self.netperf_path = netperf.rstrip()
            cmd = "which netserver"
            self.netserver_path = self.session.cmd_output(cmd).rstrip()
            install = False
        if install:
            self.build_tool = True
            self.pull_file(self.netperf_source)
            self.push_file(self.netperf_source)
            if self.pack_suffix:
                logging.debug("Compiling netserver from source")
                self.pack_compile(compile_option)

        msg = "Using local netperf: %s and %s" % (self.netperf_path,
                                                  self.netserver_path)
github autotest / autotest / client / virt / virt_test_utils.py View on Github external
'global_config.ini')
    vm.copy_files_to(g_path, global_config_guest)
    os.unlink(g_path)

    vm.copy_files_to(control_path,
                     os.path.join(destination_autotest_path, 'control'))

    # Run the test
    logging.info("Running autotest control file %s on guest, timeout %ss",
                 os.path.basename(control_path), timeout)
    session.cmd("cd %s" % destination_autotest_path)
    try:
        session.cmd("rm -f control.state")
        session.cmd("rm -rf results/*")
        session.cmd("rm -rf tmp/*")
    except aexpect.ShellError:
        pass
    try:
        bg = None
        try:
            logging.info("---------------- Test output ----------------")
            if migrate_background:
                mig_timeout = float(params.get("mig_timeout", "3600"))
                mig_protocol = params.get("migration_protocol", "tcp")

                bg = utils.InterruptedThread(session.cmd_output,
                                      kwargs={'cmd': "./autotest control",
                                              'timeout': timeout,
                                              'print_func': logging.info})

                bg.start()
github autotest / autotest / client / virt / libvirt_monitor.py View on Github external
if self.driver is None:
            uri = utils.system_output('%s uri' % self.virsh_exec)
        else:
            uri = "%s+ssh://%s@%s/system" % (self.driver, self.username,
                                             self.host)

        command = "%s --connect  %s" % (self.virsh_exec, uri)

        session = aexpect.ShellSession(command, linesep=self.linesep,
                                       prompt=self.prompt)

        if self.username is not None:
            try:
                remote._remote_login(session, self.username, self.password,
                                          self.prompt, timeout)
            except aexpect.ShellError:
                session.close()
                session = None

        return session
github avocado-framework / avocado-vt / virttest / utils_conn.py View on Github external
libvirtd_service.stop()
                        process.run("systemctl mask libvirtd.socket", shell=True)
                        process.run("systemctl mask libvirtd-admin.socket", shell=True)
                        process.run("systemctl mask libvirtd-ro.socket", shell=True)
                        process.run("systemctl mask libvirtd-tcp.socket", shell=True)
                        process.run("systemctl mask libvirtd-tls.socket", shell=True)
                        process.run("systemctl daemon-reload", shell=True)
                    else:
                        process.run("systemctl stop libvirtd.socket", shell=True)
                        libvirtd_service.stop()
                        process.run("systemctl daemon-reload", shell=True)
                        process.run("systemctl start libvirtd.socket", shell=True)
                    libvirtd_service.start()
                else:
                    libvirtd_service.restart()
            except (remote.LoginError, aexpect.ShellError,
                    process.CmdError) as detail:
                raise ConnServerRestartError(detail)

        logging.debug("UNIX connection setup successfully.")
github avocado-framework / avocado-vt / virttest / utils_test / __init__.py View on Github external
current_md5 = crypto.hash_file(host_path, algorithm="md5")

        error_context.context("Compare md5sum between original file and "
                              "transferred file", logging.info)
        if original_md5 != current_md5:
            raise exceptions.TestFail("File changed after transfer host -> guest "
                                      "and guest -> host")
    finally:
        try:
            os.remove(host_path)
        except OSError as detail:
            logging.warn("Could not remove temp files in host: '%s'", detail)
        logging.info('Cleaning temp file on guest')
        try:
            session.cmd("%s %s" % (clean_cmd, guest_path))
        except aexpect.ShellError as detail:
            logging.warn("Could not remove temp files in guest: '%s'", detail)
        finally:
            session.close()
github avocado-framework / avocado-vt / virttest / utils_test / __init__.py View on Github external
throughput = filesize / (t_end - t_begin)
        logging.info("File transfer guest -> host succeed, "
                     "estimated throughput: %.2fMB/s", throughput)

        error_context.context("Compare md5sum between original file and"
                              " transferred file", logging.info)
        if (crypto.hash_file(host_path, algorithm="md5") !=
                crypto.hash_file(host_path2, algorithm="md5")):
            raise exceptions.TestFail("File changed after transfer host -> guest "
                                      "and guest -> host")

    finally:
        logging.info('Cleaning temp file on guest')
        try:
            session.cmd("%s %s" % (clean_cmd, guest_path))
        except aexpect.ShellError, detail:
            logging.warn("Could not remove temp files in guest: '%s'", detail)

        logging.info('Cleaning temp files on host')
        try:
            os.remove(host_path)
            os.remove(host_path2)
        except OSError:
            pass
        session.close()
github libvirt / libvirt-test-API / repos / domain / send_key.py View on Github external
r"[P|p]assword:", session.prompt],
                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
github avocado-framework / avocado-vt / virttest / utils_net.py View on Github external
mac_regex = "|".join("(%s)" % mac for mac in macs)
        regex = re.compile(r"\b%s\b.*\b(%s)\b" % (ip, mac_regex), re.I)
        arping_bin = utils_path.find_command("arping")
        if session:
            arping_bin = func("which arping", timeout=timeout, **dargs)
        cmd = "%s --help" % arping_bin
        if "-C count" in func(cmd, timeout=timeout, **dargs):
            regex = re.compile(r"\b%s\b.*\b(%s)" % (mac_regex, ip), re.I)
            arping_cmd = "%s -C1 -c3 -w%d -I %s %s" % (arping_bin, int(timeout),
                                                       dev, ip)
        else:
            arping_cmd = "%s -f -c3 -w%d -I %s %s" % (arping_bin, int(timeout),
                                                      dev, ip)
        try:
            o = func(arping_cmd, timeout=timeout, **dargs)
        except (process.CmdError, aexpect.ShellError):
            return False
        return bool(regex.search(o))
github libvirt / libvirt-test-API / libvirttestapi / repos / domain / send_key.py View on Github external
r"[P|p]assword:", session.prompt],
                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