fixes #2 Catching sqlite exceptions from get_data
This commit is contained in:
@@ -19,6 +19,7 @@ from paste.deploy import appconfig
|
|||||||
import shutil
|
import shutil
|
||||||
import hashlib
|
import hashlib
|
||||||
import urllib
|
import urllib
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
from swift.account.server import DATADIR as account_server_data_dir
|
from swift.account.server import DATADIR as account_server_data_dir
|
||||||
from swift.container.server import DATADIR as container_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:
|
for filename in files:
|
||||||
if filename.endswith('.db'):
|
if filename.endswith('.db'):
|
||||||
db_path = os.path.join(root, filename)
|
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:
|
if line_data:
|
||||||
statfile.write(line_data)
|
statfile.write(line_data)
|
||||||
hasher.update(line_data)
|
hasher.update(line_data)
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import unittest
|
|||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
|
import sqlite3
|
||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
from slogging import db_stats_collector
|
from slogging import db_stats_collector
|
||||||
from tempfile import mkdtemp
|
from tempfile import mkdtemp
|
||||||
@@ -163,6 +164,15 @@ class TestDbStats(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(len(output_data), 0)
|
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):
|
def test_account_stat_run_once_container_metadata(self):
|
||||||
|
|
||||||
stat, output_data = self._gen_container_stat(set_metadata=True)
|
stat, output_data = self._gen_container_stat(set_metadata=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user