From 5c8b528f4cd0c21ccb4531db80a2f692ac03c026 Mon Sep 17 00:00:00 2001 From: Abhishek Sharma Date: Mon, 4 Dec 2017 00:39:28 -0600 Subject: [PATCH] Removed gb quota decrement in grp snapshot delete Before https://review.openstack.org/#/c/517725/, when capturing a vm we used to reserve gb quota twice. So then i changed the code such that we should only increment/reserve the gb quota once, i.e., when creating the group snapshot (not while creating volumes). Hence we no longer need to decerment gb quota when we delete the group snapshot (initially we decremented because we incremented twice). Change-Id: I64ff9c25dbea7950ca87f226c6628a730f9e3c0e Closes-Bug: 1735650 --- cinder/tests/unit/test_quota.py | 2 +- cinder/volume/api.py | 8 +++++--- cinder/volume/manager.py | 8 +------- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/cinder/tests/unit/test_quota.py b/cinder/tests/unit/test_quota.py index 2319da589cb..fa3a4e7384e 100644 --- a/cinder/tests/unit/test_quota.py +++ b/cinder/tests/unit/test_quota.py @@ -177,7 +177,7 @@ class QuotaIntegrationTestCase(test.TestCase): fake.CONSISTENCY_GROUP_ID) usages = db.quota_usage_get_all_by_project(self.context, self.project_id) - self.assertEqual(1, usages['snapshots']['in_use']) + self.assertEqual(2, usages['snapshots']['in_use']) def test_too_many_snapshots_of_type(self): resource = 'snapshots_%s' % self.volume_type_name diff --git a/cinder/volume/api.py b/cinder/volume/api.py index febbfbab447..ddcd3d5c13d 100644 --- a/cinder/volume/api.py +++ b/cinder/volume/api.py @@ -977,10 +977,12 @@ class API(base.Base): reserve_opts_list = [] total_reserve_opts = {} try: - reserve_opts_list.append({'snapshots': 1}) for volume in volume_list: - if not CONF.no_snapshot_gb_quota: - reserve_opts = {'gigabytes': volume['size']} + if CONF.no_snapshot_gb_quota: + reserve_opts = {'snapshots': 1} + else: + reserve_opts = {'snapshots': 1, + 'gigabytes': volume['size']} QUOTAS.add_volume_type_opts(context, reserve_opts, volume.get('volume_type_id')) diff --git a/cinder/volume/manager.py b/cinder/volume/manager.py index a1efefdae45..f05268e120e 100644 --- a/cinder/volume/manager.py +++ b/cinder/volume/manager.py @@ -3869,13 +3869,7 @@ class VolumeManager(manager.CleanableManager, for snapshot in snapshots: # Get reservations try: - if CONF.no_snapshot_gb_quota: - reserve_opts = {'snapshots': -1} - else: - reserve_opts = { - 'snapshots': -1, - 'gigabytes': -snapshot.volume_size, - } + reserve_opts = {'snapshots': -1} volume_ref = objects.Volume.get_by_id(context, snapshot.volume_id) QUOTAS.add_volume_type_opts(context,