summaryrefslogtreecommitdiff
path: root/ironic_python_agent
diff options
context:
space:
mode:
authorDmitry Tantsur <divius.inside@gmail.com>2017-11-17 16:34:24 +0100
committerJulia Kreger <juliaashleykreger@gmail.com>2017-12-14 19:52:53 -0500
commitdb4694de242e3b5f17fa032624d2cb915dd87ce4 (patch)
tree79c8974ea95f47a95d60cef4e49cd0630efb0afd /ironic_python_agent
parent831576c906c74519babb2751a19673e30736a9af (diff)
downloadironic-python-agent-db4694de242e3b5f17fa032624d2cb915dd87ce4.tar.gz
Do not try unmounting the EFI partition if it was not mounted
If mounting the root partition fails for some reason, we try to unmount the EFI partition, which is not mounted at this point. This results in a new exception hiding the real failure. This change fixes it. Change-Id: I0ec636a361eda71b4149e4a7ba1538a9bbf6ec34 Closes-Bug: #1732932
Diffstat (limited to 'ironic_python_agent')
-rw-r--r--ironic_python_agent/extensions/image.py4
-rw-r--r--ironic_python_agent/tests/unit/extensions/test_image.py30
2 files changed, 33 insertions, 1 deletions
diff --git a/ironic_python_agent/extensions/image.py b/ironic_python_agent/extensions/image.py
index 2ed2e9fc..9eb70c46 100644
--- a/ironic_python_agent/extensions/image.py
+++ b/ironic_python_agent/extensions/image.py
@@ -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:
diff --git a/ironic_python_agent/tests/unit/extensions/test_image.py b/ironic_python_agent/tests/unit/extensions/test_image.py
index 04b6c179..d23db27f 100644
--- a/ironic_python_agent/tests/unit/extensions/test_image.py
+++ b/ironic_python_agent/tests/unit/extensions/test_image.py
@@ -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,