def CheckACrontab(self, arguments): log = check.LogCounter() (exp_warn, exp_fail, exp_rc) = self.GetExpWFRs(arguments.crontab) self.assertEquals(check.check_crontab(arguments, log), exp_rc, 'Failed to return %d for crontab errors.' % exp_rc) self.assertEquals(log.warn_count, exp_warn, 'Found %d warns not %d.' % (log.warn_count, exp_warn)) self.assertEquals(log.error_count, exp_fail, 'Found %d errors not %d.' % (log.error_count, exp_fail))
def CheckACrontab(self, crontab): log = check.LogCounter() crontab_file = os.path.join(BASE_PATH, crontab) (exp_warn, exp_fail, exp_rc) = self.GetExpWFRs(crontab_file) self.assertEquals(check.check_crontab(crontab_file, log), exp_rc, 'Failed to return %d for crontab errors.' % exp_rc) self.assertEquals(log.warn_count, exp_warn, 'Found %d warns not %d.' % (log.warn_count, exp_warn)) self.assertEquals(log.error_count, exp_fail, 'Found %d errors not %d.' % (log.error_count, exp_fail))
def CheckACrontab(self, crontab, whitelisted_users=None): log = check.LogCounter() crontab_file = os.path.join(BASE_PATH, crontab) (exp_warn, exp_fail, exp_rc) = self.GetExpWFRs(crontab_file) self.assertEquals( check.check_crontab(crontab_file, log, whitelisted_users), exp_rc, "Failed to return %d for crontab errors." % exp_rc, ) self.assertEquals(log.warn_count, exp_warn, "Found %d warns not %d." % (log.warn_count, exp_warn)) self.assertEquals(log.error_count, exp_fail, "Found %d errors not %d." % (log.error_count, exp_fail))
def test_crontab_files_valid(self): """Crontab files should pass validation.""" for filename in CRONTAB_FILES: cronlog = chkcrontab.LogCounter() return_value = chkcrontab.check_crontab(filename, cronlog) self.assertEqual(return_value, 0, 'Problem with ' + filename)
def validate_cron(file_path): whitelisted_users = None log = check.LogCounter() return check.check_crontab(file_path, log, whitelisted_users)