1
0

test_mac_system.py 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. """
  2. integration tests for mac_system
  3. """
  4. import logging
  5. import pytest
  6. from tests.support.case import ModuleCase
  7. from tests.support.helpers import (
  8. destructiveTest,
  9. flaky,
  10. random_string,
  11. runs_on,
  12. skip_if_binaries_missing,
  13. skip_if_not_root,
  14. slowTest,
  15. )
  16. from tests.support.unit import skipIf
  17. log = logging.getLogger(__name__)
  18. SET_COMPUTER_NAME = random_string("RS-", lowercase=False)
  19. SET_SUBNET_NAME = random_string("RS-", lowercase=False)
  20. @skip_if_not_root
  21. @flaky(attempts=10)
  22. @runs_on(kernel="Darwin")
  23. @skip_if_binaries_missing("systemsetup")
  24. @pytest.mark.usefixtures("salt_sub_minion")
  25. class MacSystemModuleTest(ModuleCase):
  26. """
  27. Validate the mac_system module
  28. """
  29. ATRUN_ENABLED = False
  30. REMOTE_LOGIN_ENABLED = False
  31. REMOTE_EVENTS_ENABLED = False
  32. SUBNET_NAME = ""
  33. KEYBOARD_DISABLED = False
  34. def setUp(self):
  35. """
  36. Get current settings
  37. """
  38. self.ATRUN_ENABLED = self.run_function("service.enabled", ["com.apple.atrun"])
  39. self.REMOTE_LOGIN_ENABLED = self.run_function("system.get_remote_login")
  40. self.REMOTE_EVENTS_ENABLED = self.run_function("system.get_remote_events")
  41. self.SUBNET_NAME = self.run_function("system.get_subnet_name")
  42. self.KEYBOARD_DISABLED = self.run_function(
  43. "system.get_disable_keyboard_on_lock"
  44. )
  45. def tearDown(self):
  46. """
  47. Reset to original settings
  48. """
  49. if not self.ATRUN_ENABLED:
  50. atrun = "/System/Library/LaunchDaemons/com.apple.atrun.plist"
  51. self.run_function("service.stop", [atrun])
  52. self.run_function("system.set_remote_login", [self.REMOTE_LOGIN_ENABLED])
  53. self.run_function("system.set_remote_events", [self.REMOTE_EVENTS_ENABLED])
  54. self.run_function("system.set_subnet_name", [self.SUBNET_NAME])
  55. self.run_function(
  56. "system.set_disable_keyboard_on_lock", [self.KEYBOARD_DISABLED]
  57. )
  58. @destructiveTest
  59. @slowTest
  60. def test_get_set_remote_login(self):
  61. """
  62. Test system.get_remote_login
  63. Test system.set_remote_login
  64. """
  65. # Normal Functionality
  66. self.assertTrue(self.run_function("system.set_remote_login", [True]))
  67. self.assertTrue(self.run_function("system.get_remote_login"))
  68. self.assertTrue(self.run_function("system.set_remote_login", [False]))
  69. self.assertFalse(self.run_function("system.get_remote_login"))
  70. # Test valid input
  71. self.assertTrue(self.run_function("system.set_remote_login", [True]))
  72. self.assertTrue(self.run_function("system.set_remote_login", [False]))
  73. self.assertTrue(self.run_function("system.set_remote_login", ["yes"]))
  74. self.assertTrue(self.run_function("system.set_remote_login", ["no"]))
  75. self.assertTrue(self.run_function("system.set_remote_login", ["On"]))
  76. self.assertTrue(self.run_function("system.set_remote_login", ["Off"]))
  77. self.assertTrue(self.run_function("system.set_remote_login", [1]))
  78. self.assertTrue(self.run_function("system.set_remote_login", [0]))
  79. # Test invalid input
  80. self.assertIn(
  81. "Invalid String Value for Enabled",
  82. self.run_function("system.set_remote_login", ["spongebob"]),
  83. )
  84. @destructiveTest
  85. @slowTest
  86. def test_get_set_remote_events(self):
  87. """
  88. Test system.get_remote_events
  89. Test system.set_remote_events
  90. """
  91. # Normal Functionality
  92. self.assertTrue(self.run_function("system.set_remote_events", [True]))
  93. self.assertTrue(self.run_function("system.get_remote_events"))
  94. self.assertTrue(self.run_function("system.set_remote_events", [False]))
  95. self.assertFalse(self.run_function("system.get_remote_events"))
  96. # Test valid input
  97. self.assertTrue(self.run_function("system.set_remote_events", [True]))
  98. self.assertTrue(self.run_function("system.set_remote_events", [False]))
  99. self.assertTrue(self.run_function("system.set_remote_events", ["yes"]))
  100. self.assertTrue(self.run_function("system.set_remote_events", ["no"]))
  101. self.assertTrue(self.run_function("system.set_remote_events", ["On"]))
  102. self.assertTrue(self.run_function("system.set_remote_events", ["Off"]))
  103. self.assertTrue(self.run_function("system.set_remote_events", [1]))
  104. self.assertTrue(self.run_function("system.set_remote_events", [0]))
  105. # Test invalid input
  106. self.assertIn(
  107. "Invalid String Value for Enabled",
  108. self.run_function("system.set_remote_events", ["spongebob"]),
  109. )
  110. @destructiveTest
  111. @slowTest
  112. def test_get_set_subnet_name(self):
  113. """
  114. Test system.get_subnet_name
  115. Test system.set_subnet_name
  116. """
  117. self.assertTrue(self.run_function("system.set_subnet_name", [SET_SUBNET_NAME]))
  118. self.assertEqual(self.run_function("system.get_subnet_name"), SET_SUBNET_NAME)
  119. @slowTest
  120. def test_get_list_startup_disk(self):
  121. """
  122. Test system.get_startup_disk
  123. Test system.list_startup_disks
  124. Don't know how to test system.set_startup_disk as there's usually only
  125. one startup disk available on a system
  126. """
  127. # Test list and get
  128. ret = self.run_function("system.list_startup_disks")
  129. self.assertIsInstance(ret, list)
  130. self.assertIn(self.run_function("system.get_startup_disk"), ret)
  131. # Test passing set a bad disk
  132. self.assertIn(
  133. "Invalid value passed for path.",
  134. self.run_function("system.set_startup_disk", ["spongebob"]),
  135. )
  136. @skipIf(True, "Skip this test until mac fixes it.")
  137. def test_get_set_restart_delay(self):
  138. """
  139. Test system.get_restart_delay
  140. Test system.set_restart_delay
  141. system.set_restart_delay does not work due to an apple bug, see docs
  142. may need to disable this test as we can't control the delay value
  143. """
  144. # Normal Functionality
  145. self.assertTrue(self.run_function("system.set_restart_delay", [90]))
  146. self.assertEqual(self.run_function("system.get_restart_delay"), "90 seconds")
  147. # Pass set bad value for seconds
  148. self.assertIn(
  149. "Invalid value passed for seconds.",
  150. self.run_function("system.set_restart_delay", [70]),
  151. )
  152. @slowTest
  153. def test_get_set_disable_keyboard_on_lock(self):
  154. """
  155. Test system.get_disable_keyboard_on_lock
  156. Test system.set_disable_keyboard_on_lock
  157. """
  158. # Normal Functionality
  159. self.assertTrue(
  160. self.run_function("system.set_disable_keyboard_on_lock", [True])
  161. )
  162. self.assertTrue(self.run_function("system.get_disable_keyboard_on_lock"))
  163. self.assertTrue(
  164. self.run_function("system.set_disable_keyboard_on_lock", [False])
  165. )
  166. self.assertFalse(self.run_function("system.get_disable_keyboard_on_lock"))
  167. # Test valid input
  168. self.assertTrue(
  169. self.run_function("system.set_disable_keyboard_on_lock", [True])
  170. )
  171. self.assertTrue(
  172. self.run_function("system.set_disable_keyboard_on_lock", [False])
  173. )
  174. self.assertTrue(
  175. self.run_function("system.set_disable_keyboard_on_lock", ["yes"])
  176. )
  177. self.assertTrue(
  178. self.run_function("system.set_disable_keyboard_on_lock", ["no"])
  179. )
  180. self.assertTrue(
  181. self.run_function("system.set_disable_keyboard_on_lock", ["On"])
  182. )
  183. self.assertTrue(
  184. self.run_function("system.set_disable_keyboard_on_lock", ["Off"])
  185. )
  186. self.assertTrue(self.run_function("system.set_disable_keyboard_on_lock", [1]))
  187. self.assertTrue(self.run_function("system.set_disable_keyboard_on_lock", [0]))
  188. # Test invalid input
  189. self.assertIn(
  190. "Invalid String Value for Enabled",
  191. self.run_function("system.set_disable_keyboard_on_lock", ["spongebob"]),
  192. )
  193. @skipIf(True, "Skip this test until mac fixes it.")
  194. def test_get_set_boot_arch(self):
  195. """
  196. Test system.get_boot_arch
  197. Test system.set_boot_arch
  198. system.set_boot_arch does not work due to an apple bug, see docs
  199. may need to disable this test as we can't set the boot architecture
  200. """
  201. # Normal Functionality
  202. self.assertTrue(self.run_function("system.set_boot_arch", ["i386"]))
  203. self.assertEqual(self.run_function("system.get_boot_arch"), "i386")
  204. self.assertTrue(self.run_function("system.set_boot_arch", ["default"]))
  205. self.assertEqual(self.run_function("system.get_boot_arch"), "default")
  206. # Test invalid input
  207. self.assertIn(
  208. "Invalid value passed for arch",
  209. self.run_function("system.set_boot_arch", ["spongebob"]),
  210. )
  211. @skip_if_not_root
  212. @runs_on(kernel="Darwin")
  213. class MacSystemComputerNameTest(ModuleCase):
  214. def setUp(self):
  215. self.COMPUTER_NAME = self.run_function("system.get_computer_name")
  216. self.wait_for_all_jobs()
  217. def tearDown(self):
  218. self.run_function("system.set_computer_name", [self.COMPUTER_NAME])
  219. self.wait_for_all_jobs()
  220. # A similar test used to be skipped on py3 due to 'hanging', if we see
  221. # something similar again we may want to skip this gain until we
  222. # investigate
  223. # @skipIf(salt.utils.platform.is_darwin() and six.PY3, 'This test hangs on OS X on Py3. Skipping until #53566 is merged.')
  224. @destructiveTest
  225. @slowTest
  226. def test_get_set_computer_name(self):
  227. """
  228. Test system.get_computer_name
  229. Test system.set_computer_name
  230. """
  231. log.debug("Set name is %s", SET_COMPUTER_NAME)
  232. self.assertTrue(
  233. self.run_function("system.set_computer_name", [SET_COMPUTER_NAME])
  234. )
  235. self.assertEqual(
  236. self.run_function("system.get_computer_name"), SET_COMPUTER_NAME
  237. )