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
This commit is contained in:
Alexei Sheplyakov 2015-01-03 15:12:11 +03:00
parent e808d85431
commit 4101a23394
2 changed files with 9 additions and 4 deletions

View File

@ -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')

View File

@ -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