Skip to content

Commit

Permalink
Add bootctl tool
Browse files Browse the repository at this point in the history
- cvm_boot: use bootctl to locate root device

Signed-off-by: Thien Trung Vuong <[email protected]>
  • Loading branch information
trungams committed Feb 4, 2025
1 parent b900463 commit 54da507
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 7 deletions.
2 changes: 2 additions & 0 deletions lisa/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from .aria import Aria
from .b4 import B4
from .blkid import Blkid
from .bootctl import BootCtl
from .bzip2 import Bzip2
from .cargo import Cargo
from .chmod import Chmod
Expand Down Expand Up @@ -134,6 +135,7 @@
"Aria",
"B4",
"Blkid",
"BootCtl",
"Bzip2",
"Cargo",
"Cat",
Expand Down
45 changes: 45 additions & 0 deletions lisa/tools/bootctl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

from lisa.executable import Tool
from lisa.operating_system import CBLMariner
from lisa.util import LisaException


class BootCtl(Tool):
@property
def command(self) -> str:
return "bootctl"

@property
def can_install(self) -> bool:
return True

def _install(self) -> bool:
if isinstance(self.node.os, CBLMariner):
self.node.os.install_packages("systemd-udev")
else:
raise LisaException(
f"tool {self.command} can't be installed in distro {self.node.os.name}"
)
return self._check_exists()

def get_esp_path(self) -> str:
return self._get_cmd_output("--print-esp-path")

def get_boot_path(self) -> str:
return self._get_cmd_output("--print-boot-path")

def get_root_device(self) -> str:
return self._get_cmd_output("--print-root-device")

def _get_cmd_output(self, cmd: str) -> str:
cmd_result = self.run(
cmd,
expected_exit_code=0,
expected_exit_code_failure_message="failed to get ESP path",
shell=True,
sudo=True,
force_run=True,
)
return cmd_result.stdout
16 changes: 9 additions & 7 deletions microsoft/testsuites/cvm/cvm_boot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

import itertools
from pathlib import Path
from typing import Any, List, cast

Expand All @@ -23,7 +24,7 @@
from lisa.operating_system import CBLMariner, Posix
from lisa.sut_orchestrator import AZURE
from lisa.testsuite import TestResult, simple_requirement
from lisa.tools import Lsblk, Reboot, Tpm2
from lisa.tools import BootCtl, Lsblk, Reboot, Tpm2
from lisa.tools.lsblk import PartitionInfo
from lisa.util import (
SkippedException,
Expand Down Expand Up @@ -74,13 +75,14 @@ def verify_encrypted_root_partition(
)
if not security_profile_settings.encrypt_disk:
raise SkippedException("This test requires disk encryption to be enabled")
lsblk = node.tools[Lsblk]
disks = lsblk.get_disks(force_run=True)
partitions: List[PartitionInfo] = next(
(d.partitions for d in disks if d.name == "sda"), []

disks = node.tools[Lsblk].get_disks(force_run=True)
root_device = node.tools[BootCtl].get_root_device()
partitions = itertools.chain.from_iterable(disk.partitions for disk in disks)
root_partition = next(
(p for p in partitions if p.device_name == root_device), None
)
assert_that(partitions, "Cannot find a disk named 'sda'").is_not_empty()
root_partition = next((p for p in partitions if p.name == "sda2"), None)

assert_that(root_partition, "Cannot locate root partition").is_not_none()
assert isinstance(root_partition, PartitionInfo)
assert_that(root_partition.fstype).is_equal_to("crypto_LUKS")
Expand Down

0 comments on commit 54da507

Please sign in to comment.