Skip to content

Commit b669392

Browse files
committed
Minor refactor
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>
1 parent 1934e80 commit b669392

File tree

9 files changed

+39
-37
lines changed

9 files changed

+39
-37
lines changed

test/functional/api/cas/cache.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#
22
# Copyright(c) 2019-2021 Intel Corporation
3-
# Copyright(c) 2024 Huawei Technologies Co., Ltd.
3+
# Copyright(c) 2024-2025 Huawei Technologies Co., Ltd.
44
# SPDX-License-Identifier: BSD-3-Clause
55
#
66

@@ -32,7 +32,7 @@ def __get_cache_id(self) -> int:
3232
def __get_cache_device_path(self) -> str:
3333
return self.cache_device.path if self.cache_device is not None else "-"
3434

35-
def get_core_devices(self) -> list:
35+
def get_cores(self) -> list:
3636
return get_cores(self.cache_id)
3737

3838
def get_cache_line_size(self) -> CacheLineSize:

test/functional/tests/cli/test_cli_start_stop.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#
22
# Copyright(c) 2019-2021 Intel Corporation
3-
# Copyright(c) 2024 Huawei Technologies Co., Ltd.
3+
# Copyright(c) 2024-2025 Huawei Technologies Co., Ltd.
44
# SPDX-License-Identifier: BSD-3-Clause
55
#
66

7-
import pytest
87
from random import randint
98

9+
import pytest
10+
1011
from api.cas import casadm, casadm_parser, cli_messages
1112
from api.cas.cli import start_cmd
1213
from core.test_run import TestRun
@@ -126,9 +127,9 @@ def test_cli_add_remove_default_id(shortcut):
126127

127128
with TestRun.step("Check if the core is added to the cache."):
128129
caches = casadm_parser.get_caches()
129-
if len(caches[0].get_core_devices()) != 1:
130+
if len(caches[0].get_cores()) != 1:
130131
TestRun.fail("One core should be present in the cache.")
131-
if caches[0].get_core_devices()[0].path != core.path:
132+
if caches[0].get_cores()[0].path != core.path:
132133
TestRun.fail("The core path should be equal to the path of the core added.")
133134

134135
with TestRun.step("Remove the core from the cache."):
@@ -138,7 +139,7 @@ def test_cli_add_remove_default_id(shortcut):
138139
caches = casadm_parser.get_caches()
139140
if len(caches) != 1:
140141
TestRun.fail("One cache should be still present after removing the core.")
141-
if len(caches[0].get_core_devices()) != 0:
142+
if len(caches[0].get_cores()) != 0:
142143
TestRun.fail("No core device should be present after removing the core.")
143144

144145
with TestRun.step("Stop the cache."):
@@ -179,9 +180,9 @@ def test_cli_add_remove_custom_id(shortcut):
179180

180181
with TestRun.step("Check if the core is added to the cache."):
181182
caches = casadm_parser.get_caches()
182-
if len(caches[0].get_core_devices()) != 1:
183+
if len(caches[0].get_cores()) != 1:
183184
TestRun.fail("One core should be present in the cache.")
184-
if caches[0].get_core_devices()[0].path != core.path:
185+
if caches[0].get_cores()[0].path != core.path:
185186
TestRun.fail("The core path should be equal to the path of the core added.")
186187

187188
with TestRun.step("Remove the core from the cache."):
@@ -191,7 +192,7 @@ def test_cli_add_remove_custom_id(shortcut):
191192
caches = casadm_parser.get_caches()
192193
if len(caches) != 1:
193194
TestRun.fail("One cache should be still present after removing the core.")
194-
if len(caches[0].get_core_devices()) != 0:
195+
if len(caches[0].get_cores()) != 0:
195196
TestRun.fail("No core device should be present after removing the core.")
196197

197198
with TestRun.step("Stop the cache."):

test/functional/tests/cli/test_seq_cutoff_settings.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
#
22
# Copyright(c) 2019-2022 Intel Corporation
3-
# Copyright(c) 2024 Huawei Technologies Co., Ltd.
3+
# Copyright(c) 2024-2025 Huawei Technologies Co., Ltd.
44
# SPDX-License-Identifier: BSD-3-Clause
55
#
66

