test_status.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. import pytest
  13. @pytest.mark.windows_whitelisted
  14. class StatusModuleTest(ModuleCase):
  15. '''
  16. Test the status module
  17. '''
  18. @skipIf(salt.utils.platform.is_windows(), 'minion is windows')
  19. @flaky
  20. def test_status_pid(self):
  21. '''
  22. status.pid
  23. '''
  24. status_pid = self.run_function('status.pid', ['salt'])
  25. grab_pids = status_pid.split()[:10]
  26. random_pid = random.choice(grab_pids)
  27. grep_salt = self.run_function('cmd.run', ['ps aux | grep salt'])
  28. self.assertIn(random_pid, grep_salt)
  29. @skipIf(not salt.utils.platform.is_windows(), 'windows only test')
  30. def test_status_cpuload(self):
  31. '''
  32. status.cpuload
  33. '''
  34. ret = self.run_function('status.cpuload')
  35. self.assertTrue(isinstance(ret, float))
  36. @skipIf(not salt.utils.platform.is_windows(), 'windows only test')
  37. def test_status_saltmem(self):
  38. '''
  39. status.saltmem
  40. '''
  41. ret = self.run_function('status.saltmem')
  42. self.assertTrue(isinstance(ret, int))
  43. def test_status_diskusage(self):
  44. '''
  45. status.diskusage
  46. '''
  47. ret = self.run_function('status.diskusage')
  48. if salt.utils.platform.is_darwin():
  49. self.assertIn('not yet supported on this platform', ret)
  50. elif salt.utils.platform.is_windows():
  51. self.assertTrue(isinstance(ret['percent'], float))
  52. else:
  53. self.assertIn('total', str(ret))
  54. self.assertIn('available', str(ret))
  55. def test_status_procs(self):
  56. '''
  57. status.procs
  58. '''
  59. ret = self.run_function('status.procs')
  60. for x, y in six.iteritems(ret):
  61. self.assertIn('cmd', y)
  62. def test_status_uptime(self):
  63. '''
  64. status.uptime
  65. '''
  66. ret = self.run_function('status.uptime')
  67. if salt.utils.platform.is_windows():
  68. self.assertTrue(isinstance(ret, float))
  69. else:
  70. self.assertTrue(isinstance(ret['days'], int))