From 59fa78027ab8ec76a09d48cdde9230d8284c6b6d Mon Sep 17 00:00:00 2001 From: Kamil Páral Date: Jun 20 2018 10:38:03 +0000 Subject: executor: add friendly error when results.yml is missing --- diff --git a/docs/source/resultyaml.rst b/docs/source/resultyaml.rst index f2f8225..36225bf 100644 --- a/docs/source/resultyaml.rst +++ b/docs/source/resultyaml.rst @@ -120,6 +120,8 @@ can give them any meaning and use them for any purpose that you need. Special cases ============= +.. _empty_results: + Empty results ------------- diff --git a/docs/source/writingtasks.rst b/docs/source/writingtasks.rst index 6b998d4..a15b949 100644 --- a/docs/source/writingtasks.rst +++ b/docs/source/writingtasks.rst @@ -118,6 +118,11 @@ file. For example: with open(results_path, 'w') as results_file: results_file.write(output) +.. note:: + + In the rare case when you don't want to report any results, the + ``results.yml`` still needs to exist. See :ref:`empty_results`. + .. _task-variables: diff --git a/libtaskotron/executor.py b/libtaskotron/executor.py index f90978f..faefda0 100644 --- a/libtaskotron/executor.py +++ b/libtaskotron/executor.py @@ -477,6 +477,14 @@ class Executor(object): results_file = os.path.join(self.arg_data['artifactsdir'], test_playbook, 'taskotron', 'results.yml') log.info('Reporting results from: %s', results_file) + + if not os.path.exists(results_file): + raise exc.TaskotronDirectiveError("Results file doesn't exist, " + 'assuming the task crashed. If you wish to report no results, ' + 'the results file still needs to exist - consult ' + 'documentation. Expected results file location: %s' % + results_file) + rdb = resultsdb_directive.ResultsdbDirective() rdb.process(params={"file": results_file}, arg_data=self.arg_data)