RBD snapshot needs to be protected/unprotected after being managed/unmanaged
The managed RBD snapshot needs to be protected, just as the same with procedure of creating a new Cinder RBD snapshot, to prevent the snapshot being deleted. When unmanage RBD snapshot, unprotect the snapshot when it has no children. Change-Id: Iff0a75369a603a348163cc4a2211bb6e6ad1fea9
This commit is contained in:
committed by
Jeremy Zhang
parent
d1bae7462e
commit
557463374a
@@ -1945,9 +1945,11 @@ class RBDTestCase(test.TestCase):
|
||||
exist_snapshot = 'snapshot-exist'
|
||||
existing_ref = {'source-name': exist_snapshot}
|
||||
proxy.rename_snap.return_value = 0
|
||||
proxy.is_protected_snap.return_value = False
|
||||
self.driver.manage_existing_snapshot(self.snapshot_b, existing_ref)
|
||||
proxy.rename_snap.assert_called_with(exist_snapshot,
|
||||
self.snapshot_b.name)
|
||||
proxy.protect_snap.assert_called_with(self.snapshot_b.name)
|
||||
|
||||
@common_mocks
|
||||
def test_manage_existing_snapshot_with_exist_rbd_image(self):
|
||||
@@ -1964,6 +1966,15 @@ class RBDTestCase(test.TestCase):
|
||||
# Make sure the exception was raised
|
||||
self.assertEqual([self.mock_rbd.ImageExists], RAISED_EXCEPTIONS)
|
||||
|
||||
@common_mocks
|
||||
def test_unmanage_snapshot(self):
|
||||
proxy = self.mock_proxy.return_value
|
||||
proxy.__enter__.return_value = proxy
|
||||
proxy.list_children.return_value = []
|
||||
proxy.is_protected_snap.return_value = True
|
||||
self.driver.unmanage_snapshot(self.snapshot_b)
|
||||
proxy.unprotect_snap.assert_called_with(self.snapshot_b.name)
|
||||
|
||||
@mock.patch('cinder.volume.drivers.rbd.RBDVolumeProxy')
|
||||
@mock.patch('cinder.volume.drivers.rbd.RADOSClient')
|
||||
@mock.patch('cinder.volume.drivers.rbd.RBDDriver.RBDProxy')
|
||||
|
||||
@@ -1731,7 +1731,14 @@ class RBDDriver(driver.CloneableImageVD, driver.MigrateVD,
|
||||
snapshot_name = existing_ref['source-name']
|
||||
volume.rename_snap(utils.convert_str(snapshot_name),
|
||||
utils.convert_str(snapshot.name))
|
||||
if not volume.is_protected_snap(snapshot.name):
|
||||
volume.protect_snap(snapshot.name)
|
||||
|
||||
def unmanage_snapshot(self, snapshot):
|
||||
"""Removes the specified snapshot from Cinder management."""
|
||||
pass
|
||||
with RBDVolumeProxy(self, snapshot.volume_name) as volume:
|
||||
volume.set_snap(snapshot.name)
|
||||
children = volume.list_children()
|
||||
volume.set_snap(None)
|
||||
if not children and volume.is_protected_snap(snapshot.name):
|
||||
volume.unprotect_snap(snapshot.name)
|
||||
|
||||
Reference in New Issue
Block a user