test_status.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # -*- coding: utf-8 -*-
  2. # Import Python libs
  3. from __future__ import absolute_import, print_function, unicode_literals
  4. import random
  5. # Import Salt Testing libs
  6. from tests.support.case import ModuleCase
  7. from tests.support.helpers import flaky
  8. from tests.support.unit import skipIf
  9. # Import Salt libs
  10. from salt.ext import six
  11. import salt.utils.platform
  12. class StatusModuleTest(ModuleCase):
  13. '''
  14. Test the status module
  15. '''
  16. @skipIf(salt.utils.platform.is_windows(), 'minion is windows')
  17. @flaky
  18. def test_status_pid(self):
  19. '''
  20. status.pid
  21. '''
  22. status_pid = self.run_function('status.pid', ['salt'])
  23. grab_pids = status_pid.split()[:10]
  24. random_pid = random.choice(grab_pids)
  25. grep_salt = self.run_function('cmd.run', ['ps aux | grep salt'])
  26. self.assertIn(random_pid, grep_salt)
  27. @skipIf(not salt.utils.platform.is_windows(), 'windows only test')
  28. def test_status_cpuload(self):
  29. '''
  30. status.cpuload
  31. '''
  32. ret = self.run_function('status.cpuload')
  33. self.assertTrue(isinstance(ret, float))
  34. @skipIf(not salt.utils.platform.is_windows(), 'windows only test')
  35. def test_status_saltmem(self):
  36. '''
  37. status.saltmem
  38. '''
  39. ret = self.run_function('status.saltmem')
  40. self.assertTrue(isinstance(ret, int))
  41. def test_status_diskusage(self):
  42. '''
  43. status.diskusage
  44. '''
  45. ret = self.run_function('status.diskusage')
  46. if salt.utils.platform.is_darwin():
  47. self.assertIn('not yet supported on this platform', ret)
  48. elif salt.utils.platform.is_windows():
  49. self.assertTrue(isinstance(ret['percent'], float))
  50. else:
  51. self.assertIn('total', str(ret))
  52. self.assertIn('available', str(ret))
  53. def test_status_procs(self):
  54. '''
  55. status.procs
  56. '''
  57. ret = self.run_function('status.procs')
  58. for x, y in six.iteritems(ret):
  59. self.assertIn('cmd', y)
  60. def test_status_uptime(self):
  61. '''
  62. status.uptime
  63. '''
  64. ret = self.run_function('status.uptime')
  65. if salt.utils.platform.is_windows():
  66. self.assertTrue(isinstance(ret, float))
  67. else:
  68. self.assertTrue(isinstance(ret['days'], int))