From 70978f2d43b59d36d87778fcf1b8c35657caccf3 Mon Sep 17 00:00:00 2001 From: Boris Filippov Date: Wed, 26 Sep 2012 04:55:03 +0400 Subject: [PATCH] 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 --- nova/tests/fake_imagebackend.py | 8 ++++++++ nova/tests/fake_libvirt_utils.py | 6 +++++- nova/tests/test_libvirt.py | 11 ++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/nova/tests/fake_imagebackend.py b/nova/tests/fake_imagebackend.py index b6a052f2..978c879f 100644 --- a/nova/tests/fake_imagebackend.py +++ b/nova/tests/fake_imagebackend.py @@ -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) diff --git a/nova/tests/fake_libvirt_utils.py b/nova/tests/fake_libvirt_utils.py index 1862521c..4f7c96d4 100644 --- a/nova/tests/fake_libvirt_utils.py +++ b/nova/tests/fake_libvirt_utils.py @@ -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 diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index 7af877f2..7de72266 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -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()