Merge "New cron type for audit interval"

This commit is contained in:
Jenkins
2017-07-19 02:46:25 +00:00
committed by Gerrit Code Review
20 changed files with 326 additions and 54 deletions

View File

@@ -202,6 +202,10 @@ class InvalidUuidOrName(Invalid):
msg_fmt = _("Expected a logical name or uuid but received %(name)s")
class InvalidIntervalOrCron(Invalid):
msg_fmt = _("Expected an interval or cron syntax but received %(name)s")
class GoalNotFound(ResourceNotFound):
msg_fmt = _("Goal %(goal)s could not be found")
@@ -418,6 +422,10 @@ class WildcardCharacterIsUsed(WatcherException):
"wildcard character.")
class CronFormatIsInvalid(WatcherException):
msg_fmt = _("Provided cron is invalid: %(message)s")
# Model
class ComputeResourceNotFound(WatcherException):

View File

@@ -16,8 +16,11 @@
"""Utilities and helper functions."""
import datetime
import re
from croniter import croniter
from jsonschema import validators
from oslo_log import log as logging
from oslo_utils import strutils
@@ -63,6 +66,15 @@ is_int_like = strutils.is_int_like
strtime = timeutils.strtime
def is_cron_like(value):
"""Return True is submitted value is like cron syntax"""
try:
croniter(value, datetime.datetime.now())
except Exception as e:
raise exception.CronFormatIsInvalid(message=str(e))
return True
def safe_rstrip(value, chars=None):
"""Removes trailing characters from a string if that does not make it empty