mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
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:
parent
3ffa3921b7
commit
4114a4f5d8
2 changed files with 15 additions and 2 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue