Merge pull request #31152 from garethgreenaway/30994_beacon_add_failing_and_other_fixes

fixes to beacon module, state module and friends
This commit is contained in:
Mike Place 2016-02-12 09:27:40 -07:00
commit f5ab76801b
14 changed files with 78 additions and 79 deletions

View File

@ -56,8 +56,10 @@ def validate(config):
'''
# Configuration for load beacon should be a list of dicts
if not isinstance(config, dict):
return False, ('Configuration for btmp beacon must '
'be a list of dictionaries.')
return False
return True
return True, 'Valid beacon configuration'
# TODO: add support for only firing events for specific users and login times

View File

@ -42,9 +42,9 @@ def validate(config):
'''
# Configuration for diskusage beacon should be a list of dicts
if not isinstance(config, dict):
log.info('Configuration for diskusage beacon must be a dictionary.')
return False
return True
return False, ('Configuration for diskusage beacon '
'must be a dictionary.')
return True, 'Valid beacon configuration'
def beacon(config):

View File

@ -95,44 +95,39 @@ def validate(config):
]
# Configuration for diskusage beacon should be a list of dicts
log.debug('config {0}'.format(config))
if not isinstance(config, dict):
log.info('Configuration for inotify beacon must be a dictionary.')
return False
return False, 'Configuration for inotify beacon must be a dictionary.'
else:
for config_item in config:
if not isinstance(config[config_item], dict):
log.info('Configuration for inotify beacon must '
'be a dictionary of dictionaries.')
return False
return False, ('Configuration for inotify beacon must '
'be a dictionary of dictionaries.')
else:
if not any(j in ['mask', 'recurse', 'auto_add'] for j in config[config_item]):
log.info('Configuration for inotify beacon must '
'contain mask, recurse or auto_add items.')
return False
return False, ('Configuration for inotify beacon '
'must contain mask, recurse or auto_add items.')
if 'auto_add' in config[config_item]:
if not isinstance(config[config_item]['auto_add'], bool):
log.info('Configuration for inotify beacon '
'auto_add must be boolean.')
return False
return False, ('Configuration for inotify beacon '
'auto_add must be boolean.')
if 'recurse' in config[config_item]:
if not isinstance(config[config_item]['recurse'], bool):
log.info('Configuration for inotify beacon '
'recurse must be boolean.')
return False
return False, ('Configuration for inotify beacon '
' recurse must be boolean.')
if 'mask' in config[config_item]:
if not isinstance(config[config_item]['mask'], list):
log.info('Configuration for inotify beacon '
'mask must be list.')
return False
return False, ('Configuration for inotify beacon '
' mask must be list.')
for mask in config[config_item]['mask']:
if mask not in VALID_MASK:
log.info('Configuration for inotify beacon '
'invalid mask option {0}.'.format(mask))
return False
return True
return False, ('Configuration for inotify beacon '
'invalid mask option {0}.'.format(mask))
return True, 'Valid beacon configuration'
def beacon(config):

View File

@ -54,10 +54,9 @@ def validate(config):
else:
for item in config:
if not isinstance(config[item], dict):
log.info('Configuration for journald beacon must '
'be a dictionary of dictionaries.')
return False
return True
return False, ('Configuration for journald beacon must '
'be a dictionary of dictionaries.')
return True, 'Valid beacon configuration'
def beacon(config):

View File

@ -33,33 +33,28 @@ def validate(config):
# Configuration for load beacon should be a list of dicts
if not isinstance(config, list):
log.info('Configuration for load beacon must be a list.')
return False
return False, ('Configuration for load beacon must be a list.')
else:
for config_item in config:
if not isinstance(config_item, dict):
log.info('Configuration for load beacon must '
'be a list of dictionaries.')
return False
return False, ('Configuration for load beacon must '
'be a list of dictionaries.')
else:
if not any(j in ['1m', '5m', '15m'] for j in config_item.keys()):
log.info('Configuration for load beacon must '
'contain 1m, 5m and 15m items.')
return False
return False, ('Configuration for load beacon must '
'contain 1m, 5m and 15m items.')
for item in config_item:
if not isinstance(config_item[item], list):
log.info('Configuration for load beacon: '
'1m, 5m and 15m items must be '
'a list of two items.')
return False
return False, ('Configuration for load beacon: '
'1m, 5m and 15m items must be '
'a list of two items.')
else:
if len(config_item[item]) != 2:
log.info('Configuration for load beacon: '
'1m, 5m and 15m items must be '
'a list of two items.')
return False
return True
return False, ('Configuration for load beacon: '
'1m, 5m and 15m items must be '
'a list of two items.')
return True, 'Valid beacon configuration'
def beacon(config):

View File

