Updating the beacon state module to ensure that the format of the beacon data that is being sent along to the beacon execution module is in the right format.

This commit is contained in:
Gareth J. Greenaway 2018-11-01 15:02:21 -07:00
parent 12de4b99d4
commit f3dee43bf0
No known key found for this signature in database
GPG Key ID: 10B62F8A7CAD7A41
3 changed files with 58 additions and 3 deletions

View File

@ -134,7 +134,7 @@ def add(name, beacon_data, **kwargs):
.. code-block:: bash
salt '*' beacons.add ps "[{'salt-master': 'stopped', 'apache2': 'stopped'}]"
salt '*' beacons.add ps "[{'salt-master': 'stopped'}, {'apache2': 'stopped'}]"
'''
ret = {'comment': 'Failed to add beacon {0}.'.format(name),
@ -207,7 +207,7 @@ def modify(name, beacon_data, **kwargs):
.. code-block:: bash
salt '*' beacons.modify ps "[{'salt-master': 'stopped', 'apache2': 'stopped'}]"
salt '*' beacons.modify ps "[{'salt-master': 'stopped'}, {'apache2': 'stopped'}]"
'''
ret = {'comment': '',

View File

@ -34,6 +34,12 @@ Management of the Salt beacons
'''
from __future__ import absolute_import, print_function, unicode_literals
# Import Salt libs
from salt.ext import six
import logging
log = logging.getLogger(__name__)
def present(name,
save=False,
@ -54,7 +60,7 @@ def present(name,
'comment': []}
current_beacons = __salt__['beacons.list'](return_yaml=False)
beacon_data = [kwargs]
beacon_data = [{k: v} for k, v in six.iteritems(kwargs)]
if name in current_beacons:

View File

@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-
'''
Integration tests for the beacon states
'''
# Import Python Libs
from __future__ import absolute_import, print_function, unicode_literals
# Import Salt Testing Libs
from tests.support.case import ModuleCase
from tests.support.helpers import destructiveTest
import logging
log = logging.getLogger(__name__)
@destructiveTest
class BeaconStateTestCase(ModuleCase):
'''
Test zookeeper states
'''
def setUp(self):
'''
'''
pass
def tearDown(self):
pass
def test_present_absent(self):
kwargs = {'/': '38%', 'interval': 5}
ret = self.run_state(
'beacon.present',
name='diskusage',
**kwargs
)
self.assertSaltTrueReturn(ret)
ret = self.run_function('beacons.list', return_yaml=False)
self.assertEqual(ret, {'diskusage': [{'interval': 5}, {'/': u'38%'}]})
ret = self.run_state(
'beacon.absent',
name='diskusage',
)
self.assertSaltTrueReturn(ret)
ret = self.run_function('beacons.list', return_yaml=False)
self.assertEqual(ret, {'beacons': {}})