Merge "Handle Disk IO error Exception in swift account auditor"

This commit is contained in:
Jenkins 2015-06-02 15:23:26 +00:00 committed by Gerrit Code Review
commit 686ef51e14
2 changed files with 26 additions and 0 deletions

View File

@ -328,6 +328,8 @@ class DatabaseBroker(object):
exc_hint = 'malformed' exc_hint = 'malformed'
elif 'file is encrypted or is not a database' in str(exc_value): elif 'file is encrypted or is not a database' in str(exc_value):
exc_hint = 'corrupted' exc_hint = 'corrupted'
elif 'disk I/O error' in str(exc_value):
exc_hint = 'disk error while accessing'
else: else:
raise exc_type, exc_value, exc_traceback raise exc_type, exc_value, exc_traceback
prefix_path = os.path.dirname(self.db_dir) prefix_path = os.path.dirname(self.db_dir)

View File

@ -16,6 +16,7 @@
"""Tests for swift.common.db""" """Tests for swift.common.db"""
import os import os
import sys
import unittest import unittest
from tempfile import mkdtemp from tempfile import mkdtemp
from shutil import rmtree, copy from shutil import rmtree, copy
@ -1200,6 +1201,29 @@ class TestDatabaseBroker(unittest.TestCase):
message = str(e) message = str(e)
self.assertEqual(message, '400 Bad Request') self.assertEqual(message, '400 Bad Request')
def test_possibly_quarantine_disk_error(self):
dbpath = os.path.join(self.testdir, 'dev', 'dbs', 'par', 'pre', 'db')
mkdirs(dbpath)
qpath = os.path.join(self.testdir, 'dev', 'quarantined', 'tests', 'db')
broker = DatabaseBroker(os.path.join(dbpath, '1.db'))
broker.db_type = 'test'
def stub():
raise sqlite3.OperationalError('disk I/O error')
try:
stub()
except Exception:
try:
broker.possibly_quarantine(*sys.exc_info())
except Exception as exc:
self.assertEquals(
str(exc),
'Quarantined %s to %s due to disk error '
'while accessing database' %
(dbpath, qpath))
else:
self.fail('Expected an exception to be raised')
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()