diff options
Diffstat (limited to 'roles')
| -rw-r--r-- | roles/openshift_health_checker/action_plugins/openshift_health_check.py | 17 | ||||
| -rw-r--r-- | roles/openshift_health_checker/test/action_plugin_test.py | 16 | 
2 files changed, 24 insertions, 9 deletions
| diff --git a/roles/openshift_health_checker/action_plugins/openshift_health_check.py b/roles/openshift_health_checker/action_plugins/openshift_health_check.py index a1df9cea3..a62e4331e 100644 --- a/roles/openshift_health_checker/action_plugins/openshift_health_check.py +++ b/roles/openshift_health_checker/action_plugins/openshift_health_check.py @@ -57,17 +57,18 @@ class ActionModule(ActionBase):              display.banner("CHECK [{} : {}]".format(check_name, task_vars["ansible_host"]))              check = known_checks[check_name] -            if check_name not in user_disabled_checks and check.is_active(task_vars): +            if not check.is_active(task_vars): +                r = dict(skipped=True, skipped_reason="Not active for this host") +            elif check_name in user_disabled_checks: +                r = dict(skipped=True, skipped_reason="Disabled by user request") +            else:                  try:                      r = check.run(tmp, task_vars)                  except OpenShiftCheckException as e: -                    r = {} -                    r["failed"] = True -                    r["msg"] = str(e) -            else: -                # TODO(rhcarvalho): we may want to provide some distinctive -                # complementary message to know why a check was skipped. -                r = {"skipped": True} +                    r = dict( +                        failed=True, +                        msg=str(e), +                    )              check_results[check_name] = r diff --git a/roles/openshift_health_checker/test/action_plugin_test.py b/roles/openshift_health_checker/test/action_plugin_test.py index 2693ae37b..6ebf0ebb2 100644 --- a/roles/openshift_health_checker/test/action_plugin_test.py +++ b/roles/openshift_health_checker/test/action_plugin_test.py @@ -67,6 +67,7 @@ def changed(result):      return result.get('changed', False) +# tests whether task is skipped, not individual checks  def skipped(result):      return result.get('skipped', False) @@ -101,7 +102,20 @@ def test_action_plugin_skip_non_active_checks(plugin, task_vars, monkeypatch):      result = plugin.run(tmp=None, task_vars=task_vars) -    assert result['checks']['fake_check'] == {'skipped': True} +    assert result['checks']['fake_check'] == dict(skipped=True, skipped_reason="Not active for this host") +    assert not failed(result) +    assert not changed(result) +    assert not skipped(result) + + +def test_action_plugin_skip_disabled_checks(plugin, task_vars, monkeypatch): +    checks = [fake_check('fake_check', is_active=True)] +    monkeypatch.setattr('openshift_checks.OpenShiftCheck.subclasses', classmethod(lambda cls: checks)) + +    task_vars['openshift_disable_check'] = 'fake_check' +    result = plugin.run(tmp=None, task_vars=task_vars) + +    assert result['checks']['fake_check'] == dict(skipped=True, skipped_reason="Disabled by user request")      assert not failed(result)      assert not changed(result)      assert not skipped(result) | 
