Log data migration script output when failure
Capture script stdout and stderr. Log outputs when script fails. Do not log exception unless script cannot run. Closes-bug: 1989742 TCs: 1. No log for execution succeed 2. script output is logged when script fails 3. exception is logged when script not executed (e.g, file not found, etc) Signed-off-by: Bin Qian <bin.qian@windriver.com> Change-Id: I9c5e01e0937db02624f8c4b9bff5ccb2fae73249
This commit is contained in:
parent
ef84f4df5e
commit
b6cc163bc6
|
@ -59,8 +59,6 @@ def execute_migration_scripts(from_release, to_release, action,
|
|||
controller-1 is performing its upgrade.
|
||||
"""
|
||||
|
||||
devnull = open(os.devnull, 'w')
|
||||
|
||||
LOG.info("Executing migration scripts with from_release: %s, "
|
||||
"to_release: %s, action: %s" % (from_release, to_release, action))
|
||||
|
||||
|
@ -85,16 +83,23 @@ def execute_migration_scripts(from_release, to_release, action,
|
|||
migration_script = os.path.join(migration_script_dir, f)
|
||||
try:
|
||||
LOG.info("Executing migration script %s" % migration_script)
|
||||
subprocess.check_call([migration_script,
|
||||
from_release,
|
||||
to_release,
|
||||
action],
|
||||
stdout=devnull, stderr=devnull)
|
||||
subprocess.check_output([migration_script,
|
||||
from_release,
|
||||
to_release,
|
||||
action],
|
||||
stderr=subprocess.STDOUT,
|
||||
universal_newlines=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
LOG.exception("Migration script %s failed with returncode %d" %
|
||||
(migration_script, e.returncode))
|
||||
# log script output if script executed but failed.
|
||||
LOG.error("Migration script %s failed with returncode %d"
|
||||
"Script output: \n%s" %
|
||||
(migration_script, e.returncode, e.output))
|
||||
# Abort when a migration script fails
|
||||
raise e
|
||||
raise
|
||||
except Exception:
|
||||
# log exception if scipt not executed.
|
||||
LOG.exception()
|
||||
raise
|
||||
|
||||
|
||||
def get_db_connection(hiera_db_records, database):
|
||||
|
|
Loading…
Reference in New Issue