Provide user friendly message for FK failure

'cinder-manage db purge' command fails with DBReferenceError due
to FK constraint failure and exits with stack-trace on the command
prompt.

Made changes to give user friendly message to the user as well as
log appropriate error message in cinder-manage logs instead of
stack-trace and exit with non-zero code to notify user about
the failure.

Closes-Bug: #1542169
Change-Id: I24476af70b45150b9f9e4e5d874f46fd4c07e680
This commit is contained in:
Abhishek Kekane
2016-02-11 04:30:47 -08:00
parent 092618aab8
commit dc70025072
3 changed files with 46 additions and 4 deletions

View File

@@ -60,6 +60,7 @@ import os
import sys
from oslo_config import cfg
from oslo_db import exception as db_exc
from oslo_db.sqlalchemy import migration
from oslo_log import log as logging
import oslo_messaging as messaging
@@ -229,7 +230,13 @@ class DbCommands(object):
print(_("Must supply a positive, non-zero value for age"))
sys.exit(1)
ctxt = context.get_admin_context()
db.purge_deleted_rows(ctxt, age_in_days)
try:
db.purge_deleted_rows(ctxt, age_in_days)
except db_exc.DBReferenceError:
print(_("Purge command failed, check cinder-manage "
"logs for more details."))
sys.exit(1)
class VersionCommands(object):