Implement snapshots for raw backend

blueprint snapshots-for-everyone

Use simple qemu-img convert for raw snapshots.
Polymorphically select snapshot behavior for
raw and qcow2.
Allow images to be constructed from actual device/file path.

Change-Id: I6a57e43c6775c144c41a53382dcc7504ce6d4c43
This commit is contained in:
Boris Filippov
2012-09-26 04:55:03 +04:00
committed by Gerrit Code Review
parent fe9bc6a515
commit 70978f2d43
3 changed files with 23 additions and 2 deletions

View File

@@ -37,6 +37,9 @@ class Backend(object):
def cache(self, fetch_func, filename, size=None, *args, **kwargs):
pass
def snapshot(self, name):
pass
def libvirt_info(self, disk_bus, disk_dev, device_type,
cache_mode):
info = config.LibvirtConfigGuestDisk()
@@ -50,3 +53,8 @@ class Backend(object):
return info
return FakeImage(instance, name)
def snapshot(self, path, name, image_type=''):
#NOTE(bfilippov): this is done in favor for
# snapshot tests in test_libvirt.LibvirtConnTestCase
return imagebackend.Backend(True).snapshot(path, name, image_type)

View File

@@ -104,7 +104,7 @@ def file_open(path, mode=None):
def find_disk(virt_dom):
return "some/path"
return "filename"
def load_file(path):
@@ -115,6 +115,10 @@ def load_file(path):
return ''
def logical_volume_info(path):
return {}
def file_delete(path):
return True

View File

@@ -53,6 +53,7 @@ from nova.virt.libvirt import config
from nova.virt.libvirt import driver as libvirt_driver
from nova.virt.libvirt import firewall
from nova.virt.libvirt import imagebackend
from nova.virt.libvirt import snapshots
from nova.virt.libvirt import utils as libvirt_utils
from nova.virt.libvirt import volume
from nova.virt.libvirt import volume_nfs
@@ -484,6 +485,7 @@ class LibvirtConnTestCase(test.TestCase):
self.flags(libvirt_snapshots_directory='')
self.call_libvirt_dependant_setup = False
libvirt_driver.libvirt_utils = fake_libvirt_utils
snapshots.libvirt_utils = fake_libvirt_utils
def fake_extend(image, size):
pass
@@ -532,7 +534,7 @@ class LibvirtConnTestCase(test.TestCase):
def fake_lookup(self, instance_name):
return FakeVirtDomain()
def fake_execute(self, *args):
def fake_execute(self, *args, **kwargs):
open(args[-1], "a").close()
def create_service(self, **kwargs):
@@ -1129,6 +1131,7 @@ class LibvirtConnTestCase(test.TestCase):
libvirt_driver.LibvirtDriver._conn.lookupByName = self.fake_lookup
self.mox.StubOutWithMock(libvirt_driver.utils, 'execute')
libvirt_driver.utils.execute = self.fake_execute
libvirt_driver.libvirt_utils.disk_type = "qcow2"
self.mox.ReplayAll()
@@ -1164,6 +1167,11 @@ class LibvirtConnTestCase(test.TestCase):
libvirt_driver.utils.execute = self.fake_execute
self.stubs.Set(libvirt_driver.libvirt_utils, 'disk_type', 'raw')
def convert_image(source, dest, out_format):
libvirt_driver.libvirt_utils.files[dest] = ''
images.convert_image = convert_image
self.mox.ReplayAll()
conn = libvirt_driver.LibvirtDriver(False)
@@ -1197,6 +1205,7 @@ class LibvirtConnTestCase(test.TestCase):
libvirt_driver.LibvirtDriver._conn.lookupByName = self.fake_lookup
self.mox.StubOutWithMock(libvirt_driver.utils, 'execute')
libvirt_driver.utils.execute = self.fake_execute
libvirt_driver.libvirt_utils.disk_type = "qcow2"
self.mox.ReplayAll()