Browse Source

Merge "RBD: fix volume reference handling in clone logic" into stable/rocky

changes/07/715007/2
Zuul 3 months ago
committed by Gerrit Code Review
parent
commit
79d3d4b45f
2 changed files with 8 additions and 6 deletions
  1. +7
    -4
      cinder/tests/unit/volume/drivers/test_rbd.py
  2. +1
    -2
      cinder/volume/drivers/rbd.py

+ 7
- 4
cinder/tests/unit/volume/drivers/test_rbd.py View File

@@ -931,10 +931,13 @@ class RBDTestCase(test.TestCase):
(self.mock_rbd.Image.return_value.protect_snap
.assert_called_once_with('.'.join(
(self.volume_b.name, 'clone_snap'))))
# We expect clone() to be called exactly once.
self.assertEqual(
1, self.mock_rbd.RBD.return_value.clone.call_count)
# Without flattening, only the source volume is opened,
# so only one call to close() should occur.
self.assertEqual(
2, self.mock_rbd.Image.return_value.close.call_count)
1, self.mock_rbd.Image.return_value.close.call_count)
self.assertTrue(mock_get_clone_depth.called)
mock_resize.assert_not_called()
mock_enable_repl.assert_not_called()
@@ -970,7 +973,7 @@ class RBDTestCase(test.TestCase):
image.protect_snap.assert_called_once_with(name + '.clone_snap')
self.assertEqual(1, self.mock_rbd.RBD.return_value.clone.call_count)
self.assertEqual(
2, self.mock_rbd.Image.return_value.close.call_count)
1, self.mock_rbd.Image.return_value.close.call_count)
mock_get_clone_depth.assert_called_once_with(
self.mock_client().__enter__(), self.volume_a.name)
mock_resize.assert_not_called()
@@ -1000,7 +1003,7 @@ class RBDTestCase(test.TestCase):
self.assertEqual(
1, self.mock_rbd.RBD.return_value.clone.call_count)
self.assertEqual(
2, self.mock_rbd.Image.return_value.close.call_count)
1, self.mock_rbd.Image.return_value.close.call_count)
self.assertTrue(mock_get_clone_depth.called)
self.assertEqual(
1, mock_resize.call_count)
@@ -1057,7 +1060,7 @@ class RBDTestCase(test.TestCase):

# We expect the driver to close both volumes, so 2 is expected
self.assertEqual(
3, self.mock_rbd.Image.return_value.close.call_count)
2, self.mock_rbd.Image.return_value.close.call_count)
self.assertTrue(mock_get_clone_depth.called)
mock_enable_repl.assert_not_called()



+ 1
- 2
cinder/volume/drivers/rbd.py View File

@@ -610,6 +610,7 @@ class RBDDriver(driver.CloneableImageVD, driver.MigrateVD,
except Exception as e:
src_volume.unprotect_snap(clone_snap)
src_volume.remove_snap(clone_snap)
src_volume.close()
msg = (_("Failed to clone '%(src_vol)s@%(src_snap)s' to "
"'%(dest)s', error: %(error)s") %
{'src_vol': src_name,
@@ -618,8 +619,6 @@ class RBDDriver(driver.CloneableImageVD, driver.MigrateVD,
'error': e})
LOG.exception(msg)
raise exception.VolumeBackendAPIException(data=msg)
finally:
src_volume.close()

depth = self._get_clone_depth(client, src_name)
# If dest volume is a clone and rbd_max_clone_depth reached,


Loading…
Cancel
Save