Exemplo n.º 1
0
def check_if_dev_in_core_pool(dev, should_be_in_core_pool=True):
    cas_devices_dict = casadm_parser.get_cas_devices_dict()
    is_in_core_pool = any(dev.path == d["device"]
                          for d in cas_devices_dict["core_pool"])
    if not (should_be_in_core_pool ^ is_in_core_pool):
        TestRun.LOGGER.info(
            f"Core device {dev.path} is"
            f"{'' if should_be_in_core_pool else ' not'} listed in core pool "
            f"as expected.")
    else:
        TestRun.fail(
            f"Core device {dev.path} is{' not' if should_be_in_core_pool else ''} "
            f"listed in core pool.")
Exemplo n.º 2
0
def test_neg_udev_cache_load():
    """
        title: CAS udev rule for cache negative test.
        description: |
          Verify if CAS udev rule is executed properly for cache with valid metadata and do not
          load cache with no metadata.
        pass_criteria:
          - No kernel error
          - Cache with metadata is properly loaded
          - Cache without metadata is not loaded
          - Cores assigned to not loaded cache are not inserted to core pool after
            plugging cache disk
          - Cores assigned to not loaded cache are inserted to core pool after plugging core disk
    """
    caches_count = 2
    cores_count = 4

    with TestRun.step(
            "Create init config file with two caches and two cores per each cache."
    ):
        cache_disk = TestRun.disks["cache"]
        cache_disk.create_partitions([Size(1, Unit.GibiByte)] * caches_count)
        core_disk = TestRun.disks["core"]
        core_disk.create_partitions([Size(2, Unit.GibiByte)] * cores_count)
        first_cache_core_numbers = random.sample(range(0, cores_count), 2)
        init_conf = InitConfig()
        for i in range(0, caches_count):
            init_conf.add_cache(i + 1, cache_disk.partitions[i])
        for j in range(0, cores_count):
            init_conf.add_core(1 if j in first_cache_core_numbers else 2,
                               j + 1, core_disk.partitions[j])
        init_conf.save_config_file()

    with TestRun.step(
            "Start one cache and add two cores as defined in init config."):
        cache = casadm.start_cache(cache_disk.partitions[0])
        for i in first_cache_core_numbers:
            cache.add_core(core_disk.partitions[i])

    with TestRun.step("Stop cache."):
        cache.stop()

    with TestRun.step("Unplug and plug cache disk."):
        cache_disk.unplug()
        cache_disk.plug()
        time.sleep(1)

    with TestRun.step("Check if CAS is loaded correctly."):
        cas_devices = casadm_parser.get_cas_devices_dict()
        if len(cas_devices["core_pool"]) != 0:
            TestRun.LOGGER.error(
                f"There is wrong number of core devices in core pool. Expected: 0,"
                f" actual: {len(cas_devices['core_pool'])}")
        if len(cas_devices["caches"]) != 1:
            TestRun.LOGGER.error(
                f"There is wrong number of caches. Expected: 1, actual: "
                f"{len(cas_devices['caches'])}")
        elif cas_devices["caches"][1]["device"] != cache_disk.partitions[0].path or \
                CacheStatus[(cas_devices["caches"][1]["status"]).lower()] != CacheStatus.running:
            TestRun.LOGGER.error(
                f"Cache did not load properly: {cas_devices['caches'][1]}")
        if len(cas_devices["cores"]) != 2:
            TestRun.LOGGER.error(
                f"There is wrong number of cores. Expected: 2, actual: "
                f"{len(cas_devices['caches'])}")

        correct_core_devices = []
        for i in first_cache_core_numbers:
            correct_core_devices.append(core_disk.partitions[i].path)
        for core in cas_devices["cores"].values():
            if core["device"] not in correct_core_devices or \
                    CoreStatus[core["status"].lower()] != CoreStatus.active or \
                    core["cache_id"] != 1:
                TestRun.LOGGER.error(f"Core did not load correctly: {core}.")

    with TestRun.step("Unplug and plug core disk."):
        core_disk.unplug()
        core_disk.plug()
        time.sleep(1)

    with TestRun.step(
            "Check if two cores assigned to not loaded cache are inserted to core pool."
    ):
        cas_devices = casadm_parser.get_cas_devices_dict()
        if len(cas_devices["core_pool"]) != 2:
            TestRun.LOGGER.error(
                f"There is wrong number of cores in core pool. Expected: 2, "
                f"actual: {len(cas_devices['core_pool'])}")
        core_pool_expected_devices = []
        for i in range(0, cores_count):
            if i not in first_cache_core_numbers:
                core_pool_expected_devices.append(core_disk.partitions[i].path)
        for c in cas_devices["core_pool"]:
            if c["device"] not in core_pool_expected_devices:
                TestRun.LOGGER.error(
                    f"Wrong core device added to core pool: {c}.")
Exemplo n.º 3
0
def remove_all_detached_cores():
    from api.cas import casadm_parser
    devices = casadm_parser.get_cas_devices_dict()
    for dev in devices["core_pool"]:
        TestRun.executor.run(remove_detached_cmd(dev["device"]))