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

hyperv: expand root partition #3600

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
26 changes: 25 additions & 1 deletion lisa/sut_orchestrator/hyperv/platform_.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from lisa.environment import Environment
from lisa.node import RemoteNode
from lisa.platform_ import Platform
from lisa.tools import Cp, HyperV, Mkdir, PowerShell
from lisa.tools import Cp, HyperV, Mkdir, Mount, PowerShell
from lisa.util import LisaException, constants
from lisa.util.logger import Logger, get_logger
from lisa.util.parallel import run_in_parallel
Expand Down Expand Up @@ -315,6 +315,8 @@ def _deploy_environment(self, environment: Environment, log: Logger) -> None:
address=ip_addr, username=username, password=password
)

self._expand_root_partition(node)
squirrelsc marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a comment here explaining why we need this even though we're doing _resize_vhd_if_needed() above.


def _resize_vhd_if_needed(
self, vhd_path: PurePath, node_runbook: HypervNodeSchema
) -> None:
Expand All @@ -326,6 +328,28 @@ def _resize_vhd_if_needed(
f"-SizeBytes {node_runbook.osdisk_size_in_gb * 1024 * 1024 * 1024}"
)

def _expand_root_partition(self, node: RemoteNode) -> None:
# Get the root partition info
# The root partition is the one that has the mount point "/"
# sample root partition info: name: /dev/sda2, disk: sda,
# mount_point: /, type: ext4, options: ('rw', 'relatime')
root_partition = node.tools[Mount].get_partition_info("/")[0]
squirrelsc marked this conversation as resolved.
Show resolved Hide resolved
device_name = root_partition.name
partition = root_partition.disk
# for root partition name: /dev/sda2, partition is "sda" and
# we need to extract the partition number i.e. 2
root_part_num = device_name[-1]
Copy link
Member

Choose a reason for hiding this comment

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

Provide example of the name above.

Copy link
Member

Choose a reason for hiding this comment

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

It looks a regexp is more accurate, in case the number has two or more digits.

# Grow the partition and resize the filesystem
cmd_result = node.execute(
f"growpart /dev/{partition} {root_part_num}", sudo=True
)
# In case, the partition is already expanded to full disk size, the
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# In case, the partition is already expanded to full disk size, the
# In case the partition is already expanded to full disk size, the

# command will print "NOCHANGE: partition 2 is size <size>. it cannot
# be grown". In this case, it returns exit code 1 which we can ignore
if cmd_result.exit_code != 0 and "NOCHANGE" not in cmd_result.stdout:
raise LisaException(f"Failed to grow partition: {cmd_result.stdout}")
node.execute(f"resize2fs {device_name}", sudo=True, expected_exit_code=0)
Copy link
Member

@squirrelsc squirrelsc Jan 17, 2025

Choose a reason for hiding this comment

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

Execute only if it can be grown. Reduce the number of running commands, even it do nothing.


def _delete_environment(self, environment: Environment, log: Logger) -> None:
self._delete_nodes(environment, log)

Expand Down