Handle exceptions from checks

The original check code in Nova behaves this way, so for consistency
do it here too.
This commit is contained in:
Ben Nemec 2018-09-13 17:24:57 +00:00
parent d3877b9087
commit 3d2a3bc23f
2 changed files with 15 additions and 1 deletions

View File

@ -79,3 +79,11 @@ class TestMain(base.BaseTestCase):
inst = TestCommands()
result = upgradecheck.main(inst.check)
self.assertEqual(upgradecheck.UpgradeCheckCode.FAILURE, result)
def test_main_exception(self):
def raises():
raise Exception('test exception')
mock_argv = ['test-status', 'upgrade', 'check']
with mock.patch.object(sys, 'argv', mock_argv, create=True):
result = upgradecheck.main(raises)
self.assertEqual(255, result)

View File

@ -16,6 +16,7 @@
import functools
import sys
import textwrap
import traceback
import enum
from oslo_config import cfg
@ -148,4 +149,9 @@ def main(check_callback):
conf.register_cli_opt(opt)
conf(sys.argv[1:])
return conf.category.action_fn()
try:
return conf.category.action_fn()
except Exception:
print(_('Error:\n%s') % traceback.format_exc())
# This is 255 so it's not confused with the upgrade check exit codes.
return 255