test_git_pillar.py 97 KB

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