Fix gigabytes usage error when deleting snapshot group

When deleting snapshot group,  the number of snapshots
is well decremented  with the number of snapshots present
in the group. But not the number of gigabytes.

Change-Id: I0fe6d4682a16cbe30e563079964a5275bac728bb
Closes-Bug: #1809434
This commit is contained in:
Nolwenn Cauchois 2018-12-21 11:19:51 +01:00
parent 1c0224d901
commit e0048d4c99
2 changed files with 19 additions and 0 deletions

View File

@ -698,6 +698,11 @@ class GroupManagerTestCase(test.TestCase):
_mock_create_grp,
mock_notify):
"""Test group_snapshot can be created and deleted."""
original_add_volume_type_opts = quota.QUOTAS.add_volume_type_opts
quota.QUOTAS.add_volume_type_opts = mock.MagicMock(
side_effect=original_add_volume_type_opts
)
self.volume.cluster = cluster
group = tests_utils.create_group(
self.context,
@ -737,6 +742,18 @@ class GroupManagerTestCase(test.TestCase):
self.volume.delete_group_snapshot(self.context, group_snapshot)
reserve_opts = {
'snapshots': -1,
'gigabytes': 0
}
quota.QUOTAS.add_volume_type_opts.assert_called()
self.assertEqual(
(reserve_opts, fake.VOLUME_TYPE_ID),
quota.QUOTAS.add_volume_type_opts.call_args[0][1:]
)
quota.QUOTAS.add_volume_type_opts = original_add_volume_type_opts
self.assert_notify_called(mock_notify,
(['INFO', 'volume.create.start'],
['INFO', 'volume.create.end'],

View File

@ -4019,6 +4019,8 @@ class VolumeManager(manager.CleanableManager,
# Get reservations
try:
reserve_opts = {'snapshots': -1}
if not CONF.no_snapshot_gb_quota:
reserve_opts['gigabytes'] = -snapshot.volume_size
volume_ref = objects.Volume.get_by_id(context,
snapshot.volume_id)
QUOTAS.add_volume_type_opts(context,