From cfe6fe374fa04b9c6150256c9a760b6b340ce697 Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Thu, 8 Dec 2011 14:00:45 -0500 Subject: Add preparation for asynchronous instance faults Add InstanceFault model Migration for new instance_faults table Functions to add and get instance faults A single example of how faults should be added Change-Id: I439e2419240de24a728045046153451eb8a0d267 --- nova/compute/manager.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'nova/compute') diff --git a/nova/compute/manager.py b/nova/compute/manager.py index c657f732a..1efe368ea 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -323,10 +323,11 @@ class ComputeManager(manager.SchedulerDependentManager): except exception.InstanceNotFound: LOG.exception(_("Instance %s not found.") % instance_uuid) return # assuming the instance was already deleted - except Exception: + except Exception as e: with utils.save_and_reraise_exception(): self._instance_update(context, instance_uuid, vm_state=vm_states.ERROR) + self.add_instance_fault_from_exc(context, instance_uuid, e) def _check_instance_not_already_created(self, context, instance): """Ensure an instance with the same name is not already present.""" @@ -1917,3 +1918,29 @@ class ComputeManager(manager.SchedulerDependentManager): LOG.info(_("Reclaiming deleted instance %(instance_id)s"), locals()) self._delete_instance(context, instance) + + def add_instance_fault_from_exc(self, context, instance_uuid, fault): + """Adds the specified fault to the database.""" + if hasattr(fault, "code"): + code = fault.code + else: + code = 500 + + values = { + 'instance_uuid': instance_uuid, + 'code': code, + 'message': fault.__class__.__name__, + 'details': fault.message, + } + self.db.instance_fault_create(context, values) + + def add_instance_fault(self, context, instance_uuid, code=500, + message='', details=''): + """Adds a fault to the database using the specified values.""" + values = { + 'instance_uuid': instance_uuid, + 'code': code, + 'message': message, + 'details': details, + } + self.db.instance_fault_create(context, values) -- cgit