diff --git a/slogging/db_stats_collector.py b/slogging/db_stats_collector.py index 95efaa8..746be82 100644 --- a/slogging/db_stats_collector.py +++ b/slogging/db_stats_collector.py @@ -19,6 +19,7 @@ from paste.deploy import appconfig import shutil import hashlib import urllib +import sqlite3 from swift.account.server import DATADIR as account_server_data_dir from swift.container.server import DATADIR as container_server_data_dir @@ -89,7 +90,13 @@ class DatabaseStatsCollector(Daemon): for filename in files: if filename.endswith('.db'): db_path = os.path.join(root, filename) - line_data = self.get_data(db_path) + try: + line_data = self.get_data(db_path) + except sqlite3.Error, err: + self.logger.info( + _("Error accessing db %s: %s") % + (db_path, err)) + continue if line_data: statfile.write(line_data) hasher.update(line_data) diff --git a/test_slogging/unit/test_db_stats_collector.py b/test_slogging/unit/test_db_stats_collector.py index becd3da..cb7b99d 100644 --- a/test_slogging/unit/test_db_stats_collector.py +++ b/test_slogging/unit/test_db_stats_collector.py @@ -18,6 +18,7 @@ import unittest import os import time import uuid +import sqlite3 from shutil import rmtree from slogging import db_stats_collector from tempfile import mkdtemp @@ -163,6 +164,15 @@ class TestDbStats(unittest.TestCase): self.assertEqual(len(output_data), 0) + def test_account_stat_run_once_bad_db(self): + stat, output_data = self._gen_account_stat() + + def raise_error(path): + raise sqlite3.OperationalError('Test error') + stat.get_data = raise_error + was_errors = len(stat.logger.log_dict['info']) + stat.run_once() + def test_account_stat_run_once_container_metadata(self): stat, output_data = self._gen_container_stat(set_metadata=True)