@@ -3601,23 +3601,29 @@ def test_volume_snapshot_delete(self, mock_get_bdm):
3601
3601
'boot_index' : - 1 })
3602
3602
fake_bdm ['instance' ] = fake_instance .fake_db_instance (
3603
3603
launched_at = timeutils .utcnow (),
3604
- vm_state = vm_states .STOPPED )
3604
+ vm_state = vm_states .ACTIVE )
3605
3605
fake_bdm ['instance_uuid' ] = fake_bdm ['instance' ]['uuid' ]
3606
3606
fake_bdm = objects .BlockDeviceMapping ._from_db_object (
3607
3607
self .context , objects .BlockDeviceMapping (),
3608
3608
fake_bdm , expected_attrs = ['instance' ])
3609
3609
3610
3610
mock_get_bdm .return_value = fake_bdm
3611
+ delete_info = {
3612
+ 'merge_target_file' : 'foo.qcow2' ,
3613
+ }
3611
3614
3612
- with mock .patch .object (self .compute_api .compute_rpcapi ,
3613
- 'volume_snapshot_delete' ) as mock_snapshot :
3614
- self .compute_api .volume_snapshot_delete (self .context , volume_id ,
3615
- snapshot_id , {})
3616
-
3615
+ with mock .patch .object (
3616
+ self .compute_api .compute_rpcapi , 'volume_snapshot_delete'
3617
+ ) as mock_snapshot :
3618
+ self .compute_api .volume_snapshot_delete (
3619
+ self .context , volume_id , snapshot_id , delete_info
3620
+ )
3617
3621
mock_get_bdm .assert_called_once_with (self .context , volume_id ,
3618
3622
expected_attrs = ['instance' ])
3619
3623
mock_snapshot .assert_called_once_with (
3620
- self .context , fake_bdm ['instance' ], volume_id , snapshot_id , {})
3624
+ self .context , fake_bdm ['instance' ], volume_id , snapshot_id ,
3625
+ delete_info
3626
+ )
3621
3627
3622
3628
@mock .patch .object (
3623
3629
objects .BlockDeviceMapping , 'get_by_volume' ,
@@ -3651,6 +3657,43 @@ def test_volume_snapshot_delete_shelved_offloaded(self, bdm_get_by_volume):
3651
3657
self .context , mock .sentinel .volume_id ,
3652
3658
mock .sentinel .snapshot_id , mock .sentinel .delete_info )
3653
3659
3660
+ @mock .patch .object (compute_api .API , '_get_bdm_by_volume_id' )
3661
+ def test_volume_snapshot_delete_intermediary_commit (self , mock_get_bdm ):
3662
+ fake_bdm = fake_block_device .FakeDbBlockDeviceDict ({
3663
+ 'id' : 123 ,
3664
+ 'device_name' : '/dev/sda2' ,
3665
+ 'source_type' : 'volume' ,
3666
+ 'destination_type' : 'volume' ,
3667
+ 'connection_info' : "{'fake': 'connection_info'}" ,
3668
+ 'volume_id' : uuids .volume_id ,
3669
+ 'boot_index' : - 1
3670
+ })
3671
+ fake_bdm ['instance' ] = fake_instance .fake_db_instance (
3672
+ launched_at = timeutils .utcnow (),
3673
+ vm_state = vm_states .STOPPED )
3674
+ fake_bdm ['instance_uuid' ] = fake_bdm ['instance' ]['uuid' ]
3675
+ fake_bdm = objects .BlockDeviceMapping ._from_db_object (
3676
+ self .context , objects .BlockDeviceMapping (),
3677
+ fake_bdm , expected_attrs = ['instance' ])
3678
+ mock_get_bdm .return_value = fake_bdm
3679
+
3680
+ # c-vol can provide delete_info with merge_target_file pointing to
3681
+ # an intermediary snapshot to commit into it's base. This is only
3682
+ # supported while the instance is running at present.
3683
+ delete_info = {
3684
+ 'merge_target_file' : 'snap.img'
3685
+ }
3686
+
3687
+ # Assert that the request is rejected as offline commit isn't supported
3688
+ self .assertRaises (
3689
+ exception .InstanceInvalidState ,
3690
+ self .compute_api .volume_snapshot_delete ,
3691
+ self .context ,
3692
+ uuids .volume_id ,
3693
+ uuids .snapshot_id ,
3694
+ delete_info
3695
+ )
3696
+
3654
3697
def _create_instance_with_disabled_disk_config (self , object = False ):
3655
3698
sys_meta = {"image_auto_disk_config" : "Disabled" }
3656
3699
params = {"system_metadata" : sys_meta }
0 commit comments