Ejemplo n.º 1
0
 def __init__(self):
     # libcgroup lack libcgroup-tools dependency will introduces
     # following error,
     #     Failed to issue method call:
     #     Unit cgconfig.service failed to load:
     #     No such file or directory
     #
     # Please refer to
     # https://bugzilla.redhat.com/show_bug.cgi?format=multiple&id=882887
     mgr = manager.SoftwareManager()
     if not mgr.install('libcgroup-tools'):
         exceptions.TestError("Failed to install libcgroup-tools on host")
     self._service_manager = service.Factory.create_service("cgconfig")
Ejemplo n.º 2
0
 def test_extract_permission(self):
     mn = manager.SoftwareManager()
     with self.assertRaises(NotImplementedError) as context:
         mn.extract_from_package("/dev/null", self.tmpdir.name)
     expected = "No package manager supported was found for package "
     self.assertIn(expected, str(context.exception))
Ejemplo n.º 3
0
 def test_extract_from_deb(self):
     mn = manager.SoftwareManager()
     result = mn.extract_from_package(self.deb_path, self.tmpdir.name)
     self.assertEqual(self.tmpdir.name, result)
Ejemplo n.º 4
0
 def test_provides(self):
     sm = manager.SoftwareManager()
     self.assertEqual(sm.provides('/bin/login'), 'login')
     self.assertTrue(isinstance(sm.backend, backends.apt.AptBackend))
Ejemplo n.º 5
0
def run(test, params, env):
    """
    Setup and run syzkaller (https://github.com/google/syzkaller)
    1. Install/Setup syzkaller in host
    2. Setup Guest for passwordless ssh from host
    3. Prepare and compile Guest kernel
    4. Prepare syzkaller config with qemu params and guest params
    5. Start sykaller with above config and run for specified time(test_timeout)
    6. Test fails out incase of any host issues
    """
    start_time = time.time()
    #  Step 1: Install/Setup syzkaller in host
    sm = manager.SoftwareManager()
    if not sm.check_installed("go") and not sm.install("go"):
        test.cancel("golang package install failed")
    home = os.environ["HOME"]
    if not ("goroot/bin" in os.environ["PATH"]
            and "go/bin" in os.environ["PATH"]):
        process.run('echo "PATH=%s/goroot/bin:%s/go/bin:$PATH" >> %s/.bashrc' %
                    (home, home, home),
                    shell=True)
    process.run("source %s/.bashrc" % home, shell=True)
    process.run("go get -u -d github.com/google/syzkaller/...", shell=True)
    process.run("cd %s/go/src/github.com/google/syzkaller;make" % home,
                shell=True)
    syzkaller_path = "%s/go/src/github.com/google/syzkaller" % home

    # Step 2: Setup Guest for passwordless ssh from host
    vm = env.get_vm(params["main_vm"])
    session = vm.wait_for_login()
    ssh_key.setup_ssh_key(vm.get_address(), params.get("username"),
                          params.get("password"))
    session.close()
    vm.destroy()

    # Step 3: Prepare Guest kernel
    guest_kernel_repo = params.get("syz_kernel_repo")
    guest_kernel_branch = params.get("syz_kernel_branch")
    guest_kernel_config = params.get("syz_kernel_config")
    guest_kernel_build_path = utils_misc.get_path(test.debugdir, "linux")
    process.run(
        "git clone --depth 1 %s -b %s %s" %
        (guest_kernel_repo, guest_kernel_branch, guest_kernel_build_path),
        shell=True)
    process.run("cd %s;git log -1;make %s" %
                (guest_kernel_build_path, guest_kernel_config),
                shell=True)
    process.run(
        'cd %s; echo "CONFIG_KCOV=y\nCONFIG_GCC_PLUGINS=y" >> .config; make olddefconfig'
        % guest_kernel_build_path,
        shell=True)
    process.run("cd %s;make -j 40" % guest_kernel_build_path, shell=True)

    # Step 4: Prepare syzkaller config with qemu params and guest params
    syz_config_path = utils_misc.get_path(test.debugdir, "syzkaller_config")
    os.makedirs("%s/syzkaller" % test.debugdir)
    workdir = "%s/syzkaller" % test.debugdir
    sshkey = "%s/.ssh/id_rsa" % os.environ["HOME"]
    kernel_path = "%s/vmlinux" % guest_kernel_build_path

    vm_config = {
        "count": int(params.get("syz_count")),
        "cpu": int(params.get("smp")),
        "mem": int(params.get("mem")),
        "kernel": kernel_path,
        "cmdline": params.get("kernel_args"),
        "qemu_args": params.get("syz_qemu_args")
    }

    syz_config = {
        'target': params.get("syz_target"),
        'workdir': workdir,
        "http": params.get("syz_http"),
        "image": storage.get_image_filename(params, data_dir.get_data_dir()),
        "syzkaller": syzkaller_path,
        "procs": int(params.get("syz_procs")),
        "type": "qemu",
        "sshkey": sshkey,
        "vm": vm_config
    }
    try:
        with open(syz_config_path, "w") as fp:
            json.dump(syz_config, fp)
    except IOError as err:
        test.error("Unable to update syzkaller config: %s", err)
    end_time = time.time()
    # Step 5: Start sykaller config with specified time
    # Let's calculate the syzkaller timeout from
    # test timeout excluding current elapsed time + buffer
    testtimeout = int(
        params.get("test_timeout")) - (int(end_time - start_time) + 10)
    cmd = "%s/bin/syz-manager -config %s %s" % (
        syzkaller_path, syz_config_path, params.get("syz_cmd_params"))
    process.run(cmd,
                timeout=testtimeout,
                allow_output_check="combined",
                ignore_status=True,
                shell=True)
    # Let's delete linux kernel folder from test-results as it would
    # consume lot of space and test log have all the information about
    # it incase to retrieve it back.
    if os.path.isdir(guest_kernel_build_path):
        shutil.rmtree(guest_kernel_build_path)
