Пример #1
0
def run(test, params, env):
    """
    Run various regression tests and check whether libvirt daemon crashes.
    """
    func_name = 'run_' + params.get("func_name", "default")
    post_func_name = 'post_' + params.get("func_name", "default")
    repeat = int(params.get("repeat", "1"))
    vm_name = params.get("main_vm", "virt-tests-vm1")
    bug_url = params.get("bug_url", None)
    vm = env.get_vm(vm_name)
    # Run virtlogd foreground
    try:
        path.find_command('virtlogd')
        process.run("systemctl stop virtlogd", ignore_status=True)
        process.run("virtlogd -d")
    except path.CmdNotFoundError:
        pass
    libvirtd = LibvirtdSession(gdb=True)
    serv_tmp = "libvirt" if libvirtd.service_exec == "libvirtd" else libvirtd.service_exec
    process.run("rm -rf /var/run/libvirt/%s-*" % serv_tmp,
                shell=True,
                ignore_status=True)
    try:
        libvirtd.start()

        run_func = globals()[func_name]
        for i in xrange(repeat):
            run_func(params, libvirtd, vm)

        stopped = libvirtd.wait_for_stop(timeout=5)
        if stopped:
            logging.debug('Backtrace:')
            for line in libvirtd.back_trace():
                logging.debug(line)

            if bug_url:
                logging.error(
                    "You might met a regression bug. Please reference %s" %
                    bug_url)

            test.fail("Libvirtd stops with %s" % libvirtd.bundle['stop-info'])

        if post_func_name in globals():
            post_func = globals()[post_func_name]
            post_func(params, libvirtd, vm)
    finally:
        try:
            path.find_command('virtlogd')
            process.run('pkill virtlogd', ignore_status=True)
            process.run('systemctl restart virtlogd.socket',
                        ignore_status=True)
            Libvirtd("libvirtd.socket").restart()
        except path.CmdNotFoundError:
            pass
        libvirtd.exit()
Пример #2
0
def run(test, params, env):
    """
    Run various regression tests and check whether libvirt daemon crashes.
    """
    func_name = 'run_' + params.get("func_name", "default")
    post_func_name = 'post_' + params.get("func_name", "default")
    repeat = int(params.get("repeat", "1"))
    vm_name = params.get("main_vm", "virt-tests-vm1")
    bug_url = params.get("bug_url", None)
    vm = env.get_vm(vm_name)
    # Run virtlogd foreground
    try:
        path.find_command('virtlogd')
        process.run("systemctl stop virtlogd", ignore_status=True)
        process.run("virtlogd -d")
    except path.CmdNotFoundError:
        pass
    libvirtd = LibvirtdSession(gdb=True)
    try:
        libvirtd.start()

        run_func = globals()[func_name]
        for i in xrange(repeat):
            run_func(params, libvirtd, vm)

        stopped = libvirtd.wait_for_stop(timeout=5)
        if stopped:
            logging.debug('Backtrace:')
            for line in libvirtd.back_trace():
                logging.debug(line)

            if bug_url:
                logging.error("You might met a regression bug. Please reference %s" % bug_url)

            test.fail("Libvirtd stops with %s" % libvirtd.bundle['stop-info'])

        if post_func_name in globals():
            post_func = globals()[post_func_name]
            post_func(params, libvirtd, vm)
    finally:
        try:
            path.find_command('virtlogd')
            process.run('pkill virtlogd', ignore_status=True)
            process.run('systemctl restart virtlogd.socket', ignore_status=True)
        except path.CmdNotFoundError:
            pass
        libvirtd.exit()
