How to use the aexpect.run_bg 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 / qemu_devices / qdevices.py View on Github external
def _start_daemon(self):
        """Start the virtiofs daemon in background."""
        if self._daemon_alive():
            return

        fsd_cmd = '%s --socket-path=%s' % (self.get_param('binary'),
                                           self.get_param('sock_path'))
        fsd_cmd += ' -o source=%s' % self.get_param('source')
        fsd_cmd += ' -d'

        if self.get_param('extra_options'):
            fsd_cmd += self.get_param('extra_options')

        logging.info('Running virtiofs daemon command %s.', fsd_cmd)
        self._daemon_process = aexpect.run_bg(fsd_cmd, None,
                                              self._handle_log,
                                              auto_close=False)
        status_active = 'Waiting for vhost-user socket connection'
        self._daemon_process.read_until_any_line_matches(status_active,
                                                         timeout=5)
        logging.info("Created virtiofs daemon process with parent PID %d.",
                     self._daemon_process.get_pid())
github avocado-framework / avocado-vt / virttest / utils_net.py View on Github external
def raw_ping(command, timeout, session, output_func):
    """
    Low-level ping command execution.

    :param command: Ping command.
    :param timeout: Timeout of the ping command.
    :param session: Local executon hint or session to execute the ping command.
    """
    if session is None:
        logging.info("The command of Ping is: %s", command)
        process = aexpect.run_bg(command, output_func=output_func,
                                 timeout=timeout)

        # Send SIGINT signal to notify the timeout of running ping process,
        # Because ping have the ability to catch the SIGINT signal so we can
        # always get the packet loss ratio even if timeout.
        if process.is_alive():
            utils_misc.kill_process_tree(process.get_pid(), signal.SIGINT)

        status = process.get_status()
        output = process.get_output()

        process.close()
        return status, output
    else:
        output = ""
        try:
github avocado-framework / avocado-vt / virttest / utils_test / __init__.py View on Github external
if copy_only:
        return ("python -x %s/autotest-local --verbose %s/control" %
                (destination_autotest_path, destination_autotest_path))

    # Run the test
    logging.info("Running autotest control file %s on guest, timeout %ss",
                 os.path.basename(control_path), timeout)

    # Start a background job to run server process if needed.
    server_process = None
    if server_control_path:
        job_tag = os.path.basename(server_control_path)
        command = ("python -x %s %s --verbose -t %s" % (autotest_local_path,
                                                        server_control_path,
                                                        job_tag))
        server_process = aexpect.run_bg(command)

    try:
        bg = None
        try:
            start_time = time.time()
            logging.info("---------------- Test output ----------------")
            if migrate_background:
                mig_timeout = float(params.get("mig_timeout", "3600"))
                mig_protocol = params.get("migration_protocol", "tcp")
                cmd = "python -x ./autotest-local control"
                kwargs = {'cmd': cmd,
                          'timeout': timeout,
                          'print_func': logging.info}
                bg = utils_misc.InterruptedThread(session.cmd_output,
                                                  kwargs=kwargs)
                bg.start()
github autotest / autotest / client / virt / virt_test_utils.py View on Github external
def raw_ping(command, timeout, session, output_func):
    """
    Low-level ping command execution.

    @param command: Ping command.
    @param timeout: Timeout of the ping command.
    @param session: Local executon hint or session to execute the ping command.
    """
    if session is None:
        process = aexpect.run_bg(command, output_func=output_func,
                                        timeout=timeout)

        # Send SIGINT signal to notify the timeout of running ping process,
        # Because ping have the ability to catch the SIGINT signal so we can
        # always get the packet loss ratio even if timeout.
        if process.is_alive():
            virt_utils.kill_process_tree(process.get_pid(), signal.SIGINT)

        status = process.get_status()
        output = process.get_output()

        process.close()
        return status, output
    else:
        output = ""
        try:
github avocado-framework / avocado-vt / virttest / utils_test / __init__.py View on Github external
# Check copy_only.
    if copy_only:
        return ("%s/autotest-local --verbose %s/control" %
                (destination_autotest_path, destination_autotest_path))

    # Run the test
    logging.info("Running autotest control file %s on guest, timeout %ss",
                 os.path.basename(control_path), timeout)

    # Start a background job to run server process if needed.
    server_process = None
    if server_control_path:
        command = ("%s %s --verbose -t %s" % (autotest_local_path,
                                              server_control_path,
                                              os.path.basename(server_control_path)))
        server_process = aexpect.run_bg(command)

    try:
        bg = None
        try:
            start_time = time.time()
            logging.info("---------------- Test output ----------------")
            if migrate_background:
                mig_timeout = float(params.get("mig_timeout", "3600"))
                mig_protocol = params.get("migration_protocol", "tcp")

                bg = utils_misc.InterruptedThread(session.cmd_output,
                                                  kwargs={'cmd': "./autotest-local "
                                                          " control",
                                                          'timeout': timeout,
                                                          'print_func': logging.info})
