Skip to content

Commit

Permalink
Minor refactor
Browse files Browse the repository at this point in the history
Rename get_core_devices() to get_cores()
Removed hardcoded / in conftest for paths which can be
resolved differently depending on OS

Signed-off-by: Daniel Madej <daniel.madej@huawei.com>
  • Loading branch information
Deixx committed Nov 18, 2024
1 parent c142610 commit 268c92d
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 29 deletions.
2 changes: 1 addition & 1 deletion test/functional/api/cas/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __get_cache_id(self) -> int:
def __get_cache_device_path(self) -> str:
return self.cache_device.path if self.cache_device is not None else "-"

def get_core_devices(self) -> list:
def get_cores(self) -> list:
return get_cores(self.cache_id)

def get_cache_line_size(self) -> CacheLineSize:
Expand Down
16 changes: 9 additions & 7 deletions test/functional/tests/cli/test_cli_start_stop.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#
# Copyright(c) 2019-2021 Intel Corporation
# Copyright(c) 2024 Huawei Technologies
# SPDX-License-Identifier: BSD-3-Clause
#

import pytest
from random import randint

import pytest

from api.cas import casadm, casadm_parser, cli_messages
from api.cas.cli import start_cmd
from core.test_run import TestRun
Expand Down Expand Up @@ -125,9 +127,9 @@ def test_cli_add_remove_default_id(shortcut):

with TestRun.step("Check if the core is added to the cache."):
caches = casadm_parser.get_caches()
if len(caches[0].get_core_devices()) != 1:
if len(caches[0].get_cores()) != 1:
TestRun.fail("One core should be present in the cache.")
if caches[0].get_core_devices()[0].path != core.path:
if caches[0].get_cores()[0].path != core.path:
TestRun.fail("The core path should be equal to the path of the core added.")

with TestRun.step("Remove the core from the cache."):
Expand All @@ -137,7 +139,7 @@ def test_cli_add_remove_default_id(shortcut):
caches = casadm_parser.get_caches()
if len(caches) != 1:
TestRun.fail("One cache should be still present after removing the core.")
if len(caches[0].get_core_devices()) != 0:
if len(caches[0].get_cores()) != 0:
TestRun.fail("No core device should be present after removing the core.")

with TestRun.step("Stop the cache."):
Expand Down Expand Up @@ -178,9 +180,9 @@ def test_cli_add_remove_custom_id(shortcut):

with TestRun.step("Check if the core is added to the cache."):
caches = casadm_parser.get_caches()
if len(caches[0].get_core_devices()) != 1:
if len(caches[0].get_cores()) != 1:
TestRun.fail("One core should be present in the cache.")
if caches[0].get_core_devices()[0].path != core.path:
if caches[0].get_cores()[0].path != core.path:
TestRun.fail("The core path should be equal to the path of the core added.")

with TestRun.step("Remove the core from the cache."):
Expand All @@ -190,7 +192,7 @@ def test_cli_add_remove_custom_id(shortcut):
caches = casadm_parser.get_caches()
if len(caches) != 1:
TestRun.fail("One cache should be still present after removing the core.")
if len(caches[0].get_core_devices()) != 0:
if len(caches[0].get_cores()) != 0:
TestRun.fail("No core device should be present after removing the core.")

with TestRun.step("Stop the cache."):
Expand Down
12 changes: 7 additions & 5 deletions test/functional/tests/cli/test_seq_cutoff_settings.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
#
# Copyright(c) 2019-2022 Intel Corporation
# Copyright(c) 2024 Huawei Technologies
# SPDX-License-Identifier: BSD-3-Clause
#


import pytest
import random
from ctypes import c_uint32

import pytest

from api.cas import casadm
from api.cas.cache_config import SeqCutOffPolicy
from api.cas.core import SEQ_CUTOFF_THRESHOLD_MAX, SEQ_CUT_OFF_THRESHOLD_DEFAULT
from api.cas.casadm import set_param_cutoff_cmd
from api.cas.core import SEQ_CUTOFF_THRESHOLD_MAX, SEQ_CUT_OFF_THRESHOLD_DEFAULT
from core.test_run import TestRun

