summaryrefslogtreecommitdiff
path: root/ironic_python_agent/tests/unit/extensions
diff options
context:
space:
mode:
authorJulia Kreger <juliaashleykreger@gmail.com>2021-06-28 15:16:01 -0700
committerJulia Kreger <juliaashleykreger@gmail.com>2021-06-29 14:14:52 -0700
commite5d552474b21137ae2a66f17bdab5fc1bbf31ec6 (patch)
tree8169dc4fd7891add84b39cf687722189d008b0e2 /ironic_python_agent/tests/unit/extensions
parent20e145e4da853cd759387e8d8727086f399e51b3 (diff)
downloadironic-python-agent-e5d552474b21137ae2a66f17bdab5fc1bbf31ec6.tar.gz
Catch ismount not being handled
While investigating another grub issue, I was confused by the path taken in the logs reported, and noticed that on a ramdisk, we might not actually have a valid response to os.path.ismount, I'm guessing depending on what in memory filesystem is in use while also coupled with attempting to check a filesystem. Adds a test to validate that exceptions raised on these commands where this issue can be encountered, are properly bypassed, and also adds additional logging to make it easier to figure out what is going on in the entire bootloader setup sequence. Change-Id: Ibd3060bef2e56468ada6b1a5c1cc1632a42803c3
Diffstat (limited to 'ironic_python_agent/tests/unit/extensions')
-rw-r--r--ironic_python_agent/tests/unit/extensions/test_image.py121
1 files changed, 121 insertions, 0 deletions
diff --git a/ironic_python_agent/tests/unit/extensions/test_image.py b/ironic_python_agent/tests/unit/extensions/test_image.py
index 9661e6f3..05e937b8 100644
--- a/ironic_python_agent/tests/unit/extensions/test_image.py
+++ b/ironic_python_agent/tests/unit/extensions/test_image.py
@@ -1154,6 +1154,127 @@ 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 *_: 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)
+ @mock.patch.object(image, '_efi_boot_setup', autospec=True)
+ @mock.patch.object(os.path, 'exists', autospec=True)
+ @mock.patch.object(hardware, 'is_md_device', autospec=True)
+ @mock.patch.object(hardware, 'md_get_raid_devices', autospec=True)
+ @mock.patch.object(os, 'environ', autospec=True)
+ @mock.patch.object(os, 'makedirs', autospec=True)
+ @mock.patch.object(image, '_get_partition', autospec=True)
+ def test__install_grub2_uefi_partition_image_with_preserve_failure2(
+ self, mock_get_part_uuid, mkdir_mock,
+ environ_mock, mock_md_get_raid_devices,
+ mock_is_md_device, mock_exists,
+ mock_efi_setup,
+ mock_preserve_efi_assets,
+ mock_append_to_fstab,
+ mock_execute, mock_dispatch):
+ mock_exists.return_value = True
+ mock_efi_setup.side_effect = Exception('meow')
+ mock_get_part_uuid.side_effect = [self.fake_root_part,
+ self.fake_efi_system_part]
+ environ_mock.get.return_value = '/sbin'
+ mock_is_md_device.return_value = False
+ mock_md_get_raid_devices.return_value = {}
+ mock_preserve_efi_assets.return_value = None
+ exec_results = [('', '')] * 21
+ already_exists = processutils.ProcessExecutionError(
+ '/dev is already mounted at /path')
+ # Mark mounts as already mounted, which is where os.path.ismount
+ # usage corresponds.
+ exec_results[6] = already_exists
+ exec_results[8] = already_exists
+
+ image._install_grub2(
+ self.fake_dev, root_uuid=self.fake_root_uuid,
+ efi_system_part_uuid=self.fake_efi_system_part_uuid,
+ target_boot_mode='uefi')
+ self.assertFalse(mock_efi_setup.called)
+
+ expected = [mock.call('mount', '/dev/fake2', self.fake_dir),
+ mock.call('mount', '-o', 'bind', '/dev',
+ self.fake_dir + '/dev'),
+ mock.call('mount', '-o', 'bind', '/proc',
+ self.fake_dir + '/proc'),
+ mock.call('mount', '-o', 'bind', '/run',
+ self.fake_dir + '/run'),
+ mock.call('mount', '-t', 'sysfs', 'none',
+ self.fake_dir + '/sys'),
+ mock.call(('chroot %s /bin/sh -c '
+ '"grub2-mkconfig -o '
+ '/boot/grub2/grub.cfg"' % self.fake_dir),
+ shell=True,
+ env_variables={
+ 'PATH': '/sbin:/bin:/usr/sbin:/sbin',
+ '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={
+ 'PATH': '/sbin:/bin:/usr/sbin:/sbin'}),
+ mock.call('mount', self.fake_efi_system_part,
+ self.fake_dir + '/boot/efi'),
+ mock.call(('chroot %s /bin/sh -c "grub2-install"' %
+ self.fake_dir), shell=True,
+ env_variables={
+ 'PATH': '/sbin:/bin:/usr/sbin:/sbin'}),
+ mock.call(('chroot %s /bin/sh -c '
+ '"grub2-install --removable"' %
+ self.fake_dir), shell=True,
+ env_variables={
+ 'PATH': '/sbin:/bin:/usr/sbin:/sbin'}),
+ mock.call(
+ 'umount', self.fake_dir + '/boot/efi',
+ attempts=3, delay_on_retry=True),
+ mock.call('mount', self.fake_efi_system_part,
+ '/tmp/fake-dir/boot/efi'),
+ mock.call(('chroot %s /bin/sh -c '
+ '"grub2-mkconfig -o '
+ '/boot/grub2/grub.cfg"' % self.fake_dir),
+ shell=True,
+ env_variables={
+ 'PATH': '/sbin:/bin:/usr/sbin:/sbin',
+ 'GRUB_DISABLE_OS_PROBER': 'true',
+ 'GRUB_SAVEDEFAULT': 'true'},
+ use_standard_locale=True),
+ mock.call('umount', self.fake_dir + '/boot/efi',
+ attempts=3, delay_on_retry=True),
+ mock.call(('chroot %s /bin/sh -c "umount -a -t vfat"' %
+ (self.fake_dir)), shell=True,
+ env_variables={
+ 'PATH': '/sbin:/bin:/usr/sbin:/sbin'}),
+ mock.call('umount', self.fake_dir + '/dev',
+ attempts=3, delay_on_retry=True),
+ mock.call('umount', self.fake_dir + '/proc',
+ attempts=3, delay_on_retry=True),
+ mock.call('umount', self.fake_dir + '/run',
+ attempts=3, delay_on_retry=True),
+ mock.call('umount', self.fake_dir + '/sys',
+ attempts=3, delay_on_retry=True),
+ mock.call('umount', self.fake_dir, attempts=3,
+ delay_on_retry=True)]
+
+ mkdir_mock.assert_not_called()
+ mock_execute.assert_has_calls(expected)
+ mock_get_part_uuid.assert_any_call(self.fake_dev,
+ uuid=self.fake_root_uuid)
+ mock_get_part_uuid.assert_any_call(self.fake_dev,
+ uuid=self.fake_efi_system_part_uuid)
+ self.assertFalse(mock_dispatch.called)
+ mock_preserve_efi_assets.assert_called_with(
+ self.fake_dir,
+ self.fake_dir + '/boot/efi/EFI',
+ '/dev/fake1',
+ self.fake_dir + '/boot/efi')
+ mock_append_to_fstab.assert_called_with(self.fake_dir,
+ self.fake_efi_system_part_uuid)
+
@mock.patch.object(image, '_is_bootloader_loaded', lambda *_: False)
@mock.patch.object(os, 'listdir', autospec=True)
@mock.patch.object(shutil, 'copy2', autospec=True)