snap_ref)
def test_delete_snapshot_online_1(self):
- """Delete the newest snapshot."""
+ """Delete the newest snapshot, with only one snap present."""
(mox, drv) = self._mox, self._driver
volume = self._simple_volume()
backing file: %s
""" % (snap_file, volume_file)
img_info = imageutils.QemuImgInfo(qemu_img_info_output)
+
+ vol_qemu_img_info_output = """image: %s
+ file format: raw
+ virtual size: 1.0G (1073741824 bytes)
+ disk size: 173K
+ """ % volume_file
+ volume_img_info = imageutils.QemuImgInfo(vol_qemu_img_info_output)
+
image_utils.qemu_img_info(snap_path).AndReturn(img_info)
+ image_utils.qemu_img_info(volume_path).AndReturn(volume_img_info)
+
drv._read_info_file(info_path, empty_if_missing=True).\
AndReturn(snap_info)
delete_info = {
'type': 'qcow2',
'merge_target_file': None,
- 'file_to_merge': volume_file,
+ 'file_to_merge': None,
'volume_id': self.VOLUME_UUID
}
drv.delete_snapshot(snap_ref)
def test_delete_snapshot_online_2(self):
- """Delete the middle snapshot."""
+ """Delete the middle of 3 snapshots."""
(mox, drv) = self._mox, self._driver
volume = self._simple_volume()
""" % (snap_file, volume_file)
img_info = imageutils.QemuImgInfo(qemu_img_info_output)
+ vol_qemu_img_info_output = """image: %s
+ file format: raw
+ virtual size: 1.0G (1073741824 bytes)
+ disk size: 173K
+ """ % volume_file
+ volume_img_info = imageutils.QemuImgInfo(vol_qemu_img_info_output)
+
image_utils.qemu_img_info(snap_path).AndReturn(img_info)
+ image_utils.qemu_img_info(volume_path).AndReturn(volume_img_info)
+
drv._read_info_file(info_path, empty_if_missing=True).\
AndReturn(snap_info)
# file as base.
msg = _('No base file found for %s.') % snapshot_path
raise exception.GlusterfsException(msg)
+
+ base_path = os.path.join(
+ self._local_volume_dir(snapshot['volume']), base_file)
+ base_file_img_info = self._qemu_img_info(base_path)
+ new_base_file = base_file_img_info.backing_file
+
base_id = None
info_path = self._local_path_volume(snapshot['volume']) + '.info'
snap_info = self._read_info_file(info_path)
'active_file': active_file,
'snapshot_file': snapshot_file,
'base_file': base_file,
- 'base_id': base_id
+ 'base_id': base_id,
+ 'new_base_file': new_base_file
}
return self._delete_snapshot_online(context,
# info['base'] => snapshot_file
file_to_delete = info['base_file']
+ if info['base_id'] is None:
+ # Passing base=none to blockRebase ensures that
+ # libvirt blanks out the qcow2 backing file pointer
+ new_base = None
+ else:
+ new_base = info['new_base_file']
+ snap_info[info['base_id']] = info['snapshot_file']
- delete_info = {'file_to_merge': info['base_file'],
+ delete_info = {'file_to_merge': new_base,
'merge_target_file': None, # current
'type': 'qcow2',
'volume_id': snapshot['volume']['id']}