From 665516f72402eac00455517446716cd7d43323db Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Tue, 10 Jul 2012 22:19:25 +0000 Subject: Adds snapshot_attached_here contextmanager. This patch does three things: * Moves more code into vm_utils to better match our separation of concerns. * Reduces complexity of the vmops._destroy method. * Adds snapshot_attached_here contextmanager to make the snapshotting code a bit cleaner. Change-Id: I544dc2ba203519d32a5ecce4a87157b5c4a55076 --- nova/tests/test_xenapi.py | 8 ++++---- nova/tests/xenapi/stubs.py | 8 +++++--- 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index 0820137fa..f05ea9e5b 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -355,9 +355,9 @@ class XenAPIVMTestCase(stubs.XenAPITestBase): stubs.stubout_firewall_driver(self.stubs, self.conn) instance = self._create_instance() - name = "MySnapshot" + image_id = "my_snapshot_id" self.assertRaises(exception.NovaException, self.conn.snapshot, - self.context, instance, name) + self.context, instance, image_id) def test_instance_snapshot(self): stubs.stubout_instance_snapshot(self.stubs) @@ -367,8 +367,8 @@ class XenAPIVMTestCase(stubs.XenAPITestBase): stubs.stubout_firewall_driver(self.stubs, self.conn) instance = self._create_instance() - name = "MySnapshot" - template_vm_ref = self.conn.snapshot(self.context, instance, name) + image_id = "my_snapshot_id" + self.conn.snapshot(self.context, instance, image_id) # Ensure VM was torn down vm_labels = [] diff --git a/nova/tests/xenapi/stubs.py b/nova/tests/xenapi/stubs.py index e026f8eb5..83a17af84 100644 --- a/nova/tests/xenapi/stubs.py +++ b/nova/tests/xenapi/stubs.py @@ -15,6 +15,7 @@ """Stubouts, mocks and fixtures for the test suite""" +import contextlib import random import sys @@ -317,8 +318,9 @@ class FakeSessionForVolumeFailedTests(FakeSessionForVolumeTests): def stub_out_migration_methods(stubs): - def fake_create_snapshot(session, instance, vm_ref, label): - return 'vm_ref', dict(image='foo', snap='bar') + @contextlib.contextmanager + def fake_snapshot_attached_here(session, instance, vm_ref, label): + yield dict(image='foo', snap='bar') def fake_move_disks(self, instance, disk_info): vdi_ref = fake.create_vdi(instance['name'], 'fake') @@ -347,7 +349,7 @@ def stub_out_migration_methods(stubs): stubs.Set(vmops.VMOps, '_move_disks', fake_move_disks) stubs.Set(vm_utils, 'scan_default_sr', fake_sr) stubs.Set(vm_utils, '_scan_sr', fake_sr) - stubs.Set(vm_utils, 'create_snapshot', fake_create_snapshot) + stubs.Set(vm_utils, 'snapshot_attached_here', fake_snapshot_attached_here) stubs.Set(vm_utils, 'get_vdi_for_vm_safely', fake_get_vdi) stubs.Set(vm_utils, 'get_sr_path', fake_get_sr_path) stubs.Set(vm_utils, 'generate_ephemeral', fake_generate_ephemeral) -- cgit