Raise traceback on error when using CLI and -debug
When --debug is specified to the CLI don't just print the simple error message but actually reraise that error. Change-Id: I616eda8e033342cff7f3412e3a414a7530ef3848 Closes-Bug: #1268202
This commit is contained in:
parent
97d945e879
commit
1db0ac2d21
|
@ -421,12 +421,17 @@ class HelpFormatter(argparse.HelpFormatter):
|
|||
super(HelpFormatter, self).start_section(heading)
|
||||
|
||||
|
||||
def main():
|
||||
def main(args=None):
|
||||
try:
|
||||
HeatShell().main(sys.argv[1:])
|
||||
if args is None:
|
||||
args = sys.argv[1:]
|
||||
|
||||
HeatShell().main(args)
|
||||
except Exception as e:
|
||||
print(strutils.safe_encode(six.text_type(e)), file=sys.stderr)
|
||||
if '--debug' in args or '-d' in args:
|
||||
raise
|
||||
else:
|
||||
print(strutils.safe_encode(six.text_type(e)), file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -280,6 +280,57 @@ class ShellTestCommon(ShellBase):
|
|||
for r in required:
|
||||
self.assertRegexpMatches(help_text, r)
|
||||
|
||||
def test_debug_switch_raises_error(self):
|
||||
fakes.script_keystone_client()
|
||||
http.HTTPClient.json_request(
|
||||
'GET', '/stacks?').AndRaise(exc.Unauthorized("FAIL"))
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
fake_env = {
|
||||
'OS_USERNAME': 'username',
|
||||
'OS_PASSWORD': 'password',
|
||||
'OS_TENANT_NAME': 'tenant_name',
|
||||
'OS_AUTH_URL': 'http://no.where',
|
||||
}
|
||||
self.set_fake_env(fake_env)
|
||||
args = ['--debug', 'stack-list']
|
||||
self.assertRaises(exc.Unauthorized, heatclient.shell.main, args)
|
||||
|
||||
def test_dash_d_switch_raises_error(self):
|
||||
fakes.script_keystone_client()
|
||||
http.HTTPClient.json_request(
|
||||
'GET', '/stacks?').AndRaise(exc.CommandError("FAIL"))
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
fake_env = {
|
||||
'OS_USERNAME': 'username',
|
||||
'OS_PASSWORD': 'password',
|
||||
'OS_TENANT_NAME': 'tenant_name',
|
||||
'OS_AUTH_URL': 'http://no.where',
|
||||
}
|
||||
self.set_fake_env(fake_env)
|
||||
args = ['-d', 'stack-list']
|
||||
self.assertRaises(exc.CommandError, heatclient.shell.main, args)
|
||||
|
||||
def test_no_debug_switch_no_raises_errors(self):
|
||||
fakes.script_keystone_client()
|
||||
http.HTTPClient.json_request(
|
||||
'GET', '/stacks?').AndRaise(exc.Unauthorized("FAIL"))
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
fake_env = {
|
||||
'OS_USERNAME': 'username',
|
||||
'OS_PASSWORD': 'password',
|
||||
'OS_TENANT_NAME': 'tenant_name',
|
||||
'OS_AUTH_URL': 'http://no.where',
|
||||
}
|
||||
self.set_fake_env(fake_env)
|
||||
args = ['stack-list']
|
||||
self.assertRaises(SystemExit, heatclient.shell.main, args)
|
||||
|
||||
def test_help_on_subcommand(self):
|
||||
required = [
|
||||
'^usage: heat stack-list',
|
||||
|
|
Loading…
Reference in New Issue