fixes #2 Catching sqlite exceptions from get_data

This commit is contained in:
dfg 2011-07-06 12:31:21 -07:00
parent cf67442a18
commit 8f335a17ec
2 changed files with 18 additions and 1 deletions

View File

@ -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)

View File

@ -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)