diff --git a/nova/tests/xenapi/stubs.py b/nova/tests/xenapi/stubs.py index 299efd7e0a04..e026f8eb5824 100644 --- a/nova/tests/xenapi/stubs.py +++ b/nova/tests/xenapi/stubs.py @@ -317,7 +317,7 @@ class FakeSessionForVolumeFailedTests(FakeSessionForVolumeTests): def stub_out_migration_methods(stubs): - def fake_create_snapshot(self, instance): + def fake_create_snapshot(session, instance, vm_ref, label): return 'vm_ref', dict(image='foo', snap='bar') def fake_move_disks(self, instance, disk_info): @@ -347,7 +347,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(vmops.VMOps, '_create_snapshot', fake_create_snapshot) + stubs.Set(vm_utils, 'create_snapshot', fake_create_snapshot) 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) diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py index ca49d508fffd..0a0ab9e71106 100644 --- a/nova/virt/xenapi/vm_utils.py +++ b/nova/virt/xenapi/vm_utils.py @@ -430,6 +430,16 @@ def get_vdi_for_vm_safely(session, vm_ref): def create_snapshot(session, instance, vm_ref, label): + LOG.debug(_("Starting snapshot for VM"), instance=instance) + try: + return _create_snapshot(session, instance, vm_ref, label) + except session.XenAPI.Failure, exc: + LOG.error(_("Unable to Snapshot instance: %(exc)s"), locals(), + instance=instance) + raise + + +def _create_snapshot(session, instance, vm_ref, label): """Creates Snapshot (Template) VM, Snapshot VBD, Snapshot VDI, Snapshot VHD""" LOG.debug(_("Snapshotting with label '%(label)s'"), locals(), diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index cf1d361f99d4..0b7be1351ac9 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -601,38 +601,21 @@ class VMOps(object): Glance. """ - template_vm_ref = None + vm_ref = self._get_vm_opaque_ref(instance) + label = "%s-snapshot" % instance.name + template_vm_ref, template_vdi_uuids = vm_utils.create_snapshot( + self._session, instance, vm_ref, label) + try: - _snapshot_info = self._create_snapshot(instance) - template_vm_ref, template_vdi_uuids = _snapshot_info - # call plugin to ship snapshot off to glance - vm_utils.upload_image(context, - self._session, instance, template_vdi_uuids, image_id) + vm_utils.upload_image(context, self._session, instance, + template_vdi_uuids, image_id) finally: - if template_vm_ref: - self._destroy(instance, template_vm_ref, - destroy_kernel_ramdisk=False) + self._destroy(instance, template_vm_ref, + destroy_kernel_ramdisk=False) LOG.debug(_("Finished snapshot and upload for VM"), instance=instance) - def _create_snapshot(self, instance): - #TODO(sirp): Add quiesce and VSS locking support when Windows support - # is added - - LOG.debug(_("Starting snapshot for VM"), instance=instance) - vm_ref = self._get_vm_opaque_ref(instance) - - label = "%s-snapshot" % instance.name - try: - template_vm_ref, template_vdi_uuids = vm_utils.create_snapshot( - self._session, instance, vm_ref, label) - return template_vm_ref, template_vdi_uuids - except self._session.XenAPI.Failure, exc: - LOG.error(_("Unable to Snapshot instance: %(exc)s"), locals(), - instance=instance) - raise - def _migrate_vhd(self, instance, vdi_uuid, dest, sr_path): instance_uuid = instance['uuid'] params = {'host': dest, @@ -693,8 +676,10 @@ class VMOps(object): template_vdi_uuids = template_vm_ref = None try: # 1. Create Snapshot - _snapshot_info = self._create_snapshot(instance) - template_vm_ref, template_vdi_uuids = _snapshot_info + label = "%s-snapshot" % instance.name + template_vm_ref, template_vdi_uuids = vm_utils.create_snapshot( + self._session, instance, vm_ref, label) + self._update_instance_progress(context, instance, step=1, total_steps=RESIZE_TOTAL_STEPS)