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:
parent
d3877b9087
commit
3d2a3bc23f
@ -79,3 +79,11 @@ class TestMain(base.BaseTestCase):
|
|||||||
inst = TestCommands()
|
inst = TestCommands()
|
||||||
result = upgradecheck.main(inst.check)
|
result = upgradecheck.main(inst.check)
|
||||||
self.assertEqual(upgradecheck.UpgradeCheckCode.FAILURE, result)
|
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)
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
import functools
|
import functools
|
||||||
import sys
|
import sys
|
||||||
import textwrap
|
import textwrap
|
||||||
|
import traceback
|
||||||
|
|
||||||
import enum
|
import enum
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
@ -148,4 +149,9 @@ def main(check_callback):
|
|||||||
conf.register_cli_opt(opt)
|
conf.register_cli_opt(opt)
|
||||||
conf(sys.argv[1:])
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user