diff options
author | Jenkins <jenkins@review.openstack.org> | 2015-06-02 15:23:26 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2015-06-02 15:23:26 +0000 |
commit | 686ef51e1469035f9e91abc5f35fd4e64a5f0313 (patch) | |
tree | bcf2f09f966aef1ca0b6d4fa2f5c99693faea57f | |
parent | 1c8f6759588402916d70415508df155b1985896f (diff) | |
parent | 2759a6f159d4a90e4ad4c8e9e479085d195f8d14 (diff) | |
download | swift-686ef51e1469035f9e91abc5f35fd4e64a5f0313.tar.gz |
Merge "Handle Disk IO error Exception in swift account auditor"
-rw-r--r-- | swift/common/db.py | 2 | ||||
-rw-r--r-- | test/unit/common/test_db.py | 24 |
2 files changed, 26 insertions, 0 deletions
diff --git a/swift/common/db.py b/swift/common/db.py index c857bf105..80a855ac1 100644 --- a/swift/common/db.py +++ b/swift/common/db.py @@ -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) diff --git a/test/unit/common/test_db.py b/test/unit/common/test_db.py index 6472f36b0..cf1973094 100644 --- a/test/unit/common/test_db.py +++ b/test/unit/common/test_db.py @@ -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() |