Пример #3
0
def run(test, params, env):
    """
    Start libvirt daemon with break point inserted.
    And then kill daemon ensure no sigsegv happends.
    """
    signal_name = params.get("signal", "SIGTERM")
    send_signal_at = params.get("send_signal_at", None)

    def _signal_callback(gdb, info, params):
        """
        Callback function when a signal is received by libvirtd.
        """
        params['recieved'] = True
        logging.debug("Signal received:")
        logging.debug(info)

    def _break_callback(gdb, info, params):
        """
        Callback function when a breakpoint is reached.
        """
        for line in gdb.back_trace():
            logging.debug(line)
        gdb.send_signal(signal_name)
        gdb.cont()

    def get_service(send_signal_at):
        """
        Get the name of the service

        :param send_signal_at: The function to set breakpoint
        :return: Service name
        """
        return {
            'netcfStateInitialize': 'virtinterfaced',
            'networkStateInitialize': 'virtnetworkd',
            'nwfilterStateInitialize': 'virtnwfilterd'
        }.get(send_signal_at)

    serv_name = get_service(send_signal_at)
    bundle = {'recieved': False}

    libvirtd = LibvirtdSession(service_name=serv_name, gdb=True)
    try:
        libvirtd.set_callback('break', _break_callback)
        libvirtd.set_callback('signal', _signal_callback, bundle)

        libvirtd.insert_break(send_signal_at)

        libvirtd.start(wait_for_working=False)

        if not utils_misc.wait_for(lambda: bundle['recieved'], 20, 0.5):
            test.fail("Expect receive signal, but not.")
    finally:
        libvirtd.exit()
        # Need to restart libvirtd.socket after starting libvirtd in the foreground
        Libvirtd("libvirtd.socket").restart()
Пример #4
0
def run(test, params, env):
    """
    Start libvirt daemon with different options.
    Check socket files.
    """
    log = []

    def _logger(line):
        """
        Callback function to log libvirtd output.
        """
        log.append(line)

    def check_help(params):
        """
        Check whether the output is help and meets expectation
        """
        expected_help = params.get('expected_help', 'no') == 'yes'
        is_help = any(line.startswith('Usage:') for line in log)
        if expected_help != is_help:
            raise error.TestFail(
                'Expected output help is %s, but get output:\n%s' %
                (expected_help, '\n'.join(log)))

    def check_version(params):
        """
        Check whether the output is libvirtd version.
        """
        expected_version = params.get('expected_version', 'no') == 'yes'
        is_version = log[0].startswith('libvirtd (libvirt)')
        if expected_version != is_version:
            raise error.TestFail(
                'Expected output version is %s, but get output:\n%s' %
                (expected_version, '\n'.join(log)))

    def check_unix_socket_files():
        """
        Check whether the socket file exists.
        """
        rw_sock_path = '/var/run/libvirt/libvirt-sock'
        ro_sock_path = '/var/run/libvirt/libvirt-sock-ro'

        if libvirtd.running:
            if not os.path.exists(rw_sock_path):
                raise error.TestFail('RW unix socket file not found at %s' %
                                     rw_sock_path)
            if not os.path.exists(ro_sock_path):
                raise error.TestFail('RO unix socket file not found at %s' %
                                     ro_sock_path)
        else:
            if os.path.exists(rw_sock_path) or os.path.exists(ro_sock_path):
                raise error.TestFail('Expect unix socket file do not exists '
                                     'when libvirtd is stopped')

    def check_pid_file():
        """
        Check whether the pid file exists.
        """
        if not os.path.exists(pid_path):
            raise error.TestFail("PID file not found at %s" % pid_path)

        pid_file = open(pid_path)
        pid = int(pid_file.readline())
        pid_file.close()

        result = utils.run('pgrep libvirtd', ignore_status=True)
        expected_pid = int(result.stdout.split()[0])

        if pid != expected_pid:
            raise error.TestFail("PID file content mismatch. Expected %s "
                                 "but got %s" % (expected_pid, pid))

    def check_config_file():
        """
        Check whether the config file take effects by checking UUID.
        """
        cur_uuid = capability_xml.CapabilityXML()['uuid']
        if cur_uuid != check_uuid:
            raise error.TestFail('Expected host UUID is %s, but got %s' %
                                 (check_uuid, cur_uuid))

    MAX_TIMEOUT = 10
    arg_str = params.get("libvirtd_arg", "")
    time_tolerance = float(params.get("exit_time_tolerance", 1))
    expected_exit_time = float(params.get("expected_exit_time", 'inf'))
    config_path = params.get('expected_config_path', "")
    pid_path = params.get('expected_pid_path', "")

    if expected_exit_time == float('inf'):
        timeout = MAX_TIMEOUT
    else:
        if expected_exit_time > 0:
            if len(virsh.dom_list('--name').stdout.strip().splitlines()):
                raise error.TestNAError('Timeout option will be ignore if '
                                        'there exists living domain')
        timeout = expected_exit_time + time_tolerance

    libvirtd = LibvirtdSession(
        logging_handler=_logger,
    )

    # Setup config file.
    check_uuid = '13371337-1337-1337-1337-133713371337'
    if config_path:
        open(config_path, 'a').close()
        config = utils_config.LibvirtdConfig(config_path)
        config.host_uuid = check_uuid

    try:
        check_unix_socket_files()

        libvirtd.start(arg_str=arg_str, wait_for_working=False)

        start = time.time()
        libvirtd_exited = libvirtd.wait_for_stop(timeout=timeout, step=0.1)
        wait_time = time.time() - start

        if log:
            logging.debug("Libvirtd log:")
            for line in log:
                logging.debug(line)

            check_help(params)
            check_version(params)

        if libvirtd_exited:
            if expected_exit_time == float('inf'):
                raise error.TestFail("Expected never stop, but ran %ss" % wait_time)
            elif wait_time < expected_exit_time - time_tolerance:
                raise error.TestFail("Expected exit in %ss(+-%ss), but ran %ss" %
                                     (expected_exit_time, time_tolerance, wait_time))
        else:
            if expected_exit_time != float('inf'):
                raise error.TestFail("Expected exit in %ss(+-%ss), but ran timeout in %ss" %
                                     (expected_exit_time, time_tolerance, wait_time))

        check_unix_socket_files()
        if config_path:
            check_config_file()
        if pid_path:
            check_pid_file()
    finally:
        libvirtd.exit()

        # Clean up config file
        if config_path:
            config.restore()
            if os.path.exists(config_path):
                os.remove(config_path)
        if os.path.exists(pid_path):
            os.remove(pid_path)
Пример #5
0
def run(test, params, env):
    """
    Start libvirt daemon with different options.
    Check socket files.
    """
    log = []

    def _logger(line):
        """
        Callback function to log libvirtd output.
        """
        log.append(line)

    def check_help(params):
        """
        Check whether the output is help and meets expectation
        """
        expected_help = params.get('expected_help', 'no') == 'yes'
        is_help = any(line.startswith('Usage:') for line in log)
        if expected_help != is_help:
            raise error.TestFail(
                'Expected output help is %s, but get output:\n%s' %
                (expected_help, '\n'.join(log)))

    def check_version(params):
        """
        Check whether the output is libvirtd version.
        """
        expected_version = params.get('expected_version', 'no') == 'yes'
        is_version = log[0].startswith('libvirtd (libvirt)')
        if expected_version != is_version:
            raise error.TestFail(
                'Expected output version is %s, but get output:\n%s' %
                (expected_version, '\n'.join(log)))

    def check_unix_socket_files():
        """
        Check whether the socket file exists.
        """
        rw_sock_path = '/var/run/libvirt/libvirt-sock'
        ro_sock_path = '/var/run/libvirt/libvirt-sock-ro'

        if libvirtd.running:
            if not os.path.exists(rw_sock_path):
                raise error.TestFail('RW unix socket file not found at %s' %
                                     rw_sock_path)
            if not os.path.exists(ro_sock_path):
                raise error.TestFail('RO unix socket file not found at %s' %
                                     ro_sock_path)
        else:
            if os.path.exists(rw_sock_path) or os.path.exists(ro_sock_path):
                raise error.TestFail('Expect unix socket file do not exists '
                                     'when libvirtd is stopped')

    def check_pid_file():
        """
        Check whether the pid file exists.
        """
        if not os.path.exists(pid_path):
            raise error.TestFail("PID file not found at %s" % pid_path)

        pid_file = open(pid_path)
        pid = int(pid_file.readline())
        pid_file.close()

        result = utils.run('pgrep libvirtd', ignore_status=True)
        expected_pid = int(result.stdout.split()[0])

        if pid != expected_pid:
            raise error.TestFail("PID file content mismatch. Expected %s "
                                 "but got %s" % (expected_pid, pid))

    def check_config_file():
        """
        Check whether the config file take effects by checking UUID.
        """
        cur_uuid = capability_xml.CapabilityXML()['uuid']
        if cur_uuid != check_uuid:
            raise error.TestFail('Expected host UUID is %s, but got %s' %
                                 (check_uuid, cur_uuid))

    MAX_TIMEOUT = 10
    arg_str = params.get("libvirtd_arg", "")
    time_tolerance = float(params.get("exit_time_tolerance", 1))
    expected_exit_time = float(params.get("expected_exit_time", 'inf'))
    config_path = params.get('expected_config_path', "")
    pid_path = params.get('expected_pid_path', "")

    if expected_exit_time == float('inf'):
        timeout = MAX_TIMEOUT
    else:
        if expected_exit_time > 0:
            if len(virsh.dom_list('--name').stdout.strip().splitlines()):
                raise error.TestNAError('Timeout option will be ignore if '
                                        'there exists living domain')
        timeout = expected_exit_time + time_tolerance

    libvirtd = LibvirtdSession(logging_handler=_logger, )

    # Setup config file.
    check_uuid = '13371337-1337-1337-1337-133713371337'
    if config_path:
        open(config_path, 'a').close()
        config = utils_config.LibvirtdConfig(config_path)
        config.host_uuid = check_uuid

    try:
        check_unix_socket_files()

        libvirtd.start(arg_str=arg_str, wait_for_working=False)

        start = time.time()
        libvirtd_exited = libvirtd.wait_for_stop(timeout=timeout, step=0.1)
        wait_time = time.time() - start

        if log:
            logging.debug("Libvirtd log:")
            for line in log:
                logging.debug(line)

            check_help(params)
            check_version(params)

        if libvirtd_exited:
            if expected_exit_time == float('inf'):
                raise error.TestFail("Expected never stop, but ran %ss" %
                                     wait_time)
            elif wait_time < expected_exit_time - time_tolerance:
                raise error.TestFail(
                    "Expected exit in %ss(+-%ss), but ran %ss" %
                    (expected_exit_time, time_tolerance, wait_time))
        else:
            if expected_exit_time != float('inf'):
                raise error.TestFail(
                    "Expected exit in %ss(+-%ss), but ran timeout in %ss" %
                    (expected_exit_time, time_tolerance, wait_time))

        check_unix_socket_files()
        if config_path:
            check_config_file()
        if pid_path:
            check_pid_file()
    finally:
        libvirtd.exit()

        # Clean up config file
        if config_path:
            config.restore()
            if os.path.exists(config_path):
                os.remove(config_path)
        if os.path.exists(pid_path):
            os.remove(pid_path)
