Use sh instead of bash when installing grub

there is no guarantee that 'bash' is present in a user's image,
while 'sh' as system shell must be there.
As we do not use any bash-specific syntax (just starting commands in a
subshell) when installing the bootloader from chroot-ed user image,
let's be more supportive and use 'sh' instead of 'bash' for that.

Change-Id: I1fb82068b9c55da35166d8d2ecf9f0ba41356adb
Closes-Bug: #1657096
This commit is contained in:
Pavlo Shchelokovskyy 2017-01-16 21:32:37 +02:00
parent 51ab461af8
commit a5370d52cd
3 changed files with 17 additions and 11 deletions

View File

@ -114,7 +114,7 @@ def _install_grub2(device, root_uuid, efi_system_part_uuid=None):
path_variable = '%s:/bin' % path_variable
# Install grub
utils.execute('chroot %(path)s /bin/bash -c '
utils.execute('chroot %(path)s /bin/sh -c '
'"/usr/sbin/%(bin)s-install %(dev)s"' %
{'path': path, 'bin': binary_name, 'dev': device},
shell=True, env_variables={'PATH': path_variable})
@ -127,13 +127,13 @@ def _install_grub2(device, root_uuid, efi_system_part_uuid=None):
# the default file to be copied, destination file name, and
# prevents NVRAM from being updated.
if efi_partition:
utils.execute('chroot %(path)s /bin/bash -c '
utils.execute('chroot %(path)s /bin/sh -c '
'"/usr/sbin/%(bin)s-install %(dev)s --removable"' %
{'path': path, 'bin': binary_name, 'dev': device},
shell=True, env_variables={'PATH': path_variable})
# Generate the grub configuration file
utils.execute('chroot %(path)s /bin/bash -c '
utils.execute('chroot %(path)s /bin/sh -c '
'"/usr/sbin/%(bin)s-mkconfig -o '
'/boot/%(bin)s/grub.cfg"' %
{'path': path, 'bin': binary_name}, shell=True,

View File

@ -88,11 +88,11 @@ class TestImageExtension(test_base.BaseTestCase):
self.fake_dir + '/proc'),
mock.call('mount', '-t', 'sysfs', 'none',
self.fake_dir + '/sys'),
mock.call(('chroot %s /bin/bash -c '
mock.call(('chroot %s /bin/sh -c '
'"/usr/sbin/grub-install %s"' %
(self.fake_dir, self.fake_dev)), shell=True,
env_variables={'PATH': '/sbin:/bin'}),
mock.call(('chroot %s /bin/bash -c '
mock.call(('chroot %s /bin/sh -c '
'"/usr/sbin/grub-mkconfig -o '
'/boot/grub/grub.cfg"' % self.fake_dir),
shell=True,
@ -133,15 +133,15 @@ class TestImageExtension(test_base.BaseTestCase):
self.fake_dir + '/sys'),
mock.call('mount', self.fake_efi_system_part,
self.fake_dir + '/boot/efi'),
mock.call(('chroot %s /bin/bash -c '
mock.call(('chroot %s /bin/sh -c '
'"/usr/sbin/grub-install %s"' %
(self.fake_dir, self.fake_dev)), shell=True,
env_variables={'PATH': '/sbin:/bin'}),
mock.call(('chroot %s /bin/bash -c '
mock.call(('chroot %s /bin/sh -c '
'"/usr/sbin/grub-install %s --removable"' %
(self.fake_dir, self.fake_dev)), shell=True,
env_variables={'PATH': '/sbin:/bin'}),
mock.call(('chroot %s /bin/bash -c '
mock.call(('chroot %s /bin/sh -c '
'"/usr/sbin/grub-mkconfig -o '
'/boot/grub/grub.cfg"' % self.fake_dir),
shell=True,
@ -193,15 +193,15 @@ class TestImageExtension(test_base.BaseTestCase):
self.fake_dir + '/sys'),
mock.call('mount', self.fake_efi_system_part,
self.fake_dir + '/boot/efi'),
mock.call(('chroot %s /bin/bash -c '
mock.call(('chroot %s /bin/sh -c '
'"/usr/sbin/grub-install %s"' %
(self.fake_dir, self.fake_dev)), shell=True,
env_variables={'PATH': '/sbin:/bin'}),
mock.call(('chroot %s /bin/bash -c '
mock.call(('chroot %s /bin/sh -c '
'"/usr/sbin/grub-install %s --removable"' %
(self.fake_dir, self.fake_dev)), shell=True,
env_variables={'PATH': '/sbin:/bin'}),
mock.call(('chroot %s /bin/bash -c '
mock.call(('chroot %s /bin/sh -c '
'"/usr/sbin/grub-mkconfig -o '
'/boot/grub/grub.cfg"' % self.fake_dir),
shell=True,

View File

@ -0,0 +1,6 @@
---
fixes:
- |
Ironic Python Agent no longer requires 'bash' to be present in the user
image when preparing the partition image for local boot,
and uses default 'sh' interpreter to run 'grub'-related commands instead.