1
0

test_git_pillar.py 97 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902
  1. # -*- coding: utf-8 -*-
  2. '''
  3. Integration tests for git_pillar
  4. The base classes for all of these tests are in tests/support/gitfs.py.
  5. Repositories for the tests are generated on the fly (look for the "make_repo"
  6. function).
  7. Where possible, a test case in this module should be reproduced in the
  8. following ways:
  9. 1. GitPython over SSH (TestGitPythonSSH)
  10. 2. GitPython over HTTP (TestGitPythonHTTP)
  11. 3. GitPython over HTTP w/basic auth (TestGitPythonAuthenticatedHTTP)
  12. 4. pygit2 over SSH (TestPygit2SSH)
  13. 5. pygit2 over HTTP (TestPygit2HTTP)
  14. 6. pygit2 over HTTP w/basic auth (TestPygit2AuthenticatedHTTP)
  15. For GitPython, this is easy, since it does not support the authentication
  16. configuration parameters that pygit2 does. Therefore, this test module includes
  17. a GitPythonMixin class which can be reused for all three GitPython test
  18. classes. The only thing we vary for these tests is the URL that we use.
  19. For pygit2 this is more complicated, since it supports A) both passphraseless
  20. and passphrase-protected SSH keys, and B) both global and per-remote credential
  21. parameters. So, for SSH tests we need to run each GitPython test case in 4
  22. different ways to cover pygit2:
  23. 1. Passphraseless key, global credential options
  24. 2. Passphraseless key, per-repo credential options
  25. 3. Passphrase-protected key, global credential options
  26. 4. Passphrase-protected key, per-repo credential options
  27. For HTTP tests, we need to run each GitPython test case in 2 different ways to
  28. cover pygit2 with authentication:
  29. 1. Global credential options
  30. 2. Per-repo credential options
  31. For unauthenticated HTTP, we can just run a single case just like for a
  32. GitPython test function, with the only change being to the git_pillar_provider
  33. config option.
  34. The way we accomplish the extra test cases for pygit2 is not by writing more
  35. test functions, but to keep the same test function names both in the GitPython
  36. test classes and the pygit2 test classes, and just perform multiple pillar
  37. compilations and asserts in each pygit2 test function.
  38. For SSH tests, a system user is added and a temporary sshd instance is started
  39. on a randomized port. The user and sshd server are torn down after the tests
  40. are run.
  41. For HTTP tests, nginx + uWSGI + git-http-backend handles serving the repo.
  42. However, there was a change in git 2.4.4 which causes a fetch to hang when
  43. using uWSGI. This was worked around in uWSGI 2.0.13 by adding an additional
  44. setting. However, Ubuntu 16.04 LTS ships with uWSGI 2.0.12 in their official
  45. repos, so to work around this we pip install a newer uWSGI (with CGI support
  46. baked in) within a virtualenv the test suite creates, and then uses that uwsgi
  47. binary to start the uWSGI daemon. More info on the git issue and the uWSGI
  48. workaround can be found in the below two links:
  49. https://github.com/git/git/commit/6bc0cb5
  50. https://github.com/unbit/uwsgi/commit/ac1e354
  51. '''
  52. # Import Python libs
  53. from __future__ import absolute_import, print_function, unicode_literals
  54. import random
  55. import string
  56. # Import Salt Testing libs
  57. from tests.support.gitfs import (
  58. USERNAME,
  59. PASSWORD,
  60. GitPillarSSHTestBase,
  61. GitPillarHTTPTestBase,
  62. )
  63. from tests.support.helpers import (
  64. destructiveTest,
  65. requires_system_grains,
  66. skip_if_not_root
  67. )
  68. from tests.support.mock import NO_MOCK, NO_MOCK_REASON
  69. from tests.support.unit import skipIf
  70. # Import Salt libs
  71. import salt.utils.path
  72. import salt.utils.platform
  73. from salt.modules.virtualenv_mod import KNOWN_BINARY_NAMES as VIRTUALENV_NAMES
  74. from salt.ext.six.moves import range # pylint: disable=redefined-builtin
  75. from salt.utils.gitfs import (
  76. GITPYTHON_VERSION,
  77. GITPYTHON_MINVER,
  78. PYGIT2_VERSION,
  79. PYGIT2_MINVER,
  80. LIBGIT2_VERSION,
  81. LIBGIT2_MINVER
  82. )
  83. # Check for requisite components
  84. try:
  85. HAS_GITPYTHON = GITPYTHON_VERSION >= GITPYTHON_MINVER
  86. except Exception:
  87. HAS_GITPYTHON = False
  88. try:
  89. HAS_PYGIT2 = PYGIT2_VERSION >= PYGIT2_MINVER \
  90. and LIBGIT2_VERSION >= LIBGIT2_MINVER
  91. except Exception:
  92. HAS_PYGIT2 = False
  93. HAS_SSHD = bool(salt.utils.path.which('sshd'))
  94. HAS_NGINX = bool(salt.utils.path.which('nginx'))
  95. HAS_VIRTUALENV = bool(salt.utils.path.which_bin(VIRTUALENV_NAMES))
  96. def _rand_key_name(length):
  97. return 'id_rsa_{0}'.format(
  98. ''.join(random.choice(string.ascii_letters) for _ in range(length))
  99. )
  100. def _windows_or_mac():
  101. return salt.utils.platform.is_windows() or salt.utils.platform.is_darwin()
  102. class GitPythonMixin(object):
  103. '''
  104. GitPython doesn't support anything fancy in terms of authentication
  105. options, so all of the tests for GitPython can be re-used via this mixin.
  106. '''
  107. def test_single_source(self):
  108. '''
  109. Test using a single ext_pillar repo
  110. '''
  111. ret = self.get_pillar('''\
  112. file_ignore_regex: []
  113. file_ignore_glob: []
  114. git_pillar_provider: gitpython
  115. cachedir: {cachedir}
  116. extension_modules: {extmods}
  117. ext_pillar:
  118. - git:
  119. - master {url}
  120. ''')
  121. self.assertEqual(
  122. ret,
  123. {'branch': 'master',
  124. 'mylist': ['master'],
  125. 'mydict': {'master': True,
  126. 'nested_list': ['master'],
  127. 'nested_dict': {'master': True}}}
  128. )
  129. def test_multiple_sources_master_dev_no_merge_lists(self):
  130. '''
  131. Test using two ext_pillar dirs. Since all git_pillar repos are merged
  132. into a single dictionary, ordering matters.
  133. This tests with the master branch followed by dev, and with
  134. pillar_merge_lists disabled.
  135. '''
  136. ret = self.get_pillar('''\
  137. file_ignore_regex: []
  138. file_ignore_glob: []
  139. git_pillar_provider: gitpython
  140. cachedir: {cachedir}
  141. extension_modules: {extmods}
  142. pillar_merge_lists: False
  143. ext_pillar:
  144. - git:
  145. - master {url}
  146. - dev {url}
  147. ''')
  148. self.assertEqual(
  149. ret,
  150. {'branch': 'dev',
  151. 'mylist': ['dev'],
  152. 'mydict': {'master': True,
  153. 'dev': True,
  154. 'nested_list': ['dev'],
  155. 'nested_dict': {'master': True, 'dev': True}}}
  156. )
  157. def test_multiple_sources_dev_master_no_merge_lists(self):
  158. '''
  159. Test using two ext_pillar dirs. Since all git_pillar repos are merged
  160. into a single dictionary, ordering matters.
  161. This tests with the dev branch followed by master, and with
  162. pillar_merge_lists disabled.
  163. '''
  164. ret = self.get_pillar('''\
  165. file_ignore_regex: []
  166. file_ignore_glob: []
  167. git_pillar_provider: gitpython
  168. cachedir: {cachedir}
  169. extension_modules: {extmods}
  170. pillar_merge_lists: False
  171. ext_pillar:
  172. - git:
  173. - dev {url}
  174. - master {url}
  175. ''')
  176. self.assertEqual(
  177. ret,
  178. {'branch': 'master',
  179. 'mylist': ['master'],
  180. 'mydict': {'master': True,
  181. 'dev': True,
  182. 'nested_list': ['master'],
  183. 'nested_dict': {'master': True, 'dev': True}}}
  184. )
  185. def test_multiple_sources_master_dev_merge_lists(self):
  186. '''
  187. Test using two ext_pillar dirs. Since all git_pillar repos are merged
  188. into a single dictionary, ordering matters.
  189. This tests with the master branch followed by dev, and with
  190. pillar_merge_lists enabled.
  191. '''
  192. ret = self.get_pillar('''\
  193. file_ignore_regex: []
  194. file_ignore_glob: []
  195. git_pillar_provider: gitpython
  196. cachedir: {cachedir}
  197. extension_modules: {extmods}
  198. pillar_merge_lists: True
  199. ext_pillar:
  200. - git:
  201. - master {url}
  202. - dev {url}
  203. ''')
  204. self.assertEqual(
  205. ret,
  206. {'branch': 'dev',
  207. 'mylist': ['master', 'dev'],
  208. 'mydict': {'master': True,
  209. 'dev': True,
  210. 'nested_list': ['master', 'dev'],
  211. 'nested_dict': {'master': True, 'dev': True}}}
  212. )
  213. def test_multiple_sources_dev_master_merge_lists(self):
  214. '''
  215. Test using two ext_pillar dirs. Since all git_pillar repos are merged
  216. into a single dictionary, ordering matters.
  217. This tests with the dev branch followed by master, and with
  218. pillar_merge_lists enabled.
  219. '''
  220. ret = self.get_pillar('''\
  221. file_ignore_regex: []
  222. file_ignore_glob: []
  223. git_pillar_provider: gitpython
  224. cachedir: {cachedir}
  225. extension_modules: {extmods}
  226. pillar_merge_lists: True
  227. ext_pillar:
  228. - git:
  229. - dev {url}
  230. - master {url}
  231. ''')
  232. self.assertEqual(
  233. ret,
  234. {'branch': 'master',
  235. 'mylist': ['dev', 'master'],
  236. 'mydict': {'master': True,
  237. 'dev': True,
  238. 'nested_list': ['dev', 'master'],
  239. 'nested_dict': {'master': True, 'dev': True}}}
  240. )
  241. def test_multiple_sources_with_pillarenv(self):
  242. '''
  243. Test using pillarenv to restrict results to those from a single branch
  244. '''
  245. ret = self.get_pillar('''\
  246. file_ignore_regex: []
  247. file_ignore_glob: []
  248. git_pillar_provider: gitpython
  249. cachedir: {cachedir}
  250. extension_modules: {extmods}
  251. pillarenv: base
  252. ext_pillar:
  253. - git:
  254. - master {url}
  255. - dev {url}
  256. ''')
  257. self.assertEqual(
  258. ret,
  259. {'branch': 'master',
  260. 'mylist': ['master'],
  261. 'mydict': {'master': True,
  262. 'nested_list': ['master'],
  263. 'nested_dict': {'master': True}}}
  264. )
  265. def test_includes_enabled(self):
  266. '''
  267. Test with git_pillar_includes enabled. The top_only branch references
  268. an SLS file from the master branch, so we should see the key from that
  269. SLS file (included_pillar) in the compiled pillar data.
  270. '''
  271. ret = self.get_pillar('''\
  272. file_ignore_regex: []
  273. file_ignore_glob: []
  274. git_pillar_provider: gitpython
  275. cachedir: {cachedir}
  276. extension_modules: {extmods}
  277. ext_pillar:
  278. - git:
  279. - master {url}
  280. - top_only {url}:
  281. - env: base
  282. ''')
  283. self.assertEqual(
  284. ret,
  285. {'branch': 'master',
  286. 'mylist': ['master'],
  287. 'mydict': {'master': True,
  288. 'nested_list': ['master'],
  289. 'nested_dict': {'master': True}},
  290. 'included_pillar': True}
  291. )
  292. def test_includes_disabled(self):
  293. '''
  294. Test with git_pillar_includes enabled. The top_only branch references
  295. an SLS file from the master branch, but since includes are disabled it
  296. will not find the SLS file and the "included_pillar" key should not be
  297. present in the compiled pillar data. We should instead see an error
  298. message in the compiled data.
  299. '''
  300. ret = self.get_pillar('''\
  301. file_ignore_regex: []
  302. file_ignore_glob: []
  303. git_pillar_provider: gitpython
  304. git_pillar_includes: False
  305. cachedir: {cachedir}
  306. extension_modules: {extmods}
  307. ext_pillar:
  308. - git:
  309. - master {url}
  310. - top_only {url}:
  311. - env: base
  312. ''')
  313. self.assertEqual(
  314. ret,
  315. {'branch': 'master',
  316. 'mylist': ['master'],
  317. 'mydict': {'master': True,
  318. 'nested_list': ['master'],
  319. 'nested_dict': {'master': True}},
  320. '_errors': ["Specified SLS 'bar' in environment 'base' is not "
  321. "available on the salt master"]}
  322. )
  323. def test_includes_enabled_solves___env___with_mountpoint(self):
  324. '''
  325. Test with git_pillar_includes enabled and using "__env__" as the branch
  326. name for the configured repositories.
  327. The "gitinfo" repository contains top.sls file with a local reference
  328. and also referencing external "nowhere.foo" which is provided by "webinfo"
  329. repository mounted as "nowhere".
  330. '''
  331. ret = self.get_pillar('''\
  332. file_ignore_regex: []
  333. file_ignore_glob: []
  334. git_pillar_provider: gitpython
  335. cachedir: {cachedir}
  336. extension_modules: {extmods}
  337. ext_pillar:
  338. - git:
  339. - __env__ {url_extra_repo}:
  340. - name: gitinfo
  341. - __env__ {url}:
  342. - name: webinfo
  343. - mountpoint: nowhere
  344. ''')
  345. self.assertEqual(
  346. ret,
  347. {'branch': 'master',
  348. 'motd': 'The force will be with you. Always.',
  349. 'mylist': ['master'],
  350. 'mydict': {'master': True,
  351. 'nested_list': ['master'],
  352. 'nested_dict': {'master': True}}}
  353. )
  354. def test_root_parameter(self):
  355. '''
  356. Test root parameter
  357. '''
  358. expected = {
  359. 'from_subdir': True
  360. }
  361. ret = self.get_pillar('''\
  362. file_ignore_regex: []
  363. file_ignore_glob: []
  364. git_pillar_provider: gitpython
  365. cachedir: {cachedir}
  366. extension_modules: {extmods}
  367. ext_pillar:
  368. - git:
  369. - master {url}:
  370. - root: subdir
  371. - top_only {url}:
  372. - env: base
  373. ''')
  374. self.assertEqual(ret, expected)
  375. def test_mountpoint_parameter(self):
  376. '''
  377. Test mountpoint parameter
  378. '''
  379. expected = {
  380. 'included_pillar': True
  381. }
  382. ret = self.get_pillar('''\
  383. file_ignore_regex: []
  384. file_ignore_glob: []
  385. git_pillar_provider: gitpython
  386. cachedir: {cachedir}
  387. extension_modules: {extmods}
  388. ext_pillar:
  389. - git:
  390. - master {url}:
  391. - mountpoint: mounted
  392. - top_mounted {url}:
  393. - env: base
  394. ''')
  395. self.assertEqual(ret, expected)
  396. def test_root_and_mountpoint_parameters(self):
  397. '''
  398. Test root and mountpoint parameters
  399. '''
  400. expected = {
  401. 'from_subdir': True
  402. }
  403. ret = self.get_pillar('''\
  404. file_ignore_regex: []
  405. file_ignore_glob: []
  406. git_pillar_provider: gitpython
  407. cachedir: {cachedir}
  408. extension_modules: {extmods}
  409. ext_pillar:
  410. - git:
  411. - master {url}:
  412. - mountpoint: mounted
  413. - root: subdir
  414. - top_mounted {url}:
  415. - env: base
  416. ''')
  417. self.assertEqual(ret, expected)
  418. def test_all_saltenvs(self):
  419. '''
  420. Test all_saltenvs parameter.
  421. '''
  422. ret = self.get_pillar('''\
  423. file_ignore_regex: []
  424. file_ignore_glob: []
  425. git_pillar_provider: gitpython
  426. cachedir: {cachedir}
  427. extension_modules: {extmods}
  428. pillarenv: dev
  429. ext_pillar:
  430. - git:
  431. - __env__ {url_extra_repo}:
  432. - all_saltenvs: master
  433. - __env__ {url}:
  434. - mountpoint: nowhere
  435. ''')
  436. self.assertEqual(
  437. ret,
  438. {'branch': 'dev',
  439. 'motd': 'The force will be with you. Always.',
  440. 'mylist': ['dev'],
  441. 'mydict': {'dev': True,
  442. 'nested_list': ['dev'],
  443. 'nested_dict': {'dev': True}}}
  444. )
  445. def test_all_saltenvs_base(self):
  446. '''
  447. Test all_saltenvs parameter with base pillarenv.
  448. '''
  449. ret = self.get_pillar('''\
  450. file_ignore_regex: []
  451. file_ignore_glob: []
  452. git_pillar_provider: gitpython
  453. cachedir: {cachedir}
  454. extension_modules: {extmods}
  455. ext_pillar:
  456. - git:
  457. - __env__ {url_extra_repo}:
  458. - all_saltenvs: master
  459. - __env__ {url}:
  460. - mountpoint: nowhere
  461. ''')
  462. self.assertEqual(
  463. ret,
  464. {'branch': 'master',
  465. 'motd': 'The force will be with you. Always.',
  466. 'mylist': ['master'],
  467. 'mydict': {'master': True,
  468. 'nested_list': ['master'],
  469. 'nested_dict': {'master': True}}}
  470. )
  471. @destructiveTest
  472. @skipIf(NO_MOCK, NO_MOCK_REASON)
  473. @skipIf(_windows_or_mac(), 'minion is windows or mac')
  474. @skip_if_not_root
  475. @skipIf(not HAS_GITPYTHON, 'GitPython >= {0} required'.format(GITPYTHON_MINVER))
  476. @skipIf(not HAS_SSHD, 'sshd not present')
  477. class TestGitPythonSSH(GitPillarSSHTestBase, GitPythonMixin):
  478. '''
  479. Test git_pillar with GitPython using SSH authentication
  480. '''
  481. id_rsa_nopass = _rand_key_name(8)
  482. id_rsa_withpass = _rand_key_name(8)
  483. username = USERNAME
  484. passphrase = PASSWORD
  485. @skipIf(NO_MOCK, NO_MOCK_REASON)
  486. @skipIf(_windows_or_mac(), 'minion is windows or mac')
  487. @skip_if_not_root
  488. @skipIf(not HAS_GITPYTHON, 'GitPython >= {0} required'.format(GITPYTHON_MINVER))
  489. @skipIf(not HAS_NGINX, 'nginx not present')
  490. @skipIf(not HAS_VIRTUALENV, 'virtualenv not present')
  491. class TestGitPythonHTTP(GitPillarHTTPTestBase, GitPythonMixin):
  492. '''
  493. Test git_pillar with GitPython using unauthenticated HTTP
  494. '''
  495. pass
  496. @skipIf(NO_MOCK, NO_MOCK_REASON)
  497. @skipIf(_windows_or_mac(), 'minion is windows or mac')
  498. @skip_if_not_root
  499. @skipIf(not HAS_GITPYTHON, 'GitPython >= {0} required'.format(GITPYTHON_MINVER))
  500. @skipIf(not HAS_NGINX, 'nginx not present')
  501. @skipIf(not HAS_VIRTUALENV, 'virtualenv not present')
  502. class TestGitPythonAuthenticatedHTTP(TestGitPythonHTTP, GitPythonMixin):
  503. '''
  504. Test git_pillar with GitPython using authenticated HTTP
  505. '''
  506. username = USERNAME
  507. password = PASSWORD
  508. @classmethod
  509. def setUpClass(cls):
  510. '''
  511. Create start the webserver
  512. '''
  513. super(TestGitPythonAuthenticatedHTTP, cls).setUpClass()
  514. # Override the URL set up in the parent class to encode the
  515. # username/password into it.
  516. cls.url = 'http://{username}:{password}@127.0.0.1:{port}/repo.git'.format(
  517. username=cls.username,
  518. password=cls.password,
  519. port=cls.nginx_port)
  520. cls.url_extra_repo = 'http://{username}:{password}@127.0.0.1:{port}/extra_repo.git'.format(
  521. username=cls.username,
  522. password=cls.password,
  523. port=cls.nginx_port)
  524. cls.ext_opts['url'] = cls.url
  525. cls.ext_opts['url_extra_repo'] = cls.url_extra_repo
  526. cls.ext_opts['username'] = cls.username
  527. cls.ext_opts['password'] = cls.password
  528. @destructiveTest
  529. @skipIf(NO_MOCK, NO_MOCK_REASON)
  530. @skipIf(_windows_or_mac(), 'minion is windows or mac')
  531. @skip_if_not_root
  532. @skipIf(not HAS_PYGIT2, 'pygit2 >= {0} and libgit2 >= {1} required'.format(PYGIT2_MINVER, LIBGIT2_MINVER))
  533. @skipIf(not HAS_SSHD, 'sshd not present')
  534. class TestPygit2SSH(GitPillarSSHTestBase):
  535. '''
  536. Test git_pillar with pygit2 using SSH authentication
  537. NOTE: Any tests added to this test class should have equivalent tests (if
  538. possible) in the TestGitPythonSSH class.
  539. '''
  540. id_rsa_nopass = _rand_key_name(8)
  541. id_rsa_withpass = _rand_key_name(8)
  542. username = USERNAME
  543. passphrase = PASSWORD
  544. @requires_system_grains
  545. def test_single_source(self, grains):
  546. '''
  547. Test using a single ext_pillar repo
  548. '''
  549. expected = {
  550. 'branch': 'master',
  551. 'mylist': ['master'],
  552. 'mydict': {'master': True,
  553. 'nested_list': ['master'],
  554. 'nested_dict': {'master': True}}
  555. }
  556. # Test with passphraseless key and global credential options
  557. ret = self.get_pillar('''\
  558. file_ignore_regex: []
  559. file_ignore_glob: []
  560. git_pillar_provider: pygit2
  561. git_pillar_pubkey: {pubkey_nopass}
  562. git_pillar_privkey: {privkey_nopass}
  563. cachedir: {cachedir}
  564. extension_modules: {extmods}
  565. ext_pillar:
  566. - git:
  567. - master {url}
  568. ''')
  569. self.assertEqual(ret, expected)
  570. # Test with passphraseless key and per-repo credential options
  571. ret = self.get_pillar('''\
  572. file_ignore_regex: []
  573. file_ignore_glob: []
  574. git_pillar_provider: pygit2
  575. cachedir: {cachedir}
  576. extension_modules: {extmods}
  577. ext_pillar:
  578. - git:
  579. - master {url}:
  580. - pubkey: {pubkey_nopass}
  581. - privkey: {privkey_nopass}
  582. ''')
  583. self.assertEqual(ret, expected)
  584. if grains['os_family'] == 'Debian':
  585. # passphrase-protected currently does not work here
  586. return
  587. # Test with passphrase-protected key and global credential options
  588. ret = self.get_pillar('''\
  589. file_ignore_regex: []
  590. file_ignore_glob: []
  591. git_pillar_provider: pygit2
  592. git_pillar_pubkey: {pubkey_withpass}
  593. git_pillar_privkey: {privkey_withpass}
  594. git_pillar_passphrase: {passphrase}
  595. cachedir: {cachedir}
  596. extension_modules: {extmods}
  597. ext_pillar:
  598. - git:
  599. - master {url}
  600. ''')
  601. self.assertEqual(ret, expected)
  602. # Test with passphrase-protected key and per-repo credential options
  603. ret = self.get_pillar('''\
  604. file_ignore_regex: []
  605. file_ignore_glob: []
  606. git_pillar_provider: pygit2
  607. cachedir: {cachedir}
  608. extension_modules: {extmods}
  609. ext_pillar:
  610. - git:
  611. - master {url}:
  612. - pubkey: {pubkey_withpass}
  613. - privkey: {privkey_withpass}
  614. - passphrase: {passphrase}
  615. ''')
  616. self.assertEqual(ret, expected)
  617. @requires_system_grains
  618. def test_multiple_sources_master_dev_no_merge_lists(self, grains):
  619. '''
  620. Test using two ext_pillar dirs. Since all git_pillar repos are merged
  621. into a single dictionary, ordering matters.
  622. This tests with the master branch followed by dev, and with
  623. pillar_merge_lists disabled.
  624. '''
  625. expected = {
  626. 'branch': 'dev',
  627. 'mylist': ['dev'],
  628. 'mydict': {'master': True,
  629. 'dev': True,
  630. 'nested_list': ['dev'],
  631. 'nested_dict': {'master': True, 'dev': True}}
  632. }
  633. # Test with passphraseless key and global credential options
  634. ret = self.get_pillar('''\
  635. file_ignore_regex: []
  636. file_ignore_glob: []
  637. git_pillar_provider: pygit2
  638. git_pillar_pubkey: {pubkey_nopass}
  639. git_pillar_privkey: {privkey_nopass}
  640. cachedir: {cachedir}
  641. extension_modules: {extmods}
  642. pillar_merge_lists: False
  643. ext_pillar:
  644. - git:
  645. - master {url}
  646. - dev {url}
  647. ''')
  648. self.assertEqual(ret, expected)
  649. # Test with passphraseless key and per-repo credential options
  650. ret = self.get_pillar('''\
  651. file_ignore_regex: []
  652. file_ignore_glob: []
  653. git_pillar_provider: pygit2
  654. cachedir: {cachedir}
  655. extension_modules: {extmods}
  656. pillar_merge_lists: False
  657. ext_pillar:
  658. - git:
  659. - master {url}:
  660. - pubkey: {pubkey_nopass}
  661. - privkey: {privkey_nopass}
  662. - dev {url}:
  663. - pubkey: {pubkey_nopass}
  664. - privkey: {privkey_nopass}
  665. ''')
  666. self.assertEqual(ret, expected)
  667. if grains['os_family'] == 'Debian':
  668. # passphrase-protected currently does not work here
  669. return
  670. # Test with passphrase-protected key and global credential options
  671. ret = self.get_pillar('''\
  672. file_ignore_regex: []
  673. file_ignore_glob: []
  674. git_pillar_provider: pygit2
  675. git_pillar_pubkey: {pubkey_withpass}
  676. git_pillar_privkey: {privkey_withpass}
  677. git_pillar_passphrase: {passphrase}
  678. cachedir: {cachedir}
  679. extension_modules: {extmods}
  680. pillar_merge_lists: False
  681. ext_pillar:
  682. - git:
  683. - master {url}
  684. - dev {url}
  685. ''')
  686. self.assertEqual(ret, expected)
  687. # Test with passphrase-protected key and per-repo credential options
  688. ret = self.get_pillar('''\
  689. file_ignore_regex: []
  690. file_ignore_glob: []
  691. git_pillar_provider: pygit2
  692. cachedir: {cachedir}
  693. extension_modules: {extmods}
  694. pillar_merge_lists: False
  695. ext_pillar:
  696. - git:
  697. - master {url}:
  698. - pubkey: {pubkey_withpass}
  699. - privkey: {privkey_withpass}
  700. - passphrase: {passphrase}
  701. - dev {url}:
  702. - pubkey: {pubkey_withpass}
  703. - privkey: {privkey_withpass}
  704. - passphrase: {passphrase}
  705. ''')
  706. self.assertEqual(ret, expected)
  707. @requires_system_grains
  708. def test_multiple_sources_dev_master_no_merge_lists(self, grains):
  709. '''
  710. Test using two ext_pillar dirs. Since all git_pillar repos are merged
  711. into a single dictionary, ordering matters.
  712. This tests with the dev branch followed by master, and with
  713. pillar_merge_lists disabled.
  714. '''
  715. expected = {
  716. 'branch': 'master',
  717. 'mylist': ['master'],
  718. 'mydict': {'master': True,
  719. 'dev': True,
  720. 'nested_list': ['master'],
  721. 'nested_dict': {'master': True, 'dev': True}}
  722. }
  723. # Test with passphraseless key and global credential options
  724. ret = self.get_pillar('''\
  725. file_ignore_regex: []
  726. file_ignore_glob: []
  727. git_pillar_provider: pygit2
  728. git_pillar_pubkey: {pubkey_nopass}
  729. git_pillar_privkey: {privkey_nopass}
  730. cachedir: {cachedir}
  731. extension_modules: {extmods}
  732. pillar_merge_lists: False
  733. ext_pillar:
  734. - git:
  735. - dev {url}
  736. - master {url}
  737. ''')
  738. self.assertEqual(ret, expected)
  739. # Test with passphraseless key and per-repo credential options
  740. ret = self.get_pillar('''\
  741. file_ignore_regex: []
  742. file_ignore_glob: []
  743. git_pillar_provider: pygit2
  744. cachedir: {cachedir}
  745. extension_modules: {extmods}
  746. pillar_merge_lists: False
  747. ext_pillar:
  748. - git:
  749. - dev {url}:
  750. - pubkey: {pubkey_nopass}
  751. - privkey: {privkey_nopass}
  752. - master {url}:
  753. - pubkey: {pubkey_nopass}
  754. - privkey: {privkey_nopass}
  755. ''')
  756. self.assertEqual(ret, expected)
  757. if grains['os_family'] == 'Debian':
  758. # passphrase-protected currently does not work here
  759. return
  760. # Test with passphrase-protected key and global credential options
  761. ret = self.get_pillar('''\
  762. file_ignore_regex: []
  763. file_ignore_glob: []
  764. git_pillar_provider: pygit2
  765. git_pillar_pubkey: {pubkey_withpass}
  766. git_pillar_privkey: {privkey_withpass}
  767. git_pillar_passphrase: {passphrase}
  768. cachedir: {cachedir}
  769. extension_modules: {extmods}
  770. pillar_merge_lists: False
  771. ext_pillar:
  772. - git:
  773. - dev {url}
  774. - master {url}
  775. ''')
  776. self.assertEqual(ret, expected)
  777. # Test with passphrase-protected key and per-repo credential options
  778. ret = self.get_pillar('''\
  779. file_ignore_regex: []
  780. file_ignore_glob: []
  781. git_pillar_provider: pygit2
  782. cachedir: {cachedir}
  783. extension_modules: {extmods}
  784. pillar_merge_lists: False
  785. ext_pillar:
  786. - git:
  787. - dev {url}:
  788. - pubkey: {pubkey_withpass}
  789. - privkey: {privkey_withpass}
  790. - passphrase: {passphrase}
  791. - master {url}:
  792. - pubkey: {pubkey_withpass}
  793. - privkey: {privkey_withpass}
  794. - passphrase: {passphrase}
  795. ''')
  796. self.assertEqual(ret, expected)
  797. @requires_system_grains
  798. def test_multiple_sources_master_dev_merge_lists(self, grains):
  799. '''
  800. Test using two ext_pillar dirs. Since all git_pillar repos are merged
  801. into a single dictionary, ordering matters.
  802. This tests with the master branch followed by dev, and with
  803. pillar_merge_lists enabled.
  804. '''
  805. expected = {
  806. 'branch': 'dev',
  807. 'mylist': ['master', 'dev'],
  808. 'mydict': {'master': True,
  809. 'dev': True,
  810. 'nested_list': ['master', 'dev'],
  811. 'nested_dict': {'master': True, 'dev': True}}
  812. }
  813. # Test with passphraseless key and global credential options
  814. ret = self.get_pillar('''\
  815. file_ignore_regex: []
  816. file_ignore_glob: []
  817. git_pillar_provider: pygit2
  818. git_pillar_pubkey: {pubkey_nopass}
  819. git_pillar_privkey: {privkey_nopass}
  820. cachedir: {cachedir}
  821. extension_modules: {extmods}
  822. pillar_merge_lists: True
  823. ext_pillar:
  824. - git:
  825. - master {url}
  826. - dev {url}
  827. ''')
  828. self.assertEqual(ret, expected)
  829. # Test with passphraseless key and per-repo credential options
  830. ret = self.get_pillar('''\
  831. file_ignore_regex: []
  832. file_ignore_glob: []
  833. git_pillar_provider: pygit2
  834. cachedir: {cachedir}
  835. extension_modules: {extmods}
  836. pillar_merge_lists: True
  837. ext_pillar:
  838. - git:
  839. - master {url}:
  840. - pubkey: {pubkey_nopass}
  841. - privkey: {privkey_nopass}
  842. - dev {url}:
  843. - pubkey: {pubkey_nopass}
  844. - privkey: {privkey_nopass}
  845. ''')
  846. self.assertEqual(ret, expected)
  847. if grains['os_family'] == 'Debian':
  848. # passphrase-protected currently does not work here
  849. return
  850. # Test with passphrase-protected key and global credential options
  851. ret = self.get_pillar('''\
  852. file_ignore_regex: []
  853. file_ignore_glob: []
  854. git_pillar_provider: pygit2
  855. git_pillar_pubkey: {pubkey_withpass}
  856. git_pillar_privkey: {privkey_withpass}
  857. git_pillar_passphrase: {passphrase}
  858. cachedir: {cachedir}
  859. extension_modules: {extmods}
  860. pillar_merge_lists: True
  861. ext_pillar:
  862. - git:
  863. - master {url}
  864. - dev {url}
  865. ''')
  866. self.assertEqual(ret, expected)
  867. # Test with passphrase-protected key and per-repo credential options
  868. ret = self.get_pillar('''\
  869. file_ignore_regex: []
  870. file_ignore_glob: []
  871. git_pillar_provider: pygit2
  872. cachedir: {cachedir}
  873. extension_modules: {extmods}
  874. pillar_merge_lists: True
  875. ext_pillar:
  876. - git:
  877. - master {url}:
  878. - pubkey: {pubkey_withpass}
  879. - privkey: {privkey_withpass}
  880. - passphrase: {passphrase}
  881. - dev {url}:
  882. - pubkey: {pubkey_withpass}
  883. - privkey: {privkey_withpass}
  884. - passphrase: {passphrase}
  885. ''')
  886. self.assertEqual(ret, expected)
  887. @requires_system_grains
  888. def test_multiple_sources_dev_master_merge_lists(self, grains):
  889. '''
  890. Test using two ext_pillar dirs. Since all git_pillar repos are merged
  891. into a single dictionary, ordering matters.
  892. This tests with the dev branch followed by master, and with
  893. pillar_merge_lists enabled.
  894. '''
  895. expected = {
  896. 'branch': 'master',
  897. 'mylist': ['dev', 'master'],
  898. 'mydict': {'master': True,
  899. 'dev': True,
  900. 'nested_list': ['dev', 'master'],
  901. 'nested_dict': {'master': True, 'dev': True}}
  902. }
  903. # Test with passphraseless key and global credential options
  904. ret = self.get_pillar('''\
  905. file_ignore_regex: []
  906. file_ignore_glob: []
  907. git_pillar_provider: pygit2
  908. git_pillar_pubkey: {pubkey_nopass}
  909. git_pillar_privkey: {privkey_nopass}
  910. cachedir: {cachedir}
  911. extension_modules: {extmods}
  912. pillar_merge_lists: True
  913. ext_pillar:
  914. - git:
  915. - dev {url}
  916. - master {url}
  917. ''')
  918. self.assertEqual(ret, expected)
  919. # Test with passphraseless key and per-repo credential options
  920. ret = self.get_pillar('''\
  921. file_ignore_regex: []
  922. file_ignore_glob: []
  923. git_pillar_provider: pygit2
  924. cachedir: {cachedir}
  925. extension_modules: {extmods}
  926. pillar_merge_lists: True
  927. ext_pillar:
  928. - git:
  929. - dev {url}:
  930. - pubkey: {pubkey_nopass}
  931. - privkey: {privkey_nopass}
  932. - master {url}:
  933. - pubkey: {pubkey_nopass}
  934. - privkey: {privkey_nopass}
  935. ''')
  936. self.assertEqual(ret, expected)
  937. if grains['os_family'] == 'Debian':
  938. # passphrase-protected currently does not work here
  939. return
  940. # Test with passphrase-protected key and global credential options
  941. ret = self.get_pillar('''\
  942. file_ignore_regex: []
  943. file_ignore_glob: []
  944. git_pillar_provider: pygit2
  945. git_pillar_pubkey: {pubkey_withpass}
  946. git_pillar_privkey: {privkey_withpass}
  947. git_pillar_passphrase: {passphrase}
  948. cachedir: {cachedir}
  949. extension_modules: {extmods}
  950. pillar_merge_lists: True
  951. ext_pillar:
  952. - git:
  953. - dev {url}
  954. - master {url}
  955. ''')
  956. self.assertEqual(ret, expected)
  957. # Test with passphrase-protected key and per-repo credential options
  958. ret = self.get_pillar('''\
  959. file_ignore_regex: []
  960. file_ignore_glob: []
  961. git_pillar_provider: pygit2
  962. cachedir: {cachedir}
  963. extension_modules: {extmods}
  964. pillar_merge_lists: True
  965. ext_pillar:
  966. - git:
  967. - dev {url}:
  968. - pubkey: {pubkey_withpass}
  969. - privkey: {privkey_withpass}
  970. - passphrase: {passphrase}
  971. - master {url}:
  972. - pubkey: {pubkey_withpass}
  973. - privkey: {privkey_withpass}
  974. - passphrase: {passphrase}
  975. ''')
  976. self.assertEqual(ret, expected)
  977. @requires_system_grains
  978. def test_multiple_sources_with_pillarenv(self, grains):
  979. '''
  980. Test using pillarenv to restrict results to those from a single branch
  981. '''
  982. expected = {
  983. 'branch': 'master',
  984. 'mylist': ['master'],
  985. 'mydict': {'master': True,
  986. 'nested_list': ['master'],
  987. 'nested_dict': {'master': True}}
  988. }
  989. # Test with passphraseless key and global credential options
  990. ret = self.get_pillar('''\
  991. file_ignore_regex: []
  992. file_ignore_glob: []
  993. git_pillar_provider: pygit2
  994. git_pillar_pubkey: {pubkey_nopass}
  995. git_pillar_privkey: {privkey_nopass}
  996. cachedir: {cachedir}
  997. extension_modules: {extmods}
  998. pillarenv: base
  999. ext_pillar:
  1000. - git:
  1001. - master {url}
  1002. - dev {url}
  1003. ''')
  1004. self.assertEqual(ret, expected)
  1005. # Test with passphraseless key and per-repo credential options
  1006. ret = self.get_pillar('''\
  1007. file_ignore_regex: []
  1008. file_ignore_glob: []
  1009. git_pillar_provider: pygit2
  1010. cachedir: {cachedir}
  1011. extension_modules: {extmods}
  1012. pillarenv: base
  1013. ext_pillar:
  1014. - git:
  1015. - master {url}:
  1016. - pubkey: {pubkey_nopass}
  1017. - privkey: {privkey_nopass}
  1018. - dev {url}:
  1019. - pubkey: {pubkey_nopass}
  1020. - privkey: {privkey_nopass}
  1021. ''')
  1022. self.assertEqual(ret, expected)
  1023. if grains['os_family'] == 'Debian':
  1024. # passphrase-protected currently does not work here
  1025. return
  1026. # Test with passphrase-protected key and global credential options
  1027. ret = self.get_pillar('''\
  1028. file_ignore_regex: []
  1029. file_ignore_glob: []
  1030. git_pillar_provider: pygit2
  1031. git_pillar_pubkey: {pubkey_withpass}
  1032. git_pillar_privkey: {privkey_withpass}
  1033. git_pillar_passphrase: {passphrase}
  1034. cachedir: {cachedir}
  1035. extension_modules: {extmods}
  1036. pillarenv: base
  1037. ext_pillar:
  1038. - git:
  1039. - master {url}
  1040. - dev {url}
  1041. ''')
  1042. self.assertEqual(ret, expected)
  1043. # Test with passphrase-protected key and per-repo credential options
  1044. ret = self.get_pillar('''\
  1045. file_ignore_regex: []
  1046. file_ignore_glob: []
  1047. git_pillar_provider: pygit2
  1048. cachedir: {cachedir}
  1049. extension_modules: {extmods}
  1050. pillarenv: base
  1051. ext_pillar:
  1052. - git:
  1053. - master {url}:
  1054. - pubkey: {pubkey_withpass}
  1055. - privkey: {privkey_withpass}
  1056. - passphrase: {passphrase}
  1057. - dev {url}:
  1058. - pubkey: {pubkey_nopass}
  1059. - privkey: {privkey_nopass}
  1060. - passphrase: {passphrase}
  1061. ''')
  1062. self.assertEqual(ret, expected)
  1063. @requires_system_grains
  1064. def test_includes_enabled(self, grains):
  1065. '''
  1066. Test with git_pillar_includes enabled. The top_only branch references
  1067. an SLS file from the master branch, so we should see the
  1068. "included_pillar" key from that SLS file in the compiled pillar data.
  1069. '''
  1070. expected = {
  1071. 'branch': 'master',
  1072. 'mylist': ['master'],
  1073. 'mydict': {'master': True,
  1074. 'nested_list': ['master'],
  1075. 'nested_dict': {'master': True}},
  1076. 'included_pillar': True
  1077. }
  1078. # Test with passphraseless key and global credential options
  1079. ret = self.get_pillar('''\
  1080. file_ignore_regex: []
  1081. file_ignore_glob: []
  1082. git_pillar_provider: pygit2
  1083. git_pillar_pubkey: {pubkey_nopass}
  1084. git_pillar_privkey: {privkey_nopass}
  1085. cachedir: {cachedir}
  1086. extension_modules: {extmods}
  1087. ext_pillar:
  1088. - git:
  1089. - master {url}
  1090. - top_only {url}:
  1091. - env: base
  1092. ''')
  1093. self.assertEqual(ret, expected)
  1094. # Test with passphraseless key and per-repo credential options
  1095. ret = self.get_pillar('''\
  1096. file_ignore_regex: []
  1097. file_ignore_glob: []
  1098. git_pillar_provider: pygit2
  1099. cachedir: {cachedir}
  1100. extension_modules: {extmods}
  1101. ext_pillar:
  1102. - git:
  1103. - master {url}:
  1104. - pubkey: {pubkey_nopass}
  1105. - privkey: {privkey_nopass}
  1106. - top_only {url}:
  1107. - pubkey: {pubkey_nopass}
  1108. - privkey: {privkey_nopass}
  1109. - env: base
  1110. ''')
  1111. self.assertEqual(ret, expected)
  1112. if grains['os_family'] == 'Debian':
  1113. # passphrase-protected currently does not work here
  1114. return
  1115. # Test with passphrase-protected key and global credential options
  1116. ret = self.get_pillar('''\
  1117. file_ignore_regex: []
  1118. file_ignore_glob: []
  1119. git_pillar_provider: pygit2
  1120. git_pillar_pubkey: {pubkey_withpass}
  1121. git_pillar_privkey: {privkey_withpass}
  1122. git_pillar_passphrase: {passphrase}
  1123. cachedir: {cachedir}
  1124. extension_modules: {extmods}
  1125. ext_pillar:
  1126. - git:
  1127. - master {url}
  1128. - top_only {url}:
  1129. - env: base
  1130. ''')
  1131. self.assertEqual(ret, expected)
  1132. # Test with passphrase-protected key and per-repo credential options
  1133. ret = self.get_pillar('''\
  1134. file_ignore_regex: []
  1135. file_ignore_glob: []
  1136. git_pillar_provider: pygit2
  1137. cachedir: {cachedir}
  1138. extension_modules: {extmods}
  1139. ext_pillar:
  1140. - git:
  1141. - master {url}:
  1142. - pubkey: {pubkey_withpass}
  1143. - privkey: {privkey_withpass}
  1144. - passphrase: {passphrase}
  1145. - top_only {url}:
  1146. - pubkey: {pubkey_withpass}
  1147. - privkey: {privkey_withpass}
  1148. - passphrase: {passphrase}
  1149. - env: base
  1150. ''')
  1151. self.assertEqual(ret, expected)
  1152. @requires_system_grains
  1153. def test_includes_disabled(self, grains):
  1154. '''
  1155. Test with git_pillar_includes enabled. The top_only branch references
  1156. an SLS file from the master branch, but since includes are disabled it
  1157. will not find the SLS file and the "included_pillar" key should not be
  1158. present in the compiled pillar data. We should instead see an error
  1159. message in the compiled data.
  1160. '''
  1161. expected = {
  1162. 'branch': 'master',
  1163. 'mylist': ['master'],
  1164. 'mydict': {'master': True,
  1165. 'nested_list': ['master'],
  1166. 'nested_dict': {'master': True}},
  1167. '_errors': ["Specified SLS 'bar' in environment 'base' is not "
  1168. "available on the salt master"]
  1169. }
  1170. # Test with passphraseless key and global credential options
  1171. ret = self.get_pillar('''\
  1172. file_ignore_regex: []
  1173. file_ignore_glob: []
  1174. git_pillar_provider: pygit2
  1175. git_pillar_includes: False
  1176. git_pillar_pubkey: {pubkey_nopass}
  1177. git_pillar_privkey: {privkey_nopass}
  1178. cachedir: {cachedir}
  1179. extension_modules: {extmods}
  1180. ext_pillar:
  1181. - git:
  1182. - master {url}
  1183. - top_only {url}:
  1184. - env: base
  1185. ''')
  1186. self.assertEqual(ret, expected)
  1187. # Test with passphraseless key and per-repo credential options
  1188. ret = self.get_pillar('''\
  1189. file_ignore_regex: []
  1190. file_ignore_glob: []
  1191. git_pillar_provider: pygit2
  1192. git_pillar_includes: False
  1193. cachedir: {cachedir}
  1194. extension_modules: {extmods}
  1195. ext_pillar:
  1196. - git:
  1197. - master {url}:
  1198. - pubkey: {pubkey_nopass}
  1199. - privkey: {privkey_nopass}
  1200. - top_only {url}:
  1201. - pubkey: {pubkey_nopass}
  1202. - privkey: {privkey_nopass}
  1203. - env: base
  1204. ''')
  1205. self.assertEqual(ret, expected)
  1206. if grains['os_family'] == 'Debian':
  1207. # passphrase-protected currently does not work here
  1208. return
  1209. # Test with passphrase-protected key and global credential options
  1210. ret = self.get_pillar('''\
  1211. file_ignore_regex: []
  1212. file_ignore_glob: []
  1213. git_pillar_provider: pygit2
  1214. git_pillar_includes: False
  1215. git_pillar_pubkey: {pubkey_withpass}
  1216. git_pillar_privkey: {privkey_withpass}
  1217. git_pillar_passphrase: {passphrase}
  1218. cachedir: {cachedir}
  1219. extension_modules: {extmods}
  1220. ext_pillar:
  1221. - git:
  1222. - master {url}
  1223. - top_only {url}:
  1224. - env: base
  1225. ''')
  1226. self.assertEqual(ret, expected)
  1227. # Test with passphrase-protected key and per-repo credential options
  1228. ret = self.get_pillar('''\
  1229. file_ignore_regex: []
  1230. file_ignore_glob: []
  1231. git_pillar_provider: pygit2
  1232. git_pillar_includes: False
  1233. cachedir: {cachedir}
  1234. extension_modules: {extmods}
  1235. ext_pillar:
  1236. - git:
  1237. - master {url}:
  1238. - pubkey: {pubkey_withpass}
  1239. - privkey: {privkey_withpass}
  1240. - passphrase: {passphrase}
  1241. - top_only {url}:
  1242. - pubkey: {pubkey_withpass}
  1243. - privkey: {privkey_withpass}
  1244. - passphrase: {passphrase}
  1245. - env: base
  1246. ''')
  1247. self.assertEqual(ret, expected)
  1248. def test_includes_enabled_solves___env___with_mountpoint(self):
  1249. '''
  1250. Test with git_pillar_includes enabled and using "__env__" as the branch
  1251. name for the configured repositories.
  1252. The "gitinfo" repository contains top.sls file with a local reference
  1253. and also referencing external "nowhere.foo" which is provided by "webinfo"
  1254. repository mounted as "nowhere".
  1255. '''
  1256. ret = self.get_pillar('''\
  1257. file_ignore_regex: []
  1258. file_ignore_glob: []
  1259. git_pillar_provider: pygit2
  1260. git_pillar_pubkey: {pubkey_nopass}
  1261. git_pillar_privkey: {privkey_nopass}
  1262. cachedir: {cachedir}
  1263. extension_modules: {extmods}
  1264. ext_pillar:
  1265. - git:
  1266. - __env__ {url_extra_repo}:
  1267. - name: gitinfo
  1268. - __env__ {url}:
  1269. - name: webinfo
  1270. - mountpoint: nowhere
  1271. ''')
  1272. self.assertEqual(
  1273. ret,
  1274. {'branch': 'master',
  1275. 'motd': 'The force will be with you. Always.',
  1276. 'mylist': ['master'],
  1277. 'mydict': {'master': True,
  1278. 'nested_list': ['master'],
  1279. 'nested_dict': {'master': True}}}
  1280. )
  1281. @requires_system_grains
  1282. def test_root_parameter(self, grains):
  1283. '''
  1284. Test root parameter
  1285. '''
  1286. expected = {
  1287. 'from_subdir': True
  1288. }
  1289. # Test with passphraseless key and global credential options
  1290. ret = self.get_pillar('''\
  1291. file_ignore_regex: []
  1292. file_ignore_glob: []
  1293. git_pillar_provider: pygit2
  1294. git_pillar_pubkey: {pubkey_nopass}
  1295. git_pillar_privkey: {privkey_nopass}
  1296. cachedir: {cachedir}
  1297. extension_modules: {extmods}
  1298. ext_pillar:
  1299. - git:
  1300. - master {url}:
  1301. - root: subdir
  1302. - top_only {url}:
  1303. - env: base
  1304. ''')
  1305. self.assertEqual(ret, expected)
  1306. # Test with passphraseless key and per-repo credential options
  1307. ret = self.get_pillar('''\
  1308. file_ignore_regex: []
  1309. file_ignore_glob: []
  1310. git_pillar_provider: pygit2
  1311. cachedir: {cachedir}
  1312. extension_modules: {extmods}
  1313. ext_pillar:
  1314. - git:
  1315. - master {url}:
  1316. - root: subdir
  1317. - pubkey: {pubkey_nopass}
  1318. - privkey: {privkey_nopass}
  1319. - top_only {url}:
  1320. - pubkey: {pubkey_nopass}
  1321. - privkey: {privkey_nopass}
  1322. - env: base
  1323. ''')
  1324. self.assertEqual(ret, expected)
  1325. if grains['os_family'] == 'Debian':
  1326. # passphrase-protected currently does not work here
  1327. return
  1328. # Test with passphrase-protected key and global credential options
  1329. ret = self.get_pillar('''\
  1330. file_ignore_regex: []
  1331. file_ignore_glob: []
  1332. git_pillar_provider: pygit2
  1333. git_pillar_pubkey: {pubkey_withpass}
  1334. git_pillar_privkey: {privkey_withpass}
  1335. git_pillar_passphrase: {passphrase}
  1336. cachedir: {cachedir}
  1337. extension_modules: {extmods}
  1338. ext_pillar:
  1339. - git:
  1340. - master {url}:
  1341. - root: subdir
  1342. - top_only {url}:
  1343. - env: base
  1344. ''')
  1345. self.assertEqual(ret, expected)
  1346. # Test with passphrase-protected key and per-repo credential options
  1347. ret = self.get_pillar('''\
  1348. file_ignore_regex: []
  1349. file_ignore_glob: []
  1350. git_pillar_provider: pygit2
  1351. cachedir: {cachedir}
  1352. extension_modules: {extmods}
  1353. ext_pillar:
  1354. - git:
  1355. - master {url}:
  1356. - root: subdir
  1357. - pubkey: {pubkey_withpass}
  1358. - privkey: {privkey_withpass}
  1359. - passphrase: {passphrase}
  1360. - top_only {url}:
  1361. - pubkey: {pubkey_withpass}
  1362. - privkey: {privkey_withpass}
  1363. - passphrase: {passphrase}
  1364. - env: base
  1365. ''')
  1366. self.assertEqual(ret, expected)
  1367. @requires_system_grains
  1368. def test_mountpoint_parameter(self, grains):
  1369. '''
  1370. Test mountpoint parameter
  1371. '''
  1372. expected = {
  1373. 'included_pillar': True
  1374. }
  1375. # Test with passphraseless key and global credential options
  1376. ret = self.get_pillar('''\
  1377. file_ignore_regex: []
  1378. file_ignore_glob: []
  1379. git_pillar_provider: pygit2
  1380. git_pillar_pubkey: {pubkey_nopass}
  1381. git_pillar_privkey: {privkey_nopass}
  1382. cachedir: {cachedir}
  1383. extension_modules: {extmods}
  1384. ext_pillar:
  1385. - git:
  1386. - master {url}:
  1387. - mountpoint: mounted
  1388. - top_mounted {url}:
  1389. - env: base
  1390. ''')
  1391. self.assertEqual(ret, expected)
  1392. # Test with passphraseless key and per-repo credential options
  1393. ret = self.get_pillar('''\
  1394. file_ignore_regex: []
  1395. file_ignore_glob: []
  1396. git_pillar_provider: pygit2
  1397. cachedir: {cachedir}
  1398. extension_modules: {extmods}
  1399. ext_pillar:
  1400. - git:
  1401. - master {url}:
  1402. - mountpoint: mounted
  1403. - pubkey: {pubkey_nopass}
  1404. - privkey: {privkey_nopass}
  1405. - top_mounted {url}:
  1406. - pubkey: {pubkey_nopass}
  1407. - privkey: {privkey_nopass}
  1408. - env: base
  1409. ''')
  1410. self.assertEqual(ret, expected)
  1411. if grains['os_family'] == 'Debian':
  1412. # passphrase-protected currently does not work here
  1413. return
  1414. # Test with passphrase-protected key and global credential options
  1415. ret = self.get_pillar('''\
  1416. file_ignore_regex: []
  1417. file_ignore_glob: []
  1418. git_pillar_provider: pygit2
  1419. git_pillar_pubkey: {pubkey_withpass}
  1420. git_pillar_privkey: {privkey_withpass}
  1421. git_pillar_passphrase: {passphrase}
  1422. cachedir: {cachedir}
  1423. extension_modules: {extmods}
  1424. ext_pillar:
  1425. - git:
  1426. - master {url}:
  1427. - mountpoint: mounted
  1428. - top_mounted {url}:
  1429. - env: base
  1430. ''')
  1431. self.assertEqual(ret, expected)
  1432. # Test with passphrase-protected key and per-repo credential options
  1433. ret = self.get_pillar('''\
  1434. file_ignore_regex: []
  1435. file_ignore_glob: []
  1436. git_pillar_provider: pygit2
  1437. cachedir: {cachedir}
  1438. extension_modules: {extmods}
  1439. ext_pillar:
  1440. - git:
  1441. - master {url}:
  1442. - mountpoint: mounted
  1443. - pubkey: {pubkey_withpass}
  1444. - privkey: {privkey_withpass}
  1445. - passphrase: {passphrase}
  1446. - top_mounted {url}:
  1447. - pubkey: {pubkey_withpass}
  1448. - privkey: {privkey_withpass}
  1449. - passphrase: {passphrase}
  1450. - env: base
  1451. ''')
  1452. self.assertEqual(ret, expected)
  1453. @requires_system_grains
  1454. def test_root_and_mountpoint_parameters(self, grains):
  1455. '''
  1456. Test root and mountpoint parameters
  1457. '''
  1458. expected = {
  1459. 'from_subdir': True
  1460. }
  1461. # Test with passphraseless key and global credential options
  1462. ret = self.get_pillar('''\
  1463. file_ignore_regex: []
  1464. file_ignore_glob: []
  1465. git_pillar_provider: pygit2
  1466. git_pillar_pubkey: {pubkey_nopass}
  1467. git_pillar_privkey: {privkey_nopass}
  1468. cachedir: {cachedir}
  1469. extension_modules: {extmods}
  1470. ext_pillar:
  1471. - git:
  1472. - master {url}:
  1473. - mountpoint: mounted
  1474. - root: subdir
  1475. - top_mounted {url}:
  1476. - env: base
  1477. ''')
  1478. self.assertEqual(ret, expected)
  1479. # Test with passphraseless key and per-repo credential options
  1480. ret = self.get_pillar('''\
  1481. file_ignore_regex: []
  1482. file_ignore_glob: []
  1483. git_pillar_provider: pygit2
  1484. cachedir: {cachedir}
  1485. extension_modules: {extmods}
  1486. ext_pillar:
  1487. - git:
  1488. - master {url}:
  1489. - mountpoint: mounted
  1490. - root: subdir
  1491. - pubkey: {pubkey_nopass}
  1492. - privkey: {privkey_nopass}
  1493. - top_mounted {url}:
  1494. - pubkey: {pubkey_nopass}
  1495. - privkey: {privkey_nopass}
  1496. - env: base
  1497. ''')
  1498. self.assertEqual(ret, expected)
  1499. if grains['os_family'] == 'Debian':
  1500. # passphrase-protected currently does not work here
  1501. return
  1502. # Test with passphrase-protected key and global credential options
  1503. ret = self.get_pillar('''\
  1504. file_ignore_regex: []
  1505. file_ignore_glob: []
  1506. git_pillar_provider: pygit2
  1507. git_pillar_pubkey: {pubkey_withpass}
  1508. git_pillar_privkey: {privkey_withpass}
  1509. git_pillar_passphrase: {passphrase}
  1510. cachedir: {cachedir}
  1511. extension_modules: {extmods}
  1512. ext_pillar:
  1513. - git:
  1514. - master {url}:
  1515. - mountpoint: mounted
  1516. - root: subdir
  1517. - top_mounted {url}:
  1518. - env: base
  1519. ''')
  1520. self.assertEqual(ret, expected)
  1521. # Test with passphrase-protected key and per-repo credential options
  1522. ret = self.get_pillar('''\
  1523. file_ignore_regex: []
  1524. file_ignore_glob: []
  1525. git_pillar_provider: pygit2
  1526. cachedir: {cachedir}
  1527. extension_modules: {extmods}
  1528. ext_pillar:
  1529. - git:
  1530. - master {url}:
  1531. - mountpoint: mounted
  1532. - root: subdir
  1533. - pubkey: {pubkey_withpass}
  1534. - privkey: {privkey_withpass}
  1535. - passphrase: {passphrase}
  1536. - top_mounted {url}:
  1537. - pubkey: {pubkey_withpass}
  1538. - privkey: {privkey_withpass}
  1539. - passphrase: {passphrase}
  1540. - env: base
  1541. ''')
  1542. self.assertEqual(ret, expected)
  1543. @requires_system_grains
  1544. def test_all_saltenvs(self, grains):
  1545. '''
  1546. Test all_saltenvs parameter.
  1547. '''
  1548. expected = {'branch': 'dev',
  1549. 'motd': 'The force will be with you. Always.',
  1550. 'mylist': ['dev'],
  1551. 'mydict': {'dev': True,
  1552. 'nested_list': ['dev'],
  1553. 'nested_dict': {'dev': True}
  1554. }
  1555. }
  1556. # Test with passphraseless key and global credential options
  1557. ret = self.get_pillar('''\
  1558. file_ignore_regex: []
  1559. file_ignore_glob: []
  1560. git_pillar_provider: pygit2
  1561. git_pillar_pubkey: {pubkey_nopass}
  1562. git_pillar_privkey: {privkey_nopass}
  1563. cachedir: {cachedir}
  1564. extension_modules: {extmods}
  1565. pillarenv: dev
  1566. ext_pillar:
  1567. - git:
  1568. - __env__ {url_extra_repo}:
  1569. - all_saltenvs: master
  1570. - __env__ {url}:
  1571. - mountpoint: nowhere
  1572. ''')
  1573. self.assertEqual(ret, expected)
  1574. # Test with passphraseless key and per-repo credential options
  1575. ret = self.get_pillar('''\
  1576. file_ignore_regex: []
  1577. file_ignore_glob: []
  1578. git_pillar_provider: pygit2
  1579. cachedir: {cachedir}
  1580. extension_modules: {extmods}
  1581. pillarenv: dev
  1582. ext_pillar:
  1583. - git:
  1584. - __env__ {url_extra_repo}:
  1585. - all_saltenvs: master
  1586. - pubkey: {pubkey_nopass}
  1587. - privkey: {privkey_nopass}
  1588. - __env__ {url}:
  1589. - mountpoint: nowhere
  1590. - pubkey: {pubkey_nopass}
  1591. - privkey: {privkey_nopass}
  1592. ''')
  1593. self.assertEqual(ret, expected)
  1594. if grains['os_family'] == 'Debian':
  1595. # passphrase-protected currently does not work here
  1596. return
  1597. # Test with passphrase-protected key and global credential options
  1598. ret = self.get_pillar('''\
  1599. file_ignore_regex: []
  1600. file_ignore_glob: []
  1601. git_pillar_provider: pygit2
  1602. git_pillar_pubkey: {pubkey_withpass}
  1603. git_pillar_privkey: {privkey_withpass}
  1604. git_pillar_passphrase: {passphrase}
  1605. cachedir: {cachedir}
  1606. extension_modules: {extmods}
  1607. pillarenv: dev
  1608. ext_pillar:
  1609. - git:
  1610. - __env__ {url_extra_repo}:
  1611. - all_saltenvs: master
  1612. - __env__ {url}:
  1613. - mountpoint: nowhere
  1614. ''')
  1615. self.assertEqual(ret, expected)
  1616. # Test with passphrase-protected key and per-repo credential options
  1617. ret = self.get_pillar('''\
  1618. file_ignore_regex: []
  1619. file_ignore_glob: []
  1620. git_pillar_provider: pygit2
  1621. cachedir: {cachedir}
  1622. extension_modules: {extmods}
  1623. pillarenv: dev
  1624. ext_pillar:
  1625. - git:
  1626. - __env__ {url_extra_repo}:
  1627. - all_saltenvs: master
  1628. - pubkey: {pubkey_nopass}
  1629. - privkey: {privkey_nopass}
  1630. - passphrase: {passphrase}
  1631. - __env__ {url}:
  1632. - mountpoint: nowhere
  1633. - pubkey: {pubkey_nopass}
  1634. - privkey: {privkey_nopass}
  1635. - passphrase: {passphrase}
  1636. ''')
  1637. self.assertEqual(ret, expected)
  1638. @requires_system_grains
  1639. def test_all_saltenvs_base(self, grains):
  1640. '''
  1641. Test all_saltenvs parameter.
  1642. '''
  1643. expected = {'branch': 'master',
  1644. 'motd': 'The force will be with you. Always.',
  1645. 'mylist': ['master'],
  1646. 'mydict': {'master': True,
  1647. 'nested_list': ['master'],
  1648. 'nested_dict': {'master': True}
  1649. }
  1650. }
  1651. # Test with passphraseless key and global credential options
  1652. ret = self.get_pillar('''\
  1653. file_ignore_regex: []
  1654. file_ignore_glob: []
  1655. git_pillar_provider: pygit2
  1656. git_pillar_pubkey: {pubkey_nopass}
  1657. git_pillar_privkey: {privkey_nopass}
  1658. cachedir: {cachedir}
  1659. extension_modules: {extmods}
  1660. ext_pillar:
  1661. - git:
  1662. - __env__ {url_extra_repo}:
  1663. - all_saltenvs: master
  1664. - __env__ {url}:
  1665. - mountpoint: nowhere
  1666. ''')
  1667. self.assertEqual(ret, expected)
  1668. # Test with passphraseless key and per-repo credential options
  1669. ret = self.get_pillar('''\
  1670. file_ignore_regex: []
  1671. file_ignore_glob: []
  1672. git_pillar_provider: pygit2
  1673. cachedir: {cachedir}
  1674. extension_modules: {extmods}
  1675. ext_pillar:
  1676. - git:
  1677. - __env__ {url_extra_repo}:
  1678. - all_saltenvs: master
  1679. - pubkey: {pubkey_nopass}
  1680. - privkey: {privkey_nopass}
  1681. - __env__ {url}:
  1682. - mountpoint: nowhere
  1683. - pubkey: {pubkey_nopass}
  1684. - privkey: {privkey_nopass}
  1685. ''')
  1686. self.assertEqual(ret, expected)
  1687. if grains['os_family'] == 'Debian':
  1688. # passphrase-protected currently does not work here
  1689. return
  1690. # Test with passphrase-protected key and global credential options
  1691. ret = self.get_pillar('''\
  1692. file_ignore_regex: []
  1693. file_ignore_glob: []
  1694. git_pillar_provider: pygit2
  1695. git_pillar_pubkey: {pubkey_withpass}
  1696. git_pillar_privkey: {privkey_withpass}
  1697. git_pillar_passphrase: {passphrase}
  1698. cachedir: {cachedir}
  1699. extension_modules: {extmods}
  1700. ext_pillar:
  1701. - git:
  1702. - __env__ {url_extra_repo}:
  1703. - all_saltenvs: master
  1704. - __env__ {url}:
  1705. - mountpoint: nowhere
  1706. ''')
  1707. self.assertEqual(ret, expected)
  1708. # Test with passphrase-protected key and per-repo credential options
  1709. ret = self.get_pillar('''\
  1710. file_ignore_regex: []
  1711. file_ignore_glob: []
  1712. git_pillar_provider: pygit2
  1713. cachedir: {cachedir}
  1714. extension_modules: {extmods}
  1715. ext_pillar:
  1716. - git:
  1717. - __env__ {url_extra_repo}:
  1718. - all_saltenvs: master
  1719. - pubkey: {pubkey_nopass}
  1720. - privkey: {privkey_nopass}
  1721. - passphrase: {passphrase}
  1722. - __env__ {url}:
  1723. - mountpoint: nowhere
  1724. - pubkey: {pubkey_nopass}
  1725. - privkey: {privkey_nopass}
  1726. - passphrase: {passphrase}
  1727. ''')
  1728. self.assertEqual(ret, expected)
  1729. @skipIf(NO_MOCK, NO_MOCK_REASON)
  1730. @skipIf(_windows_or_mac(), 'minion is windows or mac')
  1731. @skip_if_not_root
  1732. @skipIf(not HAS_PYGIT2, 'pygit2 >= {0} and libgit2 >= {1} required'.format(PYGIT2_MINVER, LIBGIT2_MINVER))
  1733. @skipIf(not HAS_NGINX, 'nginx not present')
  1734. @skipIf(not HAS_VIRTUALENV, 'virtualenv not present')
  1735. class TestPygit2HTTP(GitPillarHTTPTestBase):
  1736. '''
  1737. Test git_pillar with pygit2 using SSH authentication
  1738. '''
  1739. def test_single_source(self):
  1740. '''
  1741. Test using a single ext_pillar repo
  1742. '''
  1743. expected = {
  1744. 'branch': 'master',
  1745. 'mylist': ['master'],
  1746. 'mydict': {'master': True,
  1747. 'nested_list': ['master'],
  1748. 'nested_dict': {'master': True}}
  1749. }
  1750. ret = self.get_pillar('''\
  1751. file_ignore_regex: []
  1752. file_ignore_glob: []
  1753. git_pillar_provider: pygit2
  1754. cachedir: {cachedir}
  1755. extension_modules: {extmods}
  1756. ext_pillar:
  1757. - git:
  1758. - master {url}
  1759. ''')
  1760. self.assertEqual(ret, expected)
  1761. def test_multiple_sources_master_dev_no_merge_lists(self):
  1762. '''
  1763. Test using two ext_pillar dirs. Since all git_pillar repos are merged
  1764. into a single dictionary, ordering matters.
  1765. This tests with the master branch followed by dev, and with
  1766. pillar_merge_lists disabled.
  1767. '''
  1768. expected = {
  1769. 'branch': 'dev',
  1770. 'mylist': ['dev'],
  1771. 'mydict': {'master': True,
  1772. 'dev': True,
  1773. 'nested_list': ['dev'],
  1774. 'nested_dict': {'master': True, 'dev': True}}
  1775. }
  1776. ret = self.get_pillar('''\
  1777. file_ignore_regex: []
  1778. file_ignore_glob: []
  1779. git_pillar_provider: pygit2
  1780. cachedir: {cachedir}
  1781. extension_modules: {extmods}
  1782. pillar_merge_lists: False
  1783. ext_pillar:
  1784. - git:
  1785. - master {url}
  1786. - dev {url}
  1787. ''')
  1788. self.assertEqual(ret, expected)
  1789. def test_multiple_sources_dev_master_no_merge_lists(self):
  1790. '''
  1791. Test using two ext_pillar dirs. Since all git_pillar repos are merged
  1792. into a single dictionary, ordering matters.
  1793. This tests with the dev branch followed by master, and with
  1794. pillar_merge_lists disabled.
  1795. '''
  1796. expected = {
  1797. 'branch': 'master',
  1798. 'mylist': ['master'],
  1799. 'mydict': {'master': True,
  1800. 'dev': True,
  1801. 'nested_list': ['master'],
  1802. 'nested_dict': {'master': True, 'dev': True}}
  1803. }
  1804. ret = self.get_pillar('''\
  1805. file_ignore_regex: []
  1806. file_ignore_glob: []
  1807. git_pillar_provider: pygit2
  1808. cachedir: {cachedir}
  1809. extension_modules: {extmods}
  1810. pillar_merge_lists: False
  1811. ext_pillar:
  1812. - git:
  1813. - dev {url}
  1814. - master {url}
  1815. ''')
  1816. self.assertEqual(ret, expected)
  1817. def test_multiple_sources_master_dev_merge_lists(self):
  1818. '''
  1819. Test using two ext_pillar dirs. Since all git_pillar repos are merged
  1820. into a single dictionary, ordering matters.
  1821. This tests with the master branch followed by dev, and with
  1822. pillar_merge_lists enabled.
  1823. '''
  1824. expected = {
  1825. 'branch': 'dev',
  1826. 'mylist': ['master', 'dev'],
  1827. 'mydict': {'master': True,
  1828. 'dev': True,
  1829. 'nested_list': ['master', 'dev'],
  1830. 'nested_dict': {'master': True, 'dev': True}}
  1831. }
  1832. ret = self.get_pillar('''\
  1833. file_ignore_regex: []
  1834. file_ignore_glob: []
  1835. git_pillar_provider: pygit2
  1836. cachedir: {cachedir}
  1837. extension_modules: {extmods}
  1838. pillar_merge_lists: True
  1839. ext_pillar:
  1840. - git:
  1841. - master {url}
  1842. - dev {url}
  1843. ''')
  1844. self.assertEqual(ret, expected)
  1845. def test_multiple_sources_dev_master_merge_lists(self):
  1846. '''
  1847. Test using two ext_pillar dirs. Since all git_pillar repos are merged
  1848. into a single dictionary, ordering matters.
  1849. This tests with the dev branch followed by master, and with
  1850. pillar_merge_lists enabled.
  1851. '''
  1852. expected = {
  1853. 'branch': 'master',
  1854. 'mylist': ['dev', 'master'],
  1855. 'mydict': {'master': True,
  1856. 'dev': True,
  1857. 'nested_list': ['dev', 'master'],
  1858. 'nested_dict': {'master': True, 'dev': True}}
  1859. }
  1860. ret = self.get_pillar('''\
  1861. file_ignore_regex: []
  1862. file_ignore_glob: []
  1863. git_pillar_provider: pygit2
  1864. cachedir: {cachedir}
  1865. extension_modules: {extmods}
  1866. pillar_merge_lists: True
  1867. ext_pillar:
  1868. - git:
  1869. - dev {url}
  1870. - master {url}
  1871. ''')
  1872. self.assertEqual(ret, expected)
  1873. def test_multiple_sources_with_pillarenv(self):
  1874. '''
  1875. Test using pillarenv to restrict results to those from a single branch
  1876. '''
  1877. expected = {
  1878. 'branch': 'master',
  1879. 'mylist': ['master'],
  1880. 'mydict': {'master': True,
  1881. 'nested_list': ['master'],
  1882. 'nested_dict': {'master': True}}
  1883. }
  1884. ret = self.get_pillar('''\
  1885. file_ignore_regex: []
  1886. file_ignore_glob: []
  1887. git_pillar_provider: pygit2
  1888. cachedir: {cachedir}
  1889. extension_modules: {extmods}
  1890. pillarenv: base
  1891. ext_pillar:
  1892. - git:
  1893. - master {url}
  1894. - dev {url}
  1895. ''')
  1896. self.assertEqual(ret, expected)
  1897. def test_includes_enabled(self):
  1898. '''
  1899. Test with git_pillar_includes enabled. The top_only branch references
  1900. an SLS file from the master branch, so we should see the
  1901. "included_pillar" key from that SLS file in the compiled pillar data.
  1902. '''
  1903. expected = {
  1904. 'branch': 'master',
  1905. 'mylist': ['master'],
  1906. 'mydict': {'master': True,
  1907. 'nested_list': ['master'],
  1908. 'nested_dict': {'master': True}},
  1909. 'included_pillar': True
  1910. }
  1911. ret = self.get_pillar('''\
  1912. file_ignore_regex: []
  1913. file_ignore_glob: []
  1914. git_pillar_provider: pygit2
  1915. cachedir: {cachedir}
  1916. extension_modules: {extmods}
  1917. ext_pillar:
  1918. - git:
  1919. - master {url}
  1920. - top_only {url}:
  1921. - env: base
  1922. ''')
  1923. self.assertEqual(ret, expected)
  1924. def test_includes_disabled(self):
  1925. '''
  1926. Test with git_pillar_includes enabled. The top_only branch references
  1927. an SLS file from the master branch, but since includes are disabled it
  1928. will not find the SLS file and the "included_pillar" key should not be
  1929. present in the compiled pillar data. We should instead see an error
  1930. message in the compiled data.
  1931. '''
  1932. expected = {
  1933. 'branch': 'master',
  1934. 'mylist': ['master'],
  1935. 'mydict': {'master': True,
  1936. 'nested_list': ['master'],
  1937. 'nested_dict': {'master': True}},
  1938. '_errors': ["Specified SLS 'bar' in environment 'base' is not "
  1939. "available on the salt master"]
  1940. }
  1941. ret = self.get_pillar('''\
  1942. file_ignore_regex: []
  1943. file_ignore_glob: []
  1944. git_pillar_provider: pygit2
  1945. git_pillar_includes: False
  1946. cachedir: {cachedir}
  1947. extension_modules: {extmods}
  1948. ext_pillar:
  1949. - git:
  1950. - master {url}
  1951. - top_only {url}:
  1952. - env: base
  1953. ''')
  1954. self.assertEqual(ret, expected)
  1955. def test_includes_enabled_solves___env___with_mountpoint(self):
  1956. '''
  1957. Test with git_pillar_includes enabled and using "__env__" as the branch
  1958. name for the configured repositories.
  1959. The "gitinfo" repository contains top.sls file with a local reference
  1960. and also referencing external "nowhere.foo" which is provided by "webinfo"
  1961. repository mounted as "nowhere".
  1962. '''
  1963. ret = self.get_pillar('''\
  1964. file_ignore_regex: []
  1965. file_ignore_glob: []
  1966. git_pillar_provider: pygit2
  1967. cachedir: {cachedir}
  1968. extension_modules: {extmods}
  1969. ext_pillar:
  1970. - git:
  1971. - __env__ {url_extra_repo}:
  1972. - name: gitinfo
  1973. - __env__ {url}:
  1974. - name: webinfo
  1975. - mountpoint: nowhere
  1976. ''')
  1977. self.assertEqual(
  1978. ret,
  1979. {'branch': 'master',
  1980. 'motd': 'The force will be with you. Always.',
  1981. 'mylist': ['master'],
  1982. 'mydict': {'master': True,
  1983. 'nested_list': ['master'],
  1984. 'nested_dict': {'master': True}}}
  1985. )
  1986. def test_root_parameter(self):
  1987. '''
  1988. Test root parameter
  1989. '''
  1990. expected = {
  1991. 'from_subdir': True
  1992. }
  1993. ret = self.get_pillar('''\
  1994. file_ignore_regex: []
  1995. file_ignore_glob: []
  1996. git_pillar_provider: pygit2
  1997. cachedir: {cachedir}
  1998. extension_modules: {extmods}
  1999. ext_pillar:
  2000. - git:
  2001. - master {url}:
  2002. - root: subdir
  2003. - top_only {url}:
  2004. - env: base
  2005. ''')
  2006. self.assertEqual(ret, expected)
  2007. def test_mountpoint_parameter(self):
  2008. '''
  2009. Test mountpoint parameter
  2010. '''
  2011. expected = {
  2012. 'included_pillar': True
  2013. }
  2014. ret = self.get_pillar('''\
  2015. file_ignore_regex: []
  2016. file_ignore_glob: []
  2017. git_pillar_provider: pygit2
  2018. cachedir: {cachedir}
  2019. extension_modules: {extmods}
  2020. ext_pillar:
  2021. - git:
  2022. - master {url}:
  2023. - mountpoint: mounted
  2024. - top_mounted {url}:
  2025. - env: base
  2026. ''')
  2027. self.assertEqual(ret, expected)
  2028. def test_root_and_mountpoint_parameters(self):
  2029. '''
  2030. Test root and mountpoint parameters
  2031. '''
  2032. expected = {
  2033. 'from_subdir': True
  2034. }
  2035. ret = self.get_pillar('''\
  2036. file_ignore_regex: []
  2037. file_ignore_glob: []
  2038. git_pillar_provider: pygit2
  2039. cachedir: {cachedir}
  2040. extension_modules: {extmods}
  2041. ext_pillar:
  2042. - git:
  2043. - master {url}:
  2044. - mountpoint: mounted
  2045. - root: subdir
  2046. - top_mounted {url}:
  2047. - env: base
  2048. ''')
  2049. self.assertEqual(ret, expected)
  2050. def test_all_saltenvs(self):
  2051. '''
  2052. Test all_saltenvs parameter.
  2053. '''
  2054. ret = self.get_pillar('''\
  2055. file_ignore_regex: []
  2056. file_ignore_glob: []
  2057. git_pillar_provider: pygit2
  2058. cachedir: {cachedir}
  2059. extension_modules: {extmods}
  2060. pillarenv: dev
  2061. ext_pillar:
  2062. - git:
  2063. - __env__ {url_extra_repo}:
  2064. - all_saltenvs: master
  2065. - __env__ {url}:
  2066. - mountpoint: nowhere
  2067. ''')
  2068. self.assertEqual(
  2069. ret,
  2070. {'branch': 'dev',
  2071. 'motd': 'The force will be with you. Always.',
  2072. 'mylist': ['dev'],
  2073. 'mydict': {'dev': True,
  2074. 'nested_list': ['dev'],
  2075. 'nested_dict': {'dev': True}}}
  2076. )
  2077. def test_all_saltenvs_base(self):
  2078. '''
  2079. Test all_saltenvs parameter with base pillarenv.
  2080. '''
  2081. ret = self.get_pillar('''\
  2082. file_ignore_regex: []
  2083. file_ignore_glob: []
  2084. git_pillar_provider: pygit2
  2085. cachedir: {cachedir}
  2086. extension_modules: {extmods}
  2087. ext_pillar:
  2088. - git:
  2089. - __env__ {url_extra_repo}:
  2090. - all_saltenvs: master
  2091. - __env__ {url}:
  2092. - mountpoint: nowhere
  2093. ''')
  2094. self.assertEqual(
  2095. ret,
  2096. {'branch': 'master',
  2097. 'motd': 'The force will be with you. Always.',
  2098. 'mylist': ['master'],
  2099. 'mydict': {'master': True,
  2100. 'nested_list': ['master'],
  2101. 'nested_dict': {'master': True}}}
  2102. )
  2103. @skipIf(NO_MOCK, NO_MOCK_REASON)
  2104. @skipIf(_windows_or_mac(), 'minion is windows or mac')
  2105. @skip_if_not_root
  2106. @skipIf(not HAS_PYGIT2, 'pygit2 >= {0} and libgit2 >= {1} required'.format(PYGIT2_MINVER, LIBGIT2_MINVER))
  2107. @skipIf(not HAS_NGINX, 'nginx not present')
  2108. @skipIf(not HAS_VIRTUALENV, 'virtualenv not present')
  2109. class TestPygit2AuthenticatedHTTP(GitPillarHTTPTestBase):
  2110. '''
  2111. Test git_pillar with pygit2 using SSH authentication
  2112. NOTE: Any tests added to this test class should have equivalent tests (if
  2113. possible) in the TestGitPythonSSH class.
  2114. '''
  2115. user = USERNAME
  2116. password = PASSWORD
  2117. def test_single_source(self):
  2118. '''
  2119. Test using a single ext_pillar repo
  2120. '''
  2121. expected = {
  2122. 'branch': 'master',
  2123. 'mylist': ['master'],
  2124. 'mydict': {'master': True,
  2125. 'nested_list': ['master'],
  2126. 'nested_dict': {'master': True}}
  2127. }
  2128. # Test with global credential options
  2129. ret = self.get_pillar('''\
  2130. file_ignore_regex: []
  2131. file_ignore_glob: []
  2132. git_pillar_provider: pygit2
  2133. git_pillar_user: {user}
  2134. git_pillar_password: {password}
  2135. git_pillar_insecure_auth: True
  2136. cachedir: {cachedir}
  2137. extension_modules: {extmods}
  2138. ext_pillar:
  2139. - git:
  2140. - master {url}
  2141. ''')
  2142. self.assertEqual(ret, expected)
  2143. # Test with per-repo credential options
  2144. ret = self.get_pillar('''\
  2145. file_ignore_regex: []
  2146. file_ignore_glob: []
  2147. git_pillar_provider: pygit2
  2148. cachedir: {cachedir}
  2149. extension_modules: {extmods}
  2150. ext_pillar:
  2151. - git:
  2152. - master {url}:
  2153. - user: {user}
  2154. - password: {password}
  2155. - insecure_auth: True
  2156. ''')
  2157. self.assertEqual(ret, expected)
  2158. def test_multiple_sources_master_dev_no_merge_lists(self):
  2159. '''
  2160. Test using two ext_pillar dirs. Since all git_pillar repos are merged
  2161. into a single dictionary, ordering matters.
  2162. This tests with the master branch followed by dev, and with
  2163. pillar_merge_lists disabled.
  2164. '''
  2165. expected = {
  2166. 'branch': 'dev',
  2167. 'mylist': ['dev'],
  2168. 'mydict': {'master': True,
  2169. 'dev': True,
  2170. 'nested_list': ['dev'],
  2171. 'nested_dict': {'master': True, 'dev': True}}
  2172. }
  2173. # Test with global credential options
  2174. ret = self.get_pillar('''\
  2175. file_ignore_regex: []
  2176. file_ignore_glob: []
  2177. git_pillar_provider: pygit2
  2178. git_pillar_user: {user}
  2179. git_pillar_password: {password}
  2180. git_pillar_insecure_auth: True
  2181. cachedir: {cachedir}
  2182. extension_modules: {extmods}
  2183. pillar_merge_lists: False
  2184. ext_pillar:
  2185. - git:
  2186. - master {url}
  2187. - dev {url}
  2188. ''')
  2189. self.assertEqual(ret, expected)
  2190. # Test with per-repo credential options
  2191. ret = self.get_pillar('''\
  2192. file_ignore_regex: []
  2193. file_ignore_glob: []
  2194. git_pillar_provider: pygit2
  2195. cachedir: {cachedir}
  2196. extension_modules: {extmods}
  2197. pillar_merge_lists: False
  2198. ext_pillar:
  2199. - git:
  2200. - master {url}:
  2201. - user: {user}
  2202. - password: {password}
  2203. - insecure_auth: True
  2204. - dev {url}:
  2205. - user: {user}
  2206. - password: {password}
  2207. - insecure_auth: True
  2208. ''')
  2209. self.assertEqual(ret, expected)
  2210. def test_multiple_sources_dev_master_no_merge_lists(self):
  2211. '''
  2212. Test using two ext_pillar dirs. Since all git_pillar repos are merged
  2213. into a single dictionary, ordering matters.
  2214. This tests with the dev branch followed by master, and with
  2215. pillar_merge_lists disabled.
  2216. '''
  2217. expected = {
  2218. 'branch': 'master',
  2219. 'mylist': ['master'],
  2220. 'mydict': {'master': True,
  2221. 'dev': True,
  2222. 'nested_list': ['master'],
  2223. 'nested_dict': {'master': True, 'dev': True}}
  2224. }
  2225. # Test with global credential options
  2226. ret = self.get_pillar('''\
  2227. file_ignore_regex: []
  2228. file_ignore_glob: []
  2229. git_pillar_provider: pygit2
  2230. git_pillar_user: {user}
  2231. git_pillar_password: {password}
  2232. git_pillar_insecure_auth: True
  2233. cachedir: {cachedir}
  2234. extension_modules: {extmods}
  2235. pillar_merge_lists: False
  2236. ext_pillar:
  2237. - git:
  2238. - dev {url}
  2239. - master {url}
  2240. ''')
  2241. self.assertEqual(ret, expected)
  2242. # Test with per-repo credential options
  2243. ret = self.get_pillar('''\
  2244. file_ignore_regex: []
  2245. file_ignore_glob: []
  2246. git_pillar_provider: pygit2
  2247. cachedir: {cachedir}
  2248. extension_modules: {extmods}
  2249. pillar_merge_lists: False
  2250. ext_pillar:
  2251. - git:
  2252. - dev {url}:
  2253. - user: {user}
  2254. - password: {password}
  2255. - insecure_auth: True
  2256. - master {url}:
  2257. - user: {user}
  2258. - password: {password}
  2259. - insecure_auth: True
  2260. ''')
  2261. self.assertEqual(ret, expected)
  2262. def test_multiple_sources_master_dev_merge_lists(self):
  2263. '''
  2264. Test using two ext_pillar dirs. Since all git_pillar repos are merged
  2265. into a single dictionary, ordering matters.
  2266. This tests with the master branch followed by dev, and with
  2267. pillar_merge_lists enabled.
  2268. '''
  2269. expected = {
  2270. 'branch': 'dev',
  2271. 'mylist': ['master', 'dev'],
  2272. 'mydict': {'master': True,
  2273. 'dev': True,
  2274. 'nested_list': ['master', 'dev'],
  2275. 'nested_dict': {'master': True, 'dev': True}}
  2276. }
  2277. # Test with global credential options
  2278. ret = self.get_pillar('''\
  2279. file_ignore_regex: []
  2280. file_ignore_glob: []
  2281. git_pillar_provider: pygit2
  2282. git_pillar_user: {user}
  2283. git_pillar_password: {password}
  2284. git_pillar_insecure_auth: True
  2285. cachedir: {cachedir}
  2286. extension_modules: {extmods}
  2287. pillar_merge_lists: True
  2288. ext_pillar:
  2289. - git:
  2290. - master {url}
  2291. - dev {url}
  2292. ''')
  2293. self.assertEqual(ret, expected)
  2294. # Test with per-repo credential options
  2295. ret = self.get_pillar('''\
  2296. file_ignore_regex: []
  2297. file_ignore_glob: []
  2298. git_pillar_provider: pygit2
  2299. cachedir: {cachedir}
  2300. extension_modules: {extmods}
  2301. pillar_merge_lists: True
  2302. ext_pillar:
  2303. - git:
  2304. - master {url}:
  2305. - user: {user}
  2306. - password: {password}
  2307. - insecure_auth: True
  2308. - dev {url}:
  2309. - user: {user}
  2310. - password: {password}
  2311. - insecure_auth: True
  2312. ''')
  2313. self.assertEqual(ret, expected)
  2314. def test_multiple_sources_dev_master_merge_lists(self):
  2315. '''
  2316. Test using two ext_pillar dirs. Since all git_pillar repos are merged
  2317. into a single dictionary, ordering matters.
  2318. This tests with the dev branch followed by master, and with
  2319. pillar_merge_lists enabled.
  2320. '''
  2321. expected = {
  2322. 'branch': 'master',
  2323. 'mylist': ['dev', 'master'],
  2324. 'mydict': {'master': True,
  2325. 'dev': True,
  2326. 'nested_list': ['dev', 'master'],
  2327. 'nested_dict': {'master': True, 'dev': True}}
  2328. }
  2329. # Test with global credential options
  2330. ret = self.get_pillar('''\
  2331. file_ignore_regex: []
  2332. file_ignore_glob: []
  2333. git_pillar_provider: pygit2
  2334. git_pillar_user: {user}
  2335. git_pillar_password: {password}
  2336. git_pillar_insecure_auth: True
  2337. cachedir: {cachedir}
  2338. extension_modules: {extmods}
  2339. pillar_merge_lists: True
  2340. ext_pillar:
  2341. - git:
  2342. - dev {url}
  2343. - master {url}
  2344. ''')
  2345. self.assertEqual(ret, expected)
  2346. # Test with per-repo credential options
  2347. ret = self.get_pillar('''\
  2348. file_ignore_regex: []
  2349. file_ignore_glob: []
  2350. git_pillar_provider: pygit2
  2351. cachedir: {cachedir}
  2352. extension_modules: {extmods}
  2353. pillar_merge_lists: True
  2354. ext_pillar:
  2355. - git:
  2356. - dev {url}:
  2357. - user: {user}
  2358. - password: {password}
  2359. - insecure_auth: True
  2360. - master {url}:
  2361. - user: {user}
  2362. - password: {password}
  2363. - insecure_auth: True
  2364. ''')
  2365. self.assertEqual(ret, expected)
  2366. def test_multiple_sources_with_pillarenv(self):
  2367. '''
  2368. Test using pillarenv to restrict results to those from a single branch
  2369. '''
  2370. expected = {
  2371. 'branch': 'master',
  2372. 'mylist': ['master'],
  2373. 'mydict': {'master': True,
  2374. 'nested_list': ['master'],
  2375. 'nested_dict': {'master': True}}
  2376. }
  2377. # Test with global credential options
  2378. ret = self.get_pillar('''\
  2379. file_ignore_regex: []
  2380. file_ignore_glob: []
  2381. git_pillar_provider: pygit2
  2382. git_pillar_user: {user}
  2383. git_pillar_password: {password}
  2384. git_pillar_insecure_auth: True
  2385. cachedir: {cachedir}
  2386. extension_modules: {extmods}
  2387. pillarenv: base
  2388. ext_pillar:
  2389. - git:
  2390. - master {url}
  2391. - dev {url}
  2392. ''')
  2393. self.assertEqual(ret, expected)
  2394. # Test with per-repo credential options
  2395. ret = self.get_pillar('''\
  2396. file_ignore_regex: []
  2397. file_ignore_glob: []
  2398. git_pillar_provider: pygit2
  2399. cachedir: {cachedir}
  2400. extension_modules: {extmods}
  2401. pillarenv: base
  2402. ext_pillar:
  2403. - git:
  2404. - master {url}:
  2405. - user: {user}
  2406. - password: {password}
  2407. - insecure_auth: True
  2408. - dev {url}:
  2409. - user: {user}
  2410. - password: {password}
  2411. - insecure_auth: True
  2412. ''')
  2413. self.assertEqual(ret, expected)
  2414. def test_includes_enabled(self):
  2415. '''
  2416. Test with git_pillar_includes enabled. The top_only branch references
  2417. an SLS file from the master branch, so we should see the
  2418. "included_pillar" key from that SLS file in the compiled pillar data.
  2419. '''
  2420. expected = {
  2421. 'branch': 'master',
  2422. 'mylist': ['master'],
  2423. 'mydict': {'master': True,
  2424. 'nested_list': ['master'],
  2425. 'nested_dict': {'master': True}},
  2426. 'included_pillar': True
  2427. }
  2428. # Test with global credential options
  2429. ret = self.get_pillar('''\
  2430. file_ignore_regex: []
  2431. file_ignore_glob: []
  2432. git_pillar_provider: pygit2
  2433. git_pillar_user: {user}
  2434. git_pillar_password: {password}
  2435. git_pillar_insecure_auth: True
  2436. cachedir: {cachedir}
  2437. extension_modules: {extmods}
  2438. ext_pillar:
  2439. - git:
  2440. - master {url}
  2441. - top_only {url}:
  2442. - env: base
  2443. ''')
  2444. self.assertEqual(ret, expected)
  2445. def test_mountpoint_parameter(self):
  2446. '''
  2447. Test mountpoint parameter
  2448. '''
  2449. expected = {
  2450. 'included_pillar': True
  2451. }
  2452. ret = self.get_pillar('''\
  2453. file_ignore_regex: []
  2454. file_ignore_glob: []
  2455. git_pillar_provider: pygit2
  2456. git_pillar_user: {user}
  2457. git_pillar_password: {password}
  2458. git_pillar_insecure_auth: True
  2459. cachedir: {cachedir}
  2460. extension_modules: {extmods}
  2461. ext_pillar:
  2462. - git:
  2463. - master {url}:
  2464. - mountpoint: mounted
  2465. - top_mounted {url}:
  2466. - env: base
  2467. ''')
  2468. self.assertEqual(ret, expected)
  2469. def test_root_parameter(self):
  2470. '''
  2471. Test root parameter
  2472. '''
  2473. expected = {
  2474. 'from_subdir': True
  2475. }
  2476. ret = self.get_pillar('''\
  2477. file_ignore_regex: []
  2478. file_ignore_glob: []
  2479. git_pillar_provider: pygit2
  2480. git_pillar_user: {user}
  2481. git_pillar_password: {password}
  2482. git_pillar_insecure_auth: True
  2483. cachedir: {cachedir}
  2484. extension_modules: {extmods}
  2485. ext_pillar:
  2486. - git:
  2487. - master {url}:
  2488. - root: subdir
  2489. - top_only {url}:
  2490. - env: base
  2491. ''')
  2492. self.assertEqual(ret, expected)
  2493. # Test with per-repo credential options
  2494. ret = self.get_pillar('''\
  2495. file_ignore_regex: []
  2496. file_ignore_glob: []
  2497. git_pillar_provider: pygit2
  2498. cachedir: {cachedir}
  2499. extension_modules: {extmods}
  2500. ext_pillar:
  2501. - git:
  2502. - master {url}:
  2503. - root: subdir
  2504. - user: {user}
  2505. - password: {password}
  2506. - insecure_auth: True
  2507. - top_only {url}:
  2508. - user: {user}
  2509. - password: {password}
  2510. - insecure_auth: True
  2511. - env: base
  2512. ''')
  2513. self.assertEqual(ret, expected)
  2514. def test_includes_disabled(self):
  2515. '''
  2516. Test with git_pillar_includes enabled. The top_only branch references
  2517. an SLS file from the master branch, but since includes are disabled it
  2518. will not find the SLS file and the "included_pillar" key should not be
  2519. present in the compiled pillar data. We should instead see an error
  2520. message in the compiled data.
  2521. '''
  2522. expected = {
  2523. 'branch': 'master',
  2524. 'mylist': ['master'],
  2525. 'mydict': {'master': True,
  2526. 'nested_list': ['master'],
  2527. 'nested_dict': {'master': True}},
  2528. '_errors': ["Specified SLS 'bar' in environment 'base' is not "
  2529. "available on the salt master"]
  2530. }
  2531. # Test with global credential options
  2532. ret = self.get_pillar('''\
  2533. file_ignore_regex: []
  2534. file_ignore_glob: []
  2535. git_pillar_provider: pygit2
  2536. git_pillar_includes: False
  2537. git_pillar_user: {user}
  2538. git_pillar_password: {password}
  2539. git_pillar_insecure_auth: True
  2540. cachedir: {cachedir}
  2541. extension_modules: {extmods}
  2542. ext_pillar:
  2543. - git:
  2544. - master {url}
  2545. - top_only {url}:
  2546. - env: base
  2547. ''')
  2548. self.assertEqual(ret, expected)
  2549. # Test with per-repo credential options
  2550. ret = self.get_pillar('''\
  2551. file_ignore_regex: []
  2552. file_ignore_glob: []
  2553. git_pillar_provider: pygit2
  2554. git_pillar_includes: False
  2555. cachedir: {cachedir}
  2556. extension_modules: {extmods}
  2557. ext_pillar:
  2558. - git:
  2559. - master {url}:
  2560. - user: {user}
  2561. - password: {password}
  2562. - insecure_auth: True
  2563. - top_only {url}:
  2564. - user: {user}
  2565. - password: {password}
  2566. - insecure_auth: True
  2567. - env: base
  2568. ''')
  2569. self.assertEqual(ret, expected)
  2570. def test_includes_enabled_solves___env___with_mountpoint(self):
  2571. '''
  2572. Test with git_pillar_includes enabled and using "__env__" as the branch
  2573. name for the configured repositories.
  2574. The "gitinfo" repository contains top.sls file with a local reference
  2575. and also referencing external "nowhere.foo" which is provided by "webinfo"
  2576. repository mounted as "nowhere".
  2577. '''
  2578. ret = self.get_pillar('''\
  2579. file_ignore_regex: []
  2580. file_ignore_glob: []
  2581. git_pillar_provider: pygit2
  2582. git_pillar_user: {user}
  2583. git_pillar_password: {password}
  2584. git_pillar_insecure_auth: True
  2585. cachedir: {cachedir}
  2586. extension_modules: {extmods}
  2587. ext_pillar:
  2588. - git:
  2589. - __env__ {url_extra_repo}:
  2590. - name: gitinfo
  2591. - user: {user}
  2592. - password: {password}
  2593. - insecure_auth: True
  2594. - __env__ {url}:
  2595. - name: webinfo
  2596. - mountpoint: nowhere
  2597. - user: {user}
  2598. - password: {password}
  2599. - insecure_auth: True
  2600. ''')
  2601. self.assertEqual(
  2602. ret,
  2603. {'branch': 'master',
  2604. 'motd': 'The force will be with you. Always.',
  2605. 'mylist': ['master'],
  2606. 'mydict': {'master': True,
  2607. 'nested_list': ['master'],
  2608. 'nested_dict': {'master': True}}}
  2609. )
  2610. def test_root_and_mountpoint_parameters(self):
  2611. '''
  2612. Test root and mountpoint parameters
  2613. '''
  2614. expected = {
  2615. 'from_subdir': True
  2616. }
  2617. ret = self.get_pillar('''\
  2618. file_ignore_regex: []
  2619. file_ignore_glob: []
  2620. git_pillar_provider: pygit2
  2621. git_pillar_user: {user}
  2622. git_pillar_password: {password}
  2623. git_pillar_insecure_auth: True
  2624. cachedir: {cachedir}
  2625. extension_modules: {extmods}
  2626. ext_pillar:
  2627. - git:
  2628. - master {url}:
  2629. - mountpoint: mounted
  2630. - root: subdir
  2631. - top_mounted {url}:
  2632. - env: base
  2633. ''')
  2634. self.assertEqual(ret, expected)
  2635. def test_all_saltenvs(self):
  2636. '''
  2637. Test all_saltenvs parameter.
  2638. '''
  2639. ret = self.get_pillar('''\
  2640. file_ignore_regex: []
  2641. file_ignore_glob: []
  2642. git_pillar_provider: pygit2
  2643. git_pillar_user: {user}
  2644. git_pillar_password: {password}
  2645. git_pillar_insecure_auth: True
  2646. cachedir: {cachedir}
  2647. extension_modules: {extmods}
  2648. pillarenv: dev
  2649. ext_pillar:
  2650. - git:
  2651. - __env__ {url_extra_repo}:
  2652. - all_saltenvs: master
  2653. - __env__ {url}:
  2654. - mountpoint: nowhere
  2655. ''')
  2656. self.assertEqual(
  2657. ret,
  2658. {'branch': 'dev',
  2659. 'motd': 'The force will be with you. Always.',
  2660. 'mylist': ['dev'],
  2661. 'mydict': {'dev': True,
  2662. 'nested_list': ['dev'],
  2663. 'nested_dict': {'dev': True}}}
  2664. )
  2665. def test_all_saltenvs_base(self):
  2666. '''
  2667. Test all_saltenvs parameter with base pillarenv.
  2668. '''
  2669. ret = self.get_pillar('''\
  2670. file_ignore_regex: []
  2671. file_ignore_glob: []
  2672. git_pillar_provider: pygit2
  2673. git_pillar_user: {user}
  2674. git_pillar_password: {password}
  2675. git_pillar_insecure_auth: True
  2676. cachedir: {cachedir}
  2677. extension_modules: {extmods}
  2678. ext_pillar:
  2679. - git:
  2680. - __env__ {url_extra_repo}:
  2681. - all_saltenvs: master
  2682. - __env__ {url}:
  2683. - mountpoint: nowhere
  2684. ''')
  2685. self.assertEqual(
  2686. ret,
  2687. {'branch': 'master',
  2688. 'motd': 'The force will be with you. Always.',
  2689. 'mylist': ['master'],
  2690. 'mydict': {'master': True,
  2691. 'nested_list': ['master'],
  2692. 'nested_dict': {'master': True}}}
  2693. )