Fix failure of bind mount in _install_grub2

When IPA runs _install_grub2, IPA tries to bind mount /dev, /proc and /run
to <temporal directory path root partition mounted>/{dev,proc,run}.
However that bind mount fails because there aren't such mount point path
under temporal directory.
To fix this failure, this patch add mkdir command before bind mount.

Story: 2010292
Task: 46273
Change-Id: I434ce1bf1863ee0f11c4d09918d6d2d8dc065c02
This commit is contained in:
Vanou Ishii 2022-09-13 16:53:07 +09:00
parent ed6a8d28b7
commit 0bf579c955
2 changed files with 46 additions and 3 deletions

View File

@ -425,6 +425,7 @@ def _mount_for_chroot(path):
LOG.debug('Mounting Linux standard partitions for bootloader '
'configuration generation')
for fs in BIND_MOUNTS:
utils.execute('mkdir', '-p', path + fs)
utils.execute('mount', '-o', 'bind', fs, path + fs)
utils.execute('mount', '-t', 'sysfs', 'none', path + '/sys')

View File

@ -538,10 +538,13 @@ Boot0004* ironic1 HD(1,GPT,55db8d03-c8f6-4a5b-9155-790dddc348fa,0x800,0x640
image._install_grub2(self.fake_dev, self.fake_root_uuid)
expected = [mock.call('mount', '/dev/fake2', self.fake_dir),
mock.call('mkdir', '-p', self.fake_dir + '/dev'),
mock.call('mount', '-o', 'bind', '/dev',
self.fake_dir + '/dev'),
mock.call('mkdir', '-p', self.fake_dir + '/proc'),
mock.call('mount', '-o', 'bind', '/proc',
self.fake_dir + '/proc'),
mock.call('mkdir', '-p', self.fake_dir + '/run'),
mock.call('mount', '-o', 'bind', '/run',
self.fake_dir + '/run'),
mock.call('mount', '-t', 'sysfs', 'none',
@ -601,10 +604,13 @@ Boot0004* ironic1 HD(1,GPT,55db8d03-c8f6-4a5b-9155-790dddc348fa,0x800,0x640
prep_boot_part_uuid=self.fake_prep_boot_part_uuid)
expected = [mock.call('mount', '/dev/fake2', self.fake_dir),
mock.call('mkdir', '-p', self.fake_dir + '/dev'),
mock.call('mount', '-o', 'bind', '/dev',
self.fake_dir + '/dev'),
mock.call('mkdir', '-p', self.fake_dir + '/proc'),
mock.call('mount', '-o', 'bind', '/proc',
self.fake_dir + '/proc'),
mock.call('mkdir', '-p', self.fake_dir + '/run'),
mock.call('mount', '-o', 'bind', '/run',
self.fake_dir + '/run'),
mock.call('mount', '-t', 'sysfs', 'none',
@ -674,10 +680,13 @@ Boot0004* ironic1 HD(1,GPT,55db8d03-c8f6-4a5b-9155-790dddc348fa,0x800,0x640
target_boot_mode='uefi')
expected = [mock.call('mount', '/dev/fake2', self.fake_dir),
mock.call('mkdir', '-p', self.fake_dir + '/dev'),
mock.call('mount', '-o', 'bind', '/dev',
self.fake_dir + '/dev'),
mock.call('mkdir', '-p', self.fake_dir + '/proc'),
mock.call('mount', '-o', 'bind', '/proc',
self.fake_dir + '/proc'),
mock.call('mkdir', '-p', self.fake_dir + '/run'),
mock.call('mount', '-o', 'bind', '/run',
self.fake_dir + '/run'),
mock.call('mount', '-t', 'sysfs', 'none',
@ -775,10 +784,13 @@ Boot0004* ironic1 HD(1,GPT,55db8d03-c8f6-4a5b-9155-790dddc348fa,0x800,0x640
mock_open.assert_has_calls(write_calls)
expected = [mock.call('mount', '/dev/fake2', self.fake_dir),
mock.call('mkdir', '-p', self.fake_dir + '/dev'),
mock.call('mount', '-o', 'bind', '/dev',
self.fake_dir + '/dev'),
mock.call('mkdir', '-p', self.fake_dir + '/proc'),
mock.call('mount', '-o', 'bind', '/proc',
self.fake_dir + '/proc'),
mock.call('mkdir', '-p', self.fake_dir + '/run'),
mock.call('mount', '-o', 'bind', '/run',
self.fake_dir + '/run'),
mock.call('mount', '-t', 'sysfs', 'none',
@ -883,10 +895,13 @@ Boot0004* ironic1 HD(1,GPT,55db8d03-c8f6-4a5b-9155-790dddc348fa,0x800,0x640
mock_open.assert_has_calls(write_calls)
expected = [mock.call('mount', '/dev/fake2', self.fake_dir),
mock.call('mkdir', '-p', self.fake_dir + '/dev'),
mock.call('mount', '-o', 'bind', '/dev',
self.fake_dir + '/dev'),
mock.call('mkdir', '-p', self.fake_dir + '/proc'),
mock.call('mount', '-o', 'bind', '/proc',
self.fake_dir + '/proc'),
mock.call('mkdir', '-p', self.fake_dir + '/run'),
mock.call('mount', '-o', 'bind', '/run',
self.fake_dir + '/run'),
mock.call('mount', '-t', 'sysfs', 'none',
@ -1001,10 +1016,13 @@ Boot0004* ironic1 HD(1,GPT,55db8d03-c8f6-4a5b-9155-790dddc348fa,0x800,0x640
self.fake_dir + '/boot/efi/EFI')])
expected = [mock.call('mount', '/dev/fake2', self.fake_dir),
mock.call('mkdir', '-p', self.fake_dir + '/dev'),
mock.call('mount', '-o', 'bind', '/dev',
self.fake_dir + '/dev'),
mock.call('mkdir', '-p', self.fake_dir + '/proc'),
mock.call('mount', '-o', 'bind', '/proc',
self.fake_dir + '/proc'),
mock.call('mkdir', '-p', self.fake_dir + '/run'),
mock.call('mount', '-o', 'bind', '/run',
self.fake_dir + '/run'),
mock.call('mount', '-t', 'sysfs', 'none',
@ -1087,10 +1105,13 @@ Boot0004* ironic1 HD(1,GPT,55db8d03-c8f6-4a5b-9155-790dddc348fa,0x800,0x640
self.fake_dir + '/boot/efi/EFI')])
expected = [mock.call('mount', '/dev/fake2', self.fake_dir),
mock.call('mkdir', '-p', self.fake_dir + '/dev'),
mock.call('mount', '-o', 'bind', '/dev',
self.fake_dir + '/dev'),
mock.call('mkdir', '-p', self.fake_dir + '/proc'),
mock.call('mount', '-o', 'bind', '/proc',
self.fake_dir + '/proc'),
mock.call('mkdir', '-p', self.fake_dir + '/run'),
mock.call('mount', '-o', 'bind', '/run',
self.fake_dir + '/run'),
mock.call('mount', '-t', 'sysfs', 'none',
@ -1168,10 +1189,13 @@ Boot0004* ironic1 HD(1,GPT,55db8d03-c8f6-4a5b-9155-790dddc348fa,0x800,0x640
self.assertFalse(mock_efi_setup.called)
expected = [mock.call('mount', '/dev/fake2', self.fake_dir),
mock.call('mkdir', '-p', self.fake_dir + '/dev'),
mock.call('mount', '-o', 'bind', '/dev',
self.fake_dir + '/dev'),
mock.call('mkdir', '-p', self.fake_dir + '/proc'),
mock.call('mount', '-o', 'bind', '/proc',
self.fake_dir + '/proc'),
mock.call('mkdir', '-p', self.fake_dir + '/run'),
mock.call('mount', '-o', 'bind', '/run',
self.fake_dir + '/run'),
mock.call('mount', '-t', 'sysfs', 'none',
@ -1289,10 +1313,13 @@ Boot0004* ironic1 HD(1,GPT,55db8d03-c8f6-4a5b-9155-790dddc348fa,0x800,0x640
self.assertFalse(mock_efi_setup.called)
expected = [mock.call('mount', '/dev/fake2', self.fake_dir),
mock.call('mkdir', '-p', self.fake_dir + '/dev'),
mock.call('mount', '-o', 'bind', '/dev',
self.fake_dir + '/dev'),
mock.call('mkdir', '-p', self.fake_dir + '/proc'),
mock.call('mount', '-o', 'bind', '/proc',
self.fake_dir + '/proc'),
mock.call('mkdir', '-p', self.fake_dir + '/run'),
mock.call('mount', '-o', 'bind', '/run',
self.fake_dir + '/run'),
mock.call('mount', '-t', 'sysfs', 'none',
@ -1414,10 +1441,13 @@ Boot0004* ironic1 HD(1,GPT,55db8d03-c8f6-4a5b-9155-790dddc348fa,0x800,0x640
self.fake_dir + '/boot/efi/EFI')])
expected = [mock.call('mount', '/dev/fake2', self.fake_dir),
mock.call('mkdir', '-p', self.fake_dir + '/dev'),
mock.call('mount', '-o', 'bind', '/dev',
self.fake_dir + '/dev'),
mock.call('mkdir', '-p', self.fake_dir + '/proc'),
mock.call('mount', '-o', 'bind', '/proc',
self.fake_dir + '/proc'),
mock.call('mkdir', '-p', self.fake_dir + '/run'),
mock.call('mount', '-o', 'bind', '/run',
self.fake_dir + '/run'),
mock.call('mount', '-t', 'sysfs', 'none',
@ -1494,10 +1524,13 @@ Boot0004* ironic1 HD(1,GPT,55db8d03-c8f6-4a5b-9155-790dddc348fa,0x800,0x640
target_boot_mode='uefi')
expected = [mock.call('mount', '/dev/fake2', self.fake_dir),
mock.call('mkdir', '-p', self.fake_dir + '/dev'),
mock.call('mount', '-o', 'bind', '/dev',
self.fake_dir + '/dev'),
mock.call('mkdir', '-p', self.fake_dir + '/proc'),
mock.call('mount', '-o', 'bind', '/proc',
self.fake_dir + '/proc'),
mock.call('mkdir', '-p', self.fake_dir + '/run'),
mock.call('mount', '-o', 'bind', '/run',
self.fake_dir + '/run'),
mock.call('mount', '-t', 'sysfs', 'none',
@ -1591,10 +1624,13 @@ Boot0004* ironic1 HD(1,GPT,55db8d03-c8f6-4a5b-9155-790dddc348fa,0x800,0x640
efi_system_part_uuid=self.fake_efi_system_part_uuid)
expected = [mock.call('mount', '/dev/fake2', self.fake_dir),
mock.call('mkdir', '-p', self.fake_dir + '/dev'),
mock.call('mount', '-o', 'bind', '/dev',
self.fake_dir + '/dev'),
mock.call('mkdir', '-p', self.fake_dir + '/proc'),
mock.call('mount', '-o', 'bind', '/proc',
self.fake_dir + '/proc'),
mock.call('mkdir', '-p', self.fake_dir + '/run'),
mock.call('mount', '-o', 'bind', '/run',
self.fake_dir + '/run'),
mock.call('mount', '-t', 'sysfs', 'none',
@ -1705,7 +1741,7 @@ Boot0004* ironic1 HD(1,GPT,55db8d03-c8f6-4a5b-9155-790dddc348fa,0x800,0x640
mock_execute, mock_dispatch):
# return success for every execute call
mock_execute.side_effect = [('', '')] * 21
mock_execute.side_effect = [('', '')] * 24
# make grub2-install calls fail
grub_failure = processutils.ProcessExecutionError(
@ -1716,8 +1752,8 @@ Boot0004* ironic1 HD(1,GPT,55db8d03-c8f6-4a5b-9155-790dddc348fa,0x800,0x640
exit_code=1,
cmd='grub2-install'
)
mock_execute.side_effect[9] = grub_failure
mock_execute.side_effect[10] = grub_failure
mock_execute.side_effect[12] = grub_failure
mock_execute.side_effect[13] = grub_failure
mock_get_part_uuid.side_effect = [self.fake_root_part,
self.fake_efi_system_part]
@ -1734,10 +1770,13 @@ Boot0004* ironic1 HD(1,GPT,55db8d03-c8f6-4a5b-9155-790dddc348fa,0x800,0x640
delay_on_retry=True),
mock.call('udevadm', 'settle'),
mock.call('mount', '/dev/fake2', self.fake_dir),
mock.call('mkdir', '-p', self.fake_dir + '/dev'),
mock.call('mount', '-o', 'bind', '/dev',
self.fake_dir + '/dev'),
mock.call('mkdir', '-p', self.fake_dir + '/proc'),
mock.call('mount', '-o', 'bind', '/proc',
self.fake_dir + '/proc'),
mock.call('mkdir', '-p', self.fake_dir + '/run'),
mock.call('mount', '-o', 'bind', '/run',
self.fake_dir + '/run'),
mock.call('mount', '-t', 'sysfs', 'none',
@ -1835,10 +1874,13 @@ Boot0004* ironic1 HD(1,GPT,55db8d03-c8f6-4a5b-9155-790dddc348fa,0x800,0x640
expected = [
mock.call('mount', '/dev/fake2', self.fake_dir),
mock.call('mkdir', '-p', self.fake_dir + '/dev'),
mock.call('mount', '-o', 'bind', '/dev',
self.fake_dir + '/dev'),
mock.call('mkdir', '-p', self.fake_dir + '/proc'),
mock.call('mount', '-o', 'bind', '/proc',
self.fake_dir + '/proc'),
mock.call('mkdir', '-p', self.fake_dir + '/run'),
mock.call('mount', '-o', 'bind', '/run',
self.fake_dir + '/run'),
mock.call('mount', '-t', 'sysfs', 'none',