Increase Account Auditor Test Code Coverage
Some simple additional test code to bring coverage from 82% to 99% Change-Id: I561bc0a043f3451bb0a84cad274fedc907e61ee8
This commit is contained in:
parent
0af4f035e2
commit
51fa32f53d
@ -36,6 +36,7 @@ class AccountAuditor(Daemon):
|
|||||||
self.devices = conf.get('devices', '/srv/node')
|
self.devices = conf.get('devices', '/srv/node')
|
||||||
self.mount_check = config_true_value(conf.get('mount_check', 'true'))
|
self.mount_check = config_true_value(conf.get('mount_check', 'true'))
|
||||||
self.interval = int(conf.get('interval', 1800))
|
self.interval = int(conf.get('interval', 1800))
|
||||||
|
self.logging_interval = 3600 # once an hour
|
||||||
self.account_passes = 0
|
self.account_passes = 0
|
||||||
self.account_failures = 0
|
self.account_failures = 0
|
||||||
self.accounts_running_time = 0
|
self.accounts_running_time = 0
|
||||||
@ -53,7 +54,7 @@ class AccountAuditor(Daemon):
|
|||||||
logger=self.logger)
|
logger=self.logger)
|
||||||
for path, device, partition in all_locs:
|
for path, device, partition in all_locs:
|
||||||
self.account_audit(path)
|
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: '
|
self.logger.info(_('Since %(time)s: Account audits: '
|
||||||
'%(passed)s passed audit,'
|
'%(passed)s passed audit,'
|
||||||
'%(failed)s failed audit'),
|
'%(failed)s failed audit'),
|
||||||
|
@ -20,6 +20,7 @@ import os
|
|||||||
import random
|
import random
|
||||||
from tempfile import mkdtemp
|
from tempfile import mkdtemp
|
||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
|
from eventlet import Timeout
|
||||||
|
|
||||||
from swift.account import auditor
|
from swift.account import auditor
|
||||||
from test.unit import FakeLogger
|
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_failures, 2 * call_times)
|
||||||
self.assertEqual(test_auditor.account_passes, 3 * 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)
|
@mock.patch('swift.account.auditor.AccountBroker', FakeAccountBroker)
|
||||||
def test_run_once(self):
|
def test_run_once(self):
|
||||||
conf = {}
|
conf = {}
|
||||||
@ -106,6 +118,23 @@ class TestAuditor(unittest.TestCase):
|
|||||||
self.assertEqual(test_auditor.account_failures, 2)
|
self.assertEqual(test_auditor.account_failures, 2)
|
||||||
self.assertEqual(test_auditor.account_passes, 3)
|
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)
|
@mock.patch('swift.account.auditor.AccountBroker', FakeAccountBroker)
|
||||||
def test_account_auditor(self):
|
def test_account_auditor(self):
|
||||||
conf = {}
|
conf = {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user