inspection: report guest inspection errors

Add an `error' flag to the inspection data for a guest and set it when
the inspection failed.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano 2013-11-26 21:57:06 +01:00
parent 02f3546e02
commit b3131e828e
2 changed files with 21 additions and 6 deletions

View File

@ -142,6 +142,7 @@ class vmmInspectionData(object):
self.product_variant = None
self.icon = None
self.applications = None
self.error = False
class vmmDomainSnapshot(vmmLibvirtObject):

View File

@ -122,6 +122,11 @@ class vmmInspection(vmmGObject):
if not conn.is_active():
break
def set_inspection_error(vm):
data = vmmInspectionData()
data.error = True
self._set_vm_inspection_data(vm, data)
prettyvm = vmuuid
try:
vm = conn.get_vm(vmuuid)
@ -139,7 +144,15 @@ class vmmInspection(vmmGObject):
# Whether success or failure, we've "seen" this VM now.
self._vmseen[vmuuid] = True
self._process(conn, vm, vmuuid)
try:
data = self._process(conn, vm, vmuuid)
if data:
self._set_vm_inspection_data(vm, data)
else:
set_inspection_error(vm)
except:
set_inspection_error(vm)
raise
except:
logging.exception("%s: exception while processing",
prettyvm)
@ -148,7 +161,7 @@ class vmmInspection(vmmGObject):
if re.search(r"^guestfs-", vm.get_name()):
logging.debug("ignore libvirt/guestfs temporary VM %s",
vm.get_name())
return
return None
g = GuestFS()
prettyvm = conn.get_uri() + ":" + vm.get_name()
@ -163,7 +176,7 @@ class vmmInspection(vmmGObject):
if not disks:
logging.debug("%s: nothing to inspect", prettyvm)
return
return None
# Add the disks. Note they *must* be added with readonly flag set.
for disk in disks:
@ -173,7 +186,7 @@ class vmmInspection(vmmGObject):
if not (os.path.exists(path) and os.access(path, os.R_OK)):
logging.debug("%s: cannot access '%s', skipping inspection",
prettyvm, path)
return
return None
g.add_drive_opts(path, readonly=1, format=driver_type)
@ -183,7 +196,7 @@ class vmmInspection(vmmGObject):
roots = g.inspect_os()
if len(roots) == 0:
logging.debug("%s: no operating systems found", prettyvm)
return
return None
# Arbitrarily pick the first root device.
root = roots[0]
@ -264,8 +277,9 @@ class vmmInspection(vmmGObject):
data.product_variant = str(product_variant)
data.icon = icon
data.applications = list(apps)
data.error = False
self._set_vm_inspection_data(vm, data)
return data
def _set_vm_inspection_data(self, vm, data):
vm.inspection = data