From 4b8bca855ea5463585e7e08a73bed1bee753c238 Mon Sep 17 00:00:00 2001 From: Purna Pavan Chandra Date: Wed, 8 Jan 2025 10:22:50 +0530 Subject: [PATCH] ch_tests: dynamically determine data disk path (#3583) The test VM undergoes a reboot during preparation for CH community tests, causing the device path for the data disk to potentially change. So, data disk device path is now determined dynamically just before launching the CH tests, eliminating the need for 'datadisk_name' test input variable. --- .../testsuites/cloud_hypervisor/ch_tests.py | 3 --- .../cloud_hypervisor/ch_tests_tool.py | 27 ++++++++++++++++--- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/microsoft/testsuites/cloud_hypervisor/ch_tests.py b/microsoft/testsuites/cloud_hypervisor/ch_tests.py index 5000b33fb0..8c1fbee53d 100644 --- a/microsoft/testsuites/cloud_hypervisor/ch_tests.py +++ b/microsoft/testsuites/cloud_hypervisor/ch_tests.py @@ -206,7 +206,6 @@ def _set_ms_clh_param(self, variables: Dict[str, Any]) -> None: # will not run it with data-disk and it would not add direct=on # if run_without_cache is not set to YES use_datadisk = variables.get("use_datadisk", "") - datadisk_name = variables.get("datadisk_name", "") disable_datadisk_cache = variables.get("disable_datadisk_cache", "") block_size_kb = variables.get("block_size_kb", "") @@ -232,8 +231,6 @@ def _set_ms_clh_param(self, variables: Dict[str, Any]) -> None: CloudHypervisorTests.block_size_kb = block_size_kb if use_datadisk: CloudHypervisorTests.use_datadisk = use_datadisk - if datadisk_name: - CloudHypervisorTests.datadisk_name = datadisk_name if disable_datadisk_cache: CloudHypervisorTests.disable_datadisk_cache = disable_datadisk_cache diff --git a/microsoft/testsuites/cloud_hypervisor/ch_tests_tool.py b/microsoft/testsuites/cloud_hypervisor/ch_tests_tool.py index c370dfa8b4..77c727c716 100644 --- a/microsoft/testsuites/cloud_hypervisor/ch_tests_tool.py +++ b/microsoft/testsuites/cloud_hypervisor/ch_tests_tool.py @@ -22,11 +22,12 @@ Echo, Git, Ls, + Lsblk, Mkdir, Modprobe, Whoami, ) -from lisa.util import find_groups_in_lines +from lisa.util import LisaException, find_groups_in_lines @dataclass @@ -62,7 +63,6 @@ class CloudHypervisorTests(Tool): # Block perf related env var use_datadisk = "" - datadisk_name = "" disable_datadisk_cache = "" block_size_kb = "" @@ -164,6 +164,9 @@ def run_metrics_tests( skip: Optional[List[str]] = None, subtest_timeout: Optional[int] = None, ) -> None: + if self.use_datadisk: + self._set_data_disk() + if ref: self.node.tools[Git].checkout(ref, self.repo_root) @@ -264,8 +267,6 @@ def _install(self) -> bool: if self.use_datadisk: self.env_vars["USE_DATADISK"] = self.use_datadisk - if self.datadisk_name: - self.env_vars["DATADISK_NAME"] = self.datadisk_name if self.disable_datadisk_cache: self.env_vars["DISABLE_DATADISK_CACHING"] = self.disable_datadisk_cache if self.block_size_kb: @@ -496,6 +497,24 @@ def _configure_vdpa_devices(self, node: Node) -> None: node.tools[Chown].change_owner(file=PurePath(device_path), user=user) node.tools[Chmod].chmod(path=device_path, permission=permission, sudo=True) + def _set_data_disk(self) -> None: + datadisk_name = "" + lsblk = self.node.tools[Lsblk] + disks = lsblk.get_disks() + # get the first unmounted disk (data disk) + for disk in disks: + if disk.is_mounted: + continue + if disk.name.startswith("sd"): + datadisk_name = disk.device_name + break + # running lsblk once again, just for human readable logs + lsblk.run() + if not datadisk_name: + raise LisaException("No unmounted data disk (/dev/sdX) found") + self._log.debug(f"Using data disk: {datadisk_name}") + self.env_vars["DATADISK_NAME"] = datadisk_name + def extract_jsons(input_string: str) -> List[Any]: json_results: List[Any] = []