summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArne Wiebalck <Arne.Wiebalck@cern.ch>2021-06-11 18:20:49 +0200
committerArne Wiebalck <Arne.Wiebalck@cern.ch>2021-06-25 17:57:02 +0200
commit8ce1cd5395a5b4aaf7caace144b4b0e51f9bcdf2 (patch)
treeaad76eae908884559a69116fc8a162f159b33cd4
parent0756f04b60185a504b07063e8e1b6e2743bb2835 (diff)
downloadironic-python-agent-8ce1cd5395a5b4aaf7caace144b4b0e51f9bcdf2.tar.gz
Only mount the ESP if not yet mounted
Check if the ESP is already mounted before attempting to mount it for the bootloader installation. Change-Id: Ifd738b2c5663f1a211d7e13b5ba386be631d8db1 (cherry picked from commit 27568204aeb7f063bf236ad7f2f8043db627baa9)
-rw-r--r--ironic_python_agent/extensions/image.py4
-rw-r--r--ironic_python_agent/tests/unit/extensions/test_image.py16
-rw-r--r--releasenotes/notes/check-if-ESP-is-mounted-f9e0eff3609c2668.yaml7
3 files changed, 20 insertions, 7 deletions
diff --git a/ironic_python_agent/extensions/image.py b/ironic_python_agent/extensions/image.py
index 3ec87f05..018a9374 100644
--- a/ironic_python_agent/extensions/image.py
+++ b/ironic_python_agent/extensions/image.py
@@ -664,7 +664,9 @@ def _install_grub2(device, root_uuid, efi_system_part_uuid=None,
LOG.warning("GRUB2 will be installed for UEFI on efi partition "
"%s using the install command which does not place "
"Secure Boot signed binaries.", efi_partition)
- utils.execute('mount', efi_partition, efi_partition_mount_point)
+ if not os.path.ismount(efi_partition_mount_point):
+ utils.execute('mount', efi_partition,
+ efi_partition_mount_point)
efi_mounted = True
# FIXME(rg): does not work in cross boot mode case (target
# boot mode differs from ramdisk one)
diff --git a/ironic_python_agent/tests/unit/extensions/test_image.py b/ironic_python_agent/tests/unit/extensions/test_image.py
index 55e204f0..f524bc5b 100644
--- a/ironic_python_agent/tests/unit/extensions/test_image.py
+++ b/ironic_python_agent/tests/unit/extensions/test_image.py
@@ -631,7 +631,7 @@ efibootmgr: ** Warning ** : Boot0005 has same label ironic1\n
uuid=self.fake_prep_boot_part_uuid)
self.assertFalse(mock_dispatch.called)
- @mock.patch.object(os.path, 'ismount', lambda *_: True)
+ @mock.patch.object(os.path, 'ismount', lambda *_: False)
@mock.patch.object(os.path, 'exists', lambda *_: False)
@mock.patch.object(image, '_is_bootloader_loaded', lambda *_: True)
@mock.patch.object(image, '_append_uefi_to_fstab', autospec=True)
@@ -664,6 +664,7 @@ efibootmgr: ** Warning ** : Boot0005 has same label ironic1\n
self.fake_dir + '/run'),
mock.call('mount', '-t', 'sysfs', 'none',
self.fake_dir + '/sys'),
+ mock.call('mount', '/dev/fake2', self.fake_dir),
mock.call(('chroot %s /bin/sh -c "mount -a -t vfat"' %
(self.fake_dir)), shell=True,
env_variables={
@@ -719,7 +720,7 @@ efibootmgr: ** Warning ** : Boot0005 has same label ironic1\n
mock_append_to_fstab.assert_called_with(self.fake_dir,
self.fake_efi_system_part_uuid)
- @mock.patch.object(os.path, 'ismount', lambda *_: True)
+ @mock.patch.object(os.path, 'ismount', lambda *_: False)
@mock.patch.object(image, '_is_bootloader_loaded', lambda *_: True)
@mock.patch.object(os.path, 'exists', autospec=True)
@mock.patch.object(hardware, 'is_md_device', autospec=True)
@@ -761,6 +762,7 @@ efibootmgr: ** Warning ** : Boot0005 has same label ironic1\n
self.fake_dir + '/run'),
mock.call('mount', '-t', 'sysfs', 'none',
self.fake_dir + '/sys'),
+ mock.call('mount', '/dev/fake2', self.fake_dir),
mock.call(('chroot %s /bin/sh -c "mount -a -t vfat"' %
(self.fake_dir)), shell=True,
env_variables={
@@ -815,7 +817,7 @@ efibootmgr: ** Warning ** : Boot0005 has same label ironic1\n
self.assertFalse(mock_dispatch.called)
@mock.patch.object(image, '_efi_boot_setup', lambda *_: False)
- @mock.patch.object(os.path, 'ismount', lambda *_: True)
+ @mock.patch.object(os.path, 'ismount', lambda *_: False)
@mock.patch.object(image, '_is_bootloader_loaded', lambda *_: True)
@mock.patch.object(os.path, 'exists', autospec=True)
@mock.patch.object(hardware, 'is_md_device', autospec=True)
@@ -870,6 +872,7 @@ efibootmgr: ** Warning ** : Boot0005 has same label ironic1\n
'GRUB_SAVEDEFAULT': 'true'},
use_standard_locale=True),
mock.call('umount', self.fake_dir + '/boot/efi'),
+ mock.call('mount', '/dev/fake2', self.fake_dir),
# NOTE(TheJulia): chroot mount is for whole disk images
mock.call(('chroot %s /bin/sh -c "mount -a -t vfat"' %
(self.fake_dir)), shell=True,
@@ -1092,7 +1095,7 @@ efibootmgr: ** Warning ** : Boot0005 has same label ironic1\n
uuid=self.fake_efi_system_part_uuid)
self.assertFalse(mock_dispatch.called)
- @mock.patch.object(os.path, 'ismount', lambda *_: True)
+ @mock.patch.object(os.path, 'ismount', lambda *_: False)
@mock.patch.object(image, '_is_bootloader_loaded', lambda *_: False)
@mock.patch.object(image, '_append_uefi_to_fstab', autospec=True)
@mock.patch.object(image, '_preserve_efi_assets', autospec=True)
@@ -1144,6 +1147,7 @@ efibootmgr: ** Warning ** : Boot0005 has same label ironic1\n
'GRUB_DISABLE_OS_PROBER': 'true',
'GRUB_SAVEDEFAULT': 'true'},
use_standard_locale=True),
+ mock.call('mount', '/dev/fake2', self.fake_dir),
mock.call(('chroot %s /bin/sh -c "mount -a -t vfat"' %
(self.fake_dir)), shell=True,
env_variables={
@@ -1294,7 +1298,7 @@ efibootmgr: ** Warning ** : Boot0005 has same label ironic1\n
self.assertFalse(mock_dispatch.called)
self.assertEqual(2, mock_oslistdir.call_count)
- @mock.patch.object(os.path, 'ismount', lambda *_: True)
+ @mock.patch.object(os.path, 'ismount', lambda *_: False)
@mock.patch.object(image, '_is_bootloader_loaded', lambda *_: False)
@mock.patch.object(os, 'listdir', autospec=True)
@mock.patch.object(image, '_append_uefi_to_fstab', autospec=True)
@@ -1339,7 +1343,7 @@ efibootmgr: ** Warning ** : Boot0005 has same label ironic1\n
mock.call('mount', '-t', 'vfat', '/dev/fake1',
self.fake_dir + '/boot/efi'),
mock.call('umount', self.fake_dir + '/boot/efi'),
-
+ mock.call('mount', '/dev/fake2', self.fake_dir),
mock.call(('chroot %s /bin/sh -c "mount -a -t vfat"' %
(self.fake_dir)), shell=True,
env_variables={
diff --git a/releasenotes/notes/check-if-ESP-is-mounted-f9e0eff3609c2668.yaml b/releasenotes/notes/check-if-ESP-is-mounted-f9e0eff3609c2668.yaml
new file mode 100644
index 00000000..227f1cb2
--- /dev/null
+++ b/releasenotes/notes/check-if-ESP-is-mounted-f9e0eff3609c2668.yaml
@@ -0,0 +1,7 @@
+---
+fixes:
+ - |
+ Fixes an issue with bootloader installation on a software RAID by
+ checking if the ESP is already mounted.
+
+