Fix logic error in sqlarchemy api

Change-Id: Ic3074969b8a75f7b38aa3ba9a37b23dcf133aa8e
This commit is contained in:
liyi 2017-11-08 15:26:58 +11:00
parent 2ca8d4f456
commit 51aed6e41f
2 changed files with 6 additions and 1 deletions

View File

@ -1316,12 +1316,14 @@ def service_get_all_by_args(context, host, binary, hostname):
def purge_deleted(age, granularity='days', project_id=None, batch_size=20): def purge_deleted(age, granularity='days', project_id=None, batch_size=20):
def _validate_positive_integer(val, argname): def _validate_positive_integer(val, argname):
try: try:
return int(val) val = int(val)
except ValueError: except ValueError:
raise exception.Error(_("%s should be an integer") % argname) raise exception.Error(_("%s should be an integer") % argname)
if val < 0: if val < 0:
raise exception.Error(_("%s should be a positive integer") raise exception.Error(_("%s should be a positive integer")
% argname) % argname)
return val
age = _validate_positive_integer(age, 'age') age = _validate_positive_integer(age, 'age')
batch_size = _validate_positive_integer(batch_size, 'batch_size') batch_size = _validate_positive_integer(batch_size, 'batch_size')

View File

@ -2018,6 +2018,9 @@ class DBAPIStackTest(common.HeatTestCase):
self._deleted_stack_existance(admin_ctx, stacks, resources, self._deleted_stack_existance(admin_ctx, stacks, resources,
events, tmpl_files, (), (0, 1, 2, 3, 4)) events, tmpl_files, (), (0, 1, 2, 3, 4))
# test wrong age
self.assertRaises(exception.Error, db_api.purge_deleted, -1, 'seconds')
def test_purge_project_deleted(self): def test_purge_project_deleted(self):
now = timeutils.utcnow() now = timeutils.utcnow()
delta = datetime.timedelta(seconds=3600 * 7) delta = datetime.timedelta(seconds=3600 * 7)