def test_kedr_memleak_load_cas_module(module, unload_modules, install_kedr): """ title: Loading modules with kedr started with 'memleak' configuration description: Load and unload modules with kedr started to watch for memory leaks pass_criteria: - No memory leaks observed after loading and unloading module """ with TestRun.step(f"Starting kedr against {module}"): Kedr.start(module.value) with TestRun.step(f"Loading {module}"): os_utils.load_kernel_module(module.value) with TestRun.step(f"Unloading {module}"): os_utils.unload_kernel_module(module.value, os_utils.ModuleRemoveMethod.modprobe) with TestRun.step(f"Checking for memory leaks for {module}"): try: Kedr.check_for_mem_leaks(module.value) except Exception as e: TestRun.LOGGER.error(f"{e}") with TestRun.step(f"Stopping kedr"): Kedr.stop()
def test_kedr_basic_io_raw(module, unload_modules, install_kedr): """ title: Basic IO test with kedr started with memory leaks profile description: | Load CAS modules, start kedr against one of them, start cache and add core, run simple 4 minute random IO, stop cache and unload modules pass_criteria: - No memory leaks observed """ with TestRun.step("Preparing cache device"): cache_device = TestRun.disks['cache'] cache_device.create_partitions([Size(500, Unit.MebiByte)]) cache_part = cache_device.partitions[0] with TestRun.step("Preparing core device"): core_device = TestRun.disks['core'] core_device.create_partitions([Size(1, Unit.GibiByte)]) core_part = core_device.partitions[0] with TestRun.step("Unload CAS modules if needed"): if os_utils.is_kernel_module_loaded(module.value): cas_module.unload_all_cas_modules() with TestRun.step(f"Starting kedr against {module.value}"): Kedr.start(module.value) with TestRun.step(f"Loading CAS modules"): os_utils.load_kernel_module(cas_module.CasModule.cache.value) with TestRun.step("Starting cache"): cache = casadm.start_cache(cache_part, force=True) with TestRun.step("Adding core"): core = cache.add_core(core_dev=core_part) with TestRun.step(f"Running IO"): (Fio().create_command() .io_engine(IoEngine.libaio) .run_time(timedelta(minutes=4)) .time_based() .read_write(ReadWrite.randrw) .target(f"{core.path}") .direct() ).run() with TestRun.step("Stopping cache"): cache.stop() with TestRun.step(f"Unloading CAS modules"): cas_module.unload_all_cas_modules() with TestRun.step(f"Checking for memory leaks for {module.value}"): try: Kedr.check_for_mem_leaks(module.value) except Exception as e: TestRun.LOGGER.error(f"{e}") with TestRun.step(f"Stopping kedr"): Kedr.stop()
def test_insufficient_memory_for_cas_module(): """ title: Negative test of ability to load OpenCAS kernel module with insufficient memory. description: | Check that OpenCAS kernel module won’t be loaded in case not enough memory is available. pass_criteria: - Loading OpenCAS kernel module returns error. """ with TestRun.step("Disable caching and memory over-committing."): disable_memory_affecting_functions() drop_caches() with TestRun.step("Measure memory usage without OpenCAS module."): if is_kernel_module_loaded(CasModule.cache.value): unload_kernel_module(CasModule.cache.value) unload_kernel_module(CasModule.disk.value) available_mem_before_cas = get_free_memory() with TestRun.step("Load OpenCAS module"): output = load_kernel_module(CasModule.cache.value) if output.exit_code != 0: TestRun.fail("Cannot load OpenCAS module!") with TestRun.step("Measure memory usage with OpenCAS module."): available_mem_with_cas = get_free_memory() memory_used_by_cas = available_mem_before_cas - available_mem_with_cas TestRun.LOGGER.info( f"OpenCAS module uses {memory_used_by_cas.get_value(Unit.MiB):.2f} MiB of DRAM." ) with TestRun.step("Unload OpenCAS module."): unload_kernel_module(CasModule.cache.value) unload_kernel_module(CasModule.disk.value) with TestRun.step("Allocate memory leaving not enough memory for OpenCAS module."): memory_to_leave = memory_used_by_cas * (3 / 4) try: allocate_memory(get_free_memory() - memory_to_leave) except Exception as ex: TestRun.LOGGER.error(f"{ex}") with TestRun.step( "Try to load OpenCAS module and check if error message is printed on failure." ): output = load_kernel_module(CasModule.cache.value) if output.stderr and output.exit_code != 0: memory_left = get_free_memory() TestRun.LOGGER.info( f"Memory left for OpenCAS module: {memory_left.get_value(Unit.MiB):0.2f} MiB." ) TestRun.LOGGER.info(f"Cannot load OpenCAS module as expected.\n{output.stderr}") else: TestRun.LOGGER.error("Loading OpenCAS module successfully finished, but should fail.") with TestRun.step("Set memory options to default"): unmount_ramfs() defaultize_memory_affecting_functions()
def test_kedr_start_cache(module, unload_modules, install_kedr): """ title: Start cache and add core with kedr started against one of CAS modules description: | Load CAS modules, start kedr against one of them, start cache and add core, stop cache and unload modules pass_criteria: - No memory leaks observed """ with TestRun.step("Preparing cache device"): cache_device = TestRun.disks['cache'] cache_device.create_partitions([Size(500, Unit.MebiByte)]) cache_part = cache_device.partitions[0] with TestRun.step("Preparing core device"): core_device = TestRun.disks['core'] core_device.create_partitions([Size(1, Unit.GibiByte)]) core_part = core_device.partitions[0] with TestRun.step("Unload CAS modules if needed"): if os_utils.is_kernel_module_loaded(module.value): cas_module.unload_all_cas_modules() with TestRun.step(f"Starting kedr against {module.value}"): Kedr.start(module.value) with TestRun.step(f"Loading CAS modules"): os_utils.load_kernel_module(cas_module.CasModule.cache.value) with TestRun.step("Starting cache"): cache = casadm.start_cache(cache_part, force=True) with TestRun.step("Adding core"): cache.add_core(core_dev=core_part) with TestRun.step("Stopping cache"): cache.stop() with TestRun.step(f"Unloading CAS modules"): cas_module.unload_all_cas_modules() with TestRun.step(f"Checking for memory leaks for {module}"): try: Kedr.check_for_mem_leaks(module.value) except Exception as e: TestRun.LOGGER.error(f"{e}") with TestRun.step(f"Stopping kedr"): Kedr.stop()
def reload(self): self.teardown() sleep(1) load_output = os_utils.load_kernel_module(self.module_name, self.params) if load_output.exit_code != 0: raise CmdException(f"Failed to load {self.module_name} module", load_output) TestRun.LOGGER.info(f"{self.module_name} loaded successfully.") sleep(10) TestRun.scsi_debug_devices = Device.get_scsi_debug_devices()
def test_init_status(): """ title: CAS management device status description: | Verify that CAS management device is present in OS only when CAS modules are loaded. pass_criteria: - CAS management device present in OS when CAS modules are loaded. - CAS management device not present in OS when CAS modules are not loaded. """ with TestRun.step("Check if CAS management device is present in OS."): time.sleep(5) if cas_module.is_cas_management_dev_present(): TestRun.LOGGER.info( "CAS management device is present in OS when CAS module is loaded." ) else: TestRun.fail( "CAS management device is not present in OS when CAS module is loaded." ) with TestRun.step("Remove CAS module."): cas_module.unload_all_cas_modules() with TestRun.step("Stop CAS service."): casctl.stop() with TestRun.step("Check if CAS management device is not present in OS."): time.sleep(5) if not cas_module.is_cas_management_dev_present(): TestRun.LOGGER.info( "CAS management device is not present in OS when CAS module is not loaded." ) else: TestRun.fail( "CAS management device is present in OS when CAS module is not loaded." ) with TestRun.step("Load CAS modules and start CAS service."): os_utils.load_kernel_module(CasModule.cache.value) os_utils.load_kernel_module(CasModule.disk.value) casctl.start()
def test_kedr_fsim_load_cas_module(module, unload_modules, install_kedr): """ title: Loading modules with kedr started with 'fsim' configuration description: Load and unload modules with kedr started to simulate kmalloc fails pass_criteria: - Module fails to load """ with TestRun.step(f"Starting kedr against {module}"): Kedr.start(module.value, KedrProfile.FAULT_SIM) with TestRun.step("Setting up fault simulation parameters"): Kedr.setup_fault_injections() with TestRun.step(f"Trying to load {module}"): out = os_utils.load_kernel_module(module.value) if out.exit_code == 0 \ or "Cannot allocate memory" not in out.stderr: TestRun.LOGGER.error(f"Loading module should fail because of alloc error, instead " f"modprobe's output is: {out}") with TestRun.step(f"Stopping kedr"): Kedr.stop()
def reload_all_cas_modules(): os_utils.unload_kernel_module(CasModule.cache.value, ModuleRemoveMethod.modprobe) os_utils.load_kernel_module(CasModule.cache.value)