From d8e673267557f324a7acace2a9cee19745c72ec6 Mon Sep 17 00:00:00 2001 From: rydailey Date: Wed, 4 Sep 2024 17:03:39 -0700 Subject: [PATCH] Added FreeBSD specifics to disk --- lisa/features/disks.py | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/lisa/features/disks.py b/lisa/features/disks.py index 3e60f31bd7..89a8e58616 100644 --- a/lisa/features/disks.py +++ b/lisa/features/disks.py @@ -1,6 +1,7 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT license. +import re from functools import partial from typing import Any, Dict, List, Optional, Type @@ -8,9 +9,10 @@ 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): @@ -79,6 +81,20 @@ 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 @@ -86,13 +102,20 @@ def get_os_boot_partition(self) -> Optional[PartitionInfo]: 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