Merge "make guess_grub_version actually work with GRUB 2"

This commit is contained in:
Jenkins 2015-01-19 19:55:13 +00:00 committed by Gerrit Code Review
commit 5cddad22a7
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