iXsystems / cinder

Other
35 stars 18 forks source link

Enhancement fix for #41 Cinder volume/snapshot cascade delete not successful #44

Closed YiHuangDB closed 12 months ago

YiHuangDB commented 1 year ago

Issue: when using cinder client with --cascade parameter to delete volume with snapshot attached

cinder delete --cascade 2762015d-cad8-4b03-a117-63e10ea9406b

Request to delete volume 2762015d-cad8-4b03-a117-63e10ea9406b has been accepted. Unexpected result: the snapshot and any volume cloned from this snapshot not deleted Expected result: volume, snapshot and volume cloned from snapshot all deleted

This also failed tempest test case: https://docs.openstack.org/tempest/latest/_modules/volume/test_volume_delete_cascade.html

Root cause: OpenStack requires a snapshot to be independent of child volume. However, the existing truenas /zfs/snapshot/clone api does not support this. For example, VolumeA create snapsnot volumeA@snapshot, volumeA@snapshot create child volume volumeAsnapshotchild. At this time, volumeA@snapshot should be able to removed safely. There should be no dependency between volumeA@snapshot and volumeAsnapshotchild. However this is not possible with the current Truenas/freenas /zfs/snapshot/clone api. Promote volumeAsnapshotchild won't help, cause as long as VolumeA exists there are dependencies prevented from volumeA@snapshot to be removed.

Solution: Use Truenas replication api to replicate from zfs snapshot to new Truenas zvol volume, in this way, the new volume is independent with source volume.

File changes: driver/ixsystems/common.py driver/ixsystems/freenasapi.py driver/ixsystems/iscsi.py driver/ixsystems/options.py driver/ixsystems/utils.py test/test_common.py test/test_iscsi.py test/test_utils.py

New functions added: common.py replicate_volume_from_snapshot common.py replication_stats common.py replication_delete common.py replication_run Function modified: iscsi.py create_volume_from_snapshot Changed from old zfs snapshot clone based implementation to replication api based implementation utils.py generate_freenas_snapshot_name Changed snapshot naming convention to snap-xxxxxx-1111-11-11-11-11 dual to replication api requires snapshot to have a valid schema requires the %Y (year), %m (month), %d (day), %H (hour), and %M (minute) time strings.

Unit test cases: test_common.py test_replicate_volume_from_snapshot test_common.py test_replication_delete test_common.py test_replication_run test_common.py test_replication_stats test_iscsi.py replicate_volume_from_snapshot test_utils.py test_generate_freenas_snapshot_name