From 4101a23394a5cf5b1eee650f7be3692baae09cd9 Mon Sep 17 00:00:00 2001 From: Alexei Sheplyakov Date: Sat, 3 Jan 2015 15:12:11 +0300 Subject: [PATCH] make guess_grub_version actually work with GRUB 2 * the correct switch to ask for the grub-install version is --version, -v has a totally different meaning (--verbose). Older versions of grub-install recognize the --version switch too. * grub-install from GRUB 2.x is a binary, not a shell script, and it might require the shared libraries which are available inside the chroot only (and not in the bootstrap system). Therefore grub-install should be run in the chroot even if we are asking for its version. blueprint support-ubuntu-trusty Closes-bug: #1407221 Change-Id: I08db41dc6d65c152a62f6a1544c0c1de5922f7d5 --- fuel_agent/tests/test_grub_utils.py | 6 ++++-- fuel_agent/utils/grub_utils.py | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/fuel_agent/tests/test_grub_utils.py b/fuel_agent/tests/test_grub_utils.py index 725dc00a..eac0be33 100644 --- a/fuel_agent/tests/test_grub_utils.py +++ b/fuel_agent/tests/test_grub_utils.py @@ -121,7 +121,8 @@ class TestGrubUtils(test_base.BaseTestCase): mock_ggi.return_value = '/grub_install' mock_exec.return_value = ('foo 0.97 bar', '') version = gu.guess_grub_version('/target') - mock_exec.assert_called_once_with('/target/grub_install', '-v') + cmd = 'chroot /target /grub_install --version'.split() + mock_exec.assert_called_once_with(*cmd) self.assertEqual(version, 1) @mock.patch.object(gu, 'guess_grub_install') @@ -130,7 +131,8 @@ class TestGrubUtils(test_base.BaseTestCase): mock_ggi.return_value = '/grub_install' mock_exec.return_value = ('foo bar', '') version = gu.guess_grub_version('/target') - mock_exec.assert_called_once_with('/target/grub_install', '-v') + cmd = 'chroot /target /grub_install --version'.split() + mock_exec.assert_called_once_with(*cmd) self.assertEqual(version, 2) @mock.patch.object(os.path, 'isfile') diff --git a/fuel_agent/utils/grub_utils.py b/fuel_agent/utils/grub_utils.py index 559ef351..8aefbf39 100644 --- a/fuel_agent/utils/grub_utils.py +++ b/fuel_agent/utils/grub_utils.py @@ -45,8 +45,11 @@ def guess_grub2_mkconfig(chroot=''): def guess_grub_version(chroot=''): grub_install = guess_grub_install(chroot=chroot) - LOG.debug('Trying to run %s -v' % grub_install) - result = utils.execute(chroot + grub_install, '-v') + LOG.debug('Trying to run %s --version' % grub_install) + cmd = [grub_install, '--version'] + if chroot: + cmd[:0] = ['chroot', chroot] + result = utils.execute(*cmd) version = 1 if result[0].find('0.97') > 0 else 2 LOG.debug('Looks like grub version is %s' % version) return version