From 089510f737e4beb48ba7fbfcfbd14f316e667659 Mon Sep 17 00:00:00 2001 From: SrikanthMyakam Date: Mon, 3 Feb 2025 11:53:43 +0530 Subject: [PATCH 1/5] [Hyper-v platform] Use data disk as lisa working directory --- lisa/tools/hyperv.py | 65 +++++++++++++++++++++++++ lisa/transformers/hyperv_preparation.py | 3 ++ 2 files changed, 68 insertions(+) diff --git a/lisa/tools/hyperv.py b/lisa/tools/hyperv.py index d328aa72f5..8b25cdebb3 100644 --- a/lisa/tools/hyperv.py +++ b/lisa/tools/hyperv.py @@ -445,6 +445,71 @@ def enable_internal_dhcp(self, dhcp_scope_name: str = "DHCPInternalNAT") -> None # Restart the DHCP server to apply the changes service.restart_service("dhcpserver") + # The default lisa working path is under 'C:/' which is not ideal for large data. + # This method initializes an attached disk, creates a partition, formats it, + # and mounts it to the lisa working directory + # This method expects an un-initialized (RAW) disk to be available on Hyper-V. + def configure_lisa_working_dir(self) -> None: + powershell = self.node.tools[PowerShell] + + # Get the disk that is not initialized + disk_number = powershell.run_cmdlet( + "(Get-Disk | Where-Object PartitionStyle -Eq 'RAW').Number", + force_run=True, + ) + # If no un-initialized disk is found, log a warning and return + if not disk_number: + self._log.warning("No un-initialized disk found.") + self._log.warning("Skipping lisa working dir setup on additional disk.") + return + # Initialize the disk + powershell.run_cmdlet( + f"Initialize-Disk -Number {disk_number}", + force_run=True, + ) + # Create a new partition + powershell.run_cmdlet( + f"New-Partition -DiskNumber {disk_number}" + " -UseMaximumSize -AssignDriveLetter", + force_run=True, + ) + # Get the drive letter + drive_letter = powershell.run_cmdlet( + f"(Get-Partition -DiskNumber {disk_number}" + " | Where-Object Type -Eq 'Basic').DriveLetter", + force_run=True, + ) + # Format the partition + powershell.run_cmdlet( + f"Format-Volume -DriveLetter {drive_letter}" + " -FileSystem NTFS -NewFileSystemLabel 'DataDisk01'", + force_run=True, + ) + + # Get the partition number + partition_number = powershell.run_cmdlet( + f"(Get-Partition | Where-Object DriveLetter" + f" -Eq {drive_letter}).PartitionNumber", + force_run=True, + ) + + lisa_working_path = r"$([System.Environment]::GetFolderPath('UserProfile'))\AppData\Local\Temp\lisa_working" # noqa: E501 + + # Create mount point if it doesn't exist + powershell.run_cmdlet( + f'if (-Not $(Test-Path -Path "{lisa_working_path}"))' + f' {{New-Item -ItemType Directory -Path "{lisa_working_path}"}}', + force_run=True, + ) + + # Mount the volume to the lisa working directory + powershell.run_cmdlet( + f"Add-PartitionAccessPath -DiskNumber {disk_number}" + f" -PartitionNumber {partition_number}" + f' -AccessPath "{lisa_working_path}"', + force_run=True, + ) + def _install(self) -> bool: assert isinstance(self.node.os, Windows) diff --git a/lisa/transformers/hyperv_preparation.py b/lisa/transformers/hyperv_preparation.py index f2296728c0..e9bb4f59f1 100644 --- a/lisa/transformers/hyperv_preparation.py +++ b/lisa/transformers/hyperv_preparation.py @@ -33,6 +33,9 @@ def _internal_run(self) -> Dict[str, Any]: # Enable Hyper-V hv = self._node.tools[HyperV] + # Configure lisa working path + hv.configure_lisa_working_dir() + # Create an internal switch. hv.create_switch(name=switch_name) From f8fc1a800301c01c738c250bfdd983f9fd0bed9a Mon Sep 17 00:00:00 2001 From: SrikanthMyakam Date: Mon, 3 Feb 2025 13:06:50 +0530 Subject: [PATCH 2/5] Update hyperv_preparation.py --- lisa/transformers/hyperv_preparation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lisa/transformers/hyperv_preparation.py b/lisa/transformers/hyperv_preparation.py index e9bb4f59f1..c49f3fd860 100644 --- a/lisa/transformers/hyperv_preparation.py +++ b/lisa/transformers/hyperv_preparation.py @@ -33,8 +33,8 @@ def _internal_run(self) -> Dict[str, Any]: # Enable Hyper-V hv = self._node.tools[HyperV] - # Configure lisa working path - hv.configure_lisa_working_dir() + # Configure lisa working path to use free disk. + hv.use_raw_disk_for_lisa_working_dir() # Create an internal switch. hv.create_switch(name=switch_name) From 4bd0369b50e9f631759268fd1abd9710f2eb4f30 Mon Sep 17 00:00:00 2001 From: SrikanthMyakam Date: Mon, 3 Feb 2025 13:06:54 +0530 Subject: [PATCH 3/5] Update hyperv.py --- lisa/tools/hyperv.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lisa/tools/hyperv.py b/lisa/tools/hyperv.py index 8b25cdebb3..b620e8853c 100644 --- a/lisa/tools/hyperv.py +++ b/lisa/tools/hyperv.py @@ -448,13 +448,13 @@ def enable_internal_dhcp(self, dhcp_scope_name: str = "DHCPInternalNAT") -> None # The default lisa working path is under 'C:/' which is not ideal for large data. # This method initializes an attached disk, creates a partition, formats it, # and mounts it to the lisa working directory - # This method expects an un-initialized (RAW) disk to be available on Hyper-V. - def configure_lisa_working_dir(self) -> None: + # This method expects an un-initialized (RAW) disk to be available on Hyper-V host. + def use_raw_disk_for_lisa_working_dir(self) -> None: powershell = self.node.tools[PowerShell] - # Get the disk that is not initialized + # Get the first disk that is not initialized disk_number = powershell.run_cmdlet( - "(Get-Disk | Where-Object PartitionStyle -Eq 'RAW').Number", + "(Get-Disk | Where-Object PartitionStyle -Eq 'RAW').Number[0]", force_run=True, ) # If no un-initialized disk is found, log a warning and return From df6128ad0304b4c9b899ffcf206fb90f072d329c Mon Sep 17 00:00:00 2001 From: SrikanthMyakam Date: Fri, 7 Feb 2025 15:09:51 +0530 Subject: [PATCH 4/5] Update hyperv.py --- lisa/tools/hyperv.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lisa/tools/hyperv.py b/lisa/tools/hyperv.py index b620e8853c..b38fa0ab4a 100644 --- a/lisa/tools/hyperv.py +++ b/lisa/tools/hyperv.py @@ -453,15 +453,20 @@ def use_raw_disk_for_lisa_working_dir(self) -> None: powershell = self.node.tools[PowerShell] # Get the first disk that is not initialized - disk_number = powershell.run_cmdlet( - "(Get-Disk | Where-Object PartitionStyle -Eq 'RAW').Number[0]", + raw_disks = powershell.run_cmdlet( + "Get-Disk | Where-Object PartitionStyle -Eq 'RAW'", force_run=True, + output_json=True, ) # If no un-initialized disk is found, log a warning and return - if not disk_number: + if not raw_disks: self._log.warning("No un-initialized disk found.") self._log.warning("Skipping lisa working dir setup on additional disk.") return + if isinstance(raw_disks, list): + disk_number = raw_disks[0]["Number"] + else: + disk_number = raw_disks["Number"] # Initialize the disk powershell.run_cmdlet( f"Initialize-Disk -Number {disk_number}", From 4b52c0faeb66e6077654641e3df64891817997d5 Mon Sep 17 00:00:00 2001 From: SrikanthMyakam Date: Fri, 7 Feb 2025 15:34:28 +0530 Subject: [PATCH 5/5] Update hyperv_preparation.py --- lisa/transformers/hyperv_preparation.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lisa/transformers/hyperv_preparation.py b/lisa/transformers/hyperv_preparation.py index c49f3fd860..6f025b9866 100644 --- a/lisa/transformers/hyperv_preparation.py +++ b/lisa/transformers/hyperv_preparation.py @@ -43,4 +43,7 @@ def _internal_run(self) -> Dict[str, Any]: # Configure Internal DHCP hv.enable_internal_dhcp() + + # Reboot the node to apply all the changes. + self._node.reboot() return {}