From 5f6ce5d2a4d7434e8ed39f3488d6459b955847be Mon Sep 17 00:00:00 2001 From: Kamil Gierszewski Date: Tue, 10 Dec 2024 05:21:43 +0100 Subject: [PATCH 1/3] test-framework: minor refactor Signed-off-by: Kamil Gierszewski --- test_tools/disk_tools.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/test_tools/disk_tools.py b/test_tools/disk_tools.py index c2790d6..5588d05 100644 --- a/test_tools/disk_tools.py +++ b/test_tools/disk_tools.py @@ -1,6 +1,6 @@ # # Copyright(c) 2019-2022 Intel Corporation -# Copyright(c) 2023-2024 Huawei Technologies Co., Ltd. +# Copyright(c) 2023-2025 Huawei Technologies Co., Ltd. # SPDX-License-Identifier: BSD-3-Clause # @@ -102,11 +102,11 @@ def create_partition( TestRun.executor.run_expect_success("udevadm settle") if not check_partition_after_create( - part_size, - part_number, - device.path, - part_type, - aligned): + size=part_size, + part_number=part_number, + parent_dev_path=device.path, + part_type=part_type, + aligned=aligned): raise Exception("Could not create partition!") if part_type != PartitionType.extended: @@ -147,7 +147,7 @@ def create_partitions(device, sizes: [], partition_table_type=PartitionTable.gpt for s in sizes: size = Size( - s.get_value(device.block_size) - device.block_size.value, device.block_size) + s.get_value(device.block_size) - 1, device.block_size) if partition_table_type == PartitionTable.msdos and \ len(sizes) > 4 and len(device.partitions) == 3: if available_disk_size(device) > msdos_part_max_size: @@ -162,12 +162,12 @@ def create_partitions(device, sizes: [], partition_table_type=PartitionTable.gpt partition_number_offset = 1 partition_number = len(device.partitions) + 1 + partition_number_offset - create_partition(device, - size, - partition_number, - partition_type, - Unit.MebiByte, - True) + create_partition(device=device, + part_size=size, + part_number=partition_number, + part_type=partition_type, + unit=device.block_size, + aligned=True) def get_block_size(device): @@ -197,7 +197,8 @@ def get_pci_address(device): return pci_address -def check_partition_after_create(size, part_number, parent_dev_path, part_type, aligned): +def check_partition_after_create(size: Size, part_number: int, parent_dev_path: str, + part_type: PartitionType, aligned: bool): partition_path = get_partition_path(parent_dev_path, part_number) if "dev/cas" not in partition_path: cmd = f"find {partition_path} -type l" From 0b9ea5f0ff61c195ca00ab909038d2ff8437185d Mon Sep 17 00:00:00 2001 From: Kamil Gierszewski Date: Tue, 10 Dec 2024 05:52:23 +0100 Subject: [PATCH 2/3] test-framework: code refactor in power plugin Signed-off-by: Kamil Gierszewski --- .../power_control_libvirt/__init__.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/internal_plugins/power_control_libvirt/__init__.py b/internal_plugins/power_control_libvirt/__init__.py index 2823c7f..50f231b 100644 --- a/internal_plugins/power_control_libvirt/__init__.py +++ b/internal_plugins/power_control_libvirt/__init__.py @@ -1,6 +1,6 @@ # # Copyright(c) 2020-2021 Intel Corporation -# Copyright(c) 2023-2024 Huawei Technologies Co., Ltd. +# Copyright(c) 2023-2025 Huawei Technologies Co., Ltd. # SPDX-License-Identifier: BSD-3-Clause # @@ -46,18 +46,25 @@ def post_setup(self): def teardown(self): pass - def power_cycle(self): - self.executor.run_expect_success(f"sudo virsh reset {TestRun.dut.virsh['vm_name']}") + def power_cycle(self, wait_for_connection: bool = False, delay_until_reboot: int = 0) -> None: + self.executor.run_expect_success(f"sudo virsh destroy {TestRun.dut.virsh['vm_name']}") TestRun.executor.disconnect() - TestRun.executor.wait_for_connection(timedelta(seconds=TestRun.dut.virsh["reboot_timeout"])) + self.executor.run_expect_success( + f"(sleep {delay_until_reboot} && sudo virsh start {TestRun.dut.virsh['vm_name']}) &" + ) + if wait_for_connection: + TestRun.executor.wait_for_connection( + timedelta(seconds=TestRun.dut.virsh["reboot_timeout"]) + ) def check_if_vm_exists(self, vm_name) -> bool: return self.executor.run(f"sudo virsh list|grep -w {vm_name}").exit_code == 0 def parse_virsh_config(self, vm_name, reboot_timeout=DEFAULT_REBOOT_TIMEOUT) -> dict | None: if not self.check_if_vm_exists(vm_name=vm_name): - raise ValueError(f"Virsh power plugin error: couldn't find VM {vm_name} on host " - f"{self.host}") + raise ValueError( + f"Virsh power plugin error: couldn't find VM {vm_name} on host {self.host}" + ) return { "vm_name": vm_name, "reboot_timeout": reboot_timeout, From 3374881bdd45c1212994681d9d8e3b003fce5cb3 Mon Sep 17 00:00:00 2001 From: Kamil Gierszewski Date: Thu, 2 Jan 2025 01:40:52 +0100 Subject: [PATCH 3/3] test-framework: fix config ip handle Signed-off-by: Kamil Gierszewski --- core/test_run_utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/test_run_utils.py b/core/test_run_utils.py index ef4f0b4..0f5326e 100644 --- a/core/test_run_utils.py +++ b/core/test_run_utils.py @@ -1,6 +1,6 @@ # # Copyright(c) 2019-2021 Intel Corporation -# Copyright(c) 2023-2024 Huawei Technologies Co., Ltd. +# Copyright(c) 2023-2025 Huawei Technologies Co., Ltd. # SPDX-License-Identifier: BSD-3-Clause # @@ -132,7 +132,8 @@ def __presetup(cls): if cls.config['type'] == 'ssh': try: IP(cls.config['ip']) - cls.config['host'] = cls.config['ip'] + if not cls.config['host']: + cls.config['host'] = cls.config['ip'] except ValueError: TestRun.block("IP address from config is in invalid format.") except KeyError: