diff options
author | Luke Meyer <lmeyer@redhat.com> | 2017-07-20 23:39:47 -0400 |
---|---|---|
committer | Luke Meyer <lmeyer@redhat.com> | 2017-08-02 15:03:50 -0400 |
commit | 06a6fb9642a2cc70b1ca65f403b853fe8ce9d4b2 (patch) | |
tree | 4631e75c28017e238ff84756f6cfdeb72563259a /roles/openshift_health_checker/openshift_checks/__init__.py | |
parent | bf0828bc0f2e3088df20abc77e30a162595e1c22 (diff) | |
download | openshift-06a6fb9642a2cc70b1ca65f403b853fe8ce9d4b2.tar.gz openshift-06a6fb9642a2cc70b1ca65f403b853fe8ce9d4b2.tar.bz2 openshift-06a6fb9642a2cc70b1ca65f403b853fe8ce9d4b2.tar.xz openshift-06a6fb9642a2cc70b1ca65f403b853fe8ce9d4b2.zip |
openshift_checks: refactor logging checks
Turn failure messages into exceptions that tests can look for without
depending on text meant for humans.
Turn logging_namespace property into a method.
Get rid of _exec_oc and just use logging.exec_oc.
Diffstat (limited to 'roles/openshift_health_checker/openshift_checks/__init__.py')
-rw-r--r-- | roles/openshift_health_checker/openshift_checks/__init__.py | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/roles/openshift_health_checker/openshift_checks/__init__.py b/roles/openshift_health_checker/openshift_checks/__init__.py index 5d289e522..f26008c9f 100644 --- a/roles/openshift_health_checker/openshift_checks/__init__.py +++ b/roles/openshift_health_checker/openshift_checks/__init__.py @@ -13,8 +13,30 @@ from ansible.module_utils.six.moves import reduce # pylint: disable=import-erro class OpenShiftCheckException(Exception): - """Raised when a check cannot proceed.""" - pass + """Raised when a check encounters a failure condition.""" + + def __init__(self, name, msg=None): + # msg is for the message the user will see when this is raised. + # name is for test code to identify the error without looking at msg text. + if msg is None: # for parameter backward compatibility + msg = name + name = self.__class__.__name__ + self.name = name + super(OpenShiftCheckException, self).__init__(msg) + + +class OpenShiftCheckExceptionList(OpenShiftCheckException): + """A container for multiple logging errors that may be detected in one check.""" + def __init__(self, errors): + self.errors = errors + super(OpenShiftCheckExceptionList, self).__init__( + 'OpenShiftCheckExceptionList', + '\n'.join(str(msg) for msg in errors) + ) + + # make iterable + def __getitem__(self, index): + return self.errors[index] @six.add_metaclass(ABCMeta) @@ -34,7 +56,8 @@ class OpenShiftCheck(object): self._execute_module = execute_module self.task_vars = task_vars or {} self.tmp = tmp - # set True when the check makes a change to the host so it can be reported to the user: + + # set to True when the check changes the host, for accurate total "changed" count self.changed = False @abstractproperty |