Merge "Make _get_efi_bootloaders return relative paths"
This commit is contained in:
commit
5c063c8224
@ -37,8 +37,18 @@ CONF = cfg.CONF
|
||||
|
||||
BIND_MOUNTS = ('/dev', '/proc', '/run')
|
||||
|
||||
BOOTLOADERS_EFI = ['bootaa64.efi', 'bootx64.efi', 'grubaa64.efi',
|
||||
'winload.efi']
|
||||
BOOTLOADERS_EFI = [
|
||||
'bootia32.efi',
|
||||
'bootx64.efi',
|
||||
'bootia64.efi',
|
||||
'bootarm.efi',
|
||||
'bootaa64.efi',
|
||||
'bootriscv32.efi',
|
||||
'bootriscv64.efi',
|
||||
'bootriscv128.efi',
|
||||
'grubaa64.efi',
|
||||
'winload.efi'
|
||||
]
|
||||
|
||||
|
||||
def _rescan_device(device):
|
||||
@ -215,9 +225,8 @@ def _get_efi_bootloaders(location):
|
||||
|
||||
:param location: the location where it should start looking for the
|
||||
efi files.
|
||||
:return: a list of valid efi bootloaders
|
||||
:return: a list of relative paths to valid efi bootloaders
|
||||
"""
|
||||
|
||||
# Let's find all files with .efi or .EFI extension
|
||||
LOG.debug('Looking for all efi files on %s', location)
|
||||
valid_bootloaders = []
|
||||
@ -229,7 +238,7 @@ def _get_efi_bootloaders(location):
|
||||
efi_f = os.path.join(root, name)
|
||||
LOG.debug('Checking if %s is executable', efi_f)
|
||||
if os.access(efi_f, os.X_OK):
|
||||
v_bl = efi_f.split('/boot/efi')[-1].replace('/', '\\')
|
||||
v_bl = efi_f.split(location)[-1][1:]
|
||||
LOG.debug('%s is a valid bootloader', v_bl)
|
||||
valid_bootloaders.append(v_bl)
|
||||
return valid_bootloaders
|
||||
@ -252,7 +261,8 @@ def _run_efibootmgr(valid_efi_bootloaders, device, efi_partition):
|
||||
duplicated_label = re.compile(r'^.*:\s\*\*.*\*\*\s:\s.*'
|
||||
r'Boot([0-9a-f-A-F]+)\s.*$')
|
||||
label_id = 1
|
||||
for v_efi_bl_path in valid_efi_bootloaders:
|
||||
for v_bl in valid_efi_bootloaders:
|
||||
v_efi_bl_path = '\\' + v_bl.replace('/', '\\')
|
||||
# Update the nvram using efibootmgr
|
||||
# https://linux.die.net/man/8/efibootmgr
|
||||
label = 'ironic' + str(label_id)
|
||||
|
@ -222,7 +222,7 @@ class TestImageExtension(base.IronicAgentTest):
|
||||
self.fake_dev, hardware.BootInfo(current_boot_mode='uefi')
|
||||
]
|
||||
mock_partition.side_effect = [self.fake_dev, self.fake_efi_system_part]
|
||||
mock_efi_bl.return_value = ['\\EFI\\BOOT\\BOOTX64.EFI']
|
||||
mock_efi_bl.return_value = ['EFI/BOOT/BOOTX64.EFI']
|
||||
mock_utils_efi_part.return_value = '1'
|
||||
|
||||
mock_execute.side_effect = iter([('', ''), ('', ''),
|
||||
@ -271,7 +271,7 @@ class TestImageExtension(base.IronicAgentTest):
|
||||
]
|
||||
mock_partition.return_value = self.fake_dev
|
||||
mock_utils_efi_part.return_value = '1'
|
||||
mock_efi_bl.return_value = ['\\EFI\\BOOT\\BOOTX64.EFI']
|
||||
mock_efi_bl.return_value = ['EFI/BOOT/BOOTX64.EFI']
|
||||
mock_execute.side_effect = iter([('', ''), ('', ''),
|
||||
('', ''), ('', ''),
|
||||
('', ''), ('', ''),
|
||||
@ -318,7 +318,7 @@ class TestImageExtension(base.IronicAgentTest):
|
||||
]
|
||||
mock_partition.return_value = self.fake_dev
|
||||
mock_utils_efi_part.return_value = '1'
|
||||
mock_efi_bl.return_value = ['\\EFI\\BOOT\\BOOTX64.EFI']
|
||||
mock_efi_bl.return_value = ['EFI/BOOT/BOOTX64.EFI']
|
||||
stdeer_msg = """
|
||||
efibootmgr: ** Warning ** : Boot0004 has same label ironic1\n
|
||||
efibootmgr: ** Warning ** : Boot0005 has same label ironic1\n
|
||||
@ -372,8 +372,8 @@ efibootmgr: ** Warning ** : Boot0005 has same label ironic1\n
|
||||
]
|
||||
mock_partition.return_value = self.fake_dev
|
||||
mock_utils_efi_part.return_value = '1'
|
||||
mock_efi_bl.return_value = ['\\EFI\\BOOT\\BOOTX64.EFI',
|
||||
'\\WINDOWS\\system32\\winload.efi']
|
||||
mock_efi_bl.return_value = ['EFI/BOOT/BOOTX64.EFI',
|
||||
'WINDOWS/system32/winload.efi']
|
||||
|
||||
mock_execute.side_effect = iter([('', ''), ('', ''),
|
||||
('', ''), ('', ''),
|
||||
@ -2071,7 +2071,7 @@ efibootmgr: ** Warning ** : Boot0005 has same label ironic1\n
|
||||
mock_utils_efi_part.return_value = '1'
|
||||
mock_get_part_uuid.return_value = self.fake_dev
|
||||
|
||||
mock_efi_bl.return_value = ['\\EFI\\BOOT\\BOOTX64.EFI']
|
||||
mock_efi_bl.return_value = ['EFI/BOOT/BOOTX64.EFI']
|
||||
|
||||
mock_execute.side_effect = iter([('', ''), ('', ''),
|
||||
('', ''), ('', ''),
|
||||
@ -2110,7 +2110,7 @@ efibootmgr: ** Warning ** : Boot0005 has same label ironic1\n
|
||||
mock_utils_efi_part.return_value = '1'
|
||||
mock_get_part_uuid.return_value = '/dev/fakenvme0p1'
|
||||
|
||||
mock_efi_bl.return_value = ['\\EFI\\BOOT\\BOOTX64.EFI']
|
||||
mock_efi_bl.return_value = ['EFI/BOOT/BOOTX64.EFI']
|
||||
|
||||
mock_execute.side_effect = iter([('', ''), ('', ''),
|
||||
('', ''), ('', ''),
|
||||
@ -2150,7 +2150,7 @@ efibootmgr: ** Warning ** : Boot0005 has same label ironic1\n
|
||||
mock_utils_efi_part.return_value = '1'
|
||||
mock_get_part_uuid.side_effect = Exception
|
||||
|
||||
mock_efi_bl.return_value = ['\\EFI\\BOOT\\BOOTX64.EFI']
|
||||
mock_efi_bl.return_value = ['EFI/BOOT/BOOTX64.EFI']
|
||||
|
||||
mock_execute.side_effect = iter([('', ''), ('', ''),
|
||||
('', ''), ('', ''),
|
||||
@ -2219,7 +2219,7 @@ efibootmgr: ** Warning ** : Boot0005 has same label ironic1\n
|
||||
]
|
||||
mock_access.return_value = True
|
||||
result = image._get_efi_bootloaders("/boot/efi")
|
||||
self.assertEqual(result[0], '\\EFI\\BOOT\\BOOTX64.EFI')
|
||||
self.assertEqual(result[0], 'EFI/BOOT/BOOTX64.EFI')
|
||||
|
||||
@mock.patch.object(os, 'walk', autospec=True)
|
||||
@mock.patch.object(os, 'access', autospec=True)
|
||||
@ -2233,7 +2233,7 @@ efibootmgr: ** Warning ** : Boot0005 has same label ironic1\n
|
||||
]
|
||||
mock_access.return_value = True
|
||||
result = image._get_efi_bootloaders("/boot/efi")
|
||||
self.assertEqual(result[0], '\\WINDOWS\\system32\\winload.efi')
|
||||
self.assertEqual(result[0], 'WINDOWS/system32/winload.efi')
|
||||
|
||||
def test__run_efibootmgr_no_bootloaders(self, mock_execute, mock_dispatch):
|
||||
result = image._run_efibootmgr([], self.fake_dev,
|
||||
@ -2243,7 +2243,7 @@ efibootmgr: ** Warning ** : Boot0005 has same label ironic1\n
|
||||
mock_execute.assert_has_calls(expected)
|
||||
|
||||
def test__run_efibootmgr(self, mock_execute, mock_dispatch):
|
||||
result = image._run_efibootmgr(['\\EFI\\BOOT\\BOOTX64.EFI'],
|
||||
result = image._run_efibootmgr(['EFI/BOOT/BOOTX64.EFI'],
|
||||
self.fake_dev,
|
||||
self.fake_efi_system_part)
|
||||
expected = [mock.call('efibootmgr'),
|
||||
|
Loading…
x
Reference in New Issue
Block a user