1
0

test_beacons.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # -*- coding: utf-8 -*-
  2. '''
  3. unit tests for the beacon_module parameter
  4. '''
  5. # Import Python libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. # Import Salt Testing Libs
  8. from tests.support.mixins import LoaderModuleMockMixin
  9. from tests.support.unit import TestCase
  10. from tests.support.mock import patch
  11. # Import Salt Libs
  12. import salt.beacons as beacons
  13. import salt.config
  14. import logging
  15. log = logging.getLogger(__name__)
  16. class BeaconsTestCase(TestCase, LoaderModuleMockMixin):
  17. '''
  18. Test cases for salt beacon_module parameter
  19. '''
  20. def setup_loader_modules(self):
  21. return {beacons: {}}
  22. def test_beacon_module(self):
  23. '''
  24. Test that beacon_module parameter for beacon configuration
  25. '''
  26. mock_opts = salt.config.DEFAULT_MINION_OPTS.copy()
  27. mock_opts['id'] = 'minion'
  28. mock_opts['__role'] = 'minion'
  29. mock_opts['beacons'] = {'watch_apache': [{'processes': {'apache2': 'stopped'}},
  30. {'beacon_module': 'ps'}]}
  31. with patch.dict(beacons.__opts__, mock_opts):
  32. ret = salt.beacons.Beacon(mock_opts, []).process(mock_opts['beacons'], mock_opts['grains'])
  33. _expected = [{'tag': 'salt/beacon/minion/watch_apache/',
  34. 'data': {'id': u'minion', u'apache2': u'Stopped'},
  35. 'beacon_name': 'ps'}]
  36. self.assertEqual(ret, _expected)