From 6be612be782fdf650d39d635cb967ffafcdaafe0 Mon Sep 17 00:00:00 2001 From: Katarzyna Lapinska Date: Thu, 2 Jul 2020 12:00:18 +0200 Subject: [PATCH] Add init test with different runlevels and test for management device status Signed-off-by: Katarzyna Lapinska --- test/functional/api/cas/cas_module.py | 6 +- test/functional/test-framework | 2 +- .../initialize/test_initialize_runlevel.py | 89 +++++++++++++++++++ .../initialize/test_initialize_status.py | 43 +++++++++ 4 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 test/functional/tests/initialize/test_initialize_runlevel.py create mode 100644 test/functional/tests/initialize/test_initialize_status.py diff --git a/test/functional/api/cas/cas_module.py b/test/functional/api/cas/cas_module.py index 840261f..40b801f 100644 --- a/test/functional/api/cas/cas_module.py +++ b/test/functional/api/cas/cas_module.py @@ -4,7 +4,7 @@ # from aenum import Enum - +from core.test_run import TestRun from test_utils import os_utils from test_utils.os_utils import ModuleRemoveMethod @@ -24,3 +24,7 @@ def unload_all_cas_modules(): os_utils.ModuleRemoveMethod.rmmod) os_utils.unload_kernel_module(CasModule.disk.value, os_utils.ModuleRemoveMethod.rmmod) + + +def is_cas_management_dev_present(): + return TestRun.executor.run("test -c /dev/cas_ctrl").exit_code == 0 diff --git a/test/functional/test-framework b/test/functional/test-framework index 0156c9f..e01877e 160000 --- a/test/functional/test-framework +++ b/test/functional/test-framework @@ -1 +1 @@ -Subproject commit 0156c9ff20db765c11f547a042a2146b3ce06ddc +Subproject commit e01877eb8d47a6b2ffd38fea7913e24cf15b92ad diff --git a/test/functional/tests/initialize/test_initialize_runlevel.py b/test/functional/tests/initialize/test_initialize_runlevel.py new file mode 100644 index 0000000..7444a7e --- /dev/null +++ b/test/functional/tests/initialize/test_initialize_runlevel.py @@ -0,0 +1,89 @@ +# +# Copyright(c) 2020 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +import os +import pytest +import time +from api.cas import casadm, casadm_parser +from api.cas.cache_config import CacheMode +from api.cas.init_config import InitConfig +from core.test_run import TestRun +from storage_devices.disk import DiskTypeLowerThan, DiskTypeSet, DiskType +from test_tools.disk_utils import Filesystem +from test_tools.fio.fio import Fio +from test_tools.fio.fio_param import ReadWrite, IoEngine +from test_utils import os_utils +from test_utils.os_utils import Runlevel +from test_utils.size import Size, Unit + + +mount_point = "/mnt/test" + + +@pytest.mark.require_disk("cache", DiskTypeSet([DiskType.optane, DiskType.nand])) +@pytest.mark.require_disk("core", DiskTypeLowerThan("cache")) +@pytest.mark.parametrize("runlevel", [Runlevel.runlevel5, Runlevel.runlevel3]) +@pytest.mark.parametrize("cache_mode", CacheMode) +def test_init_reboot_runlevels(runlevel, cache_mode): + """ + title: Initialize CAS devices after reboot + description: | + Verify that CAS init script starts cache properly after reboot in different runlevels. + pass_criteria: + - Cache should be loaded successfully after reboot. + """ + with TestRun.step(f"Set runlevel to {runlevel.value}."): + os_utils.change_runlevel(runlevel) + + with TestRun.step("Prepare CAS device."): + cache_disk = TestRun.disks['cache'] + cache_disk.create_partitions([Size(2, Unit.GibiByte)]) + cache_dev = cache_disk.partitions[0] + core_disk = TestRun.disks['core'] + core_disk.create_partitions([Size(1, Unit.GibiByte)]) + core_dev = core_disk.partitions[0] + + cache = casadm.start_cache(cache_dev, cache_mode, force=True) + core = cache.add_core(core_dev) + + with TestRun.step("Create CAS init config based on running configuration."): + InitConfig.create_init_config_from_running_configuration() + + with TestRun.step("Make filesystem on CAS device and mount it."): + core.create_filesystem(Filesystem.xfs) + core.mount(mount_point) + + with TestRun.step("Start writing file to CAS."): + fio = Fio().create_command()\ + .file_name(os.path.join(mount_point, "test_file"))\ + .read_write(ReadWrite.randwrite)\ + .io_engine(IoEngine.sync)\ + .num_jobs(1).direct()\ + .file_size(Size(30, Unit.GibiByte)) + + fio.run_in_background() + os_utils.sync() + os_utils.drop_caches() + + time.sleep(10) + TestRun.executor.run_expect_success("pgrep fio") + + with TestRun.step("Reboot machine during writing a file."): + TestRun.executor.reboot() + + with TestRun.step("Check if cache was properly started at boot time"): + # Wait for CAS to load after boot + time.sleep(60) + caches = casadm_parser.get_caches() + if len(caches) == 1: + TestRun.LOGGER.info("Cache started properly at boot time.") + else: + TestRun.LOGGER.error("Cache did not start properly at boot time.") + + with TestRun.step("Stop cache and set default runlevel."): + if len(caches) != 0: + casadm.stop_all_caches() + os_utils.change_runlevel(Runlevel.runlevel3) + TestRun.executor.reboot() diff --git a/test/functional/tests/initialize/test_initialize_status.py b/test/functional/tests/initialize/test_initialize_status.py new file mode 100644 index 0000000..4a766b6 --- /dev/null +++ b/test/functional/tests/initialize/test_initialize_status.py @@ -0,0 +1,43 @@ +# +# Copyright(c) 2020 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +from api.cas import cas_module, casctl +from api.cas.cas_module import CasModule +from core.test_run import TestRun +from test_utils import os_utils + + +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."): + 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."): + 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()