From 41b91cd0e4bd321ca0317fa19defef31b6925239 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Mon, 18 Apr 2016 12:01:51 -0500 Subject: [PATCH] Fix empty config error message Broken by bc819cb, which merged shortly before 8c2b6c1. Change-Id: I5b95993ee69a2082b3290aafe93643855ff7f56a --- rally/task/engine.py | 12 +++++++----- tests/functional/test_cli_task.py | 7 +++++++ tests/unit/task/test_engine.py | 3 +-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/rally/task/engine.py b/rally/task/engine.py index 05151aa2dd..07ae95bf72 100644 --- a/rally/task/engine.py +++ b/rally/task/engine.py @@ -185,11 +185,6 @@ class TaskEngine(object): :param abort_on_sla_failure: True if the execution should be stopped when some SLA check fails """ - if config is None: - msg = _("Input task is empty") - task.set_failed(log=msg) - raise exceptions.InvalidTaskException(msg) - try: self.config = TaskConfig(config) except Exception as e: @@ -456,6 +451,13 @@ class TaskConfig(object): :param config: Dict with configuration of specified task """ + if config is None: + # NOTE(stpierre): This gets reraised as + # InvalidTaskException. if we raise it here as + # InvalidTaskException, then "Task config is invalid: " + # gets prepended to the message twice. + raise Exception(_("Input task is empty")) + self.version = self._get_version(config) self._validate_version() self._validate_json(config) diff --git a/tests/functional/test_cli_task.py b/tests/functional/test_cli_task.py index 486c1335ce..df62fb8518 100644 --- a/tests/functional/test_cli_task.py +++ b/tests/functional/test_cli_task.py @@ -164,6 +164,13 @@ class TaskTestCase(unittest.TestCase): detailed_iterations_data = rally("task detailed --iterations-data") self.assertNotIn("n/a", detailed_iterations_data) + def test_start_with_empty_config(self): + rally = utils.Rally() + config = utils.TaskConfig(None) + with self.assertRaises(utils.RallyCliError) as err: + rally("task start --task %s" % config.filename) + self.assertIn("Input task is empty", err.exception.output) + def test_results(self): rally = utils.Rally() cfg = self._get_sample_task_config() diff --git a/tests/unit/task/test_engine.py b/tests/unit/task/test_engine.py index 26ccfa482b..9e9917f435 100644 --- a/tests/unit/task/test_engine.py +++ b/tests/unit/task/test_engine.py @@ -44,8 +44,7 @@ class TaskEngineTestCase(test.TestCase): self.assertEqual(eng.config, fake_task_instance) self.assertEqual(eng.task, task) - @mock.patch("rally.task.engine.TaskConfig") - def test_init_empty_config(self, mock_task_config): + def test_init_empty_config(self): config = None task = mock.Mock() exception = self.assertRaises(exceptions.InvalidTaskException,