From 865af7c9e72e84ee3d8edebcc4959d08d0ab2d88 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Jan 10 2020 08:55:42 +0000 Subject: frontend: manage.py: propagate return values to cmdline It turned out that some tests failed in 'manage.py test', but the command returned exit status 0. So we were not informed about our CI failures. This seems to be known and desired design of click, unfortunately: https://github.com/pallets/click/issues/747 --- diff --git a/frontend/coprs_frontend/manage.py b/frontend/coprs_frontend/manage.py index e4e78ce..c07e5bc 100755 --- a/frontend/coprs_frontend/manage.py +++ b/frontend/coprs_frontend/manage.py @@ -4,6 +4,7 @@ import os import sys import copy +from functools import wraps import pipes import importlib import click @@ -83,8 +84,21 @@ commands_list = [ "delete_orphans", ] + +def always_exit(function): + """ + Decorate click command function so it always exits, so each 'return STATUS' + is actually propagated to shell. + """ + @wraps(function) + def wrapper(*args, **kwargs): + sys.exit(bool(function(*args, **kwargs))) + return wrapper + + for command in commands_list: cmd_obj = getattr(getattr(commands, command), command) + cmd_obj.callback = always_exit(cmd_obj.callback) # Add underscored commands, e.g. 'add_user' for 'add-user' for compatibility # reasons. TODO: we can drop this once we have the deployment scripts fixed