test_sysctl.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # -*- coding: utf-8 -*-
  2. # Import python libs
  3. from __future__ import absolute_import, unicode_literals, print_function
  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(ret.get('vm.vmtotal').splitlines(),
  27. 1,
  28. 'Multiline value was parsed wrong')
  29. @skipIf(not sys.platform.startswith('openbsd'), 'OpenBSD specific')
  30. def test_show_openbsd(self):
  31. ret = self.run_function('sysctl.show')
  32. self.assertIn('kern.ostype', ret, 'kern.ostype absent')
  33. self.assertEqual(
  34. ret.get('kern.ostype'), 'OpenBSD', 'Incorrect kern.ostype'
  35. )
  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(
  41. ret.get('kern.ostype'), 'Darwin', 'Incorrect kern.ostype'
  42. )