Skip to content

Added FreeBSD specifics to Disk.py #3407

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

Merged
merged 1 commit into from
Sep 6, 2024
Merged
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
37 changes: 30 additions & 7 deletions lisa/features/disks.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

import re
from functools import partial
from typing import Any, Dict, List, Optional, Type

from assertpy.assertpy import assert_that

from lisa import schema
from lisa.feature import Feature
from lisa.operating_system import BSD
from lisa.tools import Mount
from lisa.tools.mount import PartitionInfo
from lisa.util import LisaException
from lisa.util import LisaException, get_matched_str


class Disk(Feature):
Expand Down Expand Up @@ -79,20 +81,41 @@ def get_os_boot_partition(self) -> Optional[PartitionInfo]:
for partition in partition_info:
if partition.mount_point.startswith("/boot"):
boot_partition = partition
if isinstance(self._node.os, BSD):
# Get the device name from the GPT since they are abstracted
# Ex. /boot is mounted on /gpt/efiesp
# This is the output of gpart show.
# Name Status Components
# gpt/efiesp N/A da0p1
# gpt/rootfs N/A da0p2
_get_device_from_gpt_bsd_regex = re.compile(
r"\n?" + re.escape(boot_partition.disk) + r"\s*\S*\s*(\S*)"
)
cmd = "glabel status"
output = self._node.execute(cmd).stdout
dev = get_matched_str(output, _get_device_from_gpt_bsd_regex)
boot_partition.disk = dev
break
return boot_partition

# Get disk controller type from the VM by checking the boot partition
def get_os_disk_controller_type(self) -> schema.DiskControllerType:
boot_partition = self.get_os_boot_partition()
assert boot_partition, "'boot_partition' must not be 'None'"

if boot_partition.disk.startswith("nvme"):
os_disk_controller_type = schema.DiskControllerType.NVME
elif boot_partition.disk.startswith("sd"):
os_disk_controller_type = schema.DiskControllerType.SCSI
if isinstance(self._node.os, BSD):
if boot_partition.disk.startswith("da"):
os_disk_controller_type = schema.DiskControllerType.SCSI
elif boot_partition.disk.startswith("nvd"):
os_disk_controller_type = schema.DiskControllerType.NVME
else:
raise LisaException(f"Unknown OS boot disk type {boot_partition.disk}")
else:
raise LisaException(f"Unknown OS boot disk type {boot_partition.disk}")
if boot_partition.disk.startswith("nvme"):
os_disk_controller_type = schema.DiskControllerType.NVME
elif boot_partition.disk.startswith("sd"):
os_disk_controller_type = schema.DiskControllerType.SCSI
else:
raise LisaException(f"Unknown OS boot disk type {boot_partition.disk}")
return os_disk_controller_type


Expand Down
Loading