You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.4 KiB

  1. import logging
  2. _logger = logging.getLogger(__name__)
  3. class CheckResult(object):
  4. SUCCESS = "success"
  5. WARNING = "warning"
  6. FAIL = "fail"
  7. def __init__(self, result, message, details=None):
  8. super(CheckResult, self).__init__()
  9. self.result = result
  10. self.message = message
  11. self.details = details
  12. class CheckSuccess(CheckResult):
  13. def __init__(self, message, **kwargs):
  14. super(CheckSuccess, self).__init__(CheckResult.SUCCESS, message, **kwargs)
  15. class CheckIssue(CheckResult, Exception):
  16. def __init__(self, result, message, **kwargs):
  17. Exception.__init__(self, message)
  18. CheckResult.__init__(self, result, message, **kwargs)
  19. class CheckFail(CheckIssue):
  20. def __init__(self, message, **kwargs):
  21. super(CheckFail, self).__init__(CheckResult.FAIL, message, **kwargs)
  22. class CheckWarning(CheckIssue):
  23. def __init__(self, message, **kwargs):
  24. super(CheckWarning, self).__init__(CheckResult.WARNING, message, **kwargs)
  25. class Check(object):
  26. def __init__(self, module):
  27. self.module = module
  28. def run(self, env):
  29. try:
  30. return self._run(env)
  31. except CheckIssue as issue:
  32. return issue
  33. except Exception as ex:
  34. _logger.exception(ex)
  35. return CheckFail("Check failed when processing: {}".format(ex))
  36. def _run(self, env):
  37. raise NotImplementedError("Should be overriden by the subclass")