Fix time machine config validator on old-style config
Existing config won't have the keys defined, so make sure we skip in that case (and just use the defaults)
This commit is contained in:
parent
66b98e5380
commit
4ea4ee3aa4
2 changed files with 13 additions and 3 deletions
|
@ -2,7 +2,13 @@ import pytest
|
|||
|
||||
from util.config.validators import ConfigValidationException
|
||||
from util.config.validators.validate_timemachine import TimeMachineValidator
|
||||
from util.morecollections import AttrDict
|
||||
|
||||
@pytest.mark.parametrize('unvalidated_config', [
|
||||
({}),
|
||||
])
|
||||
def test_validate_noop(unvalidated_config):
|
||||
TimeMachineValidator.validate(unvalidated_config, None, None)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('default_exp,options,expected_exception', [
|
||||
('2d', ['1w', '2d'], None),
|
||||
|
|
|
@ -10,15 +10,19 @@ class TimeMachineValidator(BaseValidator):
|
|||
|
||||
@classmethod
|
||||
def validate(cls, config, user, user_password):
|
||||
if not 'DEFAULT_TAG_EXPIRATION' in config:
|
||||
# Old style config
|
||||
return
|
||||
|
||||
try:
|
||||
convert_to_timedelta(config['DEFAULT_TAG_EXPIRATION']).total_seconds()
|
||||
except ValueError as ve:
|
||||
raise ConfigValidationException('Invalid default expiration: %s' % ve.message)
|
||||
|
||||
if not config['DEFAULT_TAG_EXPIRATION'] in config['TAG_EXPIRATION_OPTIONS']:
|
||||
if not config['DEFAULT_TAG_EXPIRATION'] in config.get('TAG_EXPIRATION_OPTIONS', []):
|
||||
raise ConfigValidationException('Default expiration must be in expiration options set')
|
||||
|
||||
for ts in config['TAG_EXPIRATION_OPTIONS']:
|
||||
for ts in config.get('TAG_EXPIRATION_OPTIONS', []):
|
||||
try:
|
||||
convert_to_timedelta(ts)
|
||||
except ValueError as ve:
|
||||
|
|
Reference in a new issue