77

8-
import pytest
98
import random
109
from ctypes import c_uint32
10+
11+
import pytest
12+
1113
from api.cas import casadm
1214
from api.cas.cache_config import SeqCutOffPolicy
13-
from api.cas.core import SEQ_CUTOFF_THRESHOLD_MAX, SEQ_CUT_OFF_THRESHOLD_DEFAULT
1415
from api.cas.casadm import set_param_cutoff_cmd
16+
from api.cas.core import SEQ_CUTOFF_THRESHOLD_MAX, SEQ_CUT_OFF_THRESHOLD_DEFAULT
1517
from core.test_run import TestRun
16-
1718
from storage_devices.disk import DiskType, DiskTypeSet, DiskTypeLowerThan
1819
from type_def.size import Size, Unit
1920

@@ -138,7 +139,7 @@ def test_seq_cutoff_policy_load():
138139
loaded_cache = casadm.load_cache(cache.cache_device)
139140

140141
with TestRun.step("Getting cores from loaded cache"):
141-
cores = loaded_cache.get_core_devices()
142+
cores = loaded_cache.get_cores()
142143

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

254255
with TestRun.step("Getting core from loaded cache"):
255-
cores_load = loaded_cache.get_core_devices()
256+
cores_load = loaded_cache.get_cores()
256257

257258
with TestRun.step("Check if proper sequential cut off policy was loaded"):
258259
if cores_load[0].get_seq_cut_off_threshold() != _threshold:

test/functional/tests/conftest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from datetime import timedelta
1616

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

1919
from core.test_run import Blocked
2020
from core.test_run_utils import TestRun
@@ -98,7 +98,7 @@ def pytest_runtest_setup(item):
9898
f"{ex}\nYou need to specify DUT config. See the example_dut_config.py file"
9999
)
100100

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

@@ -123,7 +123,7 @@ def pytest_runtest_setup(item):
123123
)
124124

125125
TestRun.usr = Opencas(
126-
repo_dir=os.path.join(os.path.dirname(__file__), "../../.."),
126+
repo_dir=os.path.join(os.path.dirname(__file__), "..", "..", ".."),
127127
working_dir=dut_config["working_dir"],
128128
)
129129
if item.config.getoption("--fuzzy-iter-count"):
@@ -299,7 +299,7 @@ def __drbd_cleanup():
299299
from storage_devices.drbd import Drbd
300300

301301
Drbd.down_all()
302-
# If drbd instance had been configured on top of the CAS, the previos attempt to stop
302+
# If drbd instance had been configured on top of the CAS, the previous attempt to stop
303303
# failed. As drbd has been stopped try to stop CAS one more time.
304304
if installer.check_if_installed():
305305
casadm.stop_all_caches()

test/functional/tests/incremental_load/test_inactive_cores.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#
22
# Copyright(c) 2019-2021 Intel Corporation
3-
# Copyright(c) 2024 Huawei Technologies Co., Ltd.
3+
# Copyright(c) 2024-2025 Huawei Technologies Co., Ltd.
44
# SPDX-License-Identifier: BSD-3-Clause
55
#
66

@@ -143,7 +143,7 @@ def test_core_inactive_stats_usage():
143143
active_cores_clean_stats = 0
144144
active_cores_dirty_stats = 0
145145

146-
active_cores = cache.get_core_devices()
146+
active_cores = cache.get_cores()
147147
for core in active_cores:
148148
core_stats = core.get_statistics()
149149
active_cores_occupancy_stats += core_stats.usage_stats.occupancy

test/functional/tests/incremental_load/test_incremental_load.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#
22
# Copyright(c) 2019-2022 Intel Corporation
3-
# Copyright(c) 2024 Huawei Technologies Co., Ltd.
3+
# Copyright(c) 2024-2025 Huawei Technologies Co., Ltd.
44
# SPDX-License-Identifier: BSD-3-Clause
55
#
66

7-
import pytest
87
import time
9-
108
from random import shuffle
119

