Allow purging of records less than 1 day old.
Adding ability to purge records less than 1 day old, using the glance-manage db_purge utility. Closes-Bug: #1643287 Change-Id: Ibaea583d49bd5d09ad2e6bf99d2c0efaac5cb4ec
This commit is contained in:
parent
036b1f4846
commit
d4f07cc322
@ -157,8 +157,8 @@ class DbCommands(object):
|
||||
sys.exit(_("Invalid int value for max_rows: "
|
||||
"%(max_rows)s") % {'max_rows': max_rows})
|
||||
|
||||
if age_in_days <= 0:
|
||||
sys.exit(_("Must supply a positive, non-zero value for age."))
|
||||
if age_in_days < 0:
|
||||
sys.exit(_("Must supply a non-negative value for age."))
|
||||
if age_in_days >= (int(time.time()) / 86400):
|
||||
sys.exit(_("Maximal age is count of days since epoch."))
|
||||
if max_rows < 1:
|
||||
|
@ -36,8 +36,8 @@ class DBCommandsTestCase(test_utils.BaseTestCase):
|
||||
@mock.patch.object(context, 'get_admin_context')
|
||||
def test_purge_command(self, mock_context, mock_db_purge):
|
||||
mock_context.return_value = self.context
|
||||
self.commands.purge(1, 100)
|
||||
mock_db_purge.assert_called_once_with(self.context, 1, 100)
|
||||
self.commands.purge(0, 100)
|
||||
mock_db_purge.assert_called_once_with(self.context, 0, 100)
|
||||
|
||||
def test_purge_command_negative_rows(self):
|
||||
exit = self.assertRaises(SystemExit, self.commands.purge, 1, -1)
|
||||
@ -50,6 +50,10 @@ class DBCommandsTestCase(test_utils.BaseTestCase):
|
||||
"%(age_in_days)s") % {'age_in_days': age_in_days}
|
||||
self.assertEqual(expected, ex.code)
|
||||
|
||||
def test_purge_negative_age_in_days(self):
|
||||
ex = self.assertRaises(SystemExit, self.commands.purge, '-1')
|
||||
self.assertEqual("Must supply a non-negative value for age.", ex.code)
|
||||
|
||||
def test_purge_invalid_max_rows(self):
|
||||
max_rows = 'abcd'
|
||||
ex = self.assertRaises(SystemExit, self.commands.purge, 1, max_rows)
|
||||
|
Loading…
Reference in New Issue
Block a user