Merge "Bring Object Auditor Coverage To 99%"
This commit is contained in:
commit
c20a8377c6
@ -296,8 +296,8 @@ class ObjectAuditor(Daemon):
|
||||
while True:
|
||||
try:
|
||||
self.audit_loop(parent, zbo_fps, **kwargs)
|
||||
except (Exception, Timeout):
|
||||
self.logger.exception(_('ERROR auditing'))
|
||||
except (Exception, Timeout) as err:
|
||||
self.logger.exception(_('ERROR auditing: %s' % err))
|
||||
self._sleep()
|
||||
|
||||
def run_once(self, *args, **kwargs):
|
||||
@ -317,5 +317,5 @@ class ObjectAuditor(Daemon):
|
||||
try:
|
||||
self.audit_loop(parent, zbo_fps, override_devices=override_devices,
|
||||
**kwargs)
|
||||
except (Exception, Timeout):
|
||||
self.logger.exception(_('ERROR auditing'))
|
||||
except (Exception, Timeout) as err:
|
||||
self.logger.exception(_('ERROR auditing: %s' % err))
|
||||
|
@ -216,6 +216,34 @@ class TestAuditor(unittest.TestCase):
|
||||
self.assertEquals(auditor_worker.stats_buckets[1024], 1)
|
||||
self.assertEquals(auditor_worker.stats_buckets[10240], 0)
|
||||
|
||||
# pick up some additional code coverage, large file
|
||||
data = '0' * 1024 * 1024
|
||||
etag = md5()
|
||||
with self.disk_file.create() as writer:
|
||||
writer.write(data)
|
||||
etag.update(data)
|
||||
etag = etag.hexdigest()
|
||||
metadata = {
|
||||
'ETag': etag,
|
||||
'X-Timestamp': timestamp,
|
||||
'Content-Length': str(os.fstat(writer._fd).st_size),
|
||||
}
|
||||
writer.put(metadata)
|
||||
auditor_worker.audit_all_objects(device_dirs=['sda', 'sdb'])
|
||||
self.assertEquals(auditor_worker.quarantines, pre_quarantines)
|
||||
self.assertEquals(auditor_worker.stats_buckets[1024], 1)
|
||||
self.assertEquals(auditor_worker.stats_buckets[10240], 0)
|
||||
self.assertEquals(auditor_worker.stats_buckets['OVER'], 1)
|
||||
|
||||
# pick up even more additional code coverage, misc paths
|
||||
auditor_worker.log_time = -1
|
||||
auditor_worker.stats_sizes = []
|
||||
auditor_worker.audit_all_objects(device_dirs=['sda', 'sdb'])
|
||||
self.assertEquals(auditor_worker.quarantines, pre_quarantines)
|
||||
self.assertEquals(auditor_worker.stats_buckets[1024], 1)
|
||||
self.assertEquals(auditor_worker.stats_buckets[10240], 0)
|
||||
self.assertEquals(auditor_worker.stats_buckets['OVER'], 1)
|
||||
|
||||
def test_object_run_once_no_sda(self):
|
||||
auditor_worker = auditor.AuditorWorker(self.conf, self.logger,
|
||||
self.rcache, self.devices)
|
||||
@ -395,6 +423,9 @@ class TestAuditor(unittest.TestCase):
|
||||
class StopForever(Exception):
|
||||
pass
|
||||
|
||||
class Bogus(Exception):
|
||||
pass
|
||||
|
||||
class ObjectAuditorMock(object):
|
||||
check_args = ()
|
||||
check_kwargs = {}
|
||||
@ -412,6 +443,10 @@ class TestAuditor(unittest.TestCase):
|
||||
def mock_sleep(self):
|
||||
raise StopForever('stop')
|
||||
|
||||
def mock_audit_loop_error(self, parent, zbo_fps,
|
||||
override_devices=None, **kwargs):
|
||||
raise Bogus('exception')
|
||||
|
||||
def mock_fork(self):
|
||||
self.fork_called += 1
|
||||
if self.master:
|
||||
@ -430,13 +465,25 @@ class TestAuditor(unittest.TestCase):
|
||||
mount_check='false',
|
||||
zero_byte_files_per_second=89))
|
||||
mocker = ObjectAuditorMock()
|
||||
my_auditor.logger.exception = mock.MagicMock()
|
||||
real_audit_loop = my_auditor.audit_loop
|
||||
my_auditor.audit_loop = mocker.mock_audit_loop_error
|
||||
my_auditor.run_audit = mocker.mock_run
|
||||
my_auditor._sleep = mocker.mock_sleep
|
||||
was_fork = os.fork
|
||||
was_wait = os.wait
|
||||
os.fork = mocker.mock_fork
|
||||
os.wait = mocker.mock_wait
|
||||
try:
|
||||
os.fork = mocker.mock_fork
|
||||
os.wait = mocker.mock_wait
|
||||
my_auditor.run_once(zero_byte_fps=50)
|
||||
my_auditor.logger.exception.assert_called_once_with(
|
||||
'ERROR auditing: exception')
|
||||
my_auditor.logger.exception.reset_mock()
|
||||
self.assertRaises(StopForever, my_auditor.run_forever)
|
||||
my_auditor.logger.exception.assert_called_once_with(
|
||||
'ERROR auditing: exception')
|
||||
my_auditor.audit_loop = real_audit_loop
|
||||
|
||||
self.assertRaises(StopForever,
|
||||
my_auditor.run_forever, zero_byte_fps=50)
|
||||
self.assertEquals(mocker.check_kwargs['zero_byte_fps'], 50)
|
||||
|
Loading…
x
Reference in New Issue
Block a user