1
0

test_status.py 1.9 KB

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