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

find_partition_with_freespace: refactor function to hoist to node level #1743

Merged
merged 2 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 15 additions & 1 deletion lisa/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from lisa.feature import Features
from lisa.nic import Nics
from lisa.operating_system import OperatingSystem
from lisa.tools import Echo, Reboot
from lisa.tools import Df, Echo, Reboot
from lisa.util import (
ContextMixin,
InitializableMixin,
Expand Down Expand Up @@ -426,6 +426,20 @@ def get_working_path(self) -> PurePath:

return self.get_pure_path(result.stdout)

def find_partition_with_freespace(self, size_in_gb: int) -> str:
df = self.tools[Df]
home_partition = df.get_partition_by_mountpoint("/home")
if home_partition and df.check_partition_size(home_partition, size_in_gb):
dsrivastavv marked this conversation as resolved.
Show resolved Hide resolved
return home_partition.mountpoint

mnt_partition = df.get_partition_by_mountpoint("/mnt")
if mnt_partition and df.check_partition_size(mnt_partition, size_in_gb):
return mnt_partition.mountpoint

raise LisaException(
f"No partition with Required disk space of {size_in_gb}GB found"
)


class LocalNode(Node):
def __init__(
Expand Down
14 changes: 14 additions & 0 deletions lisa/tools/df.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,17 @@ def get_partition_by_mountpoint(
if partition.mountpoint == mountpoint:
return partition
return None

def check_partition_size(
self,
partition: PartitionInfo,
size: int,
squirrelsc marked this conversation as resolved.
Show resolved Hide resolved
) -> bool:
# check if the partition has enough space to download nested image file
unused_partition_size_in_gb = (
partition.total_blocks - partition.used_blocks
) / (1024 * 1024)
if unused_partition_size_in_gb > size:
return True

return False
34 changes: 2 additions & 32 deletions microsoft/testsuites/nested/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
from lisa.operating_system import Debian, Fedora, Suse
from lisa.schema import Node
from lisa.tools import Lscpu, Qemu, Wget
from lisa.tools.df import Df, PartitionInfo
from lisa.util import LisaException, SkippedException
from lisa.util import SkippedException

NESTED_VM_IMAGE_NAME = "image.qcow2"
NESTED_VM_TEST_FILE_NAME = "message.txt"
Expand Down Expand Up @@ -44,7 +43,7 @@ def connect_nested_vm(
"run on Debian, Fedora and Suse distros."
)

image_folder_path = find_partition_with_freespace(host, image_size)
image_folder_path = host.find_partition_with_freespace(image_size)

host.tools[Wget].get(
url=guest_image_url,
Expand All @@ -69,21 +68,6 @@ def connect_nested_vm(
return nested_vm


def find_partition_with_freespace(node: RemoteNode, size_in_gb: int) -> str:
df = node.tools[Df]
home_partition = df.get_partition_by_mountpoint("/home")
if home_partition and _is_partition_capable(home_partition, size_in_gb):
return home_partition.mountpoint

mnt_partition = df.get_partition_by_mountpoint("/mnt")
if mnt_partition and _is_partition_capable(mnt_partition, size_in_gb):
return mnt_partition.mountpoint

raise LisaException(
f"No partition with Required disk space of {size_in_gb}GB found"
)


def parse_nested_image_variables(
variables: Dict[str, Any]
) -> Tuple[str, str, int, str]:
Expand All @@ -107,17 +91,3 @@ def parse_nested_image_variables(
nested_image_port,
nested_image_url,
)


def _is_partition_capable(
partition: PartitionInfo,
size: int,
) -> bool:
# check if the partition has enough space to download nested image file
unused_partition_size_in_gb = (partition.total_blocks - partition.used_blocks) / (
1024 * 1024
)
if unused_partition_size_in_gb > size:
return True

return False