test_sysctl.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # -*- coding: utf-8 -*-
  2. # Import python libs
  3. from __future__ import absolute_import, print_function, unicode_literals
  4. import sys
  5. import pytest
  6. # Import Salt Testing libs
  7. from tests.support.case import ModuleCase
  8. from tests.support.unit import skipIf
  9. class SysctlModuleTest(ModuleCase):
  10. def setUp(self):
  11. super(SysctlModuleTest, self).setUp()
  12. ret = self.run_function("cmd.has_exec", ["sysctl"])
  13. if not ret:
  14. self.skipTest("sysctl not found")
  15. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  16. def test_show(self):
  17. ret = self.run_function("sysctl.show")
  18. self.assertIsInstance(ret, dict, "sysctl.show return wrong type")
  19. self.assertGreater(len(ret), 10, "sysctl.show return few data")
  20. @skipIf(not sys.platform.startswith("linux"), "Linux specific")
  21. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  22. def test_show_linux(self):
  23. ret = self.run_function("sysctl.show")
  24. self.assertIn("kernel.ostype", ret, "kernel.ostype absent")
  25. @skipIf(not sys.platform.startswith("freebsd"), "FreeBSD specific")
  26. def test_show_freebsd(self):
  27. ret = self.run_function("sysctl.show")
  28. self.assertIn("vm.vmtotal", ret, "Multiline variable absent")
  29. self.assertGreater(
  30. len(ret.get("vm.vmtotal").splitlines()),
  31. 1,
  32. "Multiline value was parsed wrong",
  33. )
  34. @skipIf(not sys.platform.startswith("openbsd"), "OpenBSD specific")
  35. def test_show_openbsd(self):
  36. ret = self.run_function("sysctl.show")
  37. self.assertIn("kern.ostype", ret, "kern.ostype absent")
  38. self.assertEqual(ret.get("kern.ostype"), "OpenBSD", "Incorrect kern.ostype")
  39. @skipIf(not sys.platform.startswith("darwin"), "Darwin (macOS) specific")
  40. @pytest.mark.slow_test(seconds=1) # Test takes >0.1 and <=1 seconds
  41. def test_show_darwin(self):
  42. ret = self.run_function("sysctl.show")
  43. self.assertIn("kern.ostype", ret, "kern.ostype absent")
  44. self.assertEqual(ret.get("kern.ostype"), "Darwin", "Incorrect kern.ostype")