From: Ivo Jimenez Date: Tue, 7 Jul 2015 19:38:06 +0000 (-0700) Subject: Ensures that task list is a python list X-Git-Tag: 1.1.0~881^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ebdba9d545eca6fd4f7ab497392639c88fc0a312;p=teuthology.git Ensures that task list is a python list * Modifies test for task list validation * Shows contents of config['tasks'] for error msg * Properly checks distinct failure conditions * Fixes typo on kernel task AssertionError --- diff --git a/README.rst b/README.rst index 6fa645e3..30a1d35a 100644 --- a/README.rst +++ b/README.rst @@ -97,7 +97,9 @@ the nodes & use the live cluster ad hoc), might look like this:: The number of entries under ``roles`` and ``targets`` must match. -Note the colon after every task name in the ``tasks`` section. +Note the colon after every task name in the ``tasks`` section. Also note the +dashes before each task. This is the YAML syntax for an ordered list and +specifies the order in which tasks are executed. The ``install`` task needs to precede all other tasks. diff --git a/teuthology/run.py b/teuthology/run.py index 1db3aa05..48a69593 100644 --- a/teuthology/run.py +++ b/teuthology/run.py @@ -151,7 +151,7 @@ def get_summary(owner, description): def validate_tasks(config): """ - Ensures that config tasks do not include 'kernel'. + Ensures that config tasks is a list and doesn't include 'kernel'. Returns the original tasks key if found. If not, returns an empty list. @@ -161,8 +161,11 @@ def validate_tasks(config): # return the default value for tasks return [] + msg = "Expected list in 'tasks'; instead got: {0}".format(config['tasks']) + assert isinstance(config['tasks'], list), msg + for task in config['tasks']: - msg = ('kernel installation shouldn be a base-level item, not part ' + + msg = ('kernel installation should be a base-level item, not part ' + 'of the tasks list') assert 'kernel' not in task, msg diff --git a/teuthology/test/test_run.py b/teuthology/test/test_run.py index 3f4ba404..f2c4e909 100644 --- a/teuthology/test/test_run.py +++ b/teuthology/test/test_run.py @@ -74,22 +74,29 @@ class TestRun(object): assert result == {"owner": "the_owner", "success": True} def test_validate_tasks_invalid(self): - config = {"tasks": {"kernel": "can't be here"}} - with pytest.raises(AssertionError): + config = {"tasks": [{"kernel": "can't be here"}]} + with pytest.raises(AssertionError) as excinfo: run.validate_tasks(config) + assert excinfo.value.message.startswith("kernel installation") def test_validate_task_no_tasks(self): result = run.validate_tasks({}) assert result == [] def test_validate_tasks_valid(self): - expected = {"foo": "bar"} + expected = [{"foo": "bar"}, {"bar": "foo"}] result = run.validate_tasks({"tasks": expected}) assert result == expected + def test_validate_tasks_is_list(self): + with pytest.raises(AssertionError) as excinfo: + run.validate_tasks({"tasks": {"foo": "bar"}}) + assert excinfo.value.message.startswith("Expected list") + def test_get_initial_tasks_invalid(self): - with pytest.raises(AssertionError): + with pytest.raises(AssertionError) as excinfo: run.get_initial_tasks(True, {"targets": "can't be here"}, "machine_type") + assert excinfo.value.message.startswith("You cannot") def test_get_inital_tasks(self): config = {"roles": range(2), "kernel": "the_kernel", "use_existing_cluster": False}