Handle Disk IO error Exception in swift account auditor
Swift account auditor fails to quarantine corrupt db due to Disk IO error. This patch fixes that by handling Disk IO Error Exception. Closes-Bug:1169189 Change-Id: I031ee2a5775e4a88d4fb00d972d553936147c42e
This commit is contained in:
parent
e9a032f896
commit
2759a6f159
@ -328,6 +328,8 @@ class DatabaseBroker(object):
|
||||
exc_hint = 'malformed'
|
||||
elif 'file is encrypted or is not a database' in str(exc_value):
|
||||
exc_hint = 'corrupted'
|
||||
elif 'disk I/O error' in str(exc_value):
|
||||
exc_hint = 'disk error while accessing'
|
||||
else:
|
||||
raise exc_type, exc_value, exc_traceback
|
||||
prefix_path = os.path.dirname(self.db_dir)
|
||||
|
@ -16,6 +16,7 @@
|
||||
"""Tests for swift.common.db"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
from tempfile import mkdtemp
|
||||
from shutil import rmtree, copy
|
||||
@ -1200,6 +1201,29 @@ class TestDatabaseBroker(unittest.TestCase):
|
||||
message = str(e)
|
||||
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__':
|
||||
unittest.main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user