From 3ae8ed7d5e514bfa9ca8e7b7e5c44735c3f2266f Mon Sep 17 00:00:00 2001 From: Andrew Schoen Date: Fri, 30 Jan 2015 16:35:12 -0600 Subject: [PATCH] Added a 'tests' task that we can use to test teuthology features Signed-off-by: Andrew Schoen --- teuthology/task/tests.py | 53 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 teuthology/task/tests.py diff --git a/teuthology/task/tests.py b/teuthology/task/tests.py new file mode 100644 index 0000000000..5bead718aa --- /dev/null +++ b/teuthology/task/tests.py @@ -0,0 +1,53 @@ +""" +A place to put various testing functions for teuthology. Maybe at some point we +can turn this into a proper test suite of sorts. +""" +import logging + +from functools import wraps + +from teuthology.exceptions import CommandFailedError + +log = logging.getLogger(__name__) + + +def test(f): + @wraps(f) + def func(*args, **kwargs): + try: + log.info("running {name}...".format(name=f.func_name)) + f(*args, **kwargs) + except AssertionError: + log.error("***** FAILED") + args[0].summary["status"] = "fail" + except Exception: + log.error("***** ERROR") + args[0].summary["status"] = "fail" + else: + log.info("***** PASSED") + + return func + + +@test +def test_command_failed_label(ctx, config): + result = "" + try: + force_command_failure(ctx, config) + except CommandFailedError as e: + result = str(e) + + assert "working as expected" in result + + +def force_command_failure(ctx, config): + ctx.cluster.run( + args=["python", "-c", "assert False"], + label="working as expected, nothing to see here" + ) + + +def task(ctx, config): + # TODO: find a way to auto discover test functions in this file + # and execute them + test_command_failed_label(ctx, config) -- 2.39.5