mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 17:33:54 +00:00
Moving code in the add method into the else section of the if...else clause. Adding check in the delete method that the beacon was really deleted.
This commit is contained in:
parent
371643f9d4
commit
6ce0af05d5
@ -106,4 +106,10 @@ class Beacon(object):
|
|||||||
if name in self.opts['beacons']:
|
if name in self.opts['beacons']:
|
||||||
log.info('Deleting beacon item {0}'.format(name))
|
log.info('Deleting beacon item {0}'.format(name))
|
||||||
del self.opts['beacons'][name]
|
del self.opts['beacons'][name]
|
||||||
|
|
||||||
|
# Fire the complete event back along with updated list of beacons
|
||||||
|
evt = salt.utils.event.get_event('minion', opts=self.opts)
|
||||||
|
evt.fire_event({'complete': True, 'beacons': self.opts['beacons']},
|
||||||
|
tag='/salt/minion/minion_beacon_delete_complete')
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@ -62,13 +62,13 @@ def add(name, beacon_data, **kwargs):
|
|||||||
salt '*' beacons.add
|
salt '*' beacons.add
|
||||||
|
|
||||||
'''
|
'''
|
||||||
ret = {'comment': 'Failed to add beacon.',
|
ret = {'comment': 'Failed to add beacon {0}.'.format(name),
|
||||||
'result': False}
|
'result': False}
|
||||||
|
|
||||||
if 'test' in kwargs and kwargs['test']:
|
if 'test' in kwargs and kwargs['test']:
|
||||||
|
ret['result'] = True
|
||||||
ret['comment'] = 'Beacon: {0} would be added.'.format(name)
|
ret['comment'] = 'Beacon: {0} would be added.'.format(name)
|
||||||
else:
|
else:
|
||||||
|
|
||||||
# Attempt to load the beacon module so we have access to the validate function
|
# Attempt to load the beacon module so we have access to the validate function
|
||||||
try:
|
try:
|
||||||
beacon_module = __import__('salt.beacons.' + name, fromlist=['validate'])
|
beacon_module = __import__('salt.beacons.' + name, fromlist=['validate'])
|
||||||
@ -89,20 +89,20 @@ def add(name, beacon_data, **kwargs):
|
|||||||
ret['comment'] = 'Beacon {0} configuration invalid, not adding.'.format(name)
|
ret['comment'] = 'Beacon {0} configuration invalid, not adding.'.format(name)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
try:
|
try:
|
||||||
eventer = salt.utils.event.get_event('minion', opts=__opts__)
|
eventer = salt.utils.event.get_event('minion', opts=__opts__)
|
||||||
res = __salt__['event.fire']({'name': name, 'beacon_data': beacon_data, 'func': 'add'}, 'manage_beacons')
|
res = __salt__['event.fire']({'name': name, 'beacon_data': beacon_data, 'func': 'add'}, 'manage_beacons')
|
||||||
if res:
|
if res:
|
||||||
event_ret = eventer.get_event(tag='/salt/minion/minion_beacon_add_complete', wait=30)
|
event_ret = eventer.get_event(tag='/salt/minion/minion_beacon_add_complete', wait=30)
|
||||||
if event_ret and event_ret['complete']:
|
if event_ret and event_ret['complete']:
|
||||||
beacons = event_ret['beacons']
|
beacons = event_ret['beacons']
|
||||||
if name in beacons and beacons[name] == beacon_data:
|
if name in beacons and beacons[name] == beacon_data:
|
||||||
ret['result'] = True
|
ret['result'] = True
|
||||||
ret['comment'] = 'Added beacon: {0}.'.format(name)
|
ret['comment'] = 'Added beacon: {0}.'.format(name)
|
||||||
return ret
|
return ret
|
||||||
except KeyError:
|
except KeyError:
|
||||||
# Effectively a no-op, since we can't really return without an event system
|
# Effectively a no-op, since we can't really return without an event system
|
||||||
ret['comment'] = 'Event module not available. Beacon add failed.'
|
ret['comment'] = 'Event module not available. Beacon add failed.'
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
@ -120,16 +120,25 @@ def delete(name, **kwargs):
|
|||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
ret = {'comment': [],
|
ret = {'comment': 'Failed to delete beacon {0}.'.format(name),
|
||||||
'result': True}
|
'result': False}
|
||||||
|
|
||||||
if 'test' in kwargs and kwargs['test']:
|
if 'test' in kwargs and kwargs['test']:
|
||||||
|
ret['result'] = True
|
||||||
ret['comment'] = 'Beacon: {0} would be deleted.'.format(name)
|
ret['comment'] = 'Beacon: {0} would be deleted.'.format(name)
|
||||||
else:
|
else:
|
||||||
out = __salt__['event.fire']({'name': name, 'func': 'delete'}, 'manage_beacons')
|
try:
|
||||||
if out:
|
eventer = salt.utils.event.get_event('minion', opts=__opts__)
|
||||||
ret['comment'] = 'Deleted beacon: {0}.'.format(name)
|
res = __salt__['event.fire']({'name': name, 'func': 'delete'}, 'manage_beacons')
|
||||||
else:
|
if res:
|
||||||
ret['comment'] = 'Failed to delete beacon {0}.'.format(name)
|
event_ret = eventer.get_event(tag='/salt/minion/minion_beacon_delete_complete', wait=30)
|
||||||
ret['result'] = False
|
if event_ret and event_ret['complete']:
|
||||||
|
beacons = event_ret['beacons']
|
||||||
|
if name not in beacons:
|
||||||
|
ret['result'] = True
|
||||||
|
ret['comment'] = 'Deleted beacon: {0}.'.format(name)
|
||||||
|
return ret
|
||||||
|
except KeyError:
|
||||||
|
# Effectively a no-op, since we can't really return without an event system
|
||||||
|
ret['comment'] = 'Event module not available. Beacon add failed.'
|
||||||
return ret
|
return ret
|
||||||
|
Loading…
Reference in New Issue
Block a user