Skip to content

Commit

Permalink
Reply with a meaningful exception, when libvirt connection is broken.
Browse files Browse the repository at this point in the history
Libvirt driver will respond with a meaningful error on any
command, when the connection to the libvirt service is broken.

Closes-bug: #1240344
Change-Id: I823fefaffcf969ecf9eb853ac99dc18cef92d137
  • Loading branch information
vladikr committed Oct 22, 2013
1 parent d8697ab commit 86be0b7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions nova/exception.py
Expand Up @@ -392,6 +392,10 @@ class ComputeResourcesUnavailable(ServiceUnavailable):
msg_fmt = _("Insufficient compute resources.")


class HypervisorUnavailable(NovaException):
msg_fmt = _("Connection to the hypervisor is broken on host: %(host)s")


class ComputeServiceUnavailable(ServiceUnavailable):
msg_fmt = _("Compute service of %(host)s is unavailable at this time.")

Expand Down
15 changes: 15 additions & 0 deletions nova/tests/virt/libvirt/test_libvirt.py
Expand Up @@ -3820,6 +3820,21 @@ def test_broken_connection(self):

self.mox.UnsetStubs()

def test_command_with_broken_connection(self):
self.mox.UnsetStubs()
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
self.mox.StubOutWithMock(libvirt, "openAuth")
self.mox.StubOutWithMock(libvirt.libvirtError, "get_error_code")
self.mox.StubOutWithMock(libvirt.libvirtError, "get_error_domain")
libvirt.openAuth(mox.IgnoreArg(), mox.IgnoreArg(),
mox.IgnoreArg()).AndRaise(
libvirt.libvirtError("fake failure"))

self.mox.ReplayAll()
conn._close_callback(conn._wrapped_conn, 'ERROR', '')
self.assertRaises(exception.HypervisorUnavailable,
conn.get_num_instances)

def test_immediate_delete(self):
def fake_lookup_by_name(instance_name):
raise exception.InstanceNotFound(instance_id=instance_name)
Expand Down
1 change: 1 addition & 0 deletions nova/virt/libvirt/driver.py
Expand Up @@ -683,6 +683,7 @@ def _connect_auth_cb(creds, opaque):
notifier.get_notifier('compute').error(
nova_context.get_admin_context(),
'compute.libvirt.error', payload)
raise exception.HypervisorUnavailable(host=CONF.host)

def get_num_instances(self):
"""Efficient override of base instance_exists method."""
Expand Down

0 comments on commit 86be0b7

Please sign in to comment.