mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Fixing beacon state test. Adding a reset function to beacon module to clear out beacon configuration. Useful for tests runs to ensure bits are left over between runs.
This commit is contained in:
parent
2390f471ce
commit
c2354a9cb1
5 changed files with 54 additions and 3 deletions
|
@ -428,3 +428,9 @@ class Beacon(object):
|
|||
tag='/salt/minion/minion_beacon_disabled_complete')
|
||||
|
||||
return True
|
||||
|
||||
def reset(self):
|
||||
'''
|
||||
Reset the beacons to defaults
|
||||
'''
|
||||
self.opts['beacons'] = {}
|
||||
|
|
|
@ -2214,6 +2214,8 @@ class Minion(MinionBase):
|
|||
self.beacons.list_available_beacons()
|
||||
elif func == 'validate_beacon':
|
||||
self.beacons.validate_beacon(name, beacon_data)
|
||||
elif func == 'reset':
|
||||
self.beacons.reset()
|
||||
|
||||
def environ_setenv(self, tag, data):
|
||||
'''
|
||||
|
|
|
@ -571,3 +571,38 @@ def disable_beacon(name, **kwargs):
|
|||
# Effectively a no-op, since we can't really return without an event system
|
||||
ret['comment'] = 'Event module not available. Beacon disable job failed.'
|
||||
return ret
|
||||
|
||||
|
||||
def reset(**kwargs):
|
||||
'''
|
||||
Resest beacon configuration on the minion
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' beacons.reset
|
||||
'''
|
||||
|
||||
ret = {'comment': [],
|
||||
'result': True}
|
||||
|
||||
if 'test' in kwargs and kwargs['test']:
|
||||
ret['comment'] = 'Beacons would be reset.'
|
||||
else:
|
||||
try:
|
||||
eventer = salt.utils.event.get_event('minion', opts=__opts__)
|
||||
res = __salt__['event.fire']({'func': 'reset'}, 'manage_beacons')
|
||||
if res:
|
||||
event_ret = eventer.get_event(tag='/salt/minion/minion_beacon_reset_complete', wait=30)
|
||||
if event_ret and event_ret['complete']:
|
||||
ret['result'] = True
|
||||
ret['comment'] = 'Beacon configuration reset.'
|
||||
else:
|
||||
ret['result'] = False
|
||||
ret['comment'] = event_ret['comment']
|
||||
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 disable job failed.'
|
||||
return ret
|
||||
|
|
|
@ -31,6 +31,9 @@ class BeaconsAddDeleteTest(ModuleCase):
|
|||
if os.path.isfile(self.beacons_config_file_path):
|
||||
os.unlink(self.beacons_config_file_path)
|
||||
|
||||
# Reset beacons
|
||||
self.run_function('beacons.reset')
|
||||
|
||||
def test_add_and_delete(self):
|
||||
'''
|
||||
Test adding and deleting a beacon
|
||||
|
@ -81,6 +84,9 @@ class BeaconsTest(ModuleCase):
|
|||
self.run_function('beacons.delete', ['ps'])
|
||||
self.run_function('beacons.save')
|
||||
|
||||
# Reset beacons
|
||||
self.run_function('beacons.reset')
|
||||
|
||||
def test_disable(self):
|
||||
'''
|
||||
Test disabling beacons
|
||||
|
|
|
@ -23,10 +23,10 @@ class BeaconStateTestCase(ModuleCase, SaltReturnAssertsMixin):
|
|||
def setUp(self):
|
||||
'''
|
||||
'''
|
||||
pass
|
||||
self.run_function('beacons.reset')
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
self.run_function('beacons.reset')
|
||||
|
||||
def test_present_absent(self):
|
||||
kwargs = {'/': '38%', 'interval': 5}
|
||||
|
@ -38,7 +38,9 @@ class BeaconStateTestCase(ModuleCase, SaltReturnAssertsMixin):
|
|||
self.assertSaltTrueReturn(ret)
|
||||
|
||||
ret = self.run_function('beacons.list', return_yaml=False)
|
||||
self.assertEqual(ret, {'diskusage': [{'interval': 5}, {'/': u'38%'}]})
|
||||
self.assertTrue('diskusage' in ret)
|
||||
self.assertTrue({'interval': 5} in ret['diskusage'])
|
||||
self.assertTrue({'/': '38%'} in ret['diskusage'])
|
||||
|
||||
ret = self.run_state(
|
||||
'beacon.absent',
|
||||
|
|
Loading…
Add table
Reference in a new issue