From d037082e5fa2c0bf7297d5d523b246b845b4005b Mon Sep 17 00:00:00 2001 From: Anirudh Rayabharam Date: Mon, 21 Oct 2024 12:21:55 +0530 Subject: [PATCH] sut_orchestrator: hyperv: don't automatically add disks The create_vm() method of the HyperV tool, automatically finds offline disks and adds them to the VM. This behavior is not required for hyperv platform. So, introduce a parameter to control it and modify hyperv platform to disable that behavior. Signed-off-by: Anirudh Rayabharam --- lisa/sut_orchestrator/hyperv/platform_.py | 1 + lisa/tools/hyperv.py | 26 ++++++++++++----------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/lisa/sut_orchestrator/hyperv/platform_.py b/lisa/sut_orchestrator/hyperv/platform_.py index fd319ce75..e44b97633 100644 --- a/lisa/sut_orchestrator/hyperv/platform_.py +++ b/lisa/sut_orchestrator/hyperv/platform_.py @@ -296,6 +296,7 @@ class HypervPlatform(Platform): 1: com1_pipe_path, }, extra_args=extra_args, + attach_offline_disks=False, ) # perform device passthrough for the VM self.device_pool._set_device_passthrough_node_context( diff --git a/lisa/tools/hyperv.py b/lisa/tools/hyperv.py index a4c575cfb..276ac2fc2 100644 --- a/lisa/tools/hyperv.py +++ b/lisa/tools/hyperv.py @@ -72,6 +72,7 @@ class HyperV(Tool): generation: int = 1, cores: int = 2, memory: int = 2048, + attach_offline_disks: bool = True, com_ports: Optional[Dict[int, str]] = None, secure_boot: bool = True, stop_existing_vm: bool = True, @@ -119,20 +120,21 @@ class HyperV(Tool): force_run=True, ) - # add disks - disk_info = powershell.run_cmdlet( - "(Get-Disk | Where-Object {$_.OperationalStatus -eq 'offline'}).Number", - force_run=True, - ) - matched = re.findall(r"\d+", disk_info) - disk_numbers = [int(x) for x in matched] - for disk_number in disk_numbers: - self._run_hyperv_cmdlet( - "Add-VMHardDiskDrive", - f"-VMName {name} -DiskNumber {disk_number} -ControllerType 'SCSI'", - extra_args=extra_args, + # add disks if requested + if attach_offline_disks: + disk_info = powershell.run_cmdlet( + "(Get-Disk | Where-Object {$_.OperationalStatus -eq 'offline'}).Number", force_run=True, ) + matched = re.findall(r"\d+", disk_info) + disk_numbers = [int(x) for x in matched] + for disk_number in disk_numbers: + self._run_hyperv_cmdlet( + "Add-VMHardDiskDrive", + f"-VMName {name} -DiskNumber {disk_number} -ControllerType 'SCSI'", + extra_args=extra_args, + force_run=True, + ) # configure COM ports if specified if com_ports: