1
0

test_fileserver.py 7.3 KB

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