from storage_devices.disk import DiskType, DiskTypeSet, DiskTypeLowerThan
from test_utils.size import Size, Unit

Expand Down Expand Up @@ -137,7 +139,7 @@ def test_seq_cutoff_policy_load():
loaded_cache = casadm.load_cache(cache.cache_device)

with TestRun.step("Getting cores from loaded cache"):
cores = loaded_cache.get_core_devices()
cores = loaded_cache.get_cores()

for i, core in TestRun.iteration(enumerate(cores[:-1]), "Check if proper policies have "
"been loaded"):
Expand Down Expand Up @@ -251,7 +253,7 @@ def test_seq_cutoff_threshold_load(threshold):
loaded_cache = casadm.load_cache(cache.cache_device)

with TestRun.step("Getting core from loaded cache"):
cores_load = loaded_cache.get_core_devices()
cores_load = loaded_cache.get_cores()

with TestRun.step("Check if proper sequential cut off policy was loaded"):
if cores_load[0].get_seq_cut_off_threshold() != _threshold:
Expand Down
10 changes: 5 additions & 5 deletions test/functional/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import pytest
import yaml

sys.path.append(os.path.join(os.path.dirname(__file__), "../test-framework"))
sys.path.append(os.path.join(os.path.dirname(__file__), "..", "test-framework"))

from core.test_run import Blocked
from core.test_run_utils import TestRun
Expand Down Expand Up @@ -84,7 +84,7 @@ def pytest_runtest_setup(item):
raise Exception(f"{ex}\n"
f"You need to specify DUT config. See the example_dut_config.py file")

dut_config['plugins_dir'] = os.path.join(os.path.dirname(__file__), "../lib")
dut_config['plugins_dir'] = os.path.join(os.path.dirname(__file__), "..", "lib")
dut_config['opt_plugins'] = {"test_wrapper": {}, "serial_log": {}, "power_control": {}}
dut_config['extra_logs'] = {"cas": "/var/log/opencas.log"}

Expand All @@ -108,7 +108,7 @@ def pytest_runtest_setup(item):
f"{str(ex)}\n{traceback.format_exc()}")

TestRun.usr = Opencas(
repo_dir=os.path.join(os.path.dirname(__file__), "../../.."),
repo_dir=os.path.join(os.path.dirname(__file__), "..", "..", ".."),
working_dir=dut_config['working_dir'])
if item.config.getoption('--fuzzy-iter-count'):
TestRun.usr.fuzzy_iter_count = int(item.config.getoption('--fuzzy-iter-count'))
Expand Down Expand Up @@ -191,7 +191,7 @@ def pytest_addoption(parser):
TestRun.addoption(parser)
parser.addoption("--dut-config", action="append", type=str)
parser.addoption("--log-path", action="store",
default=f"{os.path.join(os.path.dirname(__file__), '../results')}")
default=f"{os.path.join(os.path.dirname(__file__), '..', 'results')}")
parser.addoption("--fuzzy-iter-count", action="store")


Expand Down Expand Up @@ -220,7 +220,7 @@ def unmount_cas_devices():
def __drbd_cleanup():
from storage_devices.drbd import Drbd
Drbd.down_all()
# If drbd instance had been configured on top of the CAS, the previos attempt to stop
# If drbd instance had been configured on top of the CAS, the previous attempt to stop
# failed. As drbd has been stopped try to stop CAS one more time.
if installer.check_if_installed():
casadm.stop_all_caches()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def test_core_inactive_stats_usage():
active_cores_clean_stats = 0
active_cores_dirty_stats = 0

active_cores = cache.get_core_devices()
active_cores = cache.get_cores()
for core in active_cores:
core_stats = core.get_statistics()
active_cores_occupancy_stats += core_stats.usage_stats.occupancy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
# SPDX-License-Identifier: BSD-3-Clause
#

import pytest
import time

from random import shuffle

import pytest

