diff --git a/swift/account/auditor.py b/swift/account/auditor.py index 486de5481d..af38ed3bde 100644 --- a/swift/account/auditor.py +++ b/swift/account/auditor.py @@ -36,6 +36,7 @@ class AccountAuditor(Daemon): self.devices = conf.get('devices', '/srv/node') self.mount_check = config_true_value(conf.get('mount_check', 'true')) self.interval = int(conf.get('interval', 1800)) + self.logging_interval = 3600 # once an hour self.account_passes = 0 self.account_failures = 0 self.accounts_running_time = 0 @@ -53,7 +54,7 @@ class AccountAuditor(Daemon): logger=self.logger) for path, device, partition in all_locs: self.account_audit(path) - if time.time() - reported >= 3600: # once an hour + if time.time() - reported >= self.logging_interval: self.logger.info(_('Since %(time)s: Account audits: ' '%(passed)s passed audit,' '%(failed)s failed audit'), diff --git a/test/unit/account/test_auditor.py b/test/unit/account/test_auditor.py index 83ca833447..499b44155d 100644 --- a/test/unit/account/test_auditor.py +++ b/test/unit/account/test_auditor.py @@ -20,6 +20,7 @@ import os import random from tempfile import mkdtemp from shutil import rmtree +from eventlet import Timeout from swift.account import auditor from test.unit import FakeLogger @@ -91,6 +92,17 @@ class TestAuditor(unittest.TestCase): self.assertEqual(test_auditor.account_failures, 2 * call_times) self.assertEqual(test_auditor.account_passes, 3 * call_times) + # now force timeout path code coverage + def fake_one_audit_pass(reported): + raise Timeout() + + with mock.patch('swift.account.auditor.AccountAuditor._one_audit_pass', + fake_one_audit_pass): + with mock.patch('swift.account.auditor.time', FakeTime()): + self.assertRaises(ValueError, test_auditor.run_forever) + self.assertEqual(test_auditor.account_failures, 2 * call_times) + self.assertEqual(test_auditor.account_passes, 3 * call_times) + @mock.patch('swift.account.auditor.AccountBroker', FakeAccountBroker) def test_run_once(self): conf = {} @@ -106,6 +118,23 @@ class TestAuditor(unittest.TestCase): self.assertEqual(test_auditor.account_failures, 2) self.assertEqual(test_auditor.account_passes, 3) + @mock.patch('swift.account.auditor.AccountBroker', FakeAccountBroker) + def test_one_audit_pass(self): + conf = {} + test_auditor = auditor.AccountAuditor(conf) + + def fake_audit_location_generator(*args, **kwargs): + files = os.listdir(self.testdir) + return [(os.path.join(self.testdir, f), '', '') for f in files] + + # force code coverage for logging path + test_auditor.logging_interval = 0 + with mock.patch('swift.account.auditor.audit_location_generator', + fake_audit_location_generator): + test_auditor._one_audit_pass(test_auditor.logging_interval) + self.assertEqual(test_auditor.account_failures, 0) + self.assertEqual(test_auditor.account_passes, 0) + @mock.patch('swift.account.auditor.AccountBroker', FakeAccountBroker) def test_account_auditor(self): conf = {}