Merge "Do not override exceptions with nested exceptions"
This commit is contained in:
commit
e2ff35c592
|
@ -64,6 +64,41 @@ def save_logs(url, path, auth_token=None, chunk_size=1024):
|
||||||
fp.flush()
|
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):
|
def log_snapshot_after_test(func):
|
||||||
"""Generate diagnostic snapshot after the end of the test.
|
"""Generate diagnostic snapshot after the end of the test.
|
||||||
|
|
||||||
|
@ -85,29 +120,7 @@ def log_snapshot_after_test(func):
|
||||||
raise SkipTest()
|
raise SkipTest()
|
||||||
except Exception:
|
except Exception:
|
||||||
name = 'error_{:s}'.format(func.__name__)
|
name = 'error_{:s}'.format(func.__name__)
|
||||||
description = "Failed in method {:s}.".format(func.__name__)
|
store_error_details(name, args[0].env)
|
||||||
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()))
|
|
||||||
logger.error(traceback.format_exc())
|
logger.error(traceback.format_exc())
|
||||||
logger.info("<" * 5 + "*" * 100 + ">" * 5)
|
logger.info("<" * 5 + "*" * 100 + ">" * 5)
|
||||||
raise
|
raise
|
||||||
|
|
|
@ -15,6 +15,13 @@
|
||||||
|
|
||||||
class UnexpectedExitCode(Exception):
|
class UnexpectedExitCode(Exception):
|
||||||
def __init__(self, command, ec, expected_ec, stdout=None, stderr=None):
|
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.ec = ec
|
||||||
self.expected_ec = expected_ec
|
self.expected_ec = expected_ec
|
||||||
self.cmd = command
|
self.cmd = command
|
||||||
|
@ -23,9 +30,9 @@ class UnexpectedExitCode(Exception):
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
message = "Command '{cmd:s}' returned unexpected exit code {code:d}," \
|
message = "Command '{cmd:s}' returned unexpected exit code {code:d}," \
|
||||||
" while waiting for {exp:d}".format(cmd=self.cmd,
|
" while waiting for {exp}".format(cmd=self.cmd,
|
||||||
code=self.ec,
|
code=self.ec,
|
||||||
exp=self.expected_ec)
|
exp=self.expected_ec)
|
||||||
if self.stdout:
|
if self.stdout:
|
||||||
message += "stdout: {}\n".format(self.stdout)
|
message += "stdout: {}\n".format(self.stdout)
|
||||||
if self.stderr:
|
if self.stderr:
|
||||||
|
|
|
@ -312,7 +312,7 @@ class EnvironmentModel(object):
|
||||||
|
|
||||||
def make_snapshot(self, snapshot_name, description="", is_make=False):
|
def make_snapshot(self, snapshot_name, description="", is_make=False):
|
||||||
if settings.MAKE_SNAPSHOT or is_make:
|
if settings.MAKE_SNAPSHOT or is_make:
|
||||||
self.d_env.suspend(verbose=False)
|
self.d_env.suspend()
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
|
|
||||||
self.d_env.snapshot(snapshot_name, force=True,
|
self.d_env.snapshot(snapshot_name, force=True,
|
||||||
|
|
|
@ -771,7 +771,7 @@ class MultinicBootstrap(TestBasic):
|
||||||
Ebtables.block_mac(mac)
|
Ebtables.block_mac(mac)
|
||||||
for mac in mac_addresses:
|
for mac in mac_addresses:
|
||||||
Ebtables.restore_mac(mac)
|
Ebtables.restore_mac(mac)
|
||||||
slave.destroy(verbose=False)
|
slave.destroy()
|
||||||
self.env.d_env.nodes().admins[0].revert("ready")
|
self.env.d_env.nodes().admins[0].revert("ready")
|
||||||
nailgun_slave = self.env.bootstrap_nodes([slave])[0]
|
nailgun_slave = self.env.bootstrap_nodes([slave])[0]
|
||||||
assert_equal(mac.upper(), nailgun_slave['mac'].upper())
|
assert_equal(mac.upper(), nailgun_slave['mac'].upper())
|
||||||
|
|
Loading…
Reference in New Issue