barbican-manage: Return non-zero return code on failure

... so that users can rely on the return code to detect failures. Also
this change removes the redundant 'fail' method, which is implemented
in multiple files, to make the exception handling consistent among
files for CLI.

Change-Id: I304a4f578be948def7e75b5dc4527efaddea7edf
This commit is contained in:
Takashi Kajinami
2024-02-26 02:01:47 +09:00
parent 73de2e8c35
commit 5286167566
4 changed files with 8 additions and 19 deletions

View File

@@ -447,7 +447,8 @@ def main():
try:
return fn(CONF, *fn_args, **fn_kwargs)
except Exception as e:
sys.exit("ERROR: %s" % e)
sys.stderr.write("ERROR: {0}\n".format(e))
sys.exit(1)
if __name__ == '__main__':

View File

@@ -54,11 +54,6 @@ from oslo_log import log
from oslo_service import service
def fail(returncode, e):
sys.stderr.write("ERROR: {0}\n".format(e))
sys.exit(returncode)
def main():
try:
config.setup_remote_pydev_debug()
@@ -85,7 +80,8 @@ def main():
else:
LOG.info("Exiting as Barbican Keystone listener is not enabled...")
except RuntimeError as e:
fail(1, e)
sys.stderr.write("ERROR: {0}\n".format(e))
sys.exit(1)
if __name__ == '__main__':

View File

@@ -51,11 +51,6 @@ from oslo_log import log
from oslo_service import service
def fail(returncode, e):
sys.stderr.write("ERROR: {0}\n".format(e))
sys.exit(returncode)
def main():
try:
CONF = config.CONF
@@ -76,7 +71,8 @@ def main():
restart_method='mutate'
).wait()
except RuntimeError as e:
fail(1, e)
sys.stderr.write("ERROR: {0}\n".format(e))
sys.exit(1)
if __name__ == '__main__':

View File

@@ -51,11 +51,6 @@ from oslo_log import log
from oslo_service import service
def fail(returncode, e):
sys.stderr.write("ERROR: {0}\n".format(e))
sys.exit(returncode)
def main():
try:
CONF = config.CONF
@@ -77,7 +72,8 @@ def main():
restart_method='mutate'
).wait()
except RuntimeError as e:
fail(1, e)
sys.stderr.write("ERROR: {0}\n".format(e))
sys.exit(1)
if __name__ == '__main__':