test_gitfs.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. # -*- coding: utf-8 -*-
  2. '''
  3. :codeauthor: Erik Johnson <erik@saltstack.com>
  4. '''
  5. # Import Python libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. import errno
  8. import os
  9. import shutil
  10. import tempfile
  11. import textwrap
  12. import salt.ext.tornado.ioloop
  13. import logging
  14. import stat
  15. try:
  16. import pwd # pylint: disable=unused-import
  17. except ImportError:
  18. pass
  19. # Import Salt Testing Libs
  20. from tests.support.runtests import RUNTIME_VARS
  21. from tests.support.mixins import LoaderModuleMockMixin
  22. from tests.support.unit import TestCase, skipIf
  23. from tests.support.mock import patch
  24. from tests.support.helpers import patched_environ
  25. # Import salt libs
  26. import salt.fileserver.gitfs as gitfs
  27. import salt.utils.files
  28. import salt.utils.platform
  29. import salt.utils.win_functions
  30. import salt.utils.yaml
  31. import salt.ext.six
  32. import salt.utils.gitfs
  33. from salt.utils.gitfs import (
  34. GITPYTHON_VERSION,
  35. GITPYTHON_MINVER,
  36. PYGIT2_VERSION,
  37. PYGIT2_MINVER,
  38. LIBGIT2_VERSION,
  39. LIBGIT2_MINVER
  40. )
  41. try:
  42. import git
  43. # We still need to use GitPython here for temp repo setup, so we do need to
  44. # actually import it. But we don't need import pygit2 in this module, we
  45. # can just use the LooseVersion instances imported along with
  46. # salt.utils.gitfs to check if we have a compatible version.
  47. HAS_GITPYTHON = GITPYTHON_VERSION >= GITPYTHON_MINVER
  48. except (ImportError, AttributeError):
  49. HAS_GITPYTHON = False
  50. try:
  51. HAS_PYGIT2 = PYGIT2_VERSION >= PYGIT2_MINVER \
  52. and LIBGIT2_VERSION >= LIBGIT2_MINVER
  53. except AttributeError:
  54. HAS_PYGIT2 = False
  55. log = logging.getLogger(__name__)
  56. UNICODE_FILENAME = 'питон.txt'
  57. UNICODE_DIRNAME = UNICODE_ENVNAME = 'соль'
  58. TAG_NAME = 'mytag'
  59. def _rmtree_error(func, path, excinfo):
  60. os.chmod(path, stat.S_IWRITE)
  61. func(path)
  62. def _clear_instance_map():
  63. try:
  64. del salt.utils.gitfs.GitFS.instance_map[salt.ext.tornado.ioloop.IOLoop.current()]
  65. except KeyError:
  66. pass
  67. @skipIf(not HAS_GITPYTHON, 'GitPython >= {0} required'.format(GITPYTHON_MINVER))
  68. class GitfsConfigTestCase(TestCase, LoaderModuleMockMixin):
  69. def setup_loader_modules(self):
  70. opts = {
  71. 'sock_dir': self.tmp_sock_dir,
  72. 'gitfs_remotes': ['file://' + self.tmp_repo_dir],
  73. 'gitfs_root': '',
  74. 'fileserver_backend': ['gitfs'],
  75. 'gitfs_base': 'master',
  76. 'fileserver_events': True,
  77. 'transport': 'zeromq',
  78. 'gitfs_mountpoint': '',
  79. 'gitfs_saltenv': [],
  80. 'gitfs_saltenv_whitelist': [],
  81. 'gitfs_saltenv_blacklist': [],
  82. 'gitfs_user': '',
  83. 'gitfs_password': '',
  84. 'gitfs_insecure_auth': False,
  85. 'gitfs_privkey': '',
  86. 'gitfs_pubkey': '',
  87. 'gitfs_passphrase': '',
  88. 'gitfs_refspecs': [
  89. '+refs/heads/*:refs/remotes/origin/*',
  90. '+refs/tags/*:refs/tags/*'
  91. ],
  92. 'gitfs_ssl_verify': True,
  93. 'gitfs_disable_saltenv_mapping': False,
  94. 'gitfs_ref_types': ['branch', 'tag', 'sha'],
  95. 'gitfs_update_interval': 60,
  96. '__role': 'master',
  97. }
  98. opts['cachedir'] = self.tmp_cachedir
  99. opts['sock_dir'] = self.tmp_sock_dir
  100. return {
  101. gitfs: {
  102. '__opts__': opts,
  103. }
  104. }
  105. @classmethod
  106. def setUpClass(cls):
  107. # Clear the instance map so that we make sure to create a new instance
  108. # for this test class.
  109. _clear_instance_map()
  110. cls.tmp_repo_dir = os.path.join(RUNTIME_VARS.TMP, 'gitfs_root')
  111. if salt.utils.platform.is_windows():
  112. cls.tmp_repo_dir = cls.tmp_repo_dir.replace('\\', '/')
  113. cls.tmp_cachedir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP)
  114. cls.tmp_sock_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP)
  115. @classmethod
  116. def tearDownClass(cls):
  117. '''
  118. Remove the temporary git repository and gitfs cache directory to ensure
  119. a clean environment for the other test class(es).
  120. '''
  121. for path in (cls.tmp_cachedir, cls.tmp_sock_dir):
  122. try:
  123. shutil.rmtree(path, onerror=_rmtree_error)
  124. except OSError as exc:
  125. if exc.errno == errno.EACCES:
  126. log.error("Access error removeing file %s", path)
  127. continue
  128. if exc.errno != errno.EEXIST:
  129. raise
  130. def test_per_saltenv_config(self):
  131. opts_override = textwrap.dedent('''
  132. gitfs_root: salt
  133. gitfs_saltenv:
  134. - baz:
  135. # when loaded, the "salt://" prefix will be removed
  136. - mountpoint: salt://baz_mountpoint
  137. - ref: baz_branch
  138. - root: baz_root
  139. gitfs_remotes:
  140. - file://{0}tmp/repo1:
  141. - saltenv:
  142. - foo:
  143. - ref: foo_branch
  144. - root: foo_root
  145. - file://{0}tmp/repo2:
  146. - mountpoint: repo2
  147. - saltenv:
  148. - baz:
  149. - mountpoint: abc
  150. '''.format('/' if salt.utils.platform.is_windows() else ''))
  151. with patch.dict(gitfs.__opts__, salt.utils.yaml.safe_load(opts_override)):
  152. git_fs = salt.utils.gitfs.GitFS(
  153. gitfs.__opts__,
  154. gitfs.__opts__['gitfs_remotes'],
  155. per_remote_overrides=gitfs.PER_REMOTE_OVERRIDES,
  156. per_remote_only=gitfs.PER_REMOTE_ONLY)
  157. # repo1 (branch: foo)
  158. # The mountpoint should take the default (from gitfs_mountpoint), while
  159. # ref and root should take the per-saltenv params.
  160. self.assertEqual(git_fs.remotes[0].mountpoint('foo'), '')
  161. self.assertEqual(git_fs.remotes[0].ref('foo'), 'foo_branch')
  162. self.assertEqual(git_fs.remotes[0].root('foo'), 'foo_root')
  163. # repo1 (branch: bar)
  164. # The 'bar' branch does not have a per-saltenv configuration set, so
  165. # each of the below values should fall back to global values.
  166. self.assertEqual(git_fs.remotes[0].mountpoint('bar'), '')
  167. self.assertEqual(git_fs.remotes[0].ref('bar'), 'bar')
  168. self.assertEqual(git_fs.remotes[0].root('bar'), 'salt')
  169. # repo1 (branch: baz)
  170. # The 'baz' branch does not have a per-saltenv configuration set, but
  171. # it is defined in the gitfs_saltenv parameter, so the values
  172. # from that parameter should be returned.
  173. self.assertEqual(git_fs.remotes[0].mountpoint('baz'), 'baz_mountpoint')
  174. self.assertEqual(git_fs.remotes[0].ref('baz'), 'baz_branch')
  175. self.assertEqual(git_fs.remotes[0].root('baz'), 'baz_root')
  176. # repo2 (branch: foo)
  177. # The mountpoint should take the per-remote mountpoint value of
  178. # 'repo2', while ref and root should fall back to global values.
  179. self.assertEqual(git_fs.remotes[1].mountpoint('foo'), 'repo2')
  180. self.assertEqual(git_fs.remotes[1].ref('foo'), 'foo')
  181. self.assertEqual(git_fs.remotes[1].root('foo'), 'salt')
  182. # repo2 (branch: bar)
  183. # The 'bar' branch does not have a per-saltenv configuration set, so
  184. # the mountpoint should take the per-remote mountpoint value of
  185. # 'repo2', while ref and root should fall back to global values.
  186. self.assertEqual(git_fs.remotes[1].mountpoint('bar'), 'repo2')
  187. self.assertEqual(git_fs.remotes[1].ref('bar'), 'bar')
  188. self.assertEqual(git_fs.remotes[1].root('bar'), 'salt')
  189. # repo2 (branch: baz)
  190. # The 'baz' branch has the mountpoint configured as a per-saltenv
  191. # parameter. The other two should take the values defined in
  192. # gitfs_saltenv.
  193. self.assertEqual(git_fs.remotes[1].mountpoint('baz'), 'abc')
  194. self.assertEqual(git_fs.remotes[1].ref('baz'), 'baz_branch')
  195. self.assertEqual(git_fs.remotes[1].root('baz'), 'baz_root')
  196. LOAD = {'saltenv': 'base'}
  197. class GitFSTestFuncs(object):
  198. '''
  199. These are where the tests go, so that they can be run using both GitPython
  200. and pygit2.
  201. NOTE: The gitfs.update() has to happen AFTER the setUp is called. This is
  202. because running it inside the setUp will spawn a new singleton, which means
  203. that tests which need to mock the __opts__ will be too late; the setUp will
  204. have created a new singleton that will bypass our mocking. To ensure that
  205. our tests are reliable and correct, we want to make sure that each test
  206. uses a new gitfs object, allowing different manipulations of the opts to be
  207. tested.
  208. Therefore, keep the following in mind:
  209. 1. Each test needs to call gitfs.update() *after* any patching, and
  210. *before* calling the function being tested.
  211. 2. Do *NOT* move the gitfs.update() into the setUp.
  212. '''
  213. def test_file_list(self):
  214. gitfs.update()
  215. ret = gitfs.file_list(LOAD)
  216. self.assertIn('testfile', ret)
  217. self.assertIn(UNICODE_FILENAME, ret)
  218. # This function does not use os.sep, the Salt fileserver uses the
  219. # forward slash, hence it being explicitly used to join here.
  220. self.assertIn('/'.join((UNICODE_DIRNAME, 'foo.txt')), ret)
  221. def test_dir_list(self):
  222. gitfs.update()
  223. ret = gitfs.dir_list(LOAD)
  224. self.assertIn('grail', ret)
  225. self.assertIn(UNICODE_DIRNAME, ret)
  226. def test_envs(self):
  227. gitfs.update()
  228. ret = gitfs.envs(ignore_cache=True)
  229. self.assertIn('base', ret)
  230. self.assertIn(UNICODE_ENVNAME, ret)
  231. self.assertIn(TAG_NAME, ret)
  232. def test_ref_types_global(self):
  233. '''
  234. Test the global gitfs_ref_types config option
  235. '''
  236. with patch.dict(gitfs.__opts__, {'gitfs_ref_types': ['branch']}):
  237. gitfs.update()
  238. ret = gitfs.envs(ignore_cache=True)
  239. # Since we are restricting to branches only, the tag should not
  240. # appear in the envs list.
  241. self.assertIn('base', ret)
  242. self.assertIn(UNICODE_ENVNAME, ret)
  243. self.assertNotIn(TAG_NAME, ret)
  244. def test_ref_types_per_remote(self):
  245. '''
  246. Test the per_remote ref_types config option, using a different
  247. ref_types setting than the global test.
  248. '''
  249. remotes = [{'file://' + self.tmp_repo_dir: [{'ref_types': ['tag']}]}]
  250. with patch.dict(gitfs.__opts__, {'gitfs_remotes': remotes}):
  251. gitfs.update()
  252. ret = gitfs.envs(ignore_cache=True)
  253. # Since we are restricting to tags only, the tag should appear in
  254. # the envs list, but the branches should not.
  255. self.assertNotIn('base', ret)
  256. self.assertNotIn(UNICODE_ENVNAME, ret)
  257. self.assertIn(TAG_NAME, ret)
  258. def test_disable_saltenv_mapping_global_with_mapping_defined_globally(self):
  259. '''
  260. Test the global gitfs_disable_saltenv_mapping config option, combined
  261. with the per-saltenv mapping being defined in the global gitfs_saltenv
  262. option.
  263. '''
  264. opts = salt.utils.yaml.safe_load(textwrap.dedent('''\
  265. gitfs_disable_saltenv_mapping: True
  266. gitfs_saltenv:
  267. - foo:
  268. - ref: somebranch
  269. '''))
  270. with patch.dict(gitfs.__opts__, opts):
  271. gitfs.update()
  272. ret = gitfs.envs(ignore_cache=True)
  273. # Since we are restricting to tags only, the tag should appear in
  274. # the envs list, but the branches should not.
  275. self.assertEqual(ret, ['base', 'foo'])
  276. def test_saltenv_blacklist(self):
  277. '''
  278. test saltenv_blacklist
  279. '''
  280. opts = salt.utils.yaml.safe_load(textwrap.dedent('''\
  281. gitfs_saltenv_blacklist: base
  282. '''))
  283. with patch.dict(gitfs.__opts__, opts):
  284. gitfs.update()
  285. ret = gitfs.envs(ignore_cache=True)
  286. assert 'base' not in ret
  287. assert UNICODE_ENVNAME in ret
  288. assert 'mytag' in ret
  289. def test_saltenv_whitelist(self):
  290. '''
  291. test saltenv_whitelist
  292. '''
  293. opts = salt.utils.yaml.safe_load(textwrap.dedent('''\
  294. gitfs_saltenv_whitelist: base
  295. '''))
  296. with patch.dict(gitfs.__opts__, opts):
  297. gitfs.update()
  298. ret = gitfs.envs(ignore_cache=True)
  299. assert 'base' in ret
  300. assert UNICODE_ENVNAME not in ret
  301. assert 'mytag' not in ret
  302. def test_env_deprecated_opts(self):
  303. '''
  304. ensure deprecated options gitfs_env_whitelist
  305. and gitfs_env_blacklist do not cause gitfs to
  306. not load.
  307. '''
  308. opts = salt.utils.yaml.safe_load(textwrap.dedent('''\
  309. gitfs_env_whitelist: base
  310. gitfs_env_blacklist: ''
  311. '''))
  312. with patch.dict(gitfs.__opts__, opts):
  313. gitfs.update()
  314. ret = gitfs.envs(ignore_cache=True)
  315. assert 'base' in ret
  316. assert UNICODE_ENVNAME in ret
  317. assert 'mytag' in ret
  318. def test_disable_saltenv_mapping_global_with_mapping_defined_per_remote(self):
  319. '''
  320. Test the global gitfs_disable_saltenv_mapping config option, combined
  321. with the per-saltenv mapping being defined in the remote itself via the
  322. "saltenv" per-remote option.
  323. '''
  324. opts = salt.utils.yaml.safe_load(textwrap.dedent('''\
  325. gitfs_disable_saltenv_mapping: True
  326. gitfs_remotes:
  327. - {0}:
  328. - saltenv:
  329. - bar:
  330. - ref: somebranch
  331. '''.format(self.tmp_repo_dir)))
  332. with patch.dict(gitfs.__opts__, opts):
  333. gitfs.update()
  334. ret = gitfs.envs(ignore_cache=True)
  335. # Since we are restricting to tags only, the tag should appear in
  336. # the envs list, but the branches should not.
  337. self.assertEqual(ret, ['bar', 'base'])
  338. def test_disable_saltenv_mapping_per_remote_with_mapping_defined_globally(self):
  339. '''
  340. Test the per-remote disable_saltenv_mapping config option, combined
  341. with the per-saltenv mapping being defined in the global gitfs_saltenv
  342. option.
  343. '''
  344. opts = salt.utils.yaml.safe_load(textwrap.dedent('''\
  345. gitfs_remotes:
  346. - {0}:
  347. - disable_saltenv_mapping: True
  348. gitfs_saltenv:
  349. - hello:
  350. - ref: somebranch
  351. '''.format(self.tmp_repo_dir)))
  352. with patch.dict(gitfs.__opts__, opts):
  353. gitfs.update()
  354. ret = gitfs.envs(ignore_cache=True)
  355. # Since we are restricting to tags only, the tag should appear in
  356. # the envs list, but the branches should not.
  357. self.assertEqual(ret, ['base', 'hello'])
  358. def test_disable_saltenv_mapping_per_remote_with_mapping_defined_per_remote(self):
  359. '''
  360. Test the per-remote disable_saltenv_mapping config option, combined
  361. with the per-saltenv mapping being defined in the remote itself via the
  362. "saltenv" per-remote option.
  363. '''
  364. opts = salt.utils.yaml.safe_load(textwrap.dedent('''\
  365. gitfs_remotes:
  366. - {0}:
  367. - disable_saltenv_mapping: True
  368. - saltenv:
  369. - world:
  370. - ref: somebranch
  371. '''.format(self.tmp_repo_dir)))
  372. with patch.dict(gitfs.__opts__, opts):
  373. gitfs.update()
  374. ret = gitfs.envs(ignore_cache=True)
  375. # Since we are restricting to tags only, the tag should appear in
  376. # the envs list, but the branches should not.
  377. self.assertEqual(ret, ['base', 'world'])
  378. class GitFSTestBase(object):
  379. @classmethod
  380. def setUpClass(cls):
  381. cls.tmp_repo_dir = os.path.join(RUNTIME_VARS.TMP, 'gitfs_root')
  382. if salt.utils.platform.is_windows():
  383. cls.tmp_repo_dir = cls.tmp_repo_dir.replace('\\', '/')
  384. cls.tmp_cachedir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP)
  385. cls.tmp_sock_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP)
  386. try:
  387. shutil.rmtree(cls.tmp_repo_dir)
  388. except OSError as exc:
  389. if exc.errno == errno.EACCES:
  390. log.error("Access error removing file %s", cls.tmp_repo_dir)
  391. elif exc.errno != errno.ENOENT:
  392. raise
  393. shutil.copytree(
  394. salt.ext.six.text_type(RUNTIME_VARS.BASE_FILES),
  395. salt.ext.six.text_type(cls.tmp_repo_dir + '/'),
  396. symlinks=True
  397. )
  398. repo = git.Repo.init(cls.tmp_repo_dir)
  399. try:
  400. if salt.utils.platform.is_windows():
  401. username = salt.utils.win_functions.get_current_user()
  402. else:
  403. username = pwd.getpwuid(os.geteuid()).pw_name
  404. except AttributeError:
  405. log.error(
  406. 'Unable to get effective username, falling back to \'root\'.'
  407. )
  408. username = str('root')
  409. with patched_environ(USERNAME=username):
  410. repo.index.add([x for x in os.listdir(cls.tmp_repo_dir)
  411. if x != '.git'])
  412. repo.index.commit('Test')
  413. # Add another branch with unicode characters in the name
  414. repo.create_head(UNICODE_ENVNAME, 'HEAD')
  415. # Add a tag
  416. repo.create_tag(TAG_NAME, 'HEAD')
  417. # Older GitPython versions do not have a close method.
  418. if hasattr(repo, 'close'):
  419. repo.close()
  420. @classmethod
  421. def tearDownClass(cls):
  422. '''
  423. Remove the temporary git repository and gitfs cache directory to ensure
  424. a clean environment for the other test class(es).
  425. '''
  426. for path in (cls.tmp_cachedir, cls.tmp_sock_dir, cls.tmp_repo_dir):
  427. try:
  428. salt.utils.files.rm_rf(path)
  429. except OSError as exc:
  430. if exc.errno == errno.EACCES:
  431. log.error("Access error removeing file %s", path)
  432. elif exc.errno != errno.EEXIST:
  433. raise
  434. def setUp(self):
  435. '''
  436. We don't want to check in another .git dir into GH because that just
  437. gets messy. Instead, we'll create a temporary repo on the fly for the
  438. tests to examine.
  439. Also ensure we A) don't re-use the singleton, and B) that the cachedirs
  440. are cleared. This keeps these performance enhancements from affecting
  441. the results of subsequent tests.
  442. '''
  443. if not gitfs.__virtual__():
  444. self.skipTest("GitFS could not be loaded. Skipping GitFS tests!")
  445. _clear_instance_map()
  446. for subdir in ('gitfs', 'file_lists'):
  447. try:
  448. salt.utils.files.rm_rf(os.path.join(self.tmp_cachedir, subdir))
  449. except OSError as exc:
  450. if exc.errno == errno.EACCES:
  451. log.warning("Access error removeing file %s", os.path.join(self.tmp_cachedir, subdir))
  452. continue
  453. if exc.errno != errno.ENOENT:
  454. raise
  455. if salt.ext.six.PY3 and salt.utils.platform.is_windows():
  456. self.setUpClass()
  457. self.setup_loader_modules()
  458. @skipIf(not HAS_GITPYTHON, 'GitPython >= {0} required'.format(GITPYTHON_MINVER))
  459. class GitPythonTest(GitFSTestBase, GitFSTestFuncs, TestCase, LoaderModuleMockMixin):
  460. def setup_loader_modules(self):
  461. opts = {
  462. 'sock_dir': self.tmp_sock_dir,
  463. 'gitfs_remotes': ['file://' + self.tmp_repo_dir],
  464. 'gitfs_root': '',
  465. 'fileserver_backend': ['gitfs'],
  466. 'gitfs_base': 'master',
  467. 'fileserver_events': True,
  468. 'transport': 'zeromq',
  469. 'gitfs_mountpoint': '',
  470. 'gitfs_saltenv': [],
  471. 'gitfs_saltenv_whitelist': [],
  472. 'gitfs_saltenv_blacklist': [],
  473. 'gitfs_user': '',
  474. 'gitfs_password': '',
  475. 'gitfs_insecure_auth': False,
  476. 'gitfs_privkey': '',
  477. 'gitfs_pubkey': '',
  478. 'gitfs_passphrase': '',
  479. 'gitfs_refspecs': [
  480. '+refs/heads/*:refs/remotes/origin/*',
  481. '+refs/tags/*:refs/tags/*'
  482. ],
  483. 'gitfs_ssl_verify': True,
  484. 'gitfs_disable_saltenv_mapping': False,
  485. 'gitfs_ref_types': ['branch', 'tag', 'sha'],
  486. 'gitfs_update_interval': 60,
  487. '__role': 'master',
  488. }
  489. opts['cachedir'] = self.tmp_cachedir
  490. opts['sock_dir'] = self.tmp_sock_dir
  491. opts['gitfs_provider'] = 'gitpython'
  492. return {
  493. gitfs: {
  494. '__opts__': opts,
  495. }
  496. }
  497. @skipIf(not HAS_GITPYTHON, 'GitPython >= {0} required for temp repo setup'.format(GITPYTHON_MINVER))
  498. @skipIf(not HAS_PYGIT2, 'pygit2 >= {0} and libgit2 >= {1} required'.format(PYGIT2_MINVER, LIBGIT2_MINVER))
  499. @skipIf(salt.utils.platform.is_windows(), 'Skip Pygit2 on windows, due to pygit2 access error on windows')
  500. class Pygit2Test(GitFSTestBase, GitFSTestFuncs, TestCase, LoaderModuleMockMixin):
  501. def setup_loader_modules(self):
  502. opts = {
  503. 'sock_dir': self.tmp_sock_dir,
  504. 'gitfs_remotes': ['file://' + self.tmp_repo_dir],
  505. 'gitfs_root': '',
  506. 'fileserver_backend': ['gitfs'],
  507. 'gitfs_base': 'master',
  508. 'fileserver_events': True,
  509. 'transport': 'zeromq',
  510. 'gitfs_mountpoint': '',
  511. 'gitfs_saltenv': [],
  512. 'gitfs_saltenv_whitelist': [],
  513. 'gitfs_saltenv_blacklist': [],
  514. 'gitfs_user': '',
  515. 'gitfs_password': '',
  516. 'gitfs_insecure_auth': False,
  517. 'gitfs_privkey': '',
  518. 'gitfs_pubkey': '',
  519. 'gitfs_passphrase': '',
  520. 'gitfs_refspecs': [
  521. '+refs/heads/*:refs/remotes/origin/*',
  522. '+refs/tags/*:refs/tags/*'
  523. ],
  524. 'gitfs_ssl_verify': True,
  525. 'gitfs_disable_saltenv_mapping': False,
  526. 'gitfs_ref_types': ['branch', 'tag', 'sha'],
  527. 'gitfs_update_interval': 60,
  528. '__role': 'master',
  529. }
  530. opts['cachedir'] = self.tmp_cachedir
  531. opts['sock_dir'] = self.tmp_sock_dir
  532. opts['gitfs_provider'] = 'pygit2'
  533. return {
  534. gitfs: {
  535. '__opts__': opts,
  536. }
  537. }