Skip to content

Commit

Permalink
Merge "Make nova-manage emit a traceback when things blow up"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Dec 17, 2016
2 parents adca1b5 + 928f046 commit f5ef0f3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
5 changes: 3 additions & 2 deletions nova/cmd/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import functools
import os
import sys
import traceback

import decorator
import netaddr
Expand Down Expand Up @@ -1583,6 +1584,6 @@ def main():
ret = fn(*fn_args, **fn_kwargs)
rpc.cleanup()
return(ret)
except Exception as ex:
print(_("error: %s") % ex)
except Exception:
print(_("An error has occurred:\n%s") % traceback.format_exc())
return(1)
21 changes: 21 additions & 0 deletions nova/tests/unit/test_nova_manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1410,3 +1410,24 @@ def test_validate_transport_url_favors_command_line(self):
from_cli = 'fake://otheruser:otherpass@otherhost:otherport'
self.assertEqual(from_cli,
self.commands._validate_transport_url(from_cli))


class TestNovaManageMain(test.NoDBTestCase):
"""Tests the nova-manage:main() setup code."""

def setUp(self):
super(TestNovaManageMain, self).setUp()
self.output = StringIO()
self.useFixture(fixtures.MonkeyPatch('sys.stdout', self.output))

@mock.patch.object(manage.config, 'parse_args')
@mock.patch.object(manage, 'CONF')
def test_error_traceback(self, mock_conf, mock_parse_args):
with mock.patch.object(manage.cmd_common, 'get_action_fn',
side_effect=test.TestingException('oops')):
self.assertEqual(1, manage.main())
# assert the traceback is dumped to stdout
output = self.output.getvalue()
self.assertIn('An error has occurred', output)
self.assertIn('Traceback', output)
self.assertIn('oops', output)

0 comments on commit f5ef0f3

Please sign in to comment.