test_status.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # -*- coding: utf-8 -*-
  2. """
  3. :codeauthor: Pedro Algarvio (pedro@algarvio.me)
  4. :copyright: Copyright 2017 by the SaltStack Team, see AUTHORS for more details.
  5. tests.unit.beacons.test_status
  6. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. Status beacon test cases
  8. """
  9. # Python libs
  10. from __future__ import absolute_import
  11. import pytest
  12. # Salt libs
  13. import salt.config
  14. import salt.loader
  15. import salt.modules.status as status_module
  16. from salt.beacons import status
  17. from tests.support.mixins import LoaderModuleMockMixin
  18. # Salt testing libs
  19. from tests.support.unit import TestCase
  20. class StatusBeaconTestCase(TestCase, LoaderModuleMockMixin):
  21. """
  22. Test case for salt.beacons.status
  23. """
  24. def setup_loader_modules(self):
  25. opts = salt.config.DEFAULT_MINION_OPTS.copy()
  26. opts["grains"] = salt.loader.grains(opts)
  27. module_globals = {
  28. "__opts__": opts,
  29. "__salt__": "autoload",
  30. "__context__": {},
  31. "__grains__": opts["grains"],
  32. }
  33. return {status: module_globals, status_module: module_globals}
  34. @pytest.mark.slow_test(seconds=60) # Test takes >30 and <=60 seconds
  35. def test_empty_config(self, *args, **kwargs):
  36. config = []
  37. ret = status.validate(config)
  38. self.assertEqual(ret, (True, "Valid beacon configuration"))
  39. ret = status.beacon(config)
  40. expected = sorted(["loadavg", "meminfo", "cpustats", "vmstats", "time"])
  41. self.assertEqual(sorted(list(ret[0]["data"])), expected)
  42. @pytest.mark.slow_test(seconds=60) # Test takes >30 and <=60 seconds
  43. def test_deprecated_dict_config(self):
  44. config = {"time": ["all"]}
  45. ret = status.validate(config)
  46. self.assertEqual(
  47. ret, (False, "Configuration for status beacon must be a list.")
  48. )
  49. @pytest.mark.slow_test(seconds=60) # Test takes >30 and <=60 seconds
  50. def test_list_config(self):
  51. config = [{"time": ["all"]}]
  52. ret = status.validate(config)
  53. self.assertEqual(ret, (True, "Valid beacon configuration"))
  54. ret = status.beacon(config)
  55. expected = ["time"]
  56. self.assertEqual(list(ret[0]["data"]), expected)