From 4ea4ee3aa4a923c1c1c969350c2db3a0e46881e7 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Thu, 27 Apr 2017 14:24:47 -0400 Subject: [PATCH] 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) --- util/config/validators/test/test_validate_timemachine.py | 8 +++++++- util/config/validators/validate_timemachine.py | 8 ++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/util/config/validators/test/test_validate_timemachine.py b/util/config/validators/test/test_validate_timemachine.py index 843e4955b..ebf9cec10 100644 --- a/util/config/validators/test/test_validate_timemachine.py +++ b/util/config/validators/test/test_validate_timemachine.py @@ -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), diff --git a/util/config/validators/validate_timemachine.py b/util/config/validators/validate_timemachine.py index ff96f9de1..750e1695e 100644 --- a/util/config/validators/validate_timemachine.py +++ b/util/config/validators/validate_timemachine.py @@ -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: