Skip to content

Commit a5370d5

Browse files
committed
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
1 parent 51ab461 commit a5370d5

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

ironic_python_agent/extensions/image.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def _install_grub2(device, root_uuid, efi_system_part_uuid=None):
114114
path_variable = '%s:/bin' % path_variable
115115

116116
# Install grub
117-
utils.execute('chroot %(path)s /bin/bash -c '
117+
utils.execute('chroot %(path)s /bin/sh -c '
118118
'"/usr/sbin/%(bin)s-install %(dev)s"' %
119119
{'path': path, 'bin': binary_name, 'dev': device},
120120
shell=True, env_variables={'PATH': path_variable})
@@ -127,13 +127,13 @@ def _install_grub2(device, root_uuid, efi_system_part_uuid=None):
127127
# the default file to be copied, destination file name, and
128128
# prevents NVRAM from being updated.
129129
if efi_partition:
130-
utils.execute('chroot %(path)s /bin/bash -c '
130+
utils.execute('chroot %(path)s /bin/sh -c '
131131
'"/usr/sbin/%(bin)s-install %(dev)s --removable"' %
132132
{'path': path, 'bin': binary_name, 'dev': device},
133133
shell=True, env_variables={'PATH': path_variable})
134134

135135
# Generate the grub configuration file
136-
utils.execute('chroot %(path)s /bin/bash -c '
136+
utils.execute('chroot %(path)s /bin/sh -c '
137137
'"/usr/sbin/%(bin)s-mkconfig -o '
138138
'/boot/%(bin)s/grub.cfg"' %
139139
{'path': path, 'bin': binary_name}, shell=True,

ironic_python_agent/tests/unit/extensions/test_image.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ def test__install_grub2(self, mock_get_part_uuid, environ_mock,
8888
self.fake_dir + '/proc'),
8989
mock.call('mount', '-t', 'sysfs', 'none',
9090
self.fake_dir + '/sys'),
91-
mock.call(('chroot %s /bin/bash -c '
91+
mock.call(('chroot %s /bin/sh -c '
9292
'"/usr/sbin/grub-install %s"' %
9393
(self.fake_dir, self.fake_dev)), shell=True,
9494
env_variables={'PATH': '/sbin:/bin'}),
95-
mock.call(('chroot %s /bin/bash -c '
95+
mock.call(('chroot %s /bin/sh -c '
9696
'"/usr/sbin/grub-mkconfig -o '
9797
'/boot/grub/grub.cfg"' % self.fake_dir),
9898
shell=True,
@@ -133,15 +133,15 @@ def test__install_grub2_uefi(self, mock_get_part_uuid, mkdir_mock,
133133
self.fake_dir + '/sys'),
134134
mock.call('mount', self.fake_efi_system_part,
135135
self.fake_dir + '/boot/efi'),
136-
mock.call(('chroot %s /bin/bash -c '
136+
mock.call(('chroot %s /bin/sh -c '
137137
'"/usr/sbin/grub-install %s"' %
138138
(self.fake_dir, self.fake_dev)), shell=True,
139139
env_variables={'PATH': '/sbin:/bin'}),
140-
mock.call(('chroot %s /bin/bash -c '
140+
mock.call(('chroot %s /bin/sh -c '
141141
'"/usr/sbin/grub-install %s --removable"' %
142142
(self.fake_dir, self.fake_dev)), shell=True,
143143
env_variables={'PATH': '/sbin:/bin'}),
144-
mock.call(('chroot %s /bin/bash -c '
144+
mock.call(('chroot %s /bin/sh -c '
145145
'"/usr/sbin/grub-mkconfig -o '
146146
'/boot/grub/grub.cfg"' % self.fake_dir),
147147
shell=True,
@@ -193,15 +193,15 @@ def umount_raise_func(*args, **kwargs):
193193
self.fake_dir + '/sys'),
194194
mock.call('mount', self.fake_efi_system_part,
195195
self.fake_dir + '/boot/efi'),
196-
mock.call(('chroot %s /bin/bash -c '
196+
mock.call(('chroot %s /bin/sh -c '
197197
'"/usr/sbin/grub-install %s"' %
198198
(self.fake_dir, self.fake_dev)), shell=True,
199199
env_variables={'PATH': '/sbin:/bin'}),
200-
mock.call(('chroot %s /bin/bash -c '
200+
mock.call(('chroot %s /bin/sh -c '
201201
'"/usr/sbin/grub-install %s --removable"' %
202202
(self.fake_dir, self.fake_dev)), shell=True,
203203
env_variables={'PATH': '/sbin:/bin'}),
204-
mock.call(('chroot %s /bin/bash -c '
204+
mock.call(('chroot %s /bin/sh -c '
205205
'"/usr/sbin/grub-mkconfig -o '
206206
'/boot/grub/grub.cfg"' % self.fake_dir),
207207
shell=True,
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
fixes:
3+
- |
4+
Ironic Python Agent no longer requires 'bash' to be present in the user
5+
image when preparing the partition image for local boot,
6+
and uses default 'sh' interpreter to run 'grub'-related commands instead.

0 commit comments

Comments
 (0)