Skip to content

Commit

Permalink
Undefine libvirt saved instances
Browse files Browse the repository at this point in the history
Fixes bug 814561

Adding a call to managedSaveRemove if the instance has a
saved instance, so they are now undefined in addition to running
instances during destroy
With test case

Also added myself to Authors

(cherry picked from commit ad7fcf2)

Change-Id: I760a15d2ab135d7c3d638ca3c4358d8600582411
  • Loading branch information
derekhiggins authored and markmc committed Nov 16, 2011
1 parent fb898d6 commit 27b0ff5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions Authors
Expand Up @@ -31,6 +31,7 @@ Dave Walker <DaveWalker@ubuntu.com>
David Pravec <David.Pravec@danix.org>
David Subiros <david.perez5@hp.com>
Dean Troyer <dtroyer@gmail.com>
Derek Higgins <higginsd@gmail.com>
Devendra Modium <dmodium@isi.edu>
Devin Carlen <devin.carlen@gmail.com>
Donal Lafferty <donal.lafferty@citrix.com>
Expand Down
22 changes: 22 additions & 0 deletions nova/tests/test_libvirt.py
Expand Up @@ -987,6 +987,28 @@ def _assert_volume_in_mapping(device_name, true_or_false):
_assert_volume_in_mapping('sdg', False)
_assert_volume_in_mapping('sdh1', False)

def test_destroy_saved(self):
"""Ensure destroy calls managedSaveRemove for saved instance"""
# Skip if non-libvirt environment
if not self.lazy_load_library_exists():
return

mock = self.mox.CreateMock(libvirt.virDomain)
mock.destroy()
mock.hasManagedSaveImage(0).AndReturn(1)
mock.managedSaveRemove(0)
mock.undefine()

self.mox.ReplayAll()

def fake_lookup_by_name(instance_name):
return mock

conn = connection.LibvirtConnection(False)
self.stubs.Set(conn, '_lookup_by_name', fake_lookup_by_name)
instance = {"name": "instancename", "id": "instanceid"}
conn.destroy(instance, [])


class NWFilterFakes:
def __init__(self):
Expand Down
11 changes: 11 additions & 0 deletions nova/virt/libvirt/connection.py
Expand Up @@ -292,6 +292,17 @@ def destroy(self, instance, network_info, cleanup=True):
locals())
raise

try:
# NOTE(derekh): we can switch to undefineFlags and
# VIR_DOMAIN_UNDEFINE_MANAGED_SAVE once we require 0.9.4
if virt_dom.hasManagedSaveImage(0):
virt_dom.managedSaveRemove(0)
except libvirt.libvirtError as e:
errcode = e.get_error_code()
LOG.warning(_("Error from libvirt during saved instance "
"removal %(instance_name)s. Code=%(errcode)s"
" Error=%(e)s") % locals())

try:
# NOTE(justinsb): We remove the domain definition. We probably
# would do better to keep it if cleanup=False (e.g. volumes?)
Expand Down

0 comments on commit 27b0ff5

Please sign in to comment.