Пример #6
0
def run(test, params, env):
    """
    Start libvirt daemon with break point inserted.
    And then kill daemon ensure no sigsegv happends.
    """
    signal_name = params.get("signal", "SIGTERM")
    send_signal_at = params.get("send_signal_at", None)

    def _signal_callback(gdb, info, params):
        """
        Callback function when a signal is recieved by libvirtd.
        """
        params['recieved'] = True
        logging.debug("Signal recieved:")
        logging.debug(info)

    def _break_callback(gdb, info, params):
        """
        Callback function when a breakpoint is reached.
        """
        for line in gdb.back_trace():
            logging.debug(line)
        gdb.send_signal(signal_name)
        gdb.cont()

    bundle = {'recieved': False}

    libvirtd = LibvirtdSession(gdb=True)
    try:
        libvirtd.set_callback('break', _break_callback)
        libvirtd.set_callback('signal', _signal_callback, bundle)

        libvirtd.insert_break(send_signal_at)

        libvirtd.start(wait_for_working=False)

        if not utils_misc.wait_for(lambda: bundle['recieved'], 20, 0.5):
            test.fail("Expect recieve signal, but not.")
    finally:
        libvirtd.exit()
        # Need to restart libvirtd.socket after starting libvirtd in the foreground
        process.system("systemctl restart libvirtd.socket", ignore_status=True)
