test_fileserver.py 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. # -*- coding: utf-8 -*-
  2. """
  3. Tests for the fileserver runner
  4. """
  5. from __future__ import absolute_import, print_function, unicode_literals
  6. import contextlib
  7. import pytest
  8. import salt.utils.platform
  9. from tests.support.case import ShellCase
  10. from tests.support.unit import skipIf
  11. @pytest.mark.windows_whitelisted
  12. class FileserverTest(ShellCase):
  13. """
  14. Test the fileserver runner
  15. """
  16. @skipIf(True, "SLOWTEST skip")
  17. def test_dir_list(self):
  18. """
  19. fileserver.dir_list
  20. """
  21. ret = self.run_run_plus(fun="fileserver.dir_list")
  22. self.assertIsInstance(ret["return"], list)
  23. self.assertTrue("_modules" in ret["return"])
  24. # Backend submitted as a string
  25. ret = self.run_run_plus(fun="fileserver.dir_list", backend="roots")
  26. self.assertIsInstance(ret["return"], list)
  27. self.assertTrue("_modules" in ret["return"])
  28. # Backend submitted as a list
  29. ret = self.run_run_plus(fun="fileserver.dir_list", backend=["roots"])
  30. self.assertIsInstance(ret["return"], list)
  31. self.assertTrue("_modules" in ret["return"])
  32. @skipIf(True, "SLOWTEST skip")
  33. def test_empty_dir_list(self):
  34. """
  35. fileserver.empty_dir_list
  36. """
  37. ret = self.run_run_plus(fun="fileserver.empty_dir_list")
  38. self.assertIsInstance(ret["return"], list)
  39. self.assertEqual(ret["return"], [])
  40. # Backend submitted as a string
  41. ret = self.run_run_plus(fun="fileserver.empty_dir_list", backend="roots")
  42. self.assertIsInstance(ret["return"], list)
  43. self.assertEqual(ret["return"], [])
  44. # Backend submitted as a list
  45. ret = self.run_run_plus(fun="fileserver.empty_dir_list", backend=["roots"])
  46. self.assertIsInstance(ret["return"], list)
  47. self.assertEqual(ret["return"], [])
  48. @skipIf(True, "SLOWTEST skip")
  49. def test_envs(self):
  50. """
  51. fileserver.envs
  52. """
  53. ret = self.run_run_plus(fun="fileserver.envs")
  54. self.assertIsInstance(ret["return"], list)
  55. # Backend submitted as a string
  56. ret = self.run_run_plus(fun="fileserver.envs", backend="roots")
  57. self.assertIsInstance(ret["return"], list)
  58. # Backend submitted as a list
  59. ret = self.run_run_plus(fun="fileserver.envs", backend=["roots"])
  60. self.assertIsInstance(ret["return"], list)
  61. @skipIf(True, "SLOWTEST skip")
  62. def test_clear_file_list_cache(self):
  63. """
  64. fileserver.clear_file_list_cache
  65. If this test fails, then something may have changed in the test suite
  66. and we may have more than just "roots" configured in the fileserver
  67. backends. This assert will need to be updated accordingly.
  68. """
  69. saltenvs = sorted(self.run_run_plus(fun="fileserver.envs")["return"])
  70. @contextlib.contextmanager
  71. def gen_cache():
  72. """
  73. Create file_list cache so we have something to clear
  74. """
  75. for saltenv in saltenvs:
  76. self.run_run_plus(fun="fileserver.file_list", saltenv=saltenv)
  77. yield
  78. # Test with no arguments
  79. with gen_cache():
  80. ret = self.run_run_plus(fun="fileserver.clear_file_list_cache")
  81. ret["return"]["roots"].sort()
  82. self.assertEqual(ret["return"], {"roots": saltenvs})
  83. # Test with backend passed as string
  84. with gen_cache():
  85. ret = self.run_run_plus(
  86. fun="fileserver.clear_file_list_cache", backend="roots"
  87. )
  88. ret["return"]["roots"].sort()
  89. self.assertEqual(ret["return"], {"roots": saltenvs})
  90. # Test with backend passed as list
  91. with gen_cache():
  92. ret = self.run_run_plus(
  93. fun="fileserver.clear_file_list_cache", backend=["roots"]
  94. )
  95. ret["return"]["roots"].sort()
  96. self.assertEqual(ret["return"], {"roots": saltenvs})
  97. # Test with backend passed as string, but with a nonsense backend
  98. with gen_cache():
  99. ret = self.run_run_plus(
  100. fun="fileserver.clear_file_list_cache", backend="notarealbackend"
  101. )
  102. self.assertEqual(ret["return"], {})
  103. # Test with saltenv passed as string
  104. with gen_cache():
  105. ret = self.run_run_plus(
  106. fun="fileserver.clear_file_list_cache", saltenv="base"
  107. )
  108. self.assertEqual(ret["return"], {"roots": ["base"]})
  109. # Test with saltenv passed as list
  110. with gen_cache():
  111. ret = self.run_run_plus(
  112. fun="fileserver.clear_file_list_cache", saltenv=["base"]
  113. )
  114. self.assertEqual(ret["return"], {"roots": ["base"]})
  115. # Test with saltenv passed as string, but with a nonsense saltenv
  116. with gen_cache():
  117. ret = self.run_run_plus(
  118. fun="fileserver.clear_file_list_cache", saltenv="notarealsaltenv"
  119. )
  120. self.assertEqual(ret["return"], {})
  121. # Test with both backend and saltenv passed
  122. with gen_cache():
  123. ret = self.run_run_plus(
  124. fun="fileserver.clear_file_list_cache", backend="roots", saltenv="base"
  125. )
  126. self.assertEqual(ret["return"], {"roots": ["base"]})
  127. @skipIf(True, "SLOWTEST skip")
  128. def test_file_list(self):
  129. """
  130. fileserver.file_list
  131. """
  132. ret = self.run_run_plus(fun="fileserver.file_list")
  133. self.assertIsInstance(ret["return"], list)
  134. self.assertTrue("grail/scene33" in ret["return"])
  135. # Backend submitted as a string
  136. ret = self.run_run_plus(fun="fileserver.file_list", backend="roots")
  137. self.assertIsInstance(ret["return"], list)
  138. self.assertTrue("grail/scene33" in ret["return"])
  139. # Backend submitted as a list
  140. ret = self.run_run_plus(fun="fileserver.file_list", backend=["roots"])
  141. self.assertIsInstance(ret["return"], list)
  142. self.assertTrue("grail/scene33" in ret["return"])
  143. # Git doesn't handle symlinks in Windows. See the thread below:
  144. # http://stackoverflow.com/questions/5917249/git-symlinks-in-windows
  145. @skipIf(
  146. salt.utils.platform.is_windows(),
  147. "Git for Windows does not preserve symbolic links when cloning",
  148. )
  149. @skipIf(True, "SLOWTEST skip")
  150. def test_symlink_list(self):
  151. """
  152. fileserver.symlink_list
  153. """
  154. ret = self.run_run_plus(fun="fileserver.symlink_list")
  155. self.assertIsInstance(ret["return"], dict)
  156. self.assertTrue("dest_sym" in ret["return"])
  157. # Backend submitted as a string
  158. ret = self.run_run_plus(fun="fileserver.symlink_list", backend="roots")
  159. self.assertIsInstance(ret["return"], dict)
  160. self.assertTrue("dest_sym" in ret["return"])
  161. # Backend submitted as a list
  162. ret = self.run_run_plus(fun="fileserver.symlink_list", backend=["roots"])
  163. self.assertIsInstance(ret["return"], dict)
  164. self.assertTrue("dest_sym" in ret["return"])
  165. @skipIf(True, "SLOWTEST skip")
  166. def test_update(self):
  167. """
  168. fileserver.update
  169. """
  170. ret = self.run_run_plus(fun="fileserver.update")
  171. self.assertTrue(ret["return"])
  172. # Backend submitted as a string
  173. ret = self.run_run_plus(fun="fileserver.update", backend="roots")
  174. self.assertTrue(ret["return"])
  175. # Backend submitted as a list
  176. ret = self.run_run_plus(fun="fileserver.update", backend=["roots"])
  177. self.assertTrue(ret["return"])