Skip to content

Commit

Permalink
facts: fix efibootmgr.EFIBootMgr if command installed but not UEFI
Browse files Browse the repository at this point in the history
  • Loading branch information
bauen1 committed Oct 31, 2024
1 parent c31f325 commit 44d12c3
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
12 changes: 10 additions & 2 deletions pyinfra/facts/efibootmgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ def requires_command(self, *args: Any, **kwargs: Any) -> str:
return "efibootmgr"

def command(self) -> str:
return "efibootmgr"
# FIXME: Use '|| true' to properly handle the case where
# 'efibootmgr' is run on a non-UEFI system
return "efibootmgr || true"

def process(self, output: Iterable[str]) -> EFIBootMgrInfoDict:
def process(self, output: Iterable[str]) -> Optional[EFIBootMgrInfoDict]:
# This parsing code closely follows the printing code of efibootmgr
# at <https://github.com/rhboot/efibootmgr/blob/main/src/efibootmgr.c#L2020-L2048>

Expand All @@ -60,6 +62,12 @@ def process(self, output: Iterable[str]) -> EFIBootMgrInfoDict:

line: Optional[str] = next(output, None)

if line is None:
# efibootmgr run on a non-UEFI system, likely printed
# "EFI variables are not supported on this system."
# to stderr
return None

# 1. Maybe have BootNext
if line and line.startswith("BootNext: "):
info["BootNext"] = int(line.removeprefix("BootNext: "), 16)
Expand Down
2 changes: 1 addition & 1 deletion tests/facts/efibootmgr.EFIBootMgr/boot_entries.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"command": "efibootmgr",
"command": "efibootmgr || true",
"requires_command": "efibootmgr",
"output": [
"BootCurrent: 0002",
Expand Down
2 changes: 1 addition & 1 deletion tests/facts/efibootmgr.EFIBootMgr/boot_entries2.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"command": "efibootmgr",
"command": "efibootmgr || true",
"requires_command": "efibootmgr",
"output": [
"BootCurrent: 0000",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"command": "efibootmgr",
"command": "efibootmgr || true",
"requires_command": "efibootmgr",
"output": [
"BootNext: 0006",
Expand Down
6 changes: 2 additions & 4 deletions tests/facts/efibootmgr.EFIBootMgr/not_uefi.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"command": "efibootmgr",
"command": "efibootmgr || true",
"requires_command": "efibootmgr",
"output": [
"EFI variables are not supported on this system."
],
"output": [],
"fact": null
}

0 comments on commit 44d12c3

Please sign in to comment.