Skip to content

Commit

Permalink
Added FreeBSD specifics to disk
Browse files Browse the repository at this point in the history
  • Loading branch information
r-dailey committed Sep 6, 2024
1 parent 225fb52 commit d8e6732
Showing 1 changed file with 30 additions and 7 deletions.
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

0 comments on commit d8e6732

Please sign in to comment.