kojivmd: narrow error handling for missing VMs

lookupByName() could raise libvirt.libvirtError for many different
reasons (libvirt connection problems, etc).

If this kojivmd host does not have this VM available
(VIR_ERR_NO_DOMAIN), and we should log the "VM not available" message
and skip taking the task.

If the error is something else, this is unexpected, and we should raise
it in the logs so the administrator can see it at non-debug log levels.
This commit is contained in:
Ken Dreyer 2022-09-07 11:28:05 -04:00 committed by Tomas Kopecek
parent 90206e38b2
commit 953bbba183

View file

@ -1033,11 +1033,14 @@ class VMTaskManager(TaskManager):
vm_name = task_info['request'][0]
try:
self.libvirt_conn.lookupByName(vm_name)
except libvirt.libvirtError:
# if this builder does not have the requested VM,
# we can't handle the task
self.logger.debug('VM %s not available, ignoring task %i', vm_name, task['id'])
return False
except libvirt.libvirtError as e:
if e.get_error_code() == libvirt.VIR_ERR_NO_DOMAIN:
# if this builder does not have the requested VM,
# we can't handle the task
self.logger.debug('VM %s not available, ignoring task %i', vm_name, task['id'])
return False
else:
raise
return super(VMTaskManager, self).takeTask(task)
def cleanupVM(self, vm_name):