Fix max_age calculation for quota usage refresh
The unit test QuotaReserveSqlAlchemyTestCase.test_quota_reserve_max_age always passes just because the unusual result for negative timedelta happens to be greater than 3600. Co-Authored-By: Michal Dulko <michal.dulko@intel.com> Change-Id: I94ad8c1428fbab9d66c29a616229bac999844807 Closes-Bug: #1612633
This commit is contained in:
parent
eb55e70a89
commit
d8613844b9
|
@ -1166,8 +1166,8 @@ def quota_reserve(context, resources, quotas, deltas, expire,
|
|||
if usages[resource].until_refresh <= 0:
|
||||
refresh = True
|
||||
elif max_age and usages[resource].updated_at is not None and (
|
||||
(usages[resource].updated_at -
|
||||
timeutils.utcnow()).seconds >= max_age):
|
||||
(timeutils.utcnow() -
|
||||
usages[resource].updated_at).total_seconds() >= max_age):
|
||||
refresh = True
|
||||
|
||||
# OK, refresh the usage
|
||||
|
|
|
@ -2002,6 +2002,42 @@ class QuotaReserveSqlAlchemyTestCase(test.TestCase):
|
|||
usage_id=self.usages['gigabytes'],
|
||||
delta=2 * 1024), ])
|
||||
|
||||
def test_quota_reserve_max_age_negative(self):
|
||||
max_age = 3600
|
||||
record_created = (timeutils.utcnow() +
|
||||
datetime.timedelta(seconds=max_age))
|
||||
self.init_usage('test_project', 'volumes', 3, 0,
|
||||
created_at=record_created, updated_at=record_created)
|
||||
self.init_usage('test_project', 'gigabytes', 3, 0,
|
||||
created_at=record_created, updated_at=record_created)
|
||||
context = FakeContext('test_project', 'test_class')
|
||||
quotas = dict(volumes=5, gigabytes=10 * 1024, )
|
||||
deltas = dict(volumes=2, gigabytes=2 * 1024, )
|
||||
self._mock_allocated_get_all_by_project()
|
||||
result = sqa_api.quota_reserve(context, self.resources, quotas,
|
||||
deltas, self.expire, 0, max_age)
|
||||
|
||||
self.assertEqual(set(), self.sync_called)
|
||||
self.compare_usage(self.usages, [dict(resource='volumes',
|
||||
project_id='test_project',
|
||||
in_use=3,
|
||||
reserved=2,
|
||||
until_refresh=None),
|
||||
dict(resource='gigabytes',
|
||||
project_id='test_project',
|
||||
in_use=3,
|
||||
reserved=2 * 1024,
|
||||
until_refresh=None), ])
|
||||
self.assertEqual({}, self.usages_created)
|
||||
self.compare_reservation(result,
|
||||
[dict(resource='volumes',
|
||||
usage_id=self.usages['volumes'],
|
||||
project_id='test_project',
|
||||
delta=2),
|
||||
dict(resource='gigabytes',
|
||||
usage_id=self.usages['gigabytes'],
|
||||
delta=2 * 1024), ])
|
||||
|
||||
def test_quota_reserve_no_refresh(self):
|
||||
self.init_usage('test_project', 'volumes', 3, 0)
|
||||
self.init_usage('test_project', 'gigabytes', 3, 0)
|
||||
|
|
Loading…
Reference in New Issue