Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Hyper-v platform] Use data disk as LISA working directory on Hyper-v host #3626

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions lisa/tools/hyperv.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,76 @@ 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a configurable path, instead of use the LISA working path. The big files should be tracked separately.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These big files are vhds used as OS and data disks. They are stored by default under relevant test log folder. Its easier if we leave them that way so that its easier to map them to the test runs and clean them up once the tests are finished.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use LISA working path as the default path, but it should be configurable for lab environments.

# 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 host.
def use_raw_disk_for_lisa_working_dir(self) -> None:
powershell = self.node.tools[PowerShell]

# Get the first disk that is not initialized
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 raw_disks:
self._log.warning("No un-initialized disk found.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Don't print warning, either print info or raise exception.
  2. The following log line should be merged into one line, so people always know they are logged together.

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}",
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)

Expand Down
6 changes: 6 additions & 0 deletions lisa/transformers/hyperv_preparation.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,17 @@ def _internal_run(self) -> Dict[str, Any]:
# Enable Hyper-V
hv = self._node.tools[HyperV]

# Configure lisa working path to use free disk.
hv.use_raw_disk_for_lisa_working_dir()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't be the default way. What happened, if it's running on Azure?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is written and tested on azure. My use case is also Azure only

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Please make it optional. Only if give a path in config, then create the data disk.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also use_raw_disk_for_lisa_working_dir() will skip if there is not raw disk available on the Host.

Copy link
Member

@squirrelsc squirrelsc Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not flexible enough. Please create configurations in the runbook. For example,

data_disk: # a list.
    - source: # new/exist/raw
      path: # for new or exist. It must be a file name for exist. It can be file name or path for new. If it ends with vhd, it means a file name, otherwise a path. If it's not set, use lisa working path for new.


# Create an internal switch.
hv.create_switch(name=switch_name)

hv.setup_nat_networking(switch_name=switch_name, nat_name=switch_name)

# Configure Internal DHCP
hv.enable_internal_dhcp()

# Reboot the node to apply all the changes.
self._node.reboot()
return {}
Loading