libvirt: Handle InstanceNotFound exception
In 'ad1c7ac2', we stopped returning NovaException from certain libvirt
operations in favour of more specific exception types. Unfortunately, as
part of this changeover we missed an exception type. Correct this
oversight.
Change-Id: I376ebda6c4626df8be2e827bc735116a90528654
Resolves-bug: #1667040
(cherry picked from commit 434a953190
)
This commit is contained in:
parent
9c37aa6810
commit
a71833131b
|
@ -5956,6 +5956,17 @@ class LibvirtConnTestCase(test.NoDBTestCase):
|
|||
("disk", "virtio", "vdb"),
|
||||
("disk", "virtio", "vdc")))
|
||||
|
||||
@mock.patch.object(host.Host, 'get_guest')
|
||||
def test_instance_exists(self, mock_get_guest):
|
||||
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
|
||||
self.assertTrue(drvr.instance_exists(None))
|
||||
|
||||
mock_get_guest.side_effect = exception.InstanceNotFound
|
||||
self.assertFalse(drvr.instance_exists(None))
|
||||
|
||||
mock_get_guest.side_effect = exception.InternalError
|
||||
self.assertFalse(drvr.instance_exists(None))
|
||||
|
||||
@mock.patch.object(host.Host, "list_instance_domains")
|
||||
def test_list_instances(self, mock_list):
|
||||
vm1 = FakeVirtDomain(id=3, name="instance00000001")
|
||||
|
|
|
@ -726,7 +726,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||
try:
|
||||
self._host.get_guest(instance)
|
||||
return True
|
||||
except exception.InternalError:
|
||||
except (exception.InternalError, exception.InstanceNotFound):
|
||||
return False
|
||||
|
||||
def list_instances(self):
|
||||
|
|
Loading…
Reference in New Issue