Ejemplo n.º 6
0
 def _get_installed_packages(self):
     sm = manager.SoftwareManager()
     installed_pkgs = sm.list_all()
     self._installed_pkgs = installed_pkgs
     return installed_pkgs
Ejemplo n.º 7
0
def run(test, params, env):
    """
    Nested test:
    1) Boot VM
    2) Install ansible and related packages
    3) Generate inventory file with L1 guest IP
    4) Generate parameter file with parameters for tests on L2 guest
    5) Execute ansible command

    :param test: QEMU test object
    :param params: Dictionary with the test parameters
    :param env: Dictionary with test environment.
    """

    setup_bridge_sh = "/root/setup_bridge.sh"

    def get_live_vms(env):
        live_vms = []
        for vm in env.get_all_vms():
            if vm.is_alive():
                live_vms.append(vm)
        if not live_vms:
            test.fail("No live VM.")
        return live_vms

    def generate_invent_file(env):
        vms = get_live_vms(env)
        tmp_dir = virttest_data_dir.get_tmp_dir()
        file_name = "inventory_file"
        ip_lst = list(map(lambda v: v.wait_for_get_address(0, 240), vms))
        invent_file = open(os.path.join(tmp_dir, file_name), "w")
        invent_file.writelines(ip_lst)
        invent_file.close()

        return invent_file.name

    def copy_network_script(env):
        login_timeout = params.get_numeric("login_timeout", 360)
        deps_dir = virttest_data_dir.get_deps_dir()

        file_name = os.path.basename(setup_bridge_sh)
        br_file = os.path.join(deps_dir, file_name)
        for vm in get_live_vms(env):
            vm.wait_for_login(timeout=login_timeout)
            vm.copy_files_to(br_file, setup_bridge_sh)

    def generate_parameter_file(params):
        tmp_dir = virttest_data_dir.get_tmp_dir()
        file_name = "parameter_file"

        guest_password = params.get("password")

        bootstrap_options = params.get("nested_bs_options")
        accept_cancel = params.get_boolean("accept_cancel")

        kar_cmd = "python3 ./ConfigTest.py "

        test_type = params.get("test_type")
        variant_name = params.get("nested_test")
        case_name = params.get("case_name", "")

        if variant_name == "check_cpu_model_l2":
            host_cpu_models = virttest_cpu.get_host_cpu_models()
            case_name = ','.join(
                ["%s.%s" % (case_name, i) for i in host_cpu_models])

        kar_cmd += " --%s=%s " % (test_type, case_name)

        l2_guest_name = params.get("l2_guest_name")
        if l2_guest_name:
            kar_cmd += " --guestname=%s" % l2_guest_name
        clone = params.get("install_node")
        if clone == "yes":
            kar_cmd += " --clone=yes"
        else:
            kar_cmd += " --clone=no"

        l2_kar_options = params.get("l2_kar_options")
        if l2_kar_options:
            kar_cmd += " %s" % l2_kar_options

        logging.info("Kar cmd: %s", kar_cmd)

        results_dir = test.logdir
        logging.info("Result_dir: %s", results_dir)

        kar_repo = params.get("kar_repo")
        cert_url = params.get("cert_url")

        data = {
            "guest_password": guest_password,
            "bootstrap_options": bootstrap_options,
            "accept_cancel": accept_cancel,
            "command_line": kar_cmd,
            "setup_br_sh": setup_bridge_sh,
            "host_log_files_dir": results_dir,
            "kar_repo": kar_repo,
            "cert_url": cert_url
        }

        json_file = open(os.path.join(tmp_dir, file_name), "w")
        json.dump(data, json_file)
        json_file.close()

        return json_file.name

    if (params.get('check_vendor', 'no') == 'yes'
            and cpu.get_vendor() != 'intel'):
        test.cancel("We only test this case with Intel platform now")

    sm = manager.SoftwareManager()
    if not sm.check_installed("ansible"):
        sm.install("ansible")

    invent_file = generate_invent_file(env)

    copy_network_script(env)

    deps_dir = virttest_data_dir.get_deps_dir()
    playbook_file = os.path.join(deps_dir, "playbook.yml")

    params_file = generate_parameter_file(params)

    ansible_cmd = "export ANSIBLE_SSH_ARGS=\"-C -o ControlMaster=auto " \
                  "-o ControlPersist=60s " \
                  "-o StrictHostKeyChecking=no " \
                  "-o UserKnownHostsFile=/dev/null\"; " \
                  "ansible-playbook %s " \
                  "--extra-vars \"@%s\" " \
                  "-i %s " \
                  % (playbook_file, params_file, invent_file)

    logging.debug("ansible cmd: %s", ansible_cmd)

    timeout = float(params.get("test_timeout", 3600))

    status, output = process.getstatusoutput(ansible_cmd, timeout)
    if status != 0:
        test.fail("ansible_cmd failed, status: %s, output: %s" %
                  (status, output))
Ejemplo n.º 8
0
def is_qemu_kvm_ma():
    """
    Check if qemu-kvm-ma is installed in host
    """
    sm = manager.SoftwareManager()
    return sm.check_installed("qemu-kvm-ma")
Ejemplo n.º 9
0
 def installed_pkgs(self):
     sm = manager.SoftwareManager()
     return sm.list_all()