from api.cas import casadm, cli, cli_messages
from api.cas.cache_config import (
CacheStatus,
Expand Down Expand Up @@ -128,7 +128,7 @@ def test_incremental_load_missing_core_device():
if core.get_status() is not CoreStatus.active:
TestRun.fail(f"Core {core.core_id} should be active but is {core.get_status()}.")

core_with_missing_device = cache.get_core_devices()[-1]
core_with_missing_device = cache.get_cores()[-1]

with TestRun.step("Stop cache."):
cache.stop()
Expand All @@ -142,7 +142,7 @@ def test_incremental_load_missing_core_device():
TestRun.fail(
f"Cache {cache.cache_id} should be incomplete but is " f"{cache.get_status()}."
)
for core in cache.get_core_devices():
for core in cache.get_cores():
if core.get_status() is not CoreStatus.active:
TestRun.fail(f"Core {core.core_id} should be Active but is {core.get_status()}.")
if core_with_missing_device.get_status() is not CoreStatus.inactive:
Expand Down
4 changes: 3 additions & 1 deletion test/functional/tests/initialize/test_negative_load.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#
# Copyright(c) 2019-2022 Intel Corporation
# Copyright(c) 2024 Huawei Technologies
# SPDX-License-Identifier: BSD-3-Clause
#


import pytest

from api.cas import casadm, casadm_parser, cli, cli_messages
from core.test_run import TestRun
from storage_devices.disk import DiskType, DiskTypeSet, DiskTypeLowerThan
Expand Down Expand Up @@ -56,7 +58,7 @@ def test_load_occupied_id():
if caches[0].cache_id != 1:
TestRun.LOGGER.error("Wrong cache id.")

cores = caches[0].get_core_devices()
cores = caches[0].get_cores()
if len(cores) != 0:
TestRun.LOGGER.error("Inappropriate number of cores after load!")

Expand Down
4 changes: 2 additions & 2 deletions test/functional/tests/initialize/test_simulation_startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_simulation_startup_from_config():
)

with TestRun.step("Verify if core is working"):
core = cache.get_core_devices()[0]
core = cache.get_cores()[0]
if core.get_status() is not CoreStatus.active:
TestRun.fail(
f"Core {core.core_id} should be active but is in {core.get_status()} " f"state."
Expand All @@ -89,7 +89,7 @@ def test_simulation_startup_from_config():
)

with TestRun.step("Verify if core is working"):
cores = cache.get_core_devices()
cores = cache.get_cores()
if not cores:
TestRun.fail("Core is not working")
core = cores[0]
Expand Down
6 changes: 3 additions & 3 deletions test/functional/tests/stats/test_ioclass_stats.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#
# Copyright(c) 2019-2021 Intel Corporation
# Copyright(c) 2024 Huawei Technologies
# SPDX-License-Identifier: BSD-3-Clause
#
import random
Expand All @@ -17,7 +18,6 @@
)
from api.cas.statistics import (
config_stats_ioclass,
usage_stats,
usage_stats_ioclass,
request_stats,
block_stats_core,
Expand Down Expand Up @@ -234,7 +234,7 @@ def test_ioclass_stats_sections(stat_filter, per_core, random_cls):
f"{'cores' if per_core else 'caches'}"):
for cache in caches:
with TestRun.group(f"Cache {cache.cache_id}"):
for core in cache.get_core_devices():
for core in cache.get_cores():
if per_core:
TestRun.LOGGER.info(f"Core {core.cache_id}-{core.core_id}")
statistics = (
Expand All @@ -256,7 +256,7 @@ def test_ioclass_stats_sections(stat_filter, per_core, random_cls):
f"class for all {'cores' if per_core else 'caches'}"):
for cache in caches:
with TestRun.group(f"Cache {cache.cache_id}"):
for core in cache.get_core_devices():
for core in cache.get_cores():
core_info = f"Core {core.cache_id}-{core.core_id} ," if per_core else ""
for class_id in range(ioclass_config.MAX_IO_CLASS_ID + 1):
with TestRun.group(core_info + f"IO class id {class_id}"):
Expand Down

0 comments on commit 268c92d

Please sign in to comment.