From a5370d52cdc25573f4c7935f5bcde784814689f3 Mon Sep 17 00:00:00 2001 From: Pavlo Shchelokovskyy Date: Mon, 16 Jan 2017 21:32:37 +0200 Subject: [PATCH] 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 --- ironic_python_agent/extensions/image.py | 6 +++--- .../tests/unit/extensions/test_image.py | 16 ++++++++-------- .../notes/no-bash-for-grub-c38369af8cc7cf26.yaml | 6 ++++++ 3 files changed, 17 insertions(+), 11 deletions(-) create mode 100644 releasenotes/notes/no-bash-for-grub-c38369af8cc7cf26.yaml diff --git a/ironic_python_agent/extensions/image.py b/ironic_python_agent/extensions/image.py index 5eded3bfc..c2de61ef6 100644 --- a/ironic_python_agent/extensions/image.py +++ b/ironic_python_agent/extensions/image.py @@ -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, diff --git a/ironic_python_agent/tests/unit/extensions/test_image.py b/ironic_python_agent/tests/unit/extensions/test_image.py index d47cce19c..211560650 100644 --- a/ironic_python_agent/tests/unit/extensions/test_image.py +++ b/ironic_python_agent/tests/unit/extensions/test_image.py @@ -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, diff --git a/releasenotes/notes/no-bash-for-grub-c38369af8cc7cf26.yaml b/releasenotes/notes/no-bash-for-grub-c38369af8cc7cf26.yaml new file mode 100644 index 000000000..7855b6e03 --- /dev/null +++ b/releasenotes/notes/no-bash-for-grub-c38369af8cc7cf26.yaml @@ -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.