Refactor check_msg + fixes in touched files
Signed-off-by: Daniel Madej <daniel.madej@intel.com>
This commit is contained in:
parent
0621ca59b3
commit
f31587fc9d
@ -33,6 +33,14 @@ stop_cache_incomplete = [
|
||||
r"Cache is in incomplete state - at least one core is inactive"
|
||||
]
|
||||
|
||||
get_stats_ioclass_id_not_configured = [
|
||||
r"IO class \d+ is not configured\."
|
||||
]
|
||||
|
||||
get_stats_ioclass_id_out_of_range = [
|
||||
r"Invalid IO class id, must be in the range 0-32\."
|
||||
]
|
||||
|
||||
remove_multilevel_core = [
|
||||
r"Error while removing core device \d+ from cache instance \d+",
|
||||
r"Device opens or mount are pending to this cache"
|
||||
@ -52,9 +60,19 @@ stop_cache_mounted_core = [
|
||||
]
|
||||
|
||||
|
||||
def check_msg(output: Output, expected_messages):
|
||||
result = '\n'.join([output.stdout, output.stderr])
|
||||
def check_stderr_msg(output: Output, expected_messages):
|
||||
return __check_string_msg(output.stderr, expected_messages)
|
||||
|
||||
|
||||
def check_stdout_msg(output: Output, expected_messages):
|
||||
return __check_string_msg(output.stdout, expected_messages)
|
||||
|
||||
|
||||
def __check_string_msg(text: str, expected_messages):
|
||||
msg_ok = True
|
||||
for msg in expected_messages:
|
||||
matches = re.search(msg, result)
|
||||
matches = re.search(msg, text)
|
||||
if not matches:
|
||||
TestRun.LOGGER.error(f"Message is incorrect, expected: {msg}\n actual: {result}.")
|
||||
TestRun.LOGGER.error(f"Message is incorrect, expected: {msg}\n actual: {text}.")
|
||||
msg_ok = False
|
||||
return msg_ok
|
||||
|
@ -2,14 +2,13 @@
|
||||
# Copyright(c) 2020 Intel Corporation
|
||||
# SPDX-License-Identifier: BSD-3-Clause-Clear
|
||||
#
|
||||
from time import sleep
|
||||
|
||||
import pytest
|
||||
|
||||
from api.cas import casadm, casadm_parser, cli, cli_messages
|
||||
from api.cas.cache_config import CacheMode, CleaningPolicy, CacheModeTrait
|
||||
from storage_devices.disk import DiskType, DiskTypeSet, DiskTypeLowerThan
|
||||
from core.test_run import TestRun
|
||||
from storage_devices.disk import DiskType, DiskTypeSet, DiskTypeLowerThan
|
||||
from test_tools import fs_utils
|
||||
from test_tools.dd import Dd
|
||||
from test_tools.disk_utils import Filesystem
|
||||
@ -69,7 +68,7 @@ def test_stop_no_flush_load_cache(cache_mode, filesystem):
|
||||
output = TestRun.executor.run_expect_fail(cli.start_cmd(
|
||||
cache_dev=str(cache_part.system_path), cache_mode=str(cache_mode.name.lower()),
|
||||
force=False, load=False))
|
||||
cli_messages.check_msg(output, cli_messages.start_cache_with_existing_metadata)
|
||||
cli_messages.check_stderr_msg(output, cli_messages.start_cache_with_existing_metadata)
|
||||
|
||||
with TestRun.step("Load cache."):
|
||||
cache = casadm.load_cache(cache.cache_device)
|
||||
@ -146,7 +145,7 @@ def test_stop_no_flush_load_cache_no_fs(cache_mode):
|
||||
output = TestRun.executor.run_expect_fail(cli.start_cmd(
|
||||
cache_dev=str(cache_part.system_path), cache_mode=str(cache_mode.name.lower()),
|
||||
force=False, load=False))
|
||||
cli_messages.check_msg(output, cli_messages.start_cache_with_existing_metadata)
|
||||
cli_messages.check_stderr_msg(output, cli_messages.start_cache_with_existing_metadata)
|
||||
|
||||
with TestRun.step("Load cache."):
|
||||
cache = casadm.load_cache(cache.cache_device)
|
||||
|
@ -7,8 +7,8 @@ import pytest
|
||||
|
||||
from api.cas import casadm, casadm_parser, cli, cli_messages
|
||||
from api.cas.cache_config import CacheMode
|
||||
from storage_devices.disk import DiskType, DiskTypeSet, DiskTypeLowerThan
|
||||
from core.test_run import TestRun
|
||||
from storage_devices.disk import DiskType, DiskTypeSet, DiskTypeLowerThan
|
||||
from test_tools import fs_utils
|
||||
from test_tools.disk_utils import Filesystem
|
||||
from test_utils.size import Size, Unit
|
||||
@ -109,11 +109,11 @@ def test_stop_cache_with_mounted_partition(cache_mode):
|
||||
with TestRun.step("Try to remove core from cache."):
|
||||
output = TestRun.executor.run_expect_fail(cli.remove_core_cmd(cache_id=str(cache.cache_id),
|
||||
core_id=str(core.core_id)))
|
||||
cli_messages.check_msg(output, cli_messages.remove_mounted_core)
|
||||
cli_messages.check_stderr_msg(output, cli_messages.remove_mounted_core)
|
||||
|
||||
with TestRun.step("Try to stop CAS."):
|
||||
output = TestRun.executor.run_expect_fail(cli.stop_cmd(cache_id=str(cache.cache_id)))
|
||||
cli_messages.check_msg(output, cli_messages.stop_cache_mounted_core)
|
||||
cli_messages.check_stderr_msg(output, cli_messages.stop_cache_mounted_core)
|
||||
|
||||
with TestRun.step("Unmount core device."):
|
||||
core.unmount()
|
||||
@ -158,12 +158,12 @@ def test_add_cached_core(cache_mode):
|
||||
output = TestRun.executor.run_expect_fail(
|
||||
cli.add_core_cmd(cache_id=str(cache2.cache_id), core_dev=str(core_part.system_path),
|
||||
core_id=str(core.core_id)))
|
||||
cli_messages.check_msg(output, cli_messages.add_cached_core)
|
||||
cli_messages.check_stderr_msg(output, cli_messages.add_cached_core)
|
||||
|
||||
with TestRun.step("Try adding the same core device to the same cache for the second time."):
|
||||
output = TestRun.executor.run_expect_fail(
|
||||
cli.add_core_cmd(cache_id=str(cache1.cache_id), core_dev=str(core_part.system_path)))
|
||||
cli_messages.check_msg(output, cli_messages.add_cached_core)
|
||||
cli_messages.check_stderr_msg(output, cli_messages.add_cached_core)
|
||||
|
||||
with TestRun.step("Stop caches."):
|
||||
casadm.stop_all_caches()
|
||||
|
@ -6,8 +6,8 @@
|
||||
import pytest
|
||||
|
||||
from api.cas import casadm, cli, cli_messages
|
||||
from storage_devices.disk import DiskType, DiskTypeSet, DiskTypeLowerThan
|
||||
from core.test_run import TestRun
|
||||
from storage_devices.disk import DiskType, DiskTypeSet, DiskTypeLowerThan
|
||||
from test_utils.size import Size, Unit
|
||||
|
||||
|
||||
@ -49,7 +49,7 @@ def test_remove_multilevel_core():
|
||||
output = TestRun.executor.run_expect_fail(cli.remove_core_cmd(cache_id=str(cache1.cache_id),
|
||||
core_id=str(core1.core_id),
|
||||
force=True))
|
||||
cli_messages.check_msg(output, cli_messages.remove_multilevel_core)
|
||||
cli_messages.check_stderr_msg(output, cli_messages.remove_multilevel_core)
|
||||
|
||||
with TestRun.step("Stop cache."):
|
||||
casadm.stop_all_caches()
|
||||
|
@ -1,16 +1,18 @@
|
||||
#
|
||||
# Copyright(c) 2019 Intel Corporation
|
||||
# Copyright(c) 2019-2020 Intel Corporation
|
||||
# SPDX-License-Identifier: BSD-3-Clause-Clear
|
||||
#
|
||||
|
||||
import time
|
||||
from datetime import timedelta
|
||||
from random import shuffle
|
||||
|
||||
import pytest
|
||||
import time
|
||||
from api.cas import casadm, init_config, cli, cli_messages
|
||||
|
||||
from api.cas import casadm, cli, cli_messages
|
||||
from api.cas.cache_config import CacheStatus, SeqCutOffPolicy
|
||||
from api.cas.core import CoreStatus, CacheMode, CleaningPolicy, FlushParametersAlru, File
|
||||
from api.cas.init_config import InitConfig
|
||||
from api.cas.statistics import CacheStats
|
||||
from core.test_run import TestRun
|
||||
from storage_devices.disk import DiskTypeSet, DiskType, DiskTypeLowerThan
|
||||
@ -47,7 +49,7 @@ def test_attach_core_to_incomplete_cache_volume():
|
||||
cache = casadm.start_cache(cache_dev, force=True)
|
||||
core = cache.add_core(core_dev)
|
||||
with TestRun.step("Create init config file using current CAS configuration."):
|
||||
init_config.create_init_config_from_running_configuration()
|
||||
InitConfig.create_init_config_from_running_configuration()
|
||||
with TestRun.step("Stop cache."):
|
||||
cache.stop()
|
||||
with TestRun.step("Load cache."):
|
||||
@ -106,7 +108,7 @@ def test_flush_inactive_devices():
|
||||
first_core = cache.add_core(first_core_dev)
|
||||
second_core = cache.add_core(second_core_dev)
|
||||
with TestRun.step("Create init config file using running CAS configuration."):
|
||||
init_config.create_init_config_from_running_configuration()
|
||||
InitConfig.create_init_config_from_running_configuration()
|
||||
with TestRun.step("Run random writes to CAS device."):
|
||||
run_fio([first_core.system_path, second_core.system_path])
|
||||
with TestRun.step("Stop cache without flushing dirty data."):
|
||||
@ -180,7 +182,7 @@ def test_list_cache_and_cache_volumes():
|
||||
if cache_status != CacheStatus.running:
|
||||
TestRun.fail(f"Cache should be in running state. Actual state: {cache_status}")
|
||||
with TestRun.step("Create init config file using current CAS configuration."):
|
||||
init_config.create_init_config_from_running_configuration()
|
||||
InitConfig.create_init_config_from_running_configuration()
|
||||
with TestRun.step("Stop cache."):
|
||||
cache.stop()
|
||||
with TestRun.step("Unplug core device."):
|
||||
@ -226,14 +228,14 @@ def test_load_cache_with_inactive_core():
|
||||
cache = casadm.start_cache(cache_dev, force=True)
|
||||
core = cache.add_core(core_dev)
|
||||
with TestRun.step("Create init config file using current CAS configuration."):
|
||||
init_config.create_init_config_from_running_configuration()
|
||||
InitConfig.create_init_config_from_running_configuration()
|
||||
with TestRun.step("Stop cache."):
|
||||
cache.stop()
|
||||
with TestRun.step("Unplug core device."):
|
||||
plug_device.unplug()
|
||||
with TestRun.step("Load cache."):
|
||||
output = TestRun.executor.run(cli.load_cmd(cache_dev.system_path))
|
||||
cli_messages.check_msg(output, cli_messages.load_inactive_core_missing)
|
||||
cli_messages.check_stderr_msg(output, cli_messages.load_inactive_core_missing)
|
||||
with TestRun.step("Plug missing device and stop cache."):
|
||||
plug_device.plug()
|
||||
core.wait_for_status_change(CoreStatus.active)
|
||||
@ -267,7 +269,7 @@ def test_preserve_data_for_inactive_device():
|
||||
cache.set_cleaning_policy(CleaningPolicy.nop)
|
||||
core = cache.add_core(core_dev)
|
||||
with TestRun.step("Create init config file using current CAS configuration."):
|
||||
init_config.create_init_config_from_running_configuration()
|
||||
InitConfig.create_init_config_from_running_configuration()
|
||||
with TestRun.step("Create filesystem on CAS device and mount it."):
|
||||
core.create_filesystem(Filesystem.ext3)
|
||||
core.mount(mount_dir)
|
||||
@ -361,7 +363,7 @@ def test_print_statistics_inactive(cache_mode):
|
||||
first_core = cache.add_core(first_core_dev)
|
||||
second_core = cache.add_core(second_core_dev)
|
||||
with TestRun.step("Create init config file using current CAS configuration."):
|
||||
init_config.create_init_config_from_running_configuration()
|
||||
InitConfig.create_init_config_from_running_configuration()
|
||||
with TestRun.step("Run IO."):
|
||||
run_fio([first_core.system_path, second_core.system_path])
|
||||
with TestRun.step("Print statistics and check if there is no inactive usage section."):
|
||||
@ -448,7 +450,7 @@ def test_remove_detached_cores():
|
||||
for d in core_devs:
|
||||
cores.append(cache.add_core(d))
|
||||
with TestRun.step("Create init config file using current CAS configuration."):
|
||||
init_config.create_init_config_from_running_configuration()
|
||||
InitConfig.create_init_config_from_running_configuration()
|
||||
with TestRun.step("Run random writes to all CAS devices."):
|
||||
run_fio([c.system_path for c in cores])
|
||||
with TestRun.step("Flush dirty data from two CAS devices and verify than other two contain "
|
||||
@ -507,7 +509,7 @@ def test_remove_inactive_devices():
|
||||
for d in core_devs:
|
||||
cores.append(cache.add_core(d))
|
||||
with TestRun.step("Create init config file using current CAS configuration."):
|
||||
init_config.create_init_config_from_running_configuration()
|
||||
InitConfig.create_init_config_from_running_configuration()
|
||||
with TestRun.step("Run random writes to all CAS devices."):
|
||||
run_fio([c.system_path for c in cores])
|
||||
with TestRun.step("Flush dirty data from two CAS devices and verify than other two "
|
||||
@ -549,7 +551,7 @@ def test_remove_inactive_devices():
|
||||
"command returned an error.")
|
||||
TestRun.LOGGER.info("Remove operation without force option is blocked for "
|
||||
"dirty CAS device as expected.")
|
||||
cli_messages.check_msg(e.output, cli_messages.remove_inactive_core)
|
||||
cli_messages.check_stderr_msg(e.output, cli_messages.remove_inactive_core)
|
||||
output = casadm.list_caches().stdout
|
||||
if core.system_path not in output:
|
||||
TestRun.fail(f"CAS device is not listed in casadm list output but it should be."
|
||||
@ -582,7 +584,7 @@ def test_stop_cache_with_inactive_devices():
|
||||
cache = casadm.start_cache(cache_dev, cache_mode=CacheMode.WB, force=True)
|
||||
core = cache.add_core(core_dev)
|
||||
with TestRun.step("Create init config file using current CAS configuration."):
|
||||
init_config.create_init_config_from_running_configuration()
|
||||
InitConfig.create_init_config_from_running_configuration()
|
||||
with TestRun.step("Run random writes and verify that CAS device contains dirty data."):
|
||||
run_fio([core.system_path])
|
||||
if core.get_dirty_blocks() == Size.zero():
|
||||
@ -629,7 +631,7 @@ def try_stop_incomplete_cache(cache):
|
||||
cache.stop()
|
||||
except CmdException as e:
|
||||
TestRun.LOGGER.info("Stopping cache without 'no data flush' option is blocked as expected.")
|
||||
cli_messages.check_msg(e.output, cli_messages.stop_cache_incomplete)
|
||||
cli_messages.check_stderr_msg(e.output, cli_messages.stop_cache_incomplete)
|
||||
|
||||
|
||||
def check_inactive_usage_stats(stats_before, stats_after, stat_name, should_be_zero):
|
||||
|
Loading…
Reference in New Issue
Block a user