Skip to content

Commit

Permalink
fixup! feat(arm,bootloader,efi): use separate BLS directory for upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Hecko committed Jan 27, 2025
1 parent dd9d401 commit c566187
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,10 @@ def modify_our_grubenv_to_have_separate_blsdir(efi_info):
)

grubenv_vars = _list_grubenv_variables()
system_bls_dir = grubenv_vars.get('blsdir', '/boot/loader/entries')
system_bls_dir = grubenv_vars.get('blsdir', '/loader/entries').lstrip('/')

# BLS dir is relative to /boot, prepend it so we can list its contents
system_bls_dir = os.path.join('/boot', system_bls_dir)

# Find our loader entry
try:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import shutil
from collections import namedtuple

import pytest
Expand All @@ -9,7 +10,9 @@
from leapp.libraries.common.testutils import CurrentActorMocked, produce_mocked
from leapp.libraries.stdlib import api
from leapp.models import (
ArmWorkaroundEFIBootloaderInfo,
BootContent,
EFIBootEntry,
KernelCmdline,
KernelCmdlineArg,
LateTargetKernelCmdlineArgTasks,
Expand Down Expand Up @@ -326,3 +329,53 @@ def readlink_mock(path):
uuid = addupgradebootentry._get_device_uuid(path)

assert uuid == 'MY_UUID1'


def test_modify_grubenv_to_have_separate_blsdir(monkeypatch):
efi_info = ArmWorkaroundEFIBootloaderInfo(
original_entry=EFIBootEntry(
boot_number='0001',
label='Redhat',
active=True,
efi_bin_source="HD(.*)/File(\\EFI\\redhat\\shimx64.efi)",
),
upgrade_entry=EFIBootEntry(
boot_number='0002',
label='Leapp',
active=True,
efi_bin_source="HD(.*)/File(\\EFI\\leapp\\shimx64.efi)",
),
upgrade_bls_dir='/boot/upgrade-loader/entries',
upgrade_entry_efi_path='/boot/efi/EFI/leapp'
)

def list_grubenv_variables_mock():
return {
'blsdir': '/blsdir'
}

def listdir_mock(dir_path):
assert dir_path == '/boot/blsdir'
return [
'4a9c76478b98444fb5e0fbf533950edf-6.12.5-200.fc41.x86_64.conf',
'4a9c76478b98444fb5e0fbf533950edf-upgrade.aarch64.conf',
]

def assert_path_correct(path):
assert path == efi_info.upgrade_bls_dir

def move_mocked(src, dst):
assert src == '/boot/blsdir/4a9c76478b98444fb5e0fbf533950edf-upgrade.aarch64.conf'
assert dst == '/boot/upgrade-loader/entries/4a9c76478b98444fb5e0fbf533950edf-upgrade.aarch64.conf'

def run_mocked(cmd, *arg, **kwargs):
assert cmd == ['grub2-editenv', '/boot/efi/EFI/leapp/grubenv', 'set', 'blsdir=/upgrade-loader/entries']

monkeypatch.setattr(addupgradebootentry, '_list_grubenv_variables', list_grubenv_variables_mock)
monkeypatch.setattr(os, 'listdir', listdir_mock)
monkeypatch.setattr(os.path, 'exists', assert_path_correct)
monkeypatch.setattr(os, 'makedirs', assert_path_correct)
monkeypatch.setattr(shutil, 'move', move_mocked)
monkeypatch.setattr(addupgradebootentry, 'run', run_mocked)

addupgradebootentry.modify_our_grubenv_to_have_separate_blsdir(efi_info)

0 comments on commit c566187

Please sign in to comment.