10+
import pytest
11+
1212
from api.cas import casadm, cli, cli_messages
1313
from api.cas.cache_config import (
1414
CacheStatus,
@@ -22,16 +22,16 @@
2222
from api.cas.core import CoreStatus
2323
from api.cas.init_config import InitConfig
2424
from api.cas.statistics import CacheStats
25+
from connection.utils.output import CmdException
2526
from core.test_run import TestRun
2627
from storage_devices.disk import DiskTypeSet, DiskType, DiskTypeLowerThan
2728
from test_tools.dd import Dd
28-
from test_tools.fs_tools import Filesystem
2929
from test_tools.fio.fio import Fio
3030
from test_tools.fio.fio_param import IoEngine, ReadWrite
31-
from test_utils.filesystem.file import File
31+
from test_tools.fs_tools import Filesystem
3232
from test_tools.os_tools import sync
3333
from test_tools.udev import Udev
34-
from connection.utils.output import CmdException
34+
from test_utils.filesystem.file import File
3535
from type_def.size import Size, Unit
3636
from type_def.time import Time
3737

@@ -129,7 +129,7 @@ def test_incremental_load_missing_core_device():
129129
if core.get_status() is not CoreStatus.active:
130130
TestRun.fail(f"Core {core.core_id} should be active but is {core.get_status()}.")
131131

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

134134
with TestRun.step("Stop cache."):
135135
cache.stop()
@@ -143,7 +143,7 @@ def test_incremental_load_missing_core_device():
143143
TestRun.fail(
144144
f"Cache {cache.cache_id} should be incomplete but is " f"{cache.get_status()}."
145145
)
146-
for core in cache.get_core_devices():
146+
for core in cache.get_cores():
147147
if core.get_status() is not CoreStatus.active:
148148
TestRun.fail(f"Core {core.core_id} should be Active but is {core.get_status()}.")
149149
if core_with_missing_device.get_status() is not CoreStatus.inactive:

test/functional/tests/initialize/test_negative_load.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#
22
# Copyright(c) 2019-2022 Intel Corporation
3-
# Copyright(c) 2024 Huawei Technologies Co., Ltd.
3+
# Copyright(c) 2024-2025 Huawei Technologies Co., Ltd.
44
# SPDX-License-Identifier: BSD-3-Clause
55
#
66

@@ -57,7 +57,7 @@ def test_load_occupied_id():
5757
if caches[0].cache_id != 1:
5858
TestRun.LOGGER.error("Wrong cache id.")
5959

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

test/functional/tests/initialize/test_simulation_startup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#
22
# Copyright(c) 2022 Intel Corporation
3-
# Copyright(c) 2024 Huawei Technologies Co., Ltd.
3+
# Copyright(c) 2024-2025 Huawei Technologies Co., Ltd.
44
# SPDX-License-Identifier: BSD-3-Clause
55
#
66

@@ -65,7 +65,7 @@ def test_simulation_startup_from_config():
6565
)
6666

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

9191
with TestRun.step("Verify if core is working"):
92-
cores = cache.get_core_devices()
92+
cores = cache.get_cores()
9393
if not cores:
9494
TestRun.fail("Core is not working")
9595
core = cores[0]

test/functional/tests/stats/test_ioclass_stats.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def test_ioclass_stats_sections(stat_filter, per_core, random_cls):
235235
f"{'cores' if per_core else 'caches'}"):
236236
for cache in caches:
237237
with TestRun.group(f"Cache {cache.cache_id}"):
238-
for core in cache.get_core_devices():
238+
for core in cache.get_cores():
239239
if per_core:
240240
TestRun.LOGGER.info(f"Core {core.cache_id}-{core.core_id}")
241241
statistics = (
@@ -257,7 +257,7 @@ def test_ioclass_stats_sections(stat_filter, per_core, random_cls):
257257
f"class for all {'cores' if per_core else 'caches'}"):
258258
for cache in caches:
259259
with TestRun.group(f"Cache {cache.cache_id}"):
260-
for core in cache.get_core_devices():
260+
for core in cache.get_cores():
261261
core_info = f"Core {core.cache_id}-{core.core_id} ," if per_core else ""
262262
for class_id in range(ioclass_config.MAX_IO_CLASS_ID + 1):
263263
with TestRun.group(core_info + f"IO class id {class_id}"):

0 commit comments

Comments
 (0)