1
0

test_sysctl.py 1.8 KB

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