1
0

test_status.py 2.2 KB

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