Пример #7
0
def run(test, params, env):
    """
    Start libvirt daemon with different options.
    Check socket files.
    """
    log = []

    def _logger(line):
        """
        Callback function to log libvirtd output.
        """
        log.append(line)

    def check_help(params):
        """
        Check whether the output is help and meets expectation
        """
        expected_help = params.get('expected_help', 'no') == 'yes'
        is_help = any(line.startswith('Usage:') for line in log)
        if expected_help != is_help:
            test.fail(
                'Expected output help is %s, but get output:\n%s' %
                (expected_help, '\n'.join(log)))

    def check_version(params):
        """
        Check whether the output is libvirtd version.
        """
        expected_version = params.get('expected_version', 'no') == 'yes'
        is_version = log[0].startswith('{} (libvirt)'.format(daemon_name))
        if expected_version != is_version:
            test.fail(
                'Expected output version is %s, but get output:\n%s' %
                (expected_version, '\n'.join(log)))

    def check_unix_socket_files():
        """
        Check whether the socket file exists.
        """
        rw_sock_path = '/var/run/libvirt/libvirt-sock'
        ro_sock_path = '/var/run/libvirt/libvirt-sock-ro'

        if libvirtd.running or libvirt_version.version_compare(5, 6, 0):
            if not os.path.exists(rw_sock_path):
                test.fail('RW unix socket file not found at %s' %
                          rw_sock_path)
            if not os.path.exists(ro_sock_path):
                test.fail('RO unix socket file not found at %s' %
                          ro_sock_path)
        else:
            if os.path.exists(rw_sock_path) or os.path.exists(ro_sock_path):
                test.fail('Expect unix socket file do not exists '
                          'when libvirtd is stopped')

    def check_pid_file():
        """
        Check whether the pid file exists.
        """
        if not os.path.exists(pid_path):
            test.fail("PID file not found at %s" % pid_path)

        with open(pid_path) as pid_file:
            pid = int(pid_file.readline())
        result = process.run('pgrep %s' % daemon_name,
                             ignore_status=True, shell=True)
        expected_pid = int(result.stdout_text.strip().split()[0])

        if pid != expected_pid:
            test.fail("PID file content mismatch. Expected %s "
                      "but got %s" % (expected_pid, pid))

    def check_config_file():
        """
        Check whether the config file take effects by checking max_clients.
        """
        connect_uri = daemon_name + ":///system"
        vp = virt_admin.VirtadminPersistent(uri=connect_uri)
        result = vp.srv_clients_info(daemon_name, uri=connect_uri, ignore_status=True, debug=True)
        output = result.stdout.strip().splitlines()
        out_split = [item.split(':') for item in output]
        out_dict = dict([[item[0].strip(), item[1].strip()] for item in out_split])
        if int(out_dict["nclients_max"]) != check_max_clients:
            test.fail('Expected max_clients is %s, but got %s' %
                      (check_max_clients, out_dict["nclients_max"]))

    MAX_TIMEOUT = 10
    arg_str = params.get("libvirtd_arg", "")
    time_tolerance = float(params.get("exit_time_tolerance", 1))
    expected_exit_time = float(params.get("expected_exit_time", 'inf'))
    config_path = params.get('expected_config_path', "")
    pid_path = params.get('expected_pid_path', "")
    daemon_name = params.get('daemon_name', "")
    test_config = params.get('test_config', "no") == "yes"
    require_modular_daemon = params.get('require_modular_daemon', "no") == "yes"

    utils_split_daemons.daemon_mode_check(require_modular_daemon)
    if expected_exit_time == float('inf'):
        timeout = MAX_TIMEOUT
    else:
        if expected_exit_time > 0:
            if len(virsh.dom_list('--name').stdout.strip().splitlines()):
                test.cancel('Timeout option will be ignore if '
                            'there exists living domain')
        timeout = expected_exit_time + time_tolerance

    libvirtd = LibvirtdSession(service_name=daemon_name, logging_handler=_logger)

    # Setup config file.
    check_max_clients = int(101)
    if test_config:
        config = utils_config.get_conf_obj(daemon_name)
        logging.debug(config.conf_path)
        config_path = config.conf_path
        config.max_clients = check_max_clients
        arg_str = arg_str + config_path

    try:
        check_unix_socket_files()

        Libvirtd(daemon_name).stop()
        libvirtd.start(arg_str=arg_str, wait_for_working=False)

        start = time.time()
        libvirtd_exited = libvirtd.wait_for_stop(timeout=timeout, step=0.1)
        wait_time = time.time() - start

        if log:
            logging.debug("Libvirtd log:")
            for line in log:
                logging.debug(line)

            check_help(params)
            check_version(params)

        if libvirtd_exited:
            if expected_exit_time == float('inf'):
                test.fail("Expected never stop, but ran %ss" % wait_time)
            elif wait_time < expected_exit_time - time_tolerance:
                test.fail("Expected exit in %ss(+-%ss), but ran %ss" %
                          (expected_exit_time, time_tolerance, wait_time))
        else:
            if expected_exit_time != float('inf'):
                test.fail("Expected exit in %ss(+-%ss), but ran timeout in %ss" %
                          (expected_exit_time, time_tolerance, wait_time))

        not libvirt_version.version_compare(5, 6, 0) and check_unix_socket_files()
        if test_config:
            check_config_file()
        if pid_path:
            check_pid_file()
    finally:
        libvirtd.exit()
        Libvirtd(daemon_name).stop()
        socket_name = daemon_name + ".socket"
        Libvirtd(socket_name).restart()
        Libvirtd(daemon_name).start()

        # Clean up config file
        if test_config:
            config.restore()
        if os.path.exists(pid_path):
            os.remove(pid_path)
Пример #8
0
def run(test, params, env):
    """
    Start libvirt daemon with break point inserted.
    And then kill daemon ensure no sigsegv happends.
    """
    signal_name = params.get("signal", "SIGTERM")
    send_signal_at = params.get("send_signal_at", None)

    def _signal_callback(gdb, info, params):
        """
        Callback function when a signal is recieved by libvirtd.
        """
        params['recieved'] = True
        logging.debug("Signal recieved:")
        logging.debug(info)

    def _break_callback(gdb, info, params):
        """
        Callback function when a breakpoint is reached.
        """
        for line in gdb.back_trace():
            logging.debug(line)
        gdb.send_signal(signal_name)
        gdb.cont()

    bundle = {'recieved': False}

    libvirtd = LibvirtdSession(gdb=True)
    try:
        libvirtd.set_callback('break', _break_callback)
        libvirtd.set_callback('signal', _signal_callback, bundle)

        libvirtd.insert_break(send_signal_at)

        libvirtd.start(wait_for_working=False)

        if not utils_misc.wait_for(lambda: bundle['recieved'], 60, 0.5):
            raise error.TestFail("Expect recieve signal, but not.")
    finally:
        libvirtd.exit()