summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-09-15 20:23:05 +0000
committerGerrit Code Review <review@openstack.org>2015-09-15 20:23:05 +0000
commit101d53dc669e9f91e1c98e45b4a3c81600d84f10 (patch)
tree3835473086c19818b728c9292d3f316db901f124
parent47838395d74fb1ebdd8ad01e22951c96d41dfc80 (diff)
parent48f9c5a046426de81a5087ce9604c030e7165c22 (diff)
downloadpython-novaclient-101d53dc669e9f91e1c98e45b4a3c81600d84f10.tar.gz
Merge "Fix unicode issue in shell.main() error handling"
-rw-r--r--novaclient/shell.py12
-rw-r--r--novaclient/tests/unit/test_shell.py10
2 files changed, 15 insertions, 7 deletions
diff --git a/novaclient/shell.py b/novaclient/shell.py
index 93f7bbe0..583cddb6 100644
--- a/novaclient/shell.py
+++ b/novaclient/shell.py
@@ -31,7 +31,6 @@ from keystoneclient import session as ksession
from oslo_utils import encodeutils
from oslo_utils import importutils
from oslo_utils import strutils
-import six
HAS_KEYRING = False
all_errors = ValueError
@@ -897,12 +896,11 @@ def main():
try:
argv = [encodeutils.safe_decode(a) for a in sys.argv[1:]]
OpenStackComputeShell().main(argv)
-
- except Exception as e:
- logger.debug(e, exc_info=1)
- details = {'name': encodeutils.safe_encode(e.__class__.__name__),
- 'msg': encodeutils.safe_encode(six.text_type(e))}
- print("ERROR (%(name)s): %(msg)s" % details,
+ except Exception as exc:
+ logger.debug(exc, exc_info=1)
+ print("ERROR (%s): %s"
+ % (exc.__class__.__name__,
+ encodeutils.exception_to_unicode(exc)),
file=sys.stderr)
sys.exit(1)
except KeyboardInterrupt:
diff --git a/novaclient/tests/unit/test_shell.py b/novaclient/tests/unit/test_shell.py
index 844306fc..a2c86b6d 100644
--- a/novaclient/tests/unit/test_shell.py
+++ b/novaclient/tests/unit/test_shell.py
@@ -521,6 +521,16 @@ class ShellTest(utils.TestCase):
self.assertEqual(password, 'password')
self.assertIs(client_kwargs['session'], None)
+ @mock.patch.object(novaclient.shell.OpenStackComputeShell, 'main')
+ def test_main_error_handling(self, mock_compute_shell):
+ class MyException(Exception):
+ pass
+ with mock.patch('sys.stderr', six.StringIO()):
+ mock_compute_shell.side_effect = MyException('message')
+ self.assertRaises(SystemExit, novaclient.shell.main)
+ err = sys.stderr.getvalue()
+ self.assertEqual(err, 'ERROR (MyException): message\n')
+
class TestLoadVersionedActions(utils.TestCase):