fixing type in load beacon module and adding option validators to config check function along with mock default values in test

This commit is contained in:
Antonio Jordan 2018-11-02 18:22:55 +00:00
parent 3ffa3921b7
commit 4114a4f5d8
No known key found for this signature in database
GPG key ID: 3394CD9220E4CB8C
2 changed files with 15 additions and 2 deletions

View file

@ -41,6 +41,16 @@ def validate(config):
_config = {}
list(map(_config.update, config))
if 'emitatstartup' in _config:
if not isinstance(_config['emitatstartup'], bool):
return False, ('Configuration for load beacon option '
'emitatstartup must be a boolean.')
if 'onchangeonly' in _config:
if not isinstance(_config['onchangeonly'], bool):
return False, ('Configuration for load beacon option '
'onchangeonly must be a boolean.')
if 'averages' not in _config:
return False, ('Averages configuration is required'
' for load beacon.')
@ -61,6 +71,7 @@ def validate(config):
return False, ('Configuration for load beacon: '
'1m, 5m and 15m items must be '
'a list of two items.')
return True, 'Valid beacon configuration'
@ -118,7 +129,7 @@ def beacon(config):
if not LAST_STATUS:
for k in ['1m', '5m', '15m']:
LAST_STATUS[k] = avg_dict[k]
if not config['emitatstartup']:
if not _config['emitatstartup']:
log.debug("Don't emit because emitatstartup is False")
return ret

View file

@ -53,7 +53,9 @@ class LoadBeaconTestCase(TestCase, LoaderModuleMockMixin):
MagicMock(return_value=(1.82, 1.84, 1.56))):
config = [{'averages': {'1m': [0.0, 2.0],
'5m': [0.0, 1.5],
'15m': [0.0, 1.0]}}]
'15m': [0.0, 1.0]},
'emitatstartup': False,
'onchangeonly': False}]
ret = load.validate(config)