def test_cas_init_with_changed_mode(cache_mode_pair): """ title: Check starting cache in other cache mode by initializing OpenCAS service from config. description: | Start cache, create config based on running configuration but with another cache mode, reinitialize OpenCAS service with '--force' option and check if cache defined in config file starts properly. Check all cache modes. pass_criteria: - Cache starts with attached core - Cache starts in mode saved in configuration file. """ with TestRun.step("Prepare partitions for cache and core."): cache_dev = TestRun.disks['cache'] cache_dev.create_partitions([Size(200, Unit.MebiByte)]) cache_part = cache_dev.partitions[0] core_dev = TestRun.disks['core'] core_dev.create_partitions([Size(400, Unit.MebiByte)]) core_part = core_dev.partitions[0] with TestRun.step( f"Start cache in the {cache_mode_pair[0]} mode and add core."): cache = casadm.start_cache(cache_part, cache_mode_pair[0], force=True) core = cache.add_core(core_part) with TestRun.step( f"Create the configuration file with a different cache mode ({cache_mode_pair[1]})" ): init_conf = InitConfig() init_conf.add_cache(cache.cache_id, cache.cache_device, cache_mode_pair[1]) init_conf.add_core(cache.cache_id, core.core_id, core.core_device) init_conf.save_config_file() with TestRun.step("Reinitialize OpenCAS service with '--force' option."): casadm.stop_all_caches() casctl.init(True) with TestRun.step( "Check if cache started in correct mode with core attached."): validate_cache(cache_mode_pair[1])
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}.")