diff --git a/glance/cmd/manage.py b/glance/cmd/manage.py index 6bff4e30b8..16e08c52e1 100644 --- a/glance/cmd/manage.py +++ b/glance/cmd/manage.py @@ -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: diff --git a/glance/tests/unit/test_glance_manage.py b/glance/tests/unit/test_glance_manage.py index e7f958c7a2..7f28aadecc 100644 --- a/glance/tests/unit/test_glance_manage.py +++ b/glance/tests/unit/test_glance_manage.py @@ -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)