Skip to content

Commit

Permalink
Execute pygrub using nova-rootwrap in xenapi
Browse files Browse the repository at this point in the history
Preserve the behavior where, if pygrub fails, compute attempts
to spawn the VM in HVM mode.

Fixes bug #1091628

Change-Id: Ia462964ebb1fc21d8e289de32557a2e7867f1257
  • Loading branch information
Armando Migliaccio committed Dec 18, 2012
1 parent 46675d8 commit e6acd86
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
3 changes: 3 additions & 0 deletions etc/nova/rootwrap.d/compute.filters
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ iscsiadm: CommandFilter, iscsiadm, root
# nova/virt/xenapi/vm_utils.py: 'parted', '--script', dev_path, ..*.
parted: CommandFilter, parted, root

# nova/virt/xenapi/vm_utils.py: 'pygrub', '-qn', dev_path
pygrub: CommandFilter, /usr/bin/pygrub, root

# nova/virt/xenapi/vm_utils.py: fdisk %(dev_path)s
fdisk: CommandFilter, /sbin/fdisk, root

Expand Down
23 changes: 15 additions & 8 deletions nova/virt/xenapi/vm_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1910,14 +1910,21 @@ def _get_this_vm_ref(session):
def _is_vdi_pv(dev):
LOG.debug(_("Running pygrub against %s"), dev)
dev_path = utils.make_dev_path(dev)
output = os.popen('pygrub -qn %s' % dev_path)
for line in output.readlines():
#try to find kernel string
m = re.search('(?<=kernel:)/.*(?:>)', line)
if m and m.group(0).find('xen') != -1:
LOG.debug(_("Found Xen kernel %s") % m.group(0))
return True
LOG.debug(_("No Xen kernel found. Booting HVM."))
try:
out, err = utils.execute('pygrub', '-qn', dev_path, run_as_root=True)
for line in out:
# try to find kernel string
m = re.search('(?<=kernel:)/.*(?:>)', line)
if m and m.group(0).find('xen') != -1:
LOG.debug(_("Found Xen kernel %s") % m.group(0))
return True
LOG.debug(_("No Xen kernel found. Booting HVM."))
except exception.ProcessExecutionError:
LOG.exception(_("Error while executing pygrub! Please, ensure the "
"binary is installed correctly, and available in your "
"PATH; on some Linux distros, pygrub may be installed "
"in /usr/lib/xen-X.Y/bin/pygrub. Attempting to boot "
"in HVM mode."))
return False


Expand Down

0 comments on commit e6acd86

Please sign in to comment.