Merge pull request #50514 from bornwitbugs/load_beacon_fix

Load beacon fix
This commit is contained in:
Gareth J. Greenaway 2018-11-14 11:20:32 -08:00 committed by GitHub
commit fa2f4a5595
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 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,12 +53,14 @@ 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': True,
'onchangeonly': False}]
ret = load.validate(config)
self.assertEqual(ret, (True, 'Valid beacon configuration'))
_expected_return = [{'15m': 1.56, '1m': 1.82, '5m': 1.84}]
_expected_return = [{'1m': 1.82, '5m': 1.84, '15m': 1.56}]
ret = load.beacon(config)
self.assertEqual(ret, _expected_return)