Skip to content

Commit

Permalink
Merge "Fix failure of bind mount in _install_grub2"
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and openstack-gerrit committed Oct 17, 2022
2 parents 929ae3d + 0bf579c commit a167075
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
1 change: 1 addition & 0 deletions ironic_python_agent/extensions/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
48 changes: 45 additions & 3 deletions ironic_python_agent/tests/unit/extensions/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,10 +538,13 @@ def test__install_grub2(self, mock_get_part_uuid, environ_mock,
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',
Expand Down Expand Up @@ -601,10 +604,13 @@ def test__install_grub2_prep(self, mock_get_part_uuid, environ_mock,
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',
Expand Down Expand Up @@ -674,10 +680,13 @@ def test__install_grub2_uefi(self, mock_get_part_uuid, mkdir_mock,
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',
Expand Down Expand Up @@ -775,10 +784,13 @@ def test__install_grub2_uefi_fstab(self, mock_get_part_uuid, mkdir_mock,
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',
Expand Down Expand Up @@ -884,10 +896,13 @@ def test__install_grub2_uefi_no_fstab(
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',
Expand Down Expand Up @@ -1003,10 +1018,13 @@ def test__install_grub2_uefi_partition_image_with_loader(
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',
Expand Down Expand Up @@ -1089,10 +1107,13 @@ def test__install_grub2_uefi_partition_image_with_loader_with_grubcfg(
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',
Expand Down Expand Up @@ -1170,10 +1191,13 @@ def test__install_grub2_uefi_partition_image_with_preserve_failure(
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',
Expand Down Expand Up @@ -1291,10 +1315,13 @@ def test__install_grub2_uefi_partition_image_with_preserve_failure2(
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',
Expand Down Expand Up @@ -1416,10 +1443,13 @@ def test__install_grub2_uefi_partition_image_with_loader_grubcfg_fails(
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',
Expand Down Expand Up @@ -1496,10 +1526,13 @@ def test__install_grub2_uefi_partition_image_with_no_loader(
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',
Expand Down Expand Up @@ -1593,10 +1626,13 @@ def umount_raise_func(*args, **kwargs):
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',
Expand Down Expand Up @@ -1707,7 +1743,7 @@ def test__install_grub2_softraid_uefi_gpt(
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(
Expand All @@ -1718,8 +1754,8 @@ def test__install_grub2_softraid_uefi_gpt(
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]
Expand All @@ -1736,10 +1772,13 @@ def test__install_grub2_softraid_uefi_gpt(
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',
Expand Down Expand Up @@ -1837,10 +1876,13 @@ def test__install_grub2_softraid_bios(

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',
Expand Down

0 comments on commit a167075

Please sign in to comment.