Re-enable stacktracing when --debug is used
Commit 1f89beb609 introduced the behaviour
that a stacktrace is printed if an exception is encountered.
This helped make the client more supportable:
$ glance --debug image-list
.
.
.
File "glanceclient/common/http.py", line 337, in get_http_client
xxx
NameError: global name 'xxx' is not defined
global name 'xxx' is not defined
The behaviour was lost at some point. This patch re-enables it.
Change-Id: I25fc8624797909d606590747f54b9cf649ade079
Closes-bug: 1563830
This commit is contained in:
@@ -22,6 +22,7 @@ except ImportError:
|
||||
import hashlib
|
||||
import os
|
||||
import sys
|
||||
import traceback
|
||||
import uuid
|
||||
|
||||
import fixtures
|
||||
@@ -150,6 +151,44 @@ class ShellTest(testutils.TestCase):
|
||||
argstr = '--os-image-api-version 2 help foofoo'
|
||||
self.assertRaises(exc.CommandError, shell.main, argstr.split())
|
||||
|
||||
@mock.patch('sys.stdout', six.StringIO())
|
||||
@mock.patch('sys.stderr', six.StringIO())
|
||||
@mock.patch('sys.argv', ['glance', 'help', 'foofoo'])
|
||||
def test_no_stacktrace_when_debug_disabled(self):
|
||||
with mock.patch.object(traceback, 'print_exc') as mock_print_exc:
|
||||
try:
|
||||
openstack_shell.main()
|
||||
except SystemExit:
|
||||
pass
|
||||
self.assertFalse(mock_print_exc.called)
|
||||
|
||||
@mock.patch('sys.stdout', six.StringIO())
|
||||
@mock.patch('sys.stderr', six.StringIO())
|
||||
@mock.patch('sys.argv', ['glance', 'help', 'foofoo'])
|
||||
def test_stacktrace_when_debug_enabled_by_env(self):
|
||||
old_environment = os.environ.copy()
|
||||
os.environ = {'GLANCECLIENT_DEBUG': '1'}
|
||||
try:
|
||||
with mock.patch.object(traceback, 'print_exc') as mock_print_exc:
|
||||
try:
|
||||
openstack_shell.main()
|
||||
except SystemExit:
|
||||
pass
|
||||
self.assertTrue(mock_print_exc.called)
|
||||
finally:
|
||||
os.environ = old_environment
|
||||
|
||||
@mock.patch('sys.stdout', six.StringIO())
|
||||
@mock.patch('sys.stderr', six.StringIO())
|
||||
@mock.patch('sys.argv', ['glance', '--debug', 'help', 'foofoo'])
|
||||
def test_stacktrace_when_debug_enabled(self):
|
||||
with mock.patch.object(traceback, 'print_exc') as mock_print_exc:
|
||||
try:
|
||||
openstack_shell.main()
|
||||
except SystemExit:
|
||||
pass
|
||||
self.assertTrue(mock_print_exc.called)
|
||||
|
||||
def test_help(self):
|
||||
shell = openstack_shell.OpenStackImagesShell()
|
||||
argstr = '--os-image-api-version 2 help'
|
||||
|
||||
Reference in New Issue
Block a user