@ -48,20 +48,17 @@ def validate(config):
# Configuration for load beacon should be a list of dicts
if not isinstance(config, dict):
log.info('Configuration for load beacon must be a dictionary.')
return False
return False, ('Configuration for load beacon must be a dictionary.')
else:
for item in config:
if not isinstance(config[item], dict):
log.info('Configuration for load beacon must '
'be a dictionary of dictionaries.')
return False
return False, ('Configuration for load beacon must '
'be a dictionary of dictionaries.')
else:
if not any(j in VALID_ITEMS for j in config[item]):
log.info('Invalid configuration item in '
'Beacon configuration.')
return False
return True
return False, ('Invalid configuration item in '
'Beacon configuration.')
return True, 'Valid beacon configuration'
def beacon(config):

View File

@ -38,9 +38,8 @@ def validate(config):
Validate the beacon configuration
'''
if not isinstance(config, dict):
log.info('Configuration for rest_example beacon must be a dictionary.')
return False
return True
return False, ('Configuration for rest_example beacon must be a dictionary.')
return True, 'Valid beacon configuration'
def beacon(config):

View File

@ -18,9 +18,8 @@ def validate(config):
'''
# Configuration for ps beacon should be a list of dicts
if not isinstance(config, dict):
log.info('Configuration for ps beacon must be a dictionary.')
return False
return True
return False, ('Configuration for ps beacon must be a dictionary.')
return True, 'Valid beacon configuration'
def beacon(config):

View File

@ -20,9 +20,8 @@ def validate(config):
'''
# Configuration for service beacon should be a list of dicts
if not isinstance(config, dict):
log.info('Configuration for service beacon must be a dictionary.')
return False
return True
return False, ('Configuration for service beacon must be a dictionary.')
return True, 'Valid beacon configuration'
def beacon(config):

View File

@ -47,9 +47,8 @@ def validate(config):
'''
# Configuration for sh beacon should be a list of dicts
if not isinstance(config, dict):
log.info('Configuration for sh beacon must be a dictionary.')
return False
return True
return False, ('Configuration for sh beacon must be a dictionary.')
return True, 'Valid beacon configuration'
def beacon(config):

View File

@ -32,9 +32,9 @@ def validate(config):
'''
# Configuration for twilio_txt_msg beacon should be a list of dicts
if not isinstance(config, dict):
log.info('Configuration for twilio_txt_msg beacon must be a dictionary.')
return False
return True
return False, ('Configuration for twilio_txt_msg beacon '
'must be a dictionary.')
return True, 'Valid beacon configuration'
def beacon(config):

View File

@ -61,9 +61,8 @@ def validate(config):
'''
# Configuration for wtmp beacon should be a list of dicts
if not isinstance(config, dict):
log.info('Configuration for wtmp beacon must be a dictionary.')
return False
return True
return False, ('Configuration for wtmp beacon must be a dictionary.')
return True, 'Valid beacon configuration'
# TODO: add support for only firing events for specific users and login times

View File

@ -100,14 +100,19 @@ def add(name, beacon_data, **kwargs):
# Attempt to validate
if hasattr(beacon_module, 'validate'):
valid = beacon_module.validate(beacon_data)
_beacon_data = beacon_data
if 'enabled' in _beacon_data:
del _beacon_data['enabled']
valid, vcomment = beacon_module.validate(_beacon_data)
else:
log.info('Beacon {0} does not have a validate'
' function, skipping validation.'.format(name))
valid = True
if not valid:
ret['comment'] = 'Beacon {0} configuration invalid, not adding.'.format(name)
ret['result'] = False
ret['comment'] = ('Beacon {0} configuration invalid, '
'not adding.\n{1}'.format(name, vcomment))
return ret
try:
@ -164,14 +169,19 @@ def modify(name, beacon_data, **kwargs):
# Attempt to validate
if hasattr(beacon_module, 'validate'):
valid = beacon_module.validate(beacon_data)
_beacon_data = beacon_data
if 'enabled' in _beacon_data:
del _beacon_data['enabled']
valid, vcomment = beacon_module.validate(_beacon_data)
else:
log.info('Beacon {0} does not have a validate'
' function, skipping validation.'.format(name))
valid = True
if not valid:
ret['comment'] = 'Beacon {0} configuration invalid, not modifying.'.format(name)
ret['result'] = False
ret['comment'] = ('Beacon {0} configuration invalid, '
'not adding.\n{1}'.format(name, vcomment))
return ret
_current = current_beacons[name]

View File

@ -30,6 +30,9 @@ Management of the Salt beacons
'''
import logging
log = logging.getLogger(__name__)
def present(name,
**kwargs):
@ -66,8 +69,11 @@ def present(name,
ret['comment'] = result['comment']
return ret
else:
ret['comment'].append('Modifying {0} in beacons'.format(name))
ret['changes'] = result['changes']
if 'changes' in result:
ret['comment'].append('Modifying {0} in beacons'.format(name))
ret['changes'] = result['changes']
else:
ret['comment'].append(result['comment'])
else:
if 'test' in __opts__ and __opts__['test']:
kwargs['test'] = True