Merge "Handle getting info on wrong database type"
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import sqlite3
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from swift.common.utils import hash_path, storage_directory
|
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:
|
else:
|
||||||
broker = ContainerBroker(db_file)
|
broker = ContainerBroker(db_file)
|
||||||
datadir = CBDATADIR
|
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']
|
account = info['account']
|
||||||
container = info['container'] if db_type == 'container' else None
|
container = info['container'] if db_type == 'container' else None
|
||||||
print_db_info_metadata(db_type, info, broker.metadata)
|
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")
|
self.fail("Unexpected exception raised")
|
||||||
else:
|
else:
|
||||||
self.assertTrue(len(out.getvalue().strip()) > 600)
|
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")
|
||||||
|
Reference in New Issue
Block a user