From e0048d4c99e8e6110ebd349c2065bf215653f880 Mon Sep 17 00:00:00 2001 From: Nolwenn Cauchois Date: Fri, 21 Dec 2018 11:19:51 +0100 Subject: [PATCH] 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 --- cinder/tests/unit/group/test_groups_manager.py | 17 +++++++++++++++++ cinder/volume/manager.py | 2 ++ 2 files changed, 19 insertions(+) diff --git a/cinder/tests/unit/group/test_groups_manager.py b/cinder/tests/unit/group/test_groups_manager.py index 7252556c4f2..3e9a5ccdbe2 100644 --- a/cinder/tests/unit/group/test_groups_manager.py +++ b/cinder/tests/unit/group/test_groups_manager.py @@ -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'], diff --git a/cinder/volume/manager.py b/cinder/volume/manager.py index 4291943df10..d737b822e39 100644 --- a/cinder/volume/manager.py +++ b/cinder/volume/manager.py @@ -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,