1
0

test_status.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. from __future__ import absolute_import
  10. import salt.config
  11. import salt.loader
  12. import salt.modules.status as status_module
  13. from salt.beacons import status
  14. from tests.support.helpers import slowTest
  15. from tests.support.mixins import LoaderModuleMockMixin
  16. from tests.support.unit import TestCase
  17. class StatusBeaconTestCase(TestCase, LoaderModuleMockMixin):
  18. """
  19. Test case for salt.beacons.status
  20. """
  21. def setup_loader_modules(self):
  22. opts = salt.config.DEFAULT_MINION_OPTS.copy()
  23. opts["grains"] = salt.loader.grains(opts)
  24. module_globals = {
  25. "__opts__": opts,
  26. "__salt__": "autoload",
  27. "__context__": {},
  28. "__grains__": opts["grains"],
  29. }
  30. return {status: module_globals, status_module: module_globals}
  31. @slowTest
  32. def test_empty_config(self, *args, **kwargs):
  33. config = []
  34. ret = status.validate(config)
  35. self.assertEqual(ret, (True, "Valid beacon configuration"))
  36. ret = status.beacon(config)
  37. expected = sorted(["loadavg", "meminfo", "cpustats", "vmstats", "time"])
  38. self.assertEqual(sorted(list(ret[0]["data"])), expected)
  39. @slowTest
  40. def test_deprecated_dict_config(self):
  41. config = {"time": ["all"]}
  42. ret = status.validate(config)
  43. self.assertEqual(
  44. ret, (False, "Configuration for status beacon must be a list.")
  45. )
  46. @slowTest
  47. def test_list_config(self):
  48. config = [{"time": ["all"]}]
  49. ret = status.validate(config)
  50. self.assertEqual(ret, (True, "Valid beacon configuration"))
  51. ret = status.beacon(config)
  52. expected = ["time"]
  53. self.assertEqual(list(ret[0]["data"]), expected)