mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 00:55:19 +00:00
Updating ps beacon to use list based configuration. Adding unit tets.
This commit is contained in:
parent
a7c6c09ea9
commit
147fd7aaa3
@ -27,13 +27,23 @@ def __virtual__():
|
||||
return __virtualname__
|
||||
|
||||
|
||||
def __validate__(config):
|
||||
def validate(config):
|
||||
'''
|
||||
Validate the beacon configuration
|
||||
'''
|
||||
# Configuration for ps beacon should be a list of dicts
|
||||
if not isinstance(config, dict):
|
||||
return False, ('Configuration for ps beacon must be a dictionary.')
|
||||
if not isinstance(config, list):
|
||||
return False, ('Configuration for ps beacon must be a list.')
|
||||
else:
|
||||
_config = {}
|
||||
list(map(_config.update, config))
|
||||
|
||||
if 'processes' not in _config:
|
||||
return False, ('Configuration for ps beacon requires processes.')
|
||||
else:
|
||||
if not isinstance(_config['processes'], dict):
|
||||
return False, ('Processes for ps beacon must be a dictionary.')
|
||||
|
||||
return True, 'Valid beacon configuration'
|
||||
|
||||
|
||||
@ -47,8 +57,9 @@ def beacon(config):
|
||||
|
||||
beacons:
|
||||
ps:
|
||||
- salt-master: running
|
||||
- mysql: stopped
|
||||
- processes:
|
||||
salt-master: running
|
||||
mysql: stopped
|
||||
|
||||
The config above sets up beacons to check that
|
||||
processes are running or stopped.
|
||||
@ -60,19 +71,21 @@ def beacon(config):
|
||||
if _name not in procs:
|
||||
procs.append(_name)
|
||||
|
||||
for entry in config:
|
||||
for process in entry:
|
||||
ret_dict = {}
|
||||
if entry[process] == 'running':
|
||||
if process in procs:
|
||||
ret_dict[process] = 'Running'
|
||||
ret.append(ret_dict)
|
||||
elif entry[process] == 'stopped':
|
||||
if process not in procs:
|
||||
ret_dict[process] = 'Stopped'
|
||||
ret.append(ret_dict)
|
||||
else:
|
||||
if process not in procs:
|
||||
ret_dict[process] = False
|
||||
ret.append(ret_dict)
|
||||
_config = {}
|
||||
list(map(_config.update, config))
|
||||
|
||||
for process in _config.get('processes', {}):
|
||||
ret_dict = {}
|
||||
if _config['processes'][process] == 'running':
|
||||
if process in procs:
|
||||
ret_dict[process] = 'Running'
|
||||
ret.append(ret_dict)
|
||||
elif _config['processes'][process] == 'stopped':
|
||||
if process not in procs:
|
||||
ret_dict[process] = 'Stopped'
|
||||
ret.append(ret_dict)
|
||||
else:
|
||||
if process not in procs:
|
||||
ret_dict[process] = False
|
||||
ret.append(ret_dict)
|
||||
return ret
|
||||
|
Loading…
Reference in New Issue
Block a user