Merge "Do not override exceptions with nested exceptions"

This commit is contained in:
Jenkins 2016-03-15 23:07:02 +00:00 committed by Gerrit Code Review
commit e2ff35c592
4 changed files with 48 additions and 28 deletions

View File

@ -64,6 +64,41 @@ def save_logs(url, path, auth_token=None, chunk_size=1024):
fp.flush()
def store_error_details(name, env):
description = "Failed in method {:s}.".format(name)
if env is not None:
try:
create_diagnostic_snapshot(env, "fail", name)
except:
logger.error("Fetching of diagnostic snapshot failed: {0}".format(
traceback.format_exception_only(sys.exc_info()[0],
sys.exc_info()[1])))
logger.debug("Fetching of diagnostic snapshot failed: {0}".
format(traceback.format_exc()))
try:
with env.d_env.get_admin_remote()\
as admin_remote:
pull_out_logs_via_ssh(admin_remote, name)
except:
logger.error("Fetching of raw logs failed: {0}".format(
traceback.format_exception_only(sys.exc_info()[0],
sys.exc_info()[1])))
logger.debug("Fetching of raw logs failed: {0}".
format(traceback.format_exc()))
finally:
try:
env.make_snapshot(snapshot_name=name[-50:],
description=description,
is_make=True)
except:
logger.error(
"Error making the environment snapshot: {0}".format(
traceback.format_exception_only(sys.exc_info()[0],
sys.exc_info()[1])))
logger.debug("Error making the environment snapshot:"
" {0}".format(traceback.format_exc()))
def log_snapshot_after_test(func):
"""Generate diagnostic snapshot after the end of the test.
@ -85,29 +120,7 @@ def log_snapshot_after_test(func):
raise SkipTest()
except Exception:
name = 'error_{:s}'.format(func.__name__)
description = "Failed in method {:s}.".format(func.__name__)
if args[0].env is not None:
try:
create_diagnostic_snapshot(args[0].env, "fail", name)
except:
logger.error("Fetching of diagnostic snapshot failed: {0}".
format(traceback.format_exc()))
try:
with args[0].env.d_env.get_admin_remote()\
as admin_remote:
pull_out_logs_via_ssh(admin_remote, name)
except:
logger.error("Fetching of raw logs failed: {0}".
format(traceback.format_exc()))
finally:
logger.debug(args)
try:
args[0].env.make_snapshot(snapshot_name=name[-50:],
description=description,
is_make=True)
except:
logger.error("Error making the environment snapshot:"
" {0}".format(traceback.format_exc()))
store_error_details(name, args[0].env)
logger.error(traceback.format_exc())
logger.info("<" * 5 + "*" * 100 + ">" * 5)
raise

View File

@ -15,6 +15,13 @@
class UnexpectedExitCode(Exception):
def __init__(self, command, ec, expected_ec, stdout=None, stderr=None):
"""Exception for unexpected exit code after executing shell/ssh command
:param command: str - executed command
:param ec: int - actual exit code
:param expected_ec: list of integers - expected exit codes
:param stdout: str
:param stderr: str
"""
self.ec = ec
self.expected_ec = expected_ec
self.cmd = command
@ -23,9 +30,9 @@ class UnexpectedExitCode(Exception):
def __str__(self):
message = "Command '{cmd:s}' returned unexpected exit code {code:d}," \
" while waiting for {exp:d}".format(cmd=self.cmd,
code=self.ec,
exp=self.expected_ec)
" while waiting for {exp}".format(cmd=self.cmd,
code=self.ec,
exp=self.expected_ec)
if self.stdout:
message += "stdout: {}\n".format(self.stdout)
if self.stderr:

View File

@ -312,7 +312,7 @@ class EnvironmentModel(object):
def make_snapshot(self, snapshot_name, description="", is_make=False):
if settings.MAKE_SNAPSHOT or is_make:
self.d_env.suspend(verbose=False)
self.d_env.suspend()
time.sleep(10)
self.d_env.snapshot(snapshot_name, force=True,

View File

@ -771,7 +771,7 @@ class MultinicBootstrap(TestBasic):
Ebtables.block_mac(mac)
for mac in mac_addresses:
Ebtables.restore_mac(mac)
slave.destroy(verbose=False)
slave.destroy()
self.env.d_env.nodes().admins[0].revert("ready")
nailgun_slave = self.env.bootstrap_nodes([slave])[0]
assert_equal(mac.upper(), nailgun_slave['mac'].upper())