Handle getting info on wrong database type
Change-Id: I32f66f6a7683180a18a2807143d0910c75bf16f0
This commit is contained in:
parent
bd65514ed0
commit
de020f0189
@ -11,6 +11,7 @@
|
||||
# under the License.
|
||||
|
||||
import os
|
||||
import sqlite3
|
||||
from datetime import datetime
|
||||
|
||||
from swift.common.utils import hash_path, storage_directory
|
||||
@ -164,7 +165,14 @@ def print_info(db_type, db_file, swift_dir='/etc/swift'):
|
||||
else:
|
||||
broker = ContainerBroker(db_file)
|
||||
datadir = CBDATADIR
|
||||
info = broker.get_info()
|
||||
try:
|
||||
info = broker.get_info()
|
||||
except sqlite3.OperationalError as err:
|
||||
if 'no such table' in err.message:
|
||||
print "Does not appear to be a DB of type \"%s\": %s" % (
|
||||
db_type, db_file)
|
||||
raise InfoSystemExit()
|
||||
raise
|
||||
account = info['account']
|
||||
container = info['container'] if db_type == 'container' else None
|
||||
print_db_info_metadata(db_type, info, broker.metadata)
|
||||
|
@ -254,3 +254,26 @@ No user metadata found in db file'''
|
||||
self.fail("Unexpected exception raised")
|
||||
else:
|
||||
self.assertTrue(len(out.getvalue().strip()) > 600)
|
||||
|
||||
out = StringIO()
|
||||
exp_raised = False
|
||||
with mock.patch('sys.stdout', out):
|
||||
db_file = os.path.join(self.testdir, 'sda1', 'containers',
|
||||
'1', 'cae',
|
||||
'd49d0ecbb53be1fcc49624f2f7c7ccae',
|
||||
'd49d0ecbb53be1fcc49624f2f7c7ccae.db')
|
||||
orig_cwd = os.getcwd()
|
||||
try:
|
||||
os.chdir(os.path.dirname(db_file))
|
||||
print_info('account', os.path.basename(db_file),
|
||||
swift_dir='/dev/null')
|
||||
except InfoSystemExit:
|
||||
exp_raised = True
|
||||
finally:
|
||||
os.chdir(orig_cwd)
|
||||
if exp_raised:
|
||||
exp_out = 'Does not appear to be a DB of type "account":' \
|
||||
' ./d49d0ecbb53be1fcc49624f2f7c7ccae.db'
|
||||
self.assertEquals(out.getvalue().strip(), exp_out)
|
||||
else:
|
||||
self.fail("Expected an InfoSystemExit exception to be raised")
|
||||
|
Loading…
x
Reference in New Issue
Block a user