Merge "Do not try unmounting the EFI partition if it was not mounted"

This commit is contained in:
Zuul 2017-12-15 08:40:16 +00:00 committed by Gerrit Code Review
commit 5ee16ee2e8
2 changed files with 33 additions and 1 deletions

View File

@ -82,6 +82,7 @@ def _install_grub2(device, root_uuid, efi_system_part_uuid=None):
root_partition = _get_partition(device, uuid=root_uuid)
efi_partition = None
efi_partition_mount_point = None
efi_mounted = False
try:
# Mount the partition and binds
@ -101,6 +102,7 @@ def _install_grub2(device, root_uuid, efi_system_part_uuid=None):
if not os.path.exists(efi_partition_mount_point):
os.makedirs(efi_partition_mount_point)
utils.execute('mount', efi_partition, efi_partition_mount_point)
efi_mounted = True
binary_name = "grub"
if os.path.exists(os.path.join(path, 'usr/sbin/grub2-install')):
@ -155,7 +157,7 @@ def _install_grub2(device, root_uuid, efi_system_part_uuid=None):
# If umount fails for efi partition, then we cannot be sure that all
# the changes were written back to the filesystem.
try:
if efi_partition:
if efi_mounted:
utils.execute('umount', efi_partition_mount_point, attempts=3,
delay_on_retry=True)
except processutils.ProcessExecutionError as e:

View File

@ -208,6 +208,36 @@ class TestImageExtension(base.IronicAgentTest):
attempts=3, delay_on_retry=True)]
mock_execute.assert_has_calls(expected)
@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_mount_fails(
self, mock_get_part_uuid, mkdir_mock, environ_mock, mock_execute,
mock_dispatch):
mock_get_part_uuid.side_effect = [self.fake_root_part,
self.fake_efi_system_part]
def mount_raise_func(*args, **kwargs):
if args[0] == 'mount':
raise processutils.ProcessExecutionError('error')
mock_execute.side_effect = mount_raise_func
self.assertRaises(errors.CommandExecutionError,
image._install_grub2,
self.fake_dev, root_uuid=self.fake_root_uuid,
efi_system_part_uuid=self.fake_efi_system_part_uuid)
expected = [mock.call('mount', '/dev/fake2', self.fake_dir),
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 + '/sys',
attempts=3, delay_on_retry=True),
mock.call('umount', self.fake_dir, attempts=3,
delay_on_retry=True)]
mock_execute.assert_has_calls(expected)
@mock.patch.object(image, '_get_partition', autospec=True)
def test__install_grub2_command_fail(self, mock_get_part_uuid,
mock_execute,