提交 8c7893eb 编写于 作者: A Amador Pahim

virt: improve error messages

Improve virt module exceptions/messages when it is not able to connect
to libvirt and when the domain is not available.

Reference: https://trello.com/c/Ni1LvaMQSigned-off-by: NAmador Pahim <apahim@redhat.com>
上级 3e61b6ce
...@@ -336,11 +336,11 @@ class VMTestRunner(RemoteTestRunner): ...@@ -336,11 +336,11 @@ class VMTestRunner(RemoteTestRunner):
""" """
# Super called after VM is found and initialized # Super called after VM is found and initialized
self.job.log.info("DOMAIN : %s", self.job.args.vm_domain) self.job.log.info("DOMAIN : %s", self.job.args.vm_domain)
self.vm = virt.vm_connect(self.job.args.vm_domain, try:
self.job.args.vm_hypervisor_uri) self.vm = virt.vm_connect(self.job.args.vm_domain,
if self.vm is None: self.job.args.vm_hypervisor_uri)
e_msg = "Could not connect to VM '%s'" % self.job.args.vm_domain except virt.VirtError as exception:
raise exceptions.JobError(e_msg) raise exceptions.JobError(exception.message)
if self.vm.start() is False: if self.vm.start() is False:
e_msg = "Could not start VM '%s'" % self.job.args.vm_domain e_msg = "Could not start VM '%s'" % self.job.args.vm_domain
raise exceptions.JobError(e_msg) raise exceptions.JobError(e_msg)
......
...@@ -38,6 +38,15 @@ if remoter.REMOTE_CAPABLE is False: ...@@ -38,6 +38,15 @@ if remoter.REMOTE_CAPABLE is False:
LOG.info('Virt module is disabled: remote module is disabled') LOG.info('Virt module is disabled: remote module is disabled')
class VirtError(Exception):
"""
Generic exception class to propagate underling
errors to the caller.
"""
pass
class Hypervisor(object): class Hypervisor(object):
""" """
...@@ -351,7 +360,13 @@ def vm_connect(domain_name, hypervisor_uri='qemu:///system'): ...@@ -351,7 +360,13 @@ def vm_connect(domain_name, hypervisor_uri='qemu:///system'):
:return: an instance of :class:`VM` :return: an instance of :class:`VM`
""" """
hyper = Hypervisor(hypervisor_uri) hyper = Hypervisor(hypervisor_uri)
hyper.connect() if hyper.connect() is None:
raise VirtError('Cannot connect to hypervisor at "%s"' %
hypervisor_uri)
dom = hyper.find_domain_by_name(domain_name) dom = hyper.find_domain_by_name(domain_name)
vm = VM(hyper, dom) if dom is None:
return vm raise VirtError('Domain "%s" could not be found' %
domain_name)
return VM(hyper, dom)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册