github autotest / autotest / client / virt / kvm_vm.py View on Github external
proxy_helper_name)
                if not proxy_helper_cmd:
                    raise virt_vm.VMCreateError("Proxy command not specified")

                p9_export_dir = params.get("9p_export_dir")
                if not p9_export_dir:
                    raise virt_vm.VMCreateError("Export dir not specified")

                proxy_helper_cmd += " -p " + p9_export_dir
                proxy_helper_cmd += " -u 0 -g 0"
                p9_socket_name = params.get("9p_socket_name")
                proxy_helper_cmd += " -s " + p9_socket_name
                proxy_helper_cmd += " -n"

                logging.info("Running Proxy Helper:\n%s", proxy_helper_cmd)
                self.process = aexpect.run_bg(proxy_helper_cmd, None,
                                              logging.info,
                                              "[9p proxy helper]")

            logging.info("Running qemu command (reformatted):")
            for item in qemu_command.replace(" -", " \n    -").splitlines():
                logging.info("%s", item)
            self.qemu_command = qemu_command
            self.process = aexpect.run_bg(qemu_command, None,
                                          logging.info, "[qemu output] ")

            # test doesn't need to hold tapfd's open
            for nic in self.virtnet:
                if nic.has_key('tapfd_id'): # implies bridge/tap
                    try:
                        os.close(int(nic.tapfd))
                        # qemu process retains access via open file
github avocado-framework / avocado-vt / virttest / qemu_vm.py View on Github external
proxy_helper_cmd += " -p " + p9_export_dir
                proxy_helper_cmd += " -u 0 -g 0"
                p9_socket_name = params.get("9p_socket_name")
                proxy_helper_cmd += " -s " + p9_socket_name
                proxy_helper_cmd += " -n"

                logging.info("Running Proxy Helper:\n%s", proxy_helper_cmd)
                self.process = aexpect.run_bg(proxy_helper_cmd, None,
                                              logging.info,
                                              "[9p proxy helper]",
                                              auto_close=False)

            logging.info("Running qemu command (reformatted):\n%s",
                    qemu_command.replace(" -", " \\\n    -"))
            self.qemu_command = qemu_command
            self.process = aexpect.run_bg(qemu_command, None,
                                          logging.info, "[qemu output] ",
                                          auto_close=False)

            # test doesn't need to hold tapfd's open
            for nic in self.virtnet:
                if nic.has_key('tapfd'): # implies bridge/tap
                    try:
                        os.close(int(nic.tapfd))
                        # qemu process retains access via open file
                        # remove this attribute from virtnet because
                        # fd numbers are not always predictable and
                        # vm instance must support cloning.
                        del nic['tapfd']
                    # File descriptor is already closed
                    except OSError:
                        pass
github autotest / autotest-client-tests / virt / virttest / kvm_vm.py View on Github external
proxy_helper_name)
                if not proxy_helper_cmd:
                    raise virt_vm.VMCreateError("Proxy command not specified")

                p9_export_dir = params.get("9p_export_dir")
                if not p9_export_dir:
                    raise virt_vm.VMCreateError("Export dir not specified")

                proxy_helper_cmd += " -p " + p9_export_dir
                proxy_helper_cmd += " -u 0 -g 0"
                p9_socket_name = params.get("9p_socket_name")
                proxy_helper_cmd += " -s " + p9_socket_name
                proxy_helper_cmd += " -n"

                logging.info("Running Proxy Helper:\n%s", proxy_helper_cmd)
                self.process = aexpect.run_bg(proxy_helper_cmd, None,
                                              logging.info,
                                              "[9p proxy helper]")

            logging.info("Running qemu command (reformatted):")
            for item in qemu_command.replace(" -", " \n    -").splitlines():
                logging.info("%s", item)
            self.qemu_command = qemu_command
            self.process = aexpect.run_bg(qemu_command, None,
                                          logging.info, "[qemu output] ")

            # test doesn't need to hold tapfd's open
            for nic in self.virtnet:
                if nic.has_key('tapfd_id'): # implies bridge/tap
                    try:
                        os.close(int(nic.tapfd))
                        # qemu process retains access via open file