test_beacons.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 logging
  8. # Import Salt Libs
  9. import salt.beacons as beacons
  10. import salt.config
  11. # Import Salt Testing Libs
  12. from tests.support.mixins import LoaderModuleMockMixin
  13. from tests.support.mock import patch
  14. from tests.support.unit import TestCase
  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"] = {
  30. "watch_apache": [
  31. {"processes": {"apache2": "stopped"}},
  32. {"beacon_module": "ps"},
  33. ]
  34. }
  35. with patch.dict(beacons.__opts__, mock_opts):
  36. ret = salt.beacons.Beacon(mock_opts, []).process(
  37. mock_opts["beacons"], mock_opts["grains"]
  38. )
  39. _expected = [
  40. {
  41. "tag": "salt/beacon/minion/watch_apache/",
  42. "data": {"id": "minion", "apache2": "Stopped"},
  43. "beacon_name": "ps",
  44. }
  45. ]
  46. self.assertEqual(ret, _expected)