Add debug possibility for nova-manage command
Sometimes if an error occurs it's good to have the ability to debug it. Changes add flag --post-mortem to use post-mortem debugging. It can be used as: nova-manage --post-mortem <category> <command> Change-Id: Ib8ab99fc6bc543500a862f414d7df763568b9b2d
This commit is contained in:
@@ -1560,10 +1560,14 @@ category_opt = cfg.SubCommandOpt('category',
|
|||||||
help='Available categories',
|
help='Available categories',
|
||||||
handler=add_command_parsers)
|
handler=add_command_parsers)
|
||||||
|
|
||||||
|
post_mortem_opt = cfg.BoolOpt('post-mortem',
|
||||||
|
default=False,
|
||||||
|
help='Allow post-mortem debugging')
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Parse options and call the appropriate class/method."""
|
"""Parse options and call the appropriate class/method."""
|
||||||
CONF.register_cli_opt(category_opt)
|
CONF.register_cli_opts([category_opt, post_mortem_opt])
|
||||||
config.parse_args(sys.argv)
|
config.parse_args(sys.argv)
|
||||||
logging.set_defaults(
|
logging.set_defaults(
|
||||||
default_log_levels=logging.get_default_log_levels() +
|
default_log_levels=logging.get_default_log_levels() +
|
||||||
@@ -1585,5 +1589,9 @@ def main():
|
|||||||
rpc.cleanup()
|
rpc.cleanup()
|
||||||
return(ret)
|
return(ret)
|
||||||
except Exception:
|
except Exception:
|
||||||
print(_("An error has occurred:\n%s") % traceback.format_exc())
|
if CONF.post_mortem:
|
||||||
|
import pdb
|
||||||
|
pdb.post_mortem()
|
||||||
|
else:
|
||||||
|
print(_("An error has occurred:\n%s") % traceback.format_exc())
|
||||||
return(1)
|
return(1)
|
||||||
|
@@ -1427,9 +1427,20 @@ class TestNovaManageMain(test.NoDBTestCase):
|
|||||||
def test_error_traceback(self, mock_conf, mock_parse_args):
|
def test_error_traceback(self, mock_conf, mock_parse_args):
|
||||||
with mock.patch.object(manage.cmd_common, 'get_action_fn',
|
with mock.patch.object(manage.cmd_common, 'get_action_fn',
|
||||||
side_effect=test.TestingException('oops')):
|
side_effect=test.TestingException('oops')):
|
||||||
|
mock_conf.post_mortem = False
|
||||||
self.assertEqual(1, manage.main())
|
self.assertEqual(1, manage.main())
|
||||||
# assert the traceback is dumped to stdout
|
# assert the traceback is dumped to stdout
|
||||||
output = self.output.getvalue()
|
output = self.output.getvalue()
|
||||||
self.assertIn('An error has occurred', output)
|
self.assertIn('An error has occurred', output)
|
||||||
self.assertIn('Traceback', output)
|
self.assertIn('Traceback', output)
|
||||||
self.assertIn('oops', output)
|
self.assertIn('oops', output)
|
||||||
|
|
||||||
|
@mock.patch('pdb.post_mortem')
|
||||||
|
@mock.patch.object(manage.config, 'parse_args')
|
||||||
|
@mock.patch.object(manage, 'CONF')
|
||||||
|
def test_error_post_mortem(self, mock_conf, mock_parse_args, mock_pm):
|
||||||
|
with mock.patch.object(manage.cmd_common, 'get_action_fn',
|
||||||
|
side_effect=test.TestingException('oops')):
|
||||||
|
mock_conf.post_mortem = True
|
||||||
|
self.assertEqual(1, manage.main())
|
||||||
|
self.assertTrue(mock_pm.called)
|
||||||
|
Reference in New Issue
Block a user