Repository: chaostoolkit/chaostoolkit-lib

Issue:
Correct activity-level control behaviour where missing controls are simply warned of in the logging

Discussion:
russmiles: Good to go ... obviously when the build is ok ;)

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 835f999..eca3b3f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,8 +8,11 @@
 
 - Fix a failure when no top-level controls were provided but an activity
   control was declared [#88][88]
+- Warn when control Python package is not installed but do not fail experiment
+  during validation [#90][90]. Controls should remain optional.
 
 [88]: https://github.com/chaostoolkit/chaostoolkit-lib/issues/88
+[90]: https://github.com/chaostoolkit/chaostoolkit-lib/issues/90
 
 
 ## [1.1.0][] - 2019-03-11
diff --git a/chaoslib/control/python.py b/chaoslib/control/python.py
index 028ac48..26e4a4c 100644
--- a/chaoslib/control/python.py
+++ b/chaoslib/control/python.py
@@ -63,9 +63,10 @@ def validate_python_control(control: Control):
     try:
         importlib.import_module(mod_name)
     except ImportError:
-        raise InvalidActivity("could not find Python module '{mod}' "
-                              "in control '{name}'".format(
-                                  mod=mod_name, name=name))
+        logger.warning("Could not find Python module '{mod}' "
+                       "in control '{name}'. Did you install the Python "
+                       "module? The experiment will carry on running "
+                       "nonetheless.".format(mod=mod_name, name=name))
 
 
 def apply_python_control(level: str, control: Control, experiment: Experiment,


Test patch:
diff --git a/tests/test_control.py b/tests/test_control.py
index 2fe3430..cb2ca95 100644
--- a/tests/test_control.py
+++ b/tests/test_control.py
@@ -2,9 +2,12 @@
 from copy import deepcopy
 from concurrent.futures import ThreadPoolExecutor
 import os
+import tempfile
 from typing import Any, Dict, List
+from unittest.mock import patch
 
 from pkg_resources import Distribution, EntryPoint, working_set
+import logzero
 import pytest
 
 from chaoslib.activity import execute_activity
@@ -208,15 +211,19 @@ def test_not_automatic_does_not_go_deep_down_the_tree():
         assert len(controls) == 0
 
 
-def test_validate_python_control_must_be_loadable():
-    with pytest.raises(InvalidActivity):
-        validate_python_control({
-            "name": "a-python-control",
-            "provider": {
-                "type": "python",
-                "module": "blah.blah"
-            }
-        })
+@patch('chaoslib.control.python.logger', autospec=True)
+def test_validate_python_control_must_be_loadable(logger):
+    validate_python_control({
+        "name": "a-python-control",
+        "provider": {
+            "type": "python",
+            "module": "blah.blah"
+        }
+    })
+    args = logger.warning.call_args
+    msg = "Could not find Python module 'blah.blah' in control " \
+        "'a-python-control'. Did you install the Python module?"
+    assert msg in args[0][0]
 
 
 def test_validate_python_control_needs_a_module():