1
0

test_status.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # -*- coding: utf-8 -*-
  2. from __future__ import absolute_import, print_function, unicode_literals
  3. import random
  4. import pytest
  5. import salt.utils.platform
  6. from salt.ext import six
  7. from tests.support.case import ModuleCase
  8. from tests.support.helpers import flaky, slowTest
  9. from tests.support.unit import skipIf
  10. @pytest.mark.windows_whitelisted
  11. class StatusModuleTest(ModuleCase):
  12. """
  13. Test the status module
  14. """
  15. @skipIf(salt.utils.platform.is_windows(), "minion is windows")
  16. @flaky
  17. def test_status_pid(self):
  18. """
  19. status.pid
  20. """
  21. status_pid = self.run_function("status.pid", ["salt"])
  22. grab_pids = status_pid.split()[:10]
  23. random_pid = random.choice(grab_pids)
  24. grep_salt = self.run_function("cmd.run", ["pgrep -f salt"])
  25. self.assertIn(random_pid, grep_salt)
  26. @skipIf(not salt.utils.platform.is_windows(), "windows only test")
  27. @slowTest
  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. @slowTest
  36. def test_status_saltmem(self):
  37. """
  38. status.saltmem
  39. """
  40. ret = self.run_function("status.saltmem")
  41. self.assertTrue(isinstance(ret, int))
  42. @slowTest
  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. @slowTest
  56. def test_status_procs(self):
  57. """
  58. status.procs
  59. """
  60. ret = self.run_function("status.procs")
  61. for x, y in six.iteritems(ret):
  62. self.assertIn("cmd", y)
  63. @slowTest
  64. def test_status_uptime(self):
  65. """
  66. status.uptime
  67. """
  68. ret = self.run_function("status.uptime")
  69. if salt.utils.platform.is_windows():
  70. self.assertTrue(isinstance(ret, float))
  71. else:
  72. self.assertTrue(isinstance(ret["days"], int))