test_git_pillar.py 118 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780
  1. # -*- coding: utf-8 -*-
  2. """
  3. Integration tests for git_pillar
  4. The base classes for all of these tests are in tests/support/gitfs.py.
  5. Repositories for the tests are generated on the fly (look for the "make_repo"
  6. function).
  7. Where possible, a test case in this module should be reproduced in the
  8. following ways:
  9. 1. GitPython over SSH (TestGitPythonSSH)
  10. 2. GitPython over HTTP (TestGitPythonHTTP)
  11. 3. GitPython over HTTP w/basic auth (TestGitPythonAuthenticatedHTTP)
  12. 4. pygit2 over SSH (TestPygit2SSH)
  13. 5. pygit2 over HTTP (TestPygit2HTTP)
  14. 6. pygit2 over HTTP w/basic auth (TestPygit2AuthenticatedHTTP)
  15. For GitPython, this is easy, since it does not support the authentication
  16. configuration parameters that pygit2 does. Therefore, this test module includes
  17. a GitPythonMixin class which can be reused for all three GitPython test
  18. classes. The only thing we vary for these tests is the URL that we use.
  19. For pygit2 this is more complicated, since it supports A) both passphraseless
  20. and passphrase-protected SSH keys, and B) both global and per-remote credential
  21. parameters. So, for SSH tests we need to run each GitPython test case in 4
  22. different ways to cover pygit2:
  23. 1. Passphraseless key, global credential options
  24. 2. Passphraseless key, per-repo credential options
  25. 3. Passphrase-protected key, global credential options
  26. 4. Passphrase-protected key, per-repo credential options
  27. For HTTP tests, we need to run each GitPython test case in 2 different ways to
  28. cover pygit2 with authentication:
  29. 1. Global credential options
  30. 2. Per-repo credential options
  31. For unauthenticated HTTP, we can just run a single case just like for a
  32. GitPython test function, with the only change being to the git_pillar_provider
  33. config option.
  34. The way we accomplish the extra test cases for pygit2 is not by writing more
  35. test functions, but to keep the same test function names both in the GitPython
  36. test classes and the pygit2 test classes, and just perform multiple pillar
  37. compilations and asserts in each pygit2 test function.
  38. For SSH tests, a system user is added and a temporary sshd instance is started
  39. on a randomized port. The user and sshd server are torn down after the tests
  40. are run.
  41. For HTTP tests, nginx + uWSGI + git-http-backend handles serving the repo.
  42. However, there was a change in git 2.4.4 which causes a fetch to hang when
  43. using uWSGI. This was worked around in uWSGI 2.0.13 by adding an additional
  44. setting. However, Ubuntu 16.04 LTS ships with uWSGI 2.0.12 in their official
  45. repos, so to work around this we pip install a newer uWSGI (with CGI support
  46. baked in) within a virtualenv the test suite creates, and then uses that uwsgi
  47. binary to start the uWSGI daemon. More info on the git issue and the uWSGI
  48. workaround can be found in the below two links:
  49. https://github.com/git/git/commit/6bc0cb5
  50. https://github.com/unbit/uwsgi/commit/ac1e354
  51. """
  52. # Import Python libs
  53. from __future__ import absolute_import, print_function, unicode_literals
  54. import random
  55. import string
  56. # Import Salt libs
  57. import salt.utils.path
  58. import salt.utils.platform
  59. from salt.ext.six.moves import range # pylint: disable=redefined-builtin
  60. from salt.modules.virtualenv_mod import KNOWN_BINARY_NAMES as VIRTUALENV_NAMES
  61. from salt.utils.gitfs import (
  62. GITPYTHON_MINVER,
  63. GITPYTHON_VERSION,
  64. LIBGIT2_MINVER,
  65. LIBGIT2_VERSION,
  66. PYGIT2_MINVER,
  67. PYGIT2_VERSION,
  68. )
  69. # Import Salt Testing libs
  70. from tests.support.gitfs import (
  71. PASSWORD,
  72. USERNAME,
  73. GitPillarHTTPTestBase,
  74. GitPillarSSHTestBase,
  75. )
  76. from tests.support.helpers import (
  77. destructiveTest,
  78. requires_system_grains,
  79. skip_if_not_root,
  80. )
  81. from tests.support.unit import skipIf
  82. # Check for requisite components
  83. try:
  84. HAS_GITPYTHON = GITPYTHON_VERSION >= GITPYTHON_MINVER
  85. except Exception: # pylint: disable=broad-except
  86. HAS_GITPYTHON = False
  87. try:
  88. HAS_PYGIT2 = PYGIT2_VERSION >= PYGIT2_MINVER and LIBGIT2_VERSION >= LIBGIT2_MINVER
  89. except Exception: # pylint: disable=broad-except
  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. @skipIf(True, "SLOWTEST skip")
  106. @skipIf(True, "SLOWTEST skip")
  107. @skipIf(True, "SLOWTEST skip")
  108. @skipIf(True, "SLOWTEST skip")
  109. @skipIf(True, "SLOWTEST skip")
  110. @skipIf(True, "SLOWTEST skip")
  111. def test_single_source(self):
  112. """
  113. Test using a single ext_pillar repo
  114. """
  115. ret = self.get_pillar(
  116. """\
  117. file_ignore_regex: []
  118. file_ignore_glob: []
  119. git_pillar_provider: gitpython
  120. cachedir: {cachedir}
  121. extension_modules: {extmods}
  122. ext_pillar:
  123. - git:
  124. - master {url}
  125. """
  126. )
  127. self.assertEqual(
  128. ret,
  129. {
  130. "branch": "master",
  131. "mylist": ["master"],
  132. "mydict": {
  133. "master": True,
  134. "nested_list": ["master"],
  135. "nested_dict": {"master": True},
  136. },
  137. },
  138. )
  139. @skipIf(True, "SLOWTEST skip")
  140. @skipIf(True, "SLOWTEST skip")
  141. @skipIf(True, "SLOWTEST skip")
  142. @skipIf(True, "SLOWTEST skip")
  143. @skipIf(True, "SLOWTEST skip")
  144. @skipIf(True, "SLOWTEST skip")
  145. def test_multiple_sources_master_dev_no_merge_lists(self):
  146. """
  147. Test using two ext_pillar dirs. Since all git_pillar repos are merged
  148. into a single dictionary, ordering matters.
  149. This tests with the master branch followed by dev, and with
  150. pillar_merge_lists disabled.
  151. """
  152. ret = self.get_pillar(
  153. """\
  154. file_ignore_regex: []
  155. file_ignore_glob: []
  156. git_pillar_provider: gitpython
  157. cachedir: {cachedir}
  158. extension_modules: {extmods}
  159. pillar_merge_lists: False
  160. ext_pillar:
  161. - git:
  162. - master {url}
  163. - dev {url}
  164. """
  165. )
  166. self.assertEqual(
  167. ret,
  168. {
  169. "branch": "dev",
  170. "mylist": ["dev"],
  171. "mydict": {
  172. "master": True,
  173. "dev": True,
  174. "nested_list": ["dev"],
  175. "nested_dict": {"master": True, "dev": True},
  176. },
  177. },
  178. )
  179. @skipIf(True, "SLOWTEST skip")
  180. @skipIf(True, "SLOWTEST skip")
  181. @skipIf(True, "SLOWTEST skip")
  182. @skipIf(True, "SLOWTEST skip")
  183. @skipIf(True, "SLOWTEST skip")
  184. @skipIf(True, "SLOWTEST skip")
  185. def test_multiple_sources_dev_master_no_merge_lists(self):
  186. """
  187. Test using two ext_pillar dirs. Since all git_pillar repos are merged
  188. into a single dictionary, ordering matters.
  189. This tests with the dev branch followed by master, and with
  190. pillar_merge_lists disabled.
  191. """
  192. ret = self.get_pillar(
  193. """\
  194. file_ignore_regex: []
  195. file_ignore_glob: []
  196. git_pillar_provider: gitpython
  197. cachedir: {cachedir}
  198. extension_modules: {extmods}
  199. pillar_merge_lists: False
  200. ext_pillar:
  201. - git:
  202. - dev {url}
  203. - master {url}
  204. """
  205. )
  206. self.assertEqual(
  207. ret,
  208. {
  209. "branch": "master",
  210. "mylist": ["master"],
  211. "mydict": {
  212. "master": True,
  213. "dev": True,
  214. "nested_list": ["master"],
  215. "nested_dict": {"master": True, "dev": True},
  216. },
  217. },
  218. )
  219. @skipIf(True, "SLOWTEST skip")
  220. @skipIf(True, "SLOWTEST skip")
  221. @skipIf(True, "SLOWTEST skip")
  222. @skipIf(True, "SLOWTEST skip")
  223. @skipIf(True, "SLOWTEST skip")
  224. @skipIf(True, "SLOWTEST skip")
  225. def test_multiple_sources_master_dev_merge_lists(self):
  226. """
  227. Test using two ext_pillar dirs. Since all git_pillar repos are merged
  228. into a single dictionary, ordering matters.
  229. This tests with the master branch followed by dev, and with
  230. pillar_merge_lists enabled.
  231. """
  232. ret = self.get_pillar(
  233. """\
  234. file_ignore_regex: []
  235. file_ignore_glob: []
  236. git_pillar_provider: gitpython
  237. cachedir: {cachedir}
  238. extension_modules: {extmods}
  239. pillar_merge_lists: True
  240. ext_pillar:
  241. - git:
  242. - master {url}
  243. - dev {url}
  244. """
  245. )
  246. self.assertEqual(
  247. ret,
  248. {
  249. "branch": "dev",
  250. "mylist": ["master", "dev"],
  251. "mydict": {
  252. "master": True,
  253. "dev": True,
  254. "nested_list": ["master", "dev"],
  255. "nested_dict": {"master": True, "dev": True},
  256. },
  257. },
  258. )
  259. @skipIf(True, "SLOWTEST skip")
  260. @skipIf(True, "SLOWTEST skip")
  261. @skipIf(True, "SLOWTEST skip")
  262. @skipIf(True, "SLOWTEST skip")
  263. @skipIf(True, "SLOWTEST skip")
  264. @skipIf(True, "SLOWTEST skip")
  265. def test_multiple_sources_dev_master_merge_lists(self):
  266. """
  267. Test using two ext_pillar dirs. Since all git_pillar repos are merged
  268. into a single dictionary, ordering matters.
  269. This tests with the dev branch followed by master, and with
  270. pillar_merge_lists enabled.
  271. """
  272. ret = self.get_pillar(
  273. """\
  274. file_ignore_regex: []
  275. file_ignore_glob: []
  276. git_pillar_provider: gitpython
  277. cachedir: {cachedir}
  278. extension_modules: {extmods}
  279. pillar_merge_lists: True
  280. ext_pillar:
  281. - git:
  282. - dev {url}
  283. - master {url}
  284. """
  285. )
  286. self.assertEqual(
  287. ret,
  288. {
  289. "branch": "master",
  290. "mylist": ["dev", "master"],
  291. "mydict": {
  292. "master": True,
  293. "dev": True,
  294. "nested_list": ["dev", "master"],
  295. "nested_dict": {"master": True, "dev": True},
  296. },
  297. },
  298. )
  299. @skipIf(True, "SLOWTEST skip")
  300. @skipIf(True, "SLOWTEST skip")
  301. @skipIf(True, "SLOWTEST skip")
  302. @skipIf(True, "SLOWTEST skip")
  303. @skipIf(True, "SLOWTEST skip")
  304. @skipIf(True, "SLOWTEST skip")
  305. def test_multiple_sources_with_pillarenv(self):
  306. """
  307. Test using pillarenv to restrict results to those from a single branch
  308. """
  309. ret = self.get_pillar(
  310. """\
  311. file_ignore_regex: []
  312. file_ignore_glob: []
  313. git_pillar_provider: gitpython
  314. cachedir: {cachedir}
  315. extension_modules: {extmods}
  316. pillarenv: base
  317. ext_pillar:
  318. - git:
  319. - master {url}
  320. - dev {url}
  321. """
  322. )
  323. self.assertEqual(
  324. ret,
  325. {
  326. "branch": "master",
  327. "mylist": ["master"],
  328. "mydict": {
  329. "master": True,
  330. "nested_list": ["master"],
  331. "nested_dict": {"master": True},
  332. },
  333. },
  334. )
  335. @skipIf(True, "SLOWTEST skip")
  336. @skipIf(True, "SLOWTEST skip")
  337. @skipIf(True, "SLOWTEST skip")
  338. @skipIf(True, "SLOWTEST skip")
  339. @skipIf(True, "SLOWTEST skip")
  340. @skipIf(True, "SLOWTEST skip")
  341. def test_includes_enabled(self):
  342. """
  343. Test with git_pillar_includes enabled. The top_only branch references
  344. an SLS file from the master branch, so we should see the key from that
  345. SLS file (included_pillar) in the compiled pillar data.
  346. """
  347. ret = self.get_pillar(
  348. """\
  349. file_ignore_regex: []
  350. file_ignore_glob: []
  351. git_pillar_provider: gitpython
  352. cachedir: {cachedir}
  353. extension_modules: {extmods}
  354. ext_pillar:
  355. - git:
  356. - master {url}
  357. - top_only {url}:
  358. - env: base
  359. """
  360. )
  361. self.assertEqual(
  362. ret,
  363. {
  364. "branch": "master",
  365. "mylist": ["master"],
  366. "mydict": {
  367. "master": True,
  368. "nested_list": ["master"],
  369. "nested_dict": {"master": True},
  370. },
  371. "included_pillar": True,
  372. },
  373. )
  374. @skipIf(True, "SLOWTEST skip")
  375. @skipIf(True, "SLOWTEST skip")
  376. @skipIf(True, "SLOWTEST skip")
  377. @skipIf(True, "SLOWTEST skip")
  378. @skipIf(True, "SLOWTEST skip")
  379. @skipIf(True, "SLOWTEST skip")
  380. def test_includes_disabled(self):
  381. """
  382. Test with git_pillar_includes enabled. The top_only branch references
  383. an SLS file from the master branch, but since includes are disabled it
  384. will not find the SLS file and the "included_pillar" key should not be
  385. present in the compiled pillar data. We should instead see an error
  386. message in the compiled data.
  387. """
  388. ret = self.get_pillar(
  389. """\
  390. file_ignore_regex: []
  391. file_ignore_glob: []
  392. git_pillar_provider: gitpython
  393. git_pillar_includes: False
  394. cachedir: {cachedir}
  395. extension_modules: {extmods}
  396. ext_pillar:
  397. - git:
  398. - master {url}
  399. - top_only {url}:
  400. - env: base
  401. """
  402. )
  403. self.assertEqual(
  404. ret,
  405. {
  406. "branch": "master",
  407. "mylist": ["master"],
  408. "mydict": {
  409. "master": True,
  410. "nested_list": ["master"],
  411. "nested_dict": {"master": True},
  412. },
  413. "_errors": [
  414. "Specified SLS 'bar' in environment 'base' is not "
  415. "available on the salt master"
  416. ],
  417. },
  418. )
  419. @skipIf(True, "SLOWTEST skip")
  420. @skipIf(True, "SLOWTEST skip")
  421. @skipIf(True, "SLOWTEST skip")
  422. @skipIf(True, "SLOWTEST skip")
  423. @skipIf(True, "SLOWTEST skip")
  424. @skipIf(True, "SLOWTEST skip")
  425. def test_includes_enabled_solves___env___with_mountpoint(self):
  426. """
  427. Test with git_pillar_includes enabled and using "__env__" as the branch
  428. name for the configured repositories.
  429. The "gitinfo" repository contains top.sls file with a local reference
  430. and also referencing external "nowhere.foo" which is provided by "webinfo"
  431. repository mounted as "nowhere".
  432. """
  433. ret = self.get_pillar(
  434. """\
  435. file_ignore_regex: []
  436. file_ignore_glob: []
  437. git_pillar_provider: gitpython
  438. cachedir: {cachedir}
  439. extension_modules: {extmods}
  440. ext_pillar:
  441. - git:
  442. - __env__ {url_extra_repo}:
  443. - name: gitinfo
  444. - __env__ {url}:
  445. - name: webinfo
  446. - mountpoint: nowhere
  447. """
  448. )
  449. self.assertEqual(
  450. ret,
  451. {
  452. "branch": "master",
  453. "motd": "The force will be with you. Always.",
  454. "mylist": ["master"],
  455. "mydict": {
  456. "master": True,
  457. "nested_list": ["master"],
  458. "nested_dict": {"master": True},
  459. },
  460. },
  461. )
  462. @skipIf(True, "SLOWTEST skip")
  463. @skipIf(True, "SLOWTEST skip")
  464. @skipIf(True, "SLOWTEST skip")
  465. @skipIf(True, "SLOWTEST skip")
  466. @skipIf(True, "SLOWTEST skip")
  467. @skipIf(True, "SLOWTEST skip")
  468. def test_root_parameter(self):
  469. """
  470. Test root parameter
  471. """
  472. expected = {"from_subdir": True}
  473. ret = self.get_pillar(
  474. """\
  475. file_ignore_regex: []
  476. file_ignore_glob: []
  477. git_pillar_provider: gitpython
  478. cachedir: {cachedir}
  479. extension_modules: {extmods}
  480. ext_pillar:
  481. - git:
  482. - master {url}:
  483. - root: subdir
  484. - top_only {url}:
  485. - env: base
  486. """
  487. )
  488. self.assertEqual(ret, expected)
  489. @skipIf(True, "SLOWTEST skip")
  490. @skipIf(True, "SLOWTEST skip")
  491. @skipIf(True, "SLOWTEST skip")
  492. @skipIf(True, "SLOWTEST skip")
  493. @skipIf(True, "SLOWTEST skip")
  494. @skipIf(True, "SLOWTEST skip")
  495. def test_mountpoint_parameter(self):
  496. """
  497. Test mountpoint parameter
  498. """
  499. expected = {"included_pillar": True}
  500. ret = self.get_pillar(
  501. """\
  502. file_ignore_regex: []
  503. file_ignore_glob: []
  504. git_pillar_provider: gitpython
  505. cachedir: {cachedir}
  506. extension_modules: {extmods}
  507. ext_pillar:
  508. - git:
  509. - master {url}:
  510. - mountpoint: mounted
  511. - top_mounted {url}:
  512. - env: base
  513. """
  514. )
  515. self.assertEqual(ret, expected)
  516. @skipIf(True, "SLOWTEST skip")
  517. @skipIf(True, "SLOWTEST skip")
  518. @skipIf(True, "SLOWTEST skip")
  519. @skipIf(True, "SLOWTEST skip")
  520. @skipIf(True, "SLOWTEST skip")
  521. @skipIf(True, "SLOWTEST skip")
  522. def test_root_and_mountpoint_parameters(self):
  523. """
  524. Test root and mountpoint parameters
  525. """
  526. expected = {"from_subdir": True}
  527. ret = self.get_pillar(
  528. """\
  529. file_ignore_regex: []
  530. file_ignore_glob: []
  531. git_pillar_provider: gitpython
  532. cachedir: {cachedir}
  533. extension_modules: {extmods}
  534. ext_pillar:
  535. - git:
  536. - master {url}:
  537. - mountpoint: mounted
  538. - root: subdir
  539. - top_mounted {url}:
  540. - env: base
  541. """
  542. )
  543. self.assertEqual(ret, expected)
  544. @skipIf(True, "SLOWTEST skip")
  545. @skipIf(True, "SLOWTEST skip")
  546. @skipIf(True, "SLOWTEST skip")
  547. @skipIf(True, "SLOWTEST skip")
  548. @skipIf(True, "SLOWTEST skip")
  549. @skipIf(True, "SLOWTEST skip")
  550. def test_all_saltenvs(self):
  551. """
  552. Test all_saltenvs parameter.
  553. """
  554. ret = self.get_pillar(
  555. """\
  556. file_ignore_regex: []
  557. file_ignore_glob: []
  558. git_pillar_provider: gitpython
  559. cachedir: {cachedir}
  560. extension_modules: {extmods}
  561. pillarenv: dev
  562. ext_pillar:
  563. - git:
  564. - __env__ {url_extra_repo}:
  565. - all_saltenvs: master
  566. - __env__ {url}:
  567. - mountpoint: nowhere
  568. """
  569. )
  570. self.assertEqual(
  571. ret,
  572. {
  573. "branch": "dev",
  574. "motd": "The force will be with you. Always.",
  575. "mylist": ["dev"],
  576. "mydict": {
  577. "dev": True,
  578. "nested_list": ["dev"],
  579. "nested_dict": {"dev": True},
  580. },
  581. },
  582. )
  583. @skipIf(True, "SLOWTEST skip")
  584. @skipIf(True, "SLOWTEST skip")
  585. @skipIf(True, "SLOWTEST skip")
  586. @skipIf(True, "SLOWTEST skip")
  587. @skipIf(True, "SLOWTEST skip")
  588. @skipIf(True, "SLOWTEST skip")
  589. def test_all_saltenvs_base(self):
  590. """
  591. Test all_saltenvs parameter with base pillarenv.
  592. """
  593. ret = self.get_pillar(
  594. """\
  595. file_ignore_regex: []
  596. file_ignore_glob: []
  597. git_pillar_provider: gitpython
  598. cachedir: {cachedir}
  599. extension_modules: {extmods}
  600. ext_pillar:
  601. - git:
  602. - __env__ {url_extra_repo}:
  603. - all_saltenvs: master
  604. - __env__ {url}:
  605. - mountpoint: nowhere
  606. """
  607. )
  608. self.assertEqual(
  609. ret,
  610. {
  611. "branch": "master",
  612. "motd": "The force will be with you. Always.",
  613. "mylist": ["master"],
  614. "mydict": {
  615. "master": True,
  616. "nested_list": ["master"],
  617. "nested_dict": {"master": True},
  618. },
  619. },
  620. )
  621. def test_fallback(self):
  622. """
  623. Test fallback parameter.
  624. """
  625. ret = self.get_pillar(
  626. """\
  627. file_ignore_regex: []
  628. file_ignore_glob: []
  629. git_pillar_provider: gitpython
  630. cachedir: {cachedir}
  631. extension_modules: {extmods}
  632. pillarenv: nonexisting
  633. ext_pillar:
  634. - git:
  635. - __env__ {url_extra_repo}:
  636. - fallback: master
  637. - __env__ {url}:
  638. - mountpoint: nowhere
  639. - fallback: dev
  640. """
  641. )
  642. self.assertEqual(
  643. ret,
  644. {
  645. "branch": "dev",
  646. "motd": "The force will be with you. Always.",
  647. "mylist": ["dev"],
  648. "mydict": {
  649. "dev": True,
  650. "nested_list": ["dev"],
  651. "nested_dict": {"dev": True},
  652. },
  653. },
  654. )
  655. @destructiveTest
  656. @skipIf(_windows_or_mac(), "minion is windows or mac")
  657. @skip_if_not_root
  658. @skipIf(not HAS_GITPYTHON, "GitPython >= {0} required".format(GITPYTHON_MINVER))
  659. @skipIf(not HAS_SSHD, "sshd not present")
  660. class TestGitPythonSSH(GitPillarSSHTestBase, GitPythonMixin):
  661. """
  662. Test git_pillar with GitPython using SSH authentication
  663. """
  664. id_rsa_nopass = _rand_key_name(8)
  665. id_rsa_withpass = _rand_key_name(8)
  666. username = USERNAME
  667. passphrase = PASSWORD
  668. @skipIf(_windows_or_mac(), "minion is windows or mac")
  669. @skip_if_not_root
  670. @skipIf(not HAS_GITPYTHON, "GitPython >= {0} required".format(GITPYTHON_MINVER))
  671. @skipIf(not HAS_NGINX, "nginx not present")
  672. @skipIf(not HAS_VIRTUALENV, "virtualenv not present")
  673. class TestGitPythonHTTP(GitPillarHTTPTestBase, GitPythonMixin):
  674. """
  675. Test git_pillar with GitPython using unauthenticated HTTP
  676. """
  677. @skipIf(_windows_or_mac(), "minion is windows or mac")
  678. @skip_if_not_root
  679. @skipIf(not HAS_GITPYTHON, "GitPython >= {0} required".format(GITPYTHON_MINVER))
  680. @skipIf(not HAS_NGINX, "nginx not present")
  681. @skipIf(not HAS_VIRTUALENV, "virtualenv not present")
  682. class TestGitPythonAuthenticatedHTTP(TestGitPythonHTTP, GitPythonMixin):
  683. """
  684. Test git_pillar with GitPython using authenticated HTTP
  685. """
  686. username = USERNAME
  687. password = PASSWORD
  688. @classmethod
  689. def setUpClass(cls):
  690. """
  691. Create start the webserver
  692. """
  693. super(TestGitPythonAuthenticatedHTTP, cls).setUpClass()
  694. # Override the URL set up in the parent class to encode the
  695. # username/password into it.
  696. cls.url = "http://{username}:{password}@127.0.0.1:{port}/repo.git".format(
  697. username=cls.username, password=cls.password, port=cls.nginx_port
  698. )
  699. cls.url_extra_repo = "http://{username}:{password}@127.0.0.1:{port}/extra_repo.git".format(
  700. username=cls.username, password=cls.password, port=cls.nginx_port
  701. )
  702. cls.ext_opts["url"] = cls.url
  703. cls.ext_opts["url_extra_repo"] = cls.url_extra_repo
  704. cls.ext_opts["username"] = cls.username
  705. cls.ext_opts["password"] = cls.password
  706. @destructiveTest
  707. @skipIf(_windows_or_mac(), "minion is windows or mac")
  708. @skip_if_not_root
  709. @skipIf(
  710. not HAS_PYGIT2,
  711. "pygit2 >= {0} and libgit2 >= {1} required".format(PYGIT2_MINVER, LIBGIT2_MINVER),
  712. )
  713. @skipIf(not HAS_SSHD, "sshd not present")
  714. class TestPygit2SSH(GitPillarSSHTestBase):
  715. """
  716. Test git_pillar with pygit2 using SSH authentication
  717. NOTE: Any tests added to this test class should have equivalent tests (if
  718. possible) in the TestGitPythonSSH class.
  719. """
  720. id_rsa_nopass = _rand_key_name(8)
  721. id_rsa_withpass = _rand_key_name(8)
  722. username = USERNAME
  723. passphrase = PASSWORD
  724. @requires_system_grains
  725. @skipIf(True, "SLOWTEST skip")
  726. @skipIf(True, "SLOWTEST skip")
  727. @skipIf(True, "SLOWTEST skip")
  728. @skipIf(True, "SLOWTEST skip")
  729. @skipIf(True, "SLOWTEST skip")
  730. @skipIf(True, "SLOWTEST skip")
  731. def test_single_source(self, grains):
  732. """
  733. Test using a single ext_pillar repo
  734. """
  735. expected = {
  736. "branch": "master",
  737. "mylist": ["master"],
  738. "mydict": {
  739. "master": True,
  740. "nested_list": ["master"],
  741. "nested_dict": {"master": True},
  742. },
  743. }
  744. # Test with passphraseless key and global credential options
  745. ret = self.get_pillar(
  746. """\
  747. file_ignore_regex: []
  748. file_ignore_glob: []
  749. git_pillar_provider: pygit2
  750. git_pillar_pubkey: {pubkey_nopass}
  751. git_pillar_privkey: {privkey_nopass}
  752. cachedir: {cachedir}
  753. extension_modules: {extmods}
  754. ext_pillar:
  755. - git:
  756. - master {url}
  757. """
  758. )
  759. self.assertEqual(ret, expected)
  760. # Test with passphraseless key and per-repo credential options
  761. ret = self.get_pillar(
  762. """\
  763. file_ignore_regex: []
  764. file_ignore_glob: []
  765. git_pillar_provider: pygit2
  766. cachedir: {cachedir}
  767. extension_modules: {extmods}
  768. ext_pillar:
  769. - git:
  770. - master {url}:
  771. - pubkey: {pubkey_nopass}
  772. - privkey: {privkey_nopass}
  773. """
  774. )
  775. self.assertEqual(ret, expected)
  776. if grains["os_family"] == "Debian":
  777. # passphrase-protected currently does not work here
  778. return
  779. # Test with passphrase-protected key and global credential options
  780. ret = self.get_pillar(
  781. """\
  782. file_ignore_regex: []
  783. file_ignore_glob: []
  784. git_pillar_provider: pygit2
  785. git_pillar_pubkey: {pubkey_withpass}
  786. git_pillar_privkey: {privkey_withpass}
  787. git_pillar_passphrase: {passphrase}
  788. cachedir: {cachedir}
  789. extension_modules: {extmods}
  790. ext_pillar:
  791. - git:
  792. - master {url}
  793. """
  794. )
  795. self.assertEqual(ret, expected)
  796. # Test with passphrase-protected key and per-repo credential options
  797. ret = self.get_pillar(
  798. """\
  799. file_ignore_regex: []
  800. file_ignore_glob: []
  801. git_pillar_provider: pygit2
  802. cachedir: {cachedir}
  803. extension_modules: {extmods}
  804. ext_pillar:
  805. - git:
  806. - master {url}:
  807. - pubkey: {pubkey_withpass}
  808. - privkey: {privkey_withpass}
  809. - passphrase: {passphrase}
  810. """
  811. )
  812. self.assertEqual(ret, expected)
  813. @requires_system_grains
  814. @skipIf(True, "SLOWTEST skip")
  815. @skipIf(True, "SLOWTEST skip")
  816. @skipIf(True, "SLOWTEST skip")
  817. @skipIf(True, "SLOWTEST skip")
  818. @skipIf(True, "SLOWTEST skip")
  819. @skipIf(True, "SLOWTEST skip")
  820. def test_multiple_sources_master_dev_no_merge_lists(self, grains):
  821. """
  822. Test using two ext_pillar dirs. Since all git_pillar repos are merged
  823. into a single dictionary, ordering matters.
  824. This tests with the master branch followed by dev, and with
  825. pillar_merge_lists disabled.
  826. """
  827. expected = {
  828. "branch": "dev",
  829. "mylist": ["dev"],
  830. "mydict": {
  831. "master": True,
  832. "dev": True,
  833. "nested_list": ["dev"],
  834. "nested_dict": {"master": True, "dev": True},
  835. },
  836. }
  837. # Test with passphraseless key and global credential options
  838. ret = self.get_pillar(
  839. """\
  840. file_ignore_regex: []
  841. file_ignore_glob: []
  842. git_pillar_provider: pygit2
  843. git_pillar_pubkey: {pubkey_nopass}
  844. git_pillar_privkey: {privkey_nopass}
  845. cachedir: {cachedir}
  846. extension_modules: {extmods}
  847. pillar_merge_lists: False
  848. ext_pillar:
  849. - git:
  850. - master {url}
  851. - dev {url}
  852. """
  853. )
  854. self.assertEqual(ret, expected)
  855. # Test with passphraseless key and per-repo credential options
  856. ret = self.get_pillar(
  857. """\
  858. file_ignore_regex: []
  859. file_ignore_glob: []
  860. git_pillar_provider: pygit2
  861. cachedir: {cachedir}
  862. extension_modules: {extmods}
  863. pillar_merge_lists: False
  864. ext_pillar:
  865. - git:
  866. - master {url}:
  867. - pubkey: {pubkey_nopass}
  868. - privkey: {privkey_nopass}
  869. - dev {url}:
  870. - pubkey: {pubkey_nopass}
  871. - privkey: {privkey_nopass}
  872. """
  873. )
  874. self.assertEqual(ret, expected)
  875. if grains["os_family"] == "Debian":
  876. # passphrase-protected currently does not work here
  877. return
  878. # Test with passphrase-protected key and global credential options
  879. ret = self.get_pillar(
  880. """\
  881. file_ignore_regex: []
  882. file_ignore_glob: []
  883. git_pillar_provider: pygit2
  884. git_pillar_pubkey: {pubkey_withpass}
  885. git_pillar_privkey: {privkey_withpass}
  886. git_pillar_passphrase: {passphrase}
  887. cachedir: {cachedir}
  888. extension_modules: {extmods}
  889. pillar_merge_lists: False
  890. ext_pillar:
  891. - git:
  892. - master {url}
  893. - dev {url}
  894. """
  895. )
  896. self.assertEqual(ret, expected)
  897. # Test with passphrase-protected key and per-repo credential options
  898. ret = self.get_pillar(
  899. """\
  900. file_ignore_regex: []
  901. file_ignore_glob: []
  902. git_pillar_provider: pygit2
  903. cachedir: {cachedir}
  904. extension_modules: {extmods}
  905. pillar_merge_lists: False
  906. ext_pillar:
  907. - git:
  908. - master {url}:
  909. - pubkey: {pubkey_withpass}
  910. - privkey: {privkey_withpass}
  911. - passphrase: {passphrase}
  912. - dev {url}:
  913. - pubkey: {pubkey_withpass}
  914. - privkey: {privkey_withpass}
  915. - passphrase: {passphrase}
  916. """
  917. )
  918. self.assertEqual(ret, expected)
  919. @requires_system_grains
  920. @skipIf(True, "SLOWTEST skip")
  921. @skipIf(True, "SLOWTEST skip")
  922. @skipIf(True, "SLOWTEST skip")
  923. @skipIf(True, "SLOWTEST skip")
  924. @skipIf(True, "SLOWTEST skip")
  925. @skipIf(True, "SLOWTEST skip")
  926. def test_multiple_sources_dev_master_no_merge_lists(self, grains):
  927. """
  928. Test using two ext_pillar dirs. Since all git_pillar repos are merged
  929. into a single dictionary, ordering matters.
  930. This tests with the dev branch followed by master, and with
  931. pillar_merge_lists disabled.
  932. """
  933. expected = {
  934. "branch": "master",
  935. "mylist": ["master"],
  936. "mydict": {
  937. "master": True,
  938. "dev": True,
  939. "nested_list": ["master"],
  940. "nested_dict": {"master": True, "dev": True},
  941. },
  942. }
  943. # Test with passphraseless key and global credential options
  944. ret = self.get_pillar(
  945. """\
  946. file_ignore_regex: []
  947. file_ignore_glob: []
  948. git_pillar_provider: pygit2
  949. git_pillar_pubkey: {pubkey_nopass}
  950. git_pillar_privkey: {privkey_nopass}
  951. cachedir: {cachedir}
  952. extension_modules: {extmods}
  953. pillar_merge_lists: False
  954. ext_pillar:
  955. - git:
  956. - dev {url}
  957. - master {url}
  958. """
  959. )
  960. self.assertEqual(ret, expected)
  961. # Test with passphraseless key and per-repo credential options
  962. ret = self.get_pillar(
  963. """\
  964. file_ignore_regex: []
  965. file_ignore_glob: []
  966. git_pillar_provider: pygit2
  967. cachedir: {cachedir}
  968. extension_modules: {extmods}
  969. pillar_merge_lists: False
  970. ext_pillar:
  971. - git:
  972. - dev {url}:
  973. - pubkey: {pubkey_nopass}
  974. - privkey: {privkey_nopass}
  975. - master {url}:
  976. - pubkey: {pubkey_nopass}
  977. - privkey: {privkey_nopass}
  978. """
  979. )
  980. self.assertEqual(ret, expected)
  981. if grains["os_family"] == "Debian":
  982. # passphrase-protected currently does not work here
  983. return
  984. # Test with passphrase-protected key and global credential options
  985. ret = self.get_pillar(
  986. """\
  987. file_ignore_regex: []
  988. file_ignore_glob: []
  989. git_pillar_provider: pygit2
  990. git_pillar_pubkey: {pubkey_withpass}
  991. git_pillar_privkey: {privkey_withpass}
  992. git_pillar_passphrase: {passphrase}
  993. cachedir: {cachedir}
  994. extension_modules: {extmods}
  995. pillar_merge_lists: False
  996. ext_pillar:
  997. - git:
  998. - dev {url}
  999. - master {url}
  1000. """
  1001. )
  1002. self.assertEqual(ret, expected)
  1003. # Test with passphrase-protected key and per-repo credential options
  1004. ret = self.get_pillar(
  1005. """\
  1006. file_ignore_regex: []
  1007. file_ignore_glob: []
  1008. git_pillar_provider: pygit2
  1009. cachedir: {cachedir}
  1010. extension_modules: {extmods}
  1011. pillar_merge_lists: False
  1012. ext_pillar:
  1013. - git:
  1014. - dev {url}:
  1015. - pubkey: {pubkey_withpass}
  1016. - privkey: {privkey_withpass}
  1017. - passphrase: {passphrase}
  1018. - master {url}:
  1019. - pubkey: {pubkey_withpass}
  1020. - privkey: {privkey_withpass}
  1021. - passphrase: {passphrase}
  1022. """
  1023. )
  1024. self.assertEqual(ret, expected)
  1025. @requires_system_grains
  1026. @skipIf(True, "SLOWTEST skip")
  1027. @skipIf(True, "SLOWTEST skip")
  1028. @skipIf(True, "SLOWTEST skip")
  1029. @skipIf(True, "SLOWTEST skip")
  1030. @skipIf(True, "SLOWTEST skip")
  1031. @skipIf(True, "SLOWTEST skip")
  1032. def test_multiple_sources_master_dev_merge_lists(self, grains):
  1033. """
  1034. Test using two ext_pillar dirs. Since all git_pillar repos are merged
  1035. into a single dictionary, ordering matters.
  1036. This tests with the master branch followed by dev, and with
  1037. pillar_merge_lists enabled.
  1038. """
  1039. expected = {
  1040. "branch": "dev",
  1041. "mylist": ["master", "dev"],
  1042. "mydict": {
  1043. "master": True,
  1044. "dev": True,
  1045. "nested_list": ["master", "dev"],
  1046. "nested_dict": {"master": True, "dev": True},
  1047. },
  1048. }
  1049. # Test with passphraseless key and global credential options
  1050. ret = self.get_pillar(
  1051. """\
  1052. file_ignore_regex: []
  1053. file_ignore_glob: []
  1054. git_pillar_provider: pygit2
  1055. git_pillar_pubkey: {pubkey_nopass}
  1056. git_pillar_privkey: {privkey_nopass}
  1057. cachedir: {cachedir}
  1058. extension_modules: {extmods}
  1059. pillar_merge_lists: True
  1060. ext_pillar:
  1061. - git:
  1062. - master {url}
  1063. - dev {url}
  1064. """
  1065. )
  1066. self.assertEqual(ret, expected)
  1067. # Test with passphraseless key and per-repo credential options
  1068. ret = self.get_pillar(
  1069. """\
  1070. file_ignore_regex: []
  1071. file_ignore_glob: []
  1072. git_pillar_provider: pygit2
  1073. cachedir: {cachedir}
  1074. extension_modules: {extmods}
  1075. pillar_merge_lists: True
  1076. ext_pillar:
  1077. - git:
  1078. - master {url}:
  1079. - pubkey: {pubkey_nopass}
  1080. - privkey: {privkey_nopass}
  1081. - dev {url}:
  1082. - pubkey: {pubkey_nopass}
  1083. - privkey: {privkey_nopass}
  1084. """
  1085. )
  1086. self.assertEqual(ret, expected)
  1087. if grains["os_family"] == "Debian":
  1088. # passphrase-protected currently does not work here
  1089. return
  1090. # Test with passphrase-protected key and global credential options
  1091. ret = self.get_pillar(
  1092. """\
  1093. file_ignore_regex: []
  1094. file_ignore_glob: []
  1095. git_pillar_provider: pygit2
  1096. git_pillar_pubkey: {pubkey_withpass}
  1097. git_pillar_privkey: {privkey_withpass}
  1098. git_pillar_passphrase: {passphrase}
  1099. cachedir: {cachedir}
  1100. extension_modules: {extmods}
  1101. pillar_merge_lists: True
  1102. ext_pillar:
  1103. - git:
  1104. - master {url}
  1105. - dev {url}
  1106. """
  1107. )
  1108. self.assertEqual(ret, expected)
  1109. # Test with passphrase-protected key and per-repo credential options
  1110. ret = self.get_pillar(
  1111. """\
  1112. file_ignore_regex: []
  1113. file_ignore_glob: []
  1114. git_pillar_provider: pygit2
  1115. cachedir: {cachedir}
  1116. extension_modules: {extmods}
  1117. pillar_merge_lists: True
  1118. ext_pillar:
  1119. - git:
  1120. - master {url}:
  1121. - pubkey: {pubkey_withpass}
  1122. - privkey: {privkey_withpass}
  1123. - passphrase: {passphrase}
  1124. - dev {url}:
  1125. - pubkey: {pubkey_withpass}
  1126. - privkey: {privkey_withpass}
  1127. - passphrase: {passphrase}
  1128. """
  1129. )
  1130. self.assertEqual(ret, expected)
  1131. @requires_system_grains
  1132. @skipIf(True, "SLOWTEST skip")
  1133. @skipIf(True, "SLOWTEST skip")
  1134. @skipIf(True, "SLOWTEST skip")
  1135. @skipIf(True, "SLOWTEST skip")
  1136. @skipIf(True, "SLOWTEST skip")
  1137. @skipIf(True, "SLOWTEST skip")
  1138. def test_multiple_sources_dev_master_merge_lists(self, grains):
  1139. """
  1140. Test using two ext_pillar dirs. Since all git_pillar repos are merged
  1141. into a single dictionary, ordering matters.
  1142. This tests with the dev branch followed by master, and with
  1143. pillar_merge_lists enabled.
  1144. """
  1145. expected = {
  1146. "branch": "master",
  1147. "mylist": ["dev", "master"],
  1148. "mydict": {
  1149. "master": True,
  1150. "dev": True,
  1151. "nested_list": ["dev", "master"],
  1152. "nested_dict": {"master": True, "dev": True},
  1153. },
  1154. }
  1155. # Test with passphraseless key and global credential options
  1156. ret = self.get_pillar(
  1157. """\
  1158. file_ignore_regex: []
  1159. file_ignore_glob: []
  1160. git_pillar_provider: pygit2
  1161. git_pillar_pubkey: {pubkey_nopass}
  1162. git_pillar_privkey: {privkey_nopass}
  1163. cachedir: {cachedir}
  1164. extension_modules: {extmods}
  1165. pillar_merge_lists: True
  1166. ext_pillar:
  1167. - git:
  1168. - dev {url}
  1169. - master {url}
  1170. """
  1171. )
  1172. self.assertEqual(ret, expected)
  1173. # Test with passphraseless key and per-repo credential options
  1174. ret = self.get_pillar(
  1175. """\
  1176. file_ignore_regex: []
  1177. file_ignore_glob: []
  1178. git_pillar_provider: pygit2
  1179. cachedir: {cachedir}
  1180. extension_modules: {extmods}
  1181. pillar_merge_lists: True
  1182. ext_pillar:
  1183. - git:
  1184. - dev {url}:
  1185. - pubkey: {pubkey_nopass}
  1186. - privkey: {privkey_nopass}
  1187. - master {url}:
  1188. - pubkey: {pubkey_nopass}
  1189. - privkey: {privkey_nopass}
  1190. """
  1191. )
  1192. self.assertEqual(ret, expected)
  1193. if grains["os_family"] == "Debian":
  1194. # passphrase-protected currently does not work here
  1195. return
  1196. # Test with passphrase-protected key and global credential options
  1197. ret = self.get_pillar(
  1198. """\
  1199. file_ignore_regex: []
  1200. file_ignore_glob: []
  1201. git_pillar_provider: pygit2
  1202. git_pillar_pubkey: {pubkey_withpass}
  1203. git_pillar_privkey: {privkey_withpass}
  1204. git_pillar_passphrase: {passphrase}
  1205. cachedir: {cachedir}
  1206. extension_modules: {extmods}
  1207. pillar_merge_lists: True
  1208. ext_pillar:
  1209. - git:
  1210. - dev {url}
  1211. - master {url}
  1212. """
  1213. )
  1214. self.assertEqual(ret, expected)
  1215. # Test with passphrase-protected key and per-repo credential options
  1216. ret = self.get_pillar(
  1217. """\
  1218. file_ignore_regex: []
  1219. file_ignore_glob: []
  1220. git_pillar_provider: pygit2
  1221. cachedir: {cachedir}
  1222. extension_modules: {extmods}
  1223. pillar_merge_lists: True
  1224. ext_pillar:
  1225. - git:
  1226. - dev {url}:
  1227. - pubkey: {pubkey_withpass}
  1228. - privkey: {privkey_withpass}
  1229. - passphrase: {passphrase}
  1230. - master {url}:
  1231. - pubkey: {pubkey_withpass}
  1232. - privkey: {privkey_withpass}
  1233. - passphrase: {passphrase}
  1234. """
  1235. )
  1236. self.assertEqual(ret, expected)
  1237. @requires_system_grains
  1238. @skipIf(True, "SLOWTEST skip")
  1239. @skipIf(True, "SLOWTEST skip")
  1240. @skipIf(True, "SLOWTEST skip")
  1241. @skipIf(True, "SLOWTEST skip")
  1242. @skipIf(True, "SLOWTEST skip")
  1243. @skipIf(True, "SLOWTEST skip")
  1244. def test_multiple_sources_with_pillarenv(self, grains):
  1245. """
  1246. Test using pillarenv to restrict results to those from a single branch
  1247. """
  1248. expected = {
  1249. "branch": "master",
  1250. "mylist": ["master"],
  1251. "mydict": {
  1252. "master": True,
  1253. "nested_list": ["master"],
  1254. "nested_dict": {"master": True},
  1255. },
  1256. }
  1257. # Test with passphraseless key and global credential options
  1258. ret = self.get_pillar(
  1259. """\
  1260. file_ignore_regex: []
  1261. file_ignore_glob: []
  1262. git_pillar_provider: pygit2
  1263. git_pillar_pubkey: {pubkey_nopass}
  1264. git_pillar_privkey: {privkey_nopass}
  1265. cachedir: {cachedir}
  1266. extension_modules: {extmods}
  1267. pillarenv: base
  1268. ext_pillar:
  1269. - git:
  1270. - master {url}
  1271. - dev {url}
  1272. """
  1273. )
  1274. self.assertEqual(ret, expected)
  1275. # Test with passphraseless key and per-repo credential options
  1276. ret = self.get_pillar(
  1277. """\
  1278. file_ignore_regex: []
  1279. file_ignore_glob: []
  1280. git_pillar_provider: pygit2
  1281. cachedir: {cachedir}
  1282. extension_modules: {extmods}
  1283. pillarenv: base
  1284. ext_pillar:
  1285. - git:
  1286. - master {url}:
  1287. - pubkey: {pubkey_nopass}
  1288. - privkey: {privkey_nopass}
  1289. - dev {url}:
  1290. - pubkey: {pubkey_nopass}
  1291. - privkey: {privkey_nopass}
  1292. """
  1293. )
  1294. self.assertEqual(ret, expected)
  1295. if grains["os_family"] == "Debian":
  1296. # passphrase-protected currently does not work here
  1297. return
  1298. # Test with passphrase-protected key and global credential options
  1299. ret = self.get_pillar(
  1300. """\
  1301. file_ignore_regex: []
  1302. file_ignore_glob: []
  1303. git_pillar_provider: pygit2
  1304. git_pillar_pubkey: {pubkey_withpass}
  1305. git_pillar_privkey: {privkey_withpass}
  1306. git_pillar_passphrase: {passphrase}
  1307. cachedir: {cachedir}
  1308. extension_modules: {extmods}
  1309. pillarenv: base
  1310. ext_pillar:
  1311. - git:
  1312. - master {url}
  1313. - dev {url}
  1314. """
  1315. )
  1316. self.assertEqual(ret, expected)
  1317. # Test with passphrase-protected key and per-repo credential options
  1318. ret = self.get_pillar(
  1319. """\
  1320. file_ignore_regex: []
  1321. file_ignore_glob: []
  1322. git_pillar_provider: pygit2
  1323. cachedir: {cachedir}
  1324. extension_modules: {extmods}
  1325. pillarenv: base
  1326. ext_pillar:
  1327. - git:
  1328. - master {url}:
  1329. - pubkey: {pubkey_withpass}
  1330. - privkey: {privkey_withpass}
  1331. - passphrase: {passphrase}
  1332. - dev {url}:
  1333. - pubkey: {pubkey_nopass}
  1334. - privkey: {privkey_nopass}
  1335. - passphrase: {passphrase}
  1336. """
  1337. )
  1338. self.assertEqual(ret, expected)
  1339. @requires_system_grains
  1340. @skipIf(True, "SLOWTEST skip")
  1341. @skipIf(True, "SLOWTEST skip")
  1342. @skipIf(True, "SLOWTEST skip")
  1343. @skipIf(True, "SLOWTEST skip")
  1344. @skipIf(True, "SLOWTEST skip")
  1345. @skipIf(True, "SLOWTEST skip")
  1346. def test_includes_enabled(self, grains):
  1347. """
  1348. Test with git_pillar_includes enabled. The top_only branch references
  1349. an SLS file from the master branch, so we should see the
  1350. "included_pillar" key from that SLS file in the compiled pillar data.
  1351. """
  1352. expected = {
  1353. "branch": "master",
  1354. "mylist": ["master"],
  1355. "mydict": {
  1356. "master": True,
  1357. "nested_list": ["master"],
  1358. "nested_dict": {"master": True},
  1359. },
  1360. "included_pillar": True,
  1361. }
  1362. # Test with passphraseless key and global credential options
  1363. ret = self.get_pillar(
  1364. """\
  1365. file_ignore_regex: []
  1366. file_ignore_glob: []
  1367. git_pillar_provider: pygit2
  1368. git_pillar_pubkey: {pubkey_nopass}
  1369. git_pillar_privkey: {privkey_nopass}
  1370. cachedir: {cachedir}
  1371. extension_modules: {extmods}
  1372. ext_pillar:
  1373. - git:
  1374. - master {url}
  1375. - top_only {url}:
  1376. - env: base
  1377. """
  1378. )
  1379. self.assertEqual(ret, expected)
  1380. # Test with passphraseless key and per-repo credential options
  1381. ret = self.get_pillar(
  1382. """\
  1383. file_ignore_regex: []
  1384. file_ignore_glob: []
  1385. git_pillar_provider: pygit2
  1386. cachedir: {cachedir}
  1387. extension_modules: {extmods}
  1388. ext_pillar:
  1389. - git:
  1390. - master {url}:
  1391. - pubkey: {pubkey_nopass}
  1392. - privkey: {privkey_nopass}
  1393. - top_only {url}:
  1394. - pubkey: {pubkey_nopass}
  1395. - privkey: {privkey_nopass}
  1396. - env: base
  1397. """
  1398. )
  1399. self.assertEqual(ret, expected)
  1400. if grains["os_family"] == "Debian":
  1401. # passphrase-protected currently does not work here
  1402. return
  1403. # Test with passphrase-protected key and global credential options
  1404. ret = self.get_pillar(
  1405. """\
  1406. file_ignore_regex: []
  1407. file_ignore_glob: []
  1408. git_pillar_provider: pygit2
  1409. git_pillar_pubkey: {pubkey_withpass}
  1410. git_pillar_privkey: {privkey_withpass}
  1411. git_pillar_passphrase: {passphrase}
  1412. cachedir: {cachedir}
  1413. extension_modules: {extmods}
  1414. ext_pillar:
  1415. - git:
  1416. - master {url}
  1417. - top_only {url}:
  1418. - env: base
  1419. """
  1420. )
  1421. self.assertEqual(ret, expected)
  1422. # Test with passphrase-protected key and per-repo credential options
  1423. ret = self.get_pillar(
  1424. """\
  1425. file_ignore_regex: []
  1426. file_ignore_glob: []
  1427. git_pillar_provider: pygit2
  1428. cachedir: {cachedir}
  1429. extension_modules: {extmods}
  1430. ext_pillar:
  1431. - git:
  1432. - master {url}:
  1433. - pubkey: {pubkey_withpass}
  1434. - privkey: {privkey_withpass}
  1435. - passphrase: {passphrase}
  1436. - top_only {url}:
  1437. - pubkey: {pubkey_withpass}
  1438. - privkey: {privkey_withpass}
  1439. - passphrase: {passphrase}
  1440. - env: base
  1441. """
  1442. )
  1443. self.assertEqual(ret, expected)
  1444. @requires_system_grains
  1445. @skipIf(True, "SLOWTEST skip")
  1446. @skipIf(True, "SLOWTEST skip")
  1447. @skipIf(True, "SLOWTEST skip")
  1448. @skipIf(True, "SLOWTEST skip")
  1449. @skipIf(True, "SLOWTEST skip")
  1450. @skipIf(True, "SLOWTEST skip")
  1451. def test_includes_disabled(self, grains):
  1452. """
  1453. Test with git_pillar_includes enabled. The top_only branch references
  1454. an SLS file from the master branch, but since includes are disabled it
  1455. will not find the SLS file and the "included_pillar" key should not be
  1456. present in the compiled pillar data. We should instead see an error
  1457. message in the compiled data.
  1458. """
  1459. expected = {
  1460. "branch": "master",
  1461. "mylist": ["master"],
  1462. "mydict": {
  1463. "master": True,
  1464. "nested_list": ["master"],
  1465. "nested_dict": {"master": True},
  1466. },
  1467. "_errors": [
  1468. "Specified SLS 'bar' in environment 'base' is not "
  1469. "available on the salt master"
  1470. ],
  1471. }
  1472. # Test with passphraseless key and global credential options
  1473. ret = self.get_pillar(
  1474. """\
  1475. file_ignore_regex: []
  1476. file_ignore_glob: []
  1477. git_pillar_provider: pygit2
  1478. git_pillar_includes: False
  1479. git_pillar_pubkey: {pubkey_nopass}
  1480. git_pillar_privkey: {privkey_nopass}
  1481. cachedir: {cachedir}
  1482. extension_modules: {extmods}
  1483. ext_pillar:
  1484. - git:
  1485. - master {url}
  1486. - top_only {url}:
  1487. - env: base
  1488. """
  1489. )
  1490. self.assertEqual(ret, expected)
  1491. # Test with passphraseless key and per-repo credential options
  1492. ret = self.get_pillar(
  1493. """\
  1494. file_ignore_regex: []
  1495. file_ignore_glob: []
  1496. git_pillar_provider: pygit2
  1497. git_pillar_includes: False
  1498. cachedir: {cachedir}
  1499. extension_modules: {extmods}
  1500. ext_pillar:
  1501. - git:
  1502. - master {url}:
  1503. - pubkey: {pubkey_nopass}
  1504. - privkey: {privkey_nopass}
  1505. - top_only {url}:
  1506. - pubkey: {pubkey_nopass}
  1507. - privkey: {privkey_nopass}
  1508. - env: base
  1509. """
  1510. )
  1511. self.assertEqual(ret, expected)
  1512. if grains["os_family"] == "Debian":
  1513. # passphrase-protected currently does not work here
  1514. return
  1515. # Test with passphrase-protected key and global credential options
  1516. ret = self.get_pillar(
  1517. """\
  1518. file_ignore_regex: []
  1519. file_ignore_glob: []
  1520. git_pillar_provider: pygit2
  1521. git_pillar_includes: False
  1522. git_pillar_pubkey: {pubkey_withpass}
  1523. git_pillar_privkey: {privkey_withpass}
  1524. git_pillar_passphrase: {passphrase}
  1525. cachedir: {cachedir}
  1526. extension_modules: {extmods}
  1527. ext_pillar:
  1528. - git:
  1529. - master {url}
  1530. - top_only {url}:
  1531. - env: base
  1532. """
  1533. )
  1534. self.assertEqual(ret, expected)
  1535. # Test with passphrase-protected key and per-repo credential options
  1536. ret = self.get_pillar(
  1537. """\
  1538. file_ignore_regex: []
  1539. file_ignore_glob: []
  1540. git_pillar_provider: pygit2
  1541. git_pillar_includes: False
  1542. cachedir: {cachedir}
  1543. extension_modules: {extmods}
  1544. ext_pillar:
  1545. - git:
  1546. - master {url}:
  1547. - pubkey: {pubkey_withpass}
  1548. - privkey: {privkey_withpass}
  1549. - passphrase: {passphrase}
  1550. - top_only {url}:
  1551. - pubkey: {pubkey_withpass}
  1552. - privkey: {privkey_withpass}
  1553. - passphrase: {passphrase}
  1554. - env: base
  1555. """
  1556. )
  1557. self.assertEqual(ret, expected)
  1558. @skipIf(True, "SLOWTEST skip")
  1559. @skipIf(True, "SLOWTEST skip")
  1560. @skipIf(True, "SLOWTEST skip")
  1561. @skipIf(True, "SLOWTEST skip")
  1562. @skipIf(True, "SLOWTEST skip")
  1563. @skipIf(True, "SLOWTEST skip")
  1564. def test_includes_enabled_solves___env___with_mountpoint(self):
  1565. """
  1566. Test with git_pillar_includes enabled and using "__env__" as the branch
  1567. name for the configured repositories.
  1568. The "gitinfo" repository contains top.sls file with a local reference
  1569. and also referencing external "nowhere.foo" which is provided by "webinfo"
  1570. repository mounted as "nowhere".
  1571. """
  1572. ret = self.get_pillar(
  1573. """\
  1574. file_ignore_regex: []
  1575. file_ignore_glob: []
  1576. git_pillar_provider: pygit2
  1577. git_pillar_pubkey: {pubkey_nopass}
  1578. git_pillar_privkey: {privkey_nopass}
  1579. cachedir: {cachedir}
  1580. extension_modules: {extmods}
  1581. ext_pillar:
  1582. - git:
  1583. - __env__ {url_extra_repo}:
  1584. - name: gitinfo
  1585. - __env__ {url}:
  1586. - name: webinfo
  1587. - mountpoint: nowhere
  1588. """
  1589. )
  1590. self.assertEqual(
  1591. ret,
  1592. {
  1593. "branch": "master",
  1594. "motd": "The force will be with you. Always.",
  1595. "mylist": ["master"],
  1596. "mydict": {
  1597. "master": True,
  1598. "nested_list": ["master"],
  1599. "nested_dict": {"master": True},
  1600. },
  1601. },
  1602. )
  1603. @requires_system_grains
  1604. @skipIf(True, "SLOWTEST skip")
  1605. @skipIf(True, "SLOWTEST skip")
  1606. @skipIf(True, "SLOWTEST skip")
  1607. @skipIf(True, "SLOWTEST skip")
  1608. @skipIf(True, "SLOWTEST skip")
  1609. @skipIf(True, "SLOWTEST skip")
  1610. def test_root_parameter(self, grains):
  1611. """
  1612. Test root parameter
  1613. """
  1614. expected = {"from_subdir": True}
  1615. # Test with passphraseless key and global credential options
  1616. ret = self.get_pillar(
  1617. """\
  1618. file_ignore_regex: []
  1619. file_ignore_glob: []
  1620. git_pillar_provider: pygit2
  1621. git_pillar_pubkey: {pubkey_nopass}
  1622. git_pillar_privkey: {privkey_nopass}
  1623. cachedir: {cachedir}
  1624. extension_modules: {extmods}
  1625. ext_pillar:
  1626. - git:
  1627. - master {url}:
  1628. - root: subdir
  1629. - top_only {url}:
  1630. - env: base
  1631. """
  1632. )
  1633. self.assertEqual(ret, expected)
  1634. # Test with passphraseless key and per-repo credential options
  1635. ret = self.get_pillar(
  1636. """\
  1637. file_ignore_regex: []
  1638. file_ignore_glob: []
  1639. git_pillar_provider: pygit2
  1640. cachedir: {cachedir}
  1641. extension_modules: {extmods}
  1642. ext_pillar:
  1643. - git:
  1644. - master {url}:
  1645. - root: subdir
  1646. - pubkey: {pubkey_nopass}
  1647. - privkey: {privkey_nopass}
  1648. - top_only {url}:
  1649. - pubkey: {pubkey_nopass}
  1650. - privkey: {privkey_nopass}
  1651. - env: base
  1652. """
  1653. )
  1654. self.assertEqual(ret, expected)
  1655. if grains["os_family"] == "Debian":
  1656. # passphrase-protected currently does not work here
  1657. return
  1658. # Test with passphrase-protected key and global credential options
  1659. ret = self.get_pillar(
  1660. """\
  1661. file_ignore_regex: []
  1662. file_ignore_glob: []
  1663. git_pillar_provider: pygit2
  1664. git_pillar_pubkey: {pubkey_withpass}
  1665. git_pillar_privkey: {privkey_withpass}
  1666. git_pillar_passphrase: {passphrase}
  1667. cachedir: {cachedir}
  1668. extension_modules: {extmods}
  1669. ext_pillar:
  1670. - git:
  1671. - master {url}:
  1672. - root: subdir
  1673. - top_only {url}:
  1674. - env: base
  1675. """
  1676. )
  1677. self.assertEqual(ret, expected)
  1678. # Test with passphrase-protected key and per-repo credential options
  1679. ret = self.get_pillar(
  1680. """\
  1681. file_ignore_regex: []
  1682. file_ignore_glob: []
  1683. git_pillar_provider: pygit2
  1684. cachedir: {cachedir}
  1685. extension_modules: {extmods}
  1686. ext_pillar:
  1687. - git:
  1688. - master {url}:
  1689. - root: subdir
  1690. - pubkey: {pubkey_withpass}
  1691. - privkey: {privkey_withpass}
  1692. - passphrase: {passphrase}
  1693. - top_only {url}:
  1694. - pubkey: {pubkey_withpass}
  1695. - privkey: {privkey_withpass}
  1696. - passphrase: {passphrase}
  1697. - env: base
  1698. """
  1699. )
  1700. self.assertEqual(ret, expected)
  1701. @requires_system_grains
  1702. @skipIf(True, "SLOWTEST skip")
  1703. @skipIf(True, "SLOWTEST skip")
  1704. @skipIf(True, "SLOWTEST skip")
  1705. @skipIf(True, "SLOWTEST skip")
  1706. @skipIf(True, "SLOWTEST skip")
  1707. @skipIf(True, "SLOWTEST skip")
  1708. def test_mountpoint_parameter(self, grains):
  1709. """
  1710. Test mountpoint parameter
  1711. """
  1712. expected = {"included_pillar": True}
  1713. # Test with passphraseless key and global credential options
  1714. ret = self.get_pillar(
  1715. """\
  1716. file_ignore_regex: []
  1717. file_ignore_glob: []
  1718. git_pillar_provider: pygit2
  1719. git_pillar_pubkey: {pubkey_nopass}
  1720. git_pillar_privkey: {privkey_nopass}
  1721. cachedir: {cachedir}
  1722. extension_modules: {extmods}
  1723. ext_pillar:
  1724. - git:
  1725. - master {url}:
  1726. - mountpoint: mounted
  1727. - top_mounted {url}:
  1728. - env: base
  1729. """
  1730. )
  1731. self.assertEqual(ret, expected)
  1732. # Test with passphraseless key and per-repo credential options
  1733. ret = self.get_pillar(
  1734. """\
  1735. file_ignore_regex: []
  1736. file_ignore_glob: []
  1737. git_pillar_provider: pygit2
  1738. cachedir: {cachedir}
  1739. extension_modules: {extmods}
  1740. ext_pillar:
  1741. - git:
  1742. - master {url}:
  1743. - mountpoint: mounted
  1744. - pubkey: {pubkey_nopass}
  1745. - privkey: {privkey_nopass}
  1746. - top_mounted {url}:
  1747. - pubkey: {pubkey_nopass}
  1748. - privkey: {privkey_nopass}
  1749. - env: base
  1750. """
  1751. )
  1752. self.assertEqual(ret, expected)
  1753. if grains["os_family"] == "Debian":
  1754. # passphrase-protected currently does not work here
  1755. return
  1756. # Test with passphrase-protected key and global credential options
  1757. ret = self.get_pillar(
  1758. """\
  1759. file_ignore_regex: []
  1760. file_ignore_glob: []
  1761. git_pillar_provider: pygit2
  1762. git_pillar_pubkey: {pubkey_withpass}
  1763. git_pillar_privkey: {privkey_withpass}
  1764. git_pillar_passphrase: {passphrase}
  1765. cachedir: {cachedir}
  1766. extension_modules: {extmods}
  1767. ext_pillar:
  1768. - git:
  1769. - master {url}:
  1770. - mountpoint: mounted
  1771. - top_mounted {url}:
  1772. - env: base
  1773. """
  1774. )
  1775. self.assertEqual(ret, expected)
  1776. # Test with passphrase-protected key and per-repo credential options
  1777. ret = self.get_pillar(
  1778. """\
  1779. file_ignore_regex: []
  1780. file_ignore_glob: []
  1781. git_pillar_provider: pygit2
  1782. cachedir: {cachedir}
  1783. extension_modules: {extmods}
  1784. ext_pillar:
  1785. - git:
  1786. - master {url}:
  1787. - mountpoint: mounted
  1788. - pubkey: {pubkey_withpass}
  1789. - privkey: {privkey_withpass}
  1790. - passphrase: {passphrase}
  1791. - top_mounted {url}:
  1792. - pubkey: {pubkey_withpass}
  1793. - privkey: {privkey_withpass}
  1794. - passphrase: {passphrase}
  1795. - env: base
  1796. """
  1797. )
  1798. self.assertEqual(ret, expected)
  1799. @requires_system_grains
  1800. @skipIf(True, "SLOWTEST skip")
  1801. @skipIf(True, "SLOWTEST skip")
  1802. @skipIf(True, "SLOWTEST skip")
  1803. @skipIf(True, "SLOWTEST skip")
  1804. @skipIf(True, "SLOWTEST skip")
  1805. @skipIf(True, "SLOWTEST skip")
  1806. def test_root_and_mountpoint_parameters(self, grains):
  1807. """
  1808. Test root and mountpoint parameters
  1809. """
  1810. expected = {"from_subdir": True}
  1811. # Test with passphraseless key and global credential options
  1812. ret = self.get_pillar(
  1813. """\
  1814. file_ignore_regex: []
  1815. file_ignore_glob: []
  1816. git_pillar_provider: pygit2
  1817. git_pillar_pubkey: {pubkey_nopass}
  1818. git_pillar_privkey: {privkey_nopass}
  1819. cachedir: {cachedir}
  1820. extension_modules: {extmods}
  1821. ext_pillar:
  1822. - git:
  1823. - master {url}:
  1824. - mountpoint: mounted
  1825. - root: subdir
  1826. - top_mounted {url}:
  1827. - env: base
  1828. """
  1829. )
  1830. self.assertEqual(ret, expected)
  1831. # Test with passphraseless key and per-repo credential options
  1832. ret = self.get_pillar(
  1833. """\
  1834. file_ignore_regex: []
  1835. file_ignore_glob: []
  1836. git_pillar_provider: pygit2
  1837. cachedir: {cachedir}
  1838. extension_modules: {extmods}
  1839. ext_pillar:
  1840. - git:
  1841. - master {url}:
  1842. - mountpoint: mounted
  1843. - root: subdir
  1844. - pubkey: {pubkey_nopass}
  1845. - privkey: {privkey_nopass}
  1846. - top_mounted {url}:
  1847. - pubkey: {pubkey_nopass}
  1848. - privkey: {privkey_nopass}
  1849. - env: base
  1850. """
  1851. )
  1852. self.assertEqual(ret, expected)
  1853. if grains["os_family"] == "Debian":
  1854. # passphrase-protected currently does not work here
  1855. return
  1856. # Test with passphrase-protected key and global credential options
  1857. ret = self.get_pillar(
  1858. """\
  1859. file_ignore_regex: []
  1860. file_ignore_glob: []
  1861. git_pillar_provider: pygit2
  1862. git_pillar_pubkey: {pubkey_withpass}
  1863. git_pillar_privkey: {privkey_withpass}
  1864. git_pillar_passphrase: {passphrase}
  1865. cachedir: {cachedir}
  1866. extension_modules: {extmods}
  1867. ext_pillar:
  1868. - git:
  1869. - master {url}:
  1870. - mountpoint: mounted
  1871. - root: subdir
  1872. - top_mounted {url}:
  1873. - env: base
  1874. """
  1875. )
  1876. self.assertEqual(ret, expected)
  1877. # Test with passphrase-protected key and per-repo credential options
  1878. ret = self.get_pillar(
  1879. """\
  1880. file_ignore_regex: []
  1881. file_ignore_glob: []
  1882. git_pillar_provider: pygit2
  1883. cachedir: {cachedir}
  1884. extension_modules: {extmods}
  1885. ext_pillar:
  1886. - git:
  1887. - master {url}:
  1888. - mountpoint: mounted
  1889. - root: subdir
  1890. - pubkey: {pubkey_withpass}
  1891. - privkey: {privkey_withpass}
  1892. - passphrase: {passphrase}
  1893. - top_mounted {url}:
  1894. - pubkey: {pubkey_withpass}
  1895. - privkey: {privkey_withpass}
  1896. - passphrase: {passphrase}
  1897. - env: base
  1898. """
  1899. )
  1900. self.assertEqual(ret, expected)
  1901. @requires_system_grains
  1902. @skipIf(True, "SLOWTEST skip")
  1903. @skipIf(True, "SLOWTEST skip")
  1904. @skipIf(True, "SLOWTEST skip")
  1905. @skipIf(True, "SLOWTEST skip")
  1906. @skipIf(True, "SLOWTEST skip")
  1907. @skipIf(True, "SLOWTEST skip")
  1908. def test_all_saltenvs(self, grains):
  1909. """
  1910. Test all_saltenvs parameter.
  1911. """
  1912. expected = {
  1913. "branch": "dev",
  1914. "motd": "The force will be with you. Always.",
  1915. "mylist": ["dev"],
  1916. "mydict": {
  1917. "dev": True,
  1918. "nested_list": ["dev"],
  1919. "nested_dict": {"dev": True},
  1920. },
  1921. }
  1922. # Test with passphraseless key and global credential options
  1923. ret = self.get_pillar(
  1924. """\
  1925. file_ignore_regex: []
  1926. file_ignore_glob: []
  1927. git_pillar_provider: pygit2
  1928. git_pillar_pubkey: {pubkey_nopass}
  1929. git_pillar_privkey: {privkey_nopass}
  1930. cachedir: {cachedir}
  1931. extension_modules: {extmods}
  1932. pillarenv: dev
  1933. ext_pillar:
  1934. - git:
  1935. - __env__ {url_extra_repo}:
  1936. - all_saltenvs: master
  1937. - __env__ {url}:
  1938. - mountpoint: nowhere
  1939. """
  1940. )
  1941. self.assertEqual(ret, expected)
  1942. # Test with passphraseless key and per-repo credential options
  1943. ret = self.get_pillar(
  1944. """\
  1945. file_ignore_regex: []
  1946. file_ignore_glob: []
  1947. git_pillar_provider: pygit2
  1948. cachedir: {cachedir}
  1949. extension_modules: {extmods}
  1950. pillarenv: dev
  1951. ext_pillar:
  1952. - git:
  1953. - __env__ {url_extra_repo}:
  1954. - all_saltenvs: master
  1955. - pubkey: {pubkey_nopass}
  1956. - privkey: {privkey_nopass}
  1957. - __env__ {url}:
  1958. - mountpoint: nowhere
  1959. - pubkey: {pubkey_nopass}
  1960. - privkey: {privkey_nopass}
  1961. """
  1962. )
  1963. self.assertEqual(ret, expected)
  1964. if grains["os_family"] == "Debian":
  1965. # passphrase-protected currently does not work here
  1966. return
  1967. # Test with passphrase-protected key and global credential options
  1968. ret = self.get_pillar(
  1969. """\
  1970. file_ignore_regex: []
  1971. file_ignore_glob: []
  1972. git_pillar_provider: pygit2
  1973. git_pillar_pubkey: {pubkey_withpass}
  1974. git_pillar_privkey: {privkey_withpass}
  1975. git_pillar_passphrase: {passphrase}
  1976. cachedir: {cachedir}
  1977. extension_modules: {extmods}
  1978. pillarenv: dev
  1979. ext_pillar:
  1980. - git:
  1981. - __env__ {url_extra_repo}:
  1982. - all_saltenvs: master
  1983. - __env__ {url}:
  1984. - mountpoint: nowhere
  1985. """
  1986. )
  1987. self.assertEqual(ret, expected)
  1988. # Test with passphrase-protected key and per-repo credential options
  1989. ret = self.get_pillar(
  1990. """\
  1991. file_ignore_regex: []
  1992. file_ignore_glob: []
  1993. git_pillar_provider: pygit2
  1994. cachedir: {cachedir}
  1995. extension_modules: {extmods}
  1996. pillarenv: dev
  1997. ext_pillar:
  1998. - git:
  1999. - __env__ {url_extra_repo}:
  2000. - all_saltenvs: master
  2001. - pubkey: {pubkey_nopass}
  2002. - privkey: {privkey_nopass}
  2003. - passphrase: {passphrase}
  2004. - __env__ {url}:
  2005. - mountpoint: nowhere
  2006. - pubkey: {pubkey_nopass}
  2007. - privkey: {privkey_nopass}
  2008. - passphrase: {passphrase}
  2009. """
  2010. )
  2011. self.assertEqual(ret, expected)
  2012. @requires_system_grains
  2013. @skipIf(True, "SLOWTEST skip")
  2014. @skipIf(True, "SLOWTEST skip")
  2015. @skipIf(True, "SLOWTEST skip")
  2016. @skipIf(True, "SLOWTEST skip")
  2017. @skipIf(True, "SLOWTEST skip")
  2018. @skipIf(True, "SLOWTEST skip")
  2019. def test_all_saltenvs_base(self, grains):
  2020. """
  2021. Test all_saltenvs parameter.
  2022. """
  2023. expected = {
  2024. "branch": "master",
  2025. "motd": "The force will be with you. Always.",
  2026. "mylist": ["master"],
  2027. "mydict": {
  2028. "master": True,
  2029. "nested_list": ["master"],
  2030. "nested_dict": {"master": True},
  2031. },
  2032. }
  2033. # Test with passphraseless key and global credential options
  2034. ret = self.get_pillar(
  2035. """\
  2036. file_ignore_regex: []
  2037. file_ignore_glob: []
  2038. git_pillar_provider: pygit2
  2039. git_pillar_pubkey: {pubkey_nopass}
  2040. git_pillar_privkey: {privkey_nopass}
  2041. cachedir: {cachedir}
  2042. extension_modules: {extmods}
  2043. ext_pillar:
  2044. - git:
  2045. - __env__ {url_extra_repo}:
  2046. - all_saltenvs: master
  2047. - __env__ {url}:
  2048. - mountpoint: nowhere
  2049. """
  2050. )
  2051. self.assertEqual(ret, expected)
  2052. # Test with passphraseless key and per-repo credential options
  2053. ret = self.get_pillar(
  2054. """\
  2055. file_ignore_regex: []
  2056. file_ignore_glob: []
  2057. git_pillar_provider: pygit2
  2058. cachedir: {cachedir}
  2059. extension_modules: {extmods}
  2060. ext_pillar:
  2061. - git:
  2062. - __env__ {url_extra_repo}:
  2063. - all_saltenvs: master
  2064. - pubkey: {pubkey_nopass}
  2065. - privkey: {privkey_nopass}
  2066. - __env__ {url}:
  2067. - mountpoint: nowhere
  2068. - pubkey: {pubkey_nopass}
  2069. - privkey: {privkey_nopass}
  2070. """
  2071. )
  2072. self.assertEqual(ret, expected)
  2073. if grains["os_family"] == "Debian":
  2074. # passphrase-protected currently does not work here
  2075. return
  2076. # Test with passphrase-protected key and global credential options
  2077. ret = self.get_pillar(
  2078. """\
  2079. file_ignore_regex: []
  2080. file_ignore_glob: []
  2081. git_pillar_provider: pygit2
  2082. git_pillar_pubkey: {pubkey_withpass}
  2083. git_pillar_privkey: {privkey_withpass}
  2084. git_pillar_passphrase: {passphrase}
  2085. cachedir: {cachedir}
  2086. extension_modules: {extmods}
  2087. ext_pillar:
  2088. - git:
  2089. - __env__ {url_extra_repo}:
  2090. - all_saltenvs: master
  2091. - __env__ {url}:
  2092. - mountpoint: nowhere
  2093. """
  2094. )
  2095. self.assertEqual(ret, expected)
  2096. # Test with passphrase-protected key and per-repo credential options
  2097. ret = self.get_pillar(
  2098. """\
  2099. file_ignore_regex: []
  2100. file_ignore_glob: []
  2101. git_pillar_provider: pygit2
  2102. cachedir: {cachedir}
  2103. extension_modules: {extmods}
  2104. ext_pillar:
  2105. - git:
  2106. - __env__ {url_extra_repo}:
  2107. - all_saltenvs: master
  2108. - pubkey: {pubkey_nopass}
  2109. - privkey: {privkey_nopass}
  2110. - passphrase: {passphrase}
  2111. - __env__ {url}:
  2112. - mountpoint: nowhere
  2113. - pubkey: {pubkey_nopass}
  2114. - privkey: {privkey_nopass}
  2115. - passphrase: {passphrase}
  2116. """
  2117. )
  2118. self.assertEqual(ret, expected)
  2119. @requires_system_grains
  2120. def test_fallback(self, grains):
  2121. """
  2122. Test fallback parameter.
  2123. """
  2124. expected = {
  2125. "branch": "dev",
  2126. "motd": "The force will be with you. Always.",
  2127. "mylist": ["dev"],
  2128. "mydict": {
  2129. "dev": True,
  2130. "nested_list": ["dev"],
  2131. "nested_dict": {"dev": True},
  2132. },
  2133. }
  2134. # Test with passphraseless key and global credential options
  2135. ret = self.get_pillar(
  2136. """\
  2137. file_ignore_regex: []
  2138. file_ignore_glob: []
  2139. git_pillar_provider: pygit2
  2140. git_pillar_pubkey: {pubkey_nopass}
  2141. git_pillar_privkey: {privkey_nopass}
  2142. cachedir: {cachedir}
  2143. extension_modules: {extmods}
  2144. pillarenv: nonexisting
  2145. ext_pillar:
  2146. - git:
  2147. - __env__ {url_extra_repo}:
  2148. - fallback: master
  2149. - __env__ {url}:
  2150. - mountpoint: nowhere
  2151. - fallback: dev
  2152. """
  2153. )
  2154. self.assertEqual(ret, expected)
  2155. # Test with passphraseless key and per-repo credential options
  2156. ret = self.get_pillar(
  2157. """\
  2158. file_ignore_regex: []
  2159. file_ignore_glob: []
  2160. git_pillar_provider: pygit2
  2161. cachedir: {cachedir}
  2162. extension_modules: {extmods}
  2163. pillarenv: nonexisting
  2164. ext_pillar:
  2165. - git:
  2166. - __env__ {url_extra_repo}:
  2167. - fallback: master
  2168. - pubkey: {pubkey_nopass}
  2169. - privkey: {privkey_nopass}
  2170. - __env__ {url}:
  2171. - mountpoint: nowhere
  2172. - fallback: dev
  2173. - pubkey: {pubkey_nopass}
  2174. - privkey: {privkey_nopass}
  2175. """
  2176. )
  2177. self.assertEqual(ret, expected)
  2178. if grains["os_family"] == "Debian":
  2179. # passphrase-protected currently does not work here
  2180. return
  2181. # Test with passphrase-protected key and global credential options
  2182. ret = self.get_pillar(
  2183. """\
  2184. file_ignore_regex: []
  2185. file_ignore_glob: []
  2186. git_pillar_provider: pygit2
  2187. git_pillar_pubkey: {pubkey_withpass}
  2188. git_pillar_privkey: {privkey_withpass}
  2189. git_pillar_passphrase: {passphrase}
  2190. cachedir: {cachedir}
  2191. extension_modules: {extmods}
  2192. pillarenv: nonexisting
  2193. ext_pillar:
  2194. - git:
  2195. - __env__ {url_extra_repo}:
  2196. - fallback: master
  2197. - __env__ {url}:
  2198. - mountpoint: nowhere
  2199. - fallback: dev
  2200. """
  2201. )
  2202. self.assertEqual(ret, expected)
  2203. # Test with passphrase-protected key and per-repo credential options
  2204. ret = self.get_pillar(
  2205. """\
  2206. file_ignore_regex: []
  2207. file_ignore_glob: []
  2208. git_pillar_provider: pygit2
  2209. cachedir: {cachedir}
  2210. extension_modules: {extmods}
  2211. pillarenv: nonexisting
  2212. ext_pillar:
  2213. - git:
  2214. - __env__ {url_extra_repo}:
  2215. - fallback: master
  2216. - pubkey: {pubkey_nopass}
  2217. - privkey: {privkey_nopass}
  2218. - passphrase: {passphrase}
  2219. - __env__ {url}:
  2220. - mountpoint: nowhere
  2221. - fallback: dev
  2222. - pubkey: {pubkey_nopass}
  2223. - privkey: {privkey_nopass}
  2224. - passphrase: {passphrase}
  2225. """
  2226. )
  2227. self.assertEqual(ret, expected)
  2228. @skipIf(_windows_or_mac(), "minion is windows or mac")
  2229. @skip_if_not_root
  2230. @skipIf(
  2231. not HAS_PYGIT2,
  2232. "pygit2 >= {0} and libgit2 >= {1} required".format(PYGIT2_MINVER, LIBGIT2_MINVER),
  2233. )
  2234. @skipIf(not HAS_NGINX, "nginx not present")
  2235. @skipIf(not HAS_VIRTUALENV, "virtualenv not present")
  2236. class TestPygit2HTTP(GitPillarHTTPTestBase):
  2237. """
  2238. Test git_pillar with pygit2 using SSH authentication
  2239. """
  2240. @skipIf(True, "SLOWTEST skip")
  2241. @skipIf(True, "SLOWTEST skip")
  2242. @skipIf(True, "SLOWTEST skip")
  2243. @skipIf(True, "SLOWTEST skip")
  2244. @skipIf(True, "SLOWTEST skip")
  2245. @skipIf(True, "SLOWTEST skip")
  2246. def test_single_source(self):
  2247. """
  2248. Test using a single ext_pillar repo
  2249. """
  2250. expected = {
  2251. "branch": "master",
  2252. "mylist": ["master"],
  2253. "mydict": {
  2254. "master": True,
  2255. "nested_list": ["master"],
  2256. "nested_dict": {"master": True},
  2257. },
  2258. }
  2259. ret = self.get_pillar(
  2260. """\
  2261. file_ignore_regex: []
  2262. file_ignore_glob: []
  2263. git_pillar_provider: pygit2
  2264. cachedir: {cachedir}
  2265. extension_modules: {extmods}
  2266. ext_pillar:
  2267. - git:
  2268. - master {url}
  2269. """
  2270. )
  2271. self.assertEqual(ret, expected)
  2272. @skipIf(True, "SLOWTEST skip")
  2273. @skipIf(True, "SLOWTEST skip")
  2274. @skipIf(True, "SLOWTEST skip")
  2275. @skipIf(True, "SLOWTEST skip")
  2276. @skipIf(True, "SLOWTEST skip")
  2277. @skipIf(True, "SLOWTEST skip")
  2278. def test_multiple_sources_master_dev_no_merge_lists(self):
  2279. """
  2280. Test using two ext_pillar dirs. Since all git_pillar repos are merged
  2281. into a single dictionary, ordering matters.
  2282. This tests with the master branch followed by dev, and with
  2283. pillar_merge_lists disabled.
  2284. """
  2285. expected = {
  2286. "branch": "dev",
  2287. "mylist": ["dev"],
  2288. "mydict": {
  2289. "master": True,
  2290. "dev": True,
  2291. "nested_list": ["dev"],
  2292. "nested_dict": {"master": True, "dev": True},
  2293. },
  2294. }
  2295. ret = self.get_pillar(
  2296. """\
  2297. file_ignore_regex: []
  2298. file_ignore_glob: []
  2299. git_pillar_provider: pygit2
  2300. cachedir: {cachedir}
  2301. extension_modules: {extmods}
  2302. pillar_merge_lists: False
  2303. ext_pillar:
  2304. - git:
  2305. - master {url}
  2306. - dev {url}
  2307. """
  2308. )
  2309. self.assertEqual(ret, expected)
  2310. @skipIf(True, "SLOWTEST skip")
  2311. @skipIf(True, "SLOWTEST skip")
  2312. @skipIf(True, "SLOWTEST skip")
  2313. @skipIf(True, "SLOWTEST skip")
  2314. @skipIf(True, "SLOWTEST skip")
  2315. @skipIf(True, "SLOWTEST skip")
  2316. def test_multiple_sources_dev_master_no_merge_lists(self):
  2317. """
  2318. Test using two ext_pillar dirs. Since all git_pillar repos are merged
  2319. into a single dictionary, ordering matters.
  2320. This tests with the dev branch followed by master, and with
  2321. pillar_merge_lists disabled.
  2322. """
  2323. expected = {
  2324. "branch": "master",
  2325. "mylist": ["master"],
  2326. "mydict": {
  2327. "master": True,
  2328. "dev": True,
  2329. "nested_list": ["master"],
  2330. "nested_dict": {"master": True, "dev": True},
  2331. },
  2332. }
  2333. ret = self.get_pillar(
  2334. """\
  2335. file_ignore_regex: []
  2336. file_ignore_glob: []
  2337. git_pillar_provider: pygit2
  2338. cachedir: {cachedir}
  2339. extension_modules: {extmods}
  2340. pillar_merge_lists: False
  2341. ext_pillar:
  2342. - git:
  2343. - dev {url}
  2344. - master {url}
  2345. """
  2346. )
  2347. self.assertEqual(ret, expected)
  2348. @skipIf(True, "SLOWTEST skip")
  2349. @skipIf(True, "SLOWTEST skip")
  2350. @skipIf(True, "SLOWTEST skip")
  2351. @skipIf(True, "SLOWTEST skip")
  2352. @skipIf(True, "SLOWTEST skip")
  2353. @skipIf(True, "SLOWTEST skip")
  2354. def test_multiple_sources_master_dev_merge_lists(self):
  2355. """
  2356. Test using two ext_pillar dirs. Since all git_pillar repos are merged
  2357. into a single dictionary, ordering matters.
  2358. This tests with the master branch followed by dev, and with
  2359. pillar_merge_lists enabled.
  2360. """
  2361. expected = {
  2362. "branch": "dev",
  2363. "mylist": ["master", "dev"],
  2364. "mydict": {
  2365. "master": True,
  2366. "dev": True,
  2367. "nested_list": ["master", "dev"],
  2368. "nested_dict": {"master": True, "dev": True},
  2369. },
  2370. }
  2371. ret = self.get_pillar(
  2372. """\
  2373. file_ignore_regex: []
  2374. file_ignore_glob: []
  2375. git_pillar_provider: pygit2
  2376. cachedir: {cachedir}
  2377. extension_modules: {extmods}
  2378. pillar_merge_lists: True
  2379. ext_pillar:
  2380. - git:
  2381. - master {url}
  2382. - dev {url}
  2383. """
  2384. )
  2385. self.assertEqual(ret, expected)
  2386. @skipIf(True, "SLOWTEST skip")
  2387. @skipIf(True, "SLOWTEST skip")
  2388. @skipIf(True, "SLOWTEST skip")
  2389. @skipIf(True, "SLOWTEST skip")
  2390. @skipIf(True, "SLOWTEST skip")
  2391. @skipIf(True, "SLOWTEST skip")
  2392. def test_multiple_sources_dev_master_merge_lists(self):
  2393. """
  2394. Test using two ext_pillar dirs. Since all git_pillar repos are merged
  2395. into a single dictionary, ordering matters.
  2396. This tests with the dev branch followed by master, and with
  2397. pillar_merge_lists enabled.
  2398. """
  2399. expected = {
  2400. "branch": "master",
  2401. "mylist": ["dev", "master"],
  2402. "mydict": {
  2403. "master": True,
  2404. "dev": True,
  2405. "nested_list": ["dev", "master"],
  2406. "nested_dict": {"master": True, "dev": True},
  2407. },
  2408. }
  2409. ret = self.get_pillar(
  2410. """\
  2411. file_ignore_regex: []
  2412. file_ignore_glob: []
  2413. git_pillar_provider: pygit2
  2414. cachedir: {cachedir}
  2415. extension_modules: {extmods}
  2416. pillar_merge_lists: True
  2417. ext_pillar:
  2418. - git:
  2419. - dev {url}
  2420. - master {url}
  2421. """
  2422. )
  2423. self.assertEqual(ret, expected)
  2424. @skipIf(True, "SLOWTEST skip")
  2425. @skipIf(True, "SLOWTEST skip")
  2426. @skipIf(True, "SLOWTEST skip")
  2427. @skipIf(True, "SLOWTEST skip")
  2428. @skipIf(True, "SLOWTEST skip")
  2429. @skipIf(True, "SLOWTEST skip")
  2430. def test_multiple_sources_with_pillarenv(self):
  2431. """
  2432. Test using pillarenv to restrict results to those from a single branch
  2433. """
  2434. expected = {
  2435. "branch": "master",
  2436. "mylist": ["master"],
  2437. "mydict": {
  2438. "master": True,
  2439. "nested_list": ["master"],
  2440. "nested_dict": {"master": True},
  2441. },
  2442. }
  2443. ret = self.get_pillar(
  2444. """\
  2445. file_ignore_regex: []
  2446. file_ignore_glob: []
  2447. git_pillar_provider: pygit2
  2448. cachedir: {cachedir}
  2449. extension_modules: {extmods}
  2450. pillarenv: base
  2451. ext_pillar:
  2452. - git:
  2453. - master {url}
  2454. - dev {url}
  2455. """
  2456. )
  2457. self.assertEqual(ret, expected)
  2458. @skipIf(True, "SLOWTEST skip")
  2459. @skipIf(True, "SLOWTEST skip")
  2460. @skipIf(True, "SLOWTEST skip")
  2461. @skipIf(True, "SLOWTEST skip")
  2462. @skipIf(True, "SLOWTEST skip")
  2463. @skipIf(True, "SLOWTEST skip")
  2464. def test_includes_enabled(self):
  2465. """
  2466. Test with git_pillar_includes enabled. The top_only branch references
  2467. an SLS file from the master branch, so we should see the
  2468. "included_pillar" key from that SLS file in the compiled pillar data.
  2469. """
  2470. expected = {
  2471. "branch": "master",
  2472. "mylist": ["master"],
  2473. "mydict": {
  2474. "master": True,
  2475. "nested_list": ["master"],
  2476. "nested_dict": {"master": True},
  2477. },
  2478. "included_pillar": True,
  2479. }
  2480. ret = self.get_pillar(
  2481. """\
  2482. file_ignore_regex: []
  2483. file_ignore_glob: []
  2484. git_pillar_provider: pygit2
  2485. cachedir: {cachedir}
  2486. extension_modules: {extmods}
  2487. ext_pillar:
  2488. - git:
  2489. - master {url}
  2490. - top_only {url}:
  2491. - env: base
  2492. """
  2493. )
  2494. self.assertEqual(ret, expected)
  2495. @skipIf(True, "SLOWTEST skip")
  2496. @skipIf(True, "SLOWTEST skip")
  2497. @skipIf(True, "SLOWTEST skip")
  2498. @skipIf(True, "SLOWTEST skip")
  2499. @skipIf(True, "SLOWTEST skip")
  2500. @skipIf(True, "SLOWTEST skip")
  2501. def test_includes_disabled(self):
  2502. """
  2503. Test with git_pillar_includes enabled. The top_only branch references
  2504. an SLS file from the master branch, but since includes are disabled it
  2505. will not find the SLS file and the "included_pillar" key should not be
  2506. present in the compiled pillar data. We should instead see an error
  2507. message in the compiled data.
  2508. """
  2509. expected = {
  2510. "branch": "master",
  2511. "mylist": ["master"],
  2512. "mydict": {
  2513. "master": True,
  2514. "nested_list": ["master"],
  2515. "nested_dict": {"master": True},
  2516. },
  2517. "_errors": [
  2518. "Specified SLS 'bar' in environment 'base' is not "
  2519. "available on the salt master"
  2520. ],
  2521. }
  2522. ret = self.get_pillar(
  2523. """\
  2524. file_ignore_regex: []
  2525. file_ignore_glob: []
  2526. git_pillar_provider: pygit2
  2527. git_pillar_includes: False
  2528. cachedir: {cachedir}
  2529. extension_modules: {extmods}
  2530. ext_pillar:
  2531. - git:
  2532. - master {url}
  2533. - top_only {url}:
  2534. - env: base
  2535. """
  2536. )
  2537. self.assertEqual(ret, expected)
  2538. @skipIf(True, "SLOWTEST skip")
  2539. @skipIf(True, "SLOWTEST skip")
  2540. @skipIf(True, "SLOWTEST skip")
  2541. @skipIf(True, "SLOWTEST skip")
  2542. @skipIf(True, "SLOWTEST skip")
  2543. @skipIf(True, "SLOWTEST skip")
  2544. def test_includes_enabled_solves___env___with_mountpoint(self):
  2545. """
  2546. Test with git_pillar_includes enabled and using "__env__" as the branch
  2547. name for the configured repositories.
  2548. The "gitinfo" repository contains top.sls file with a local reference
  2549. and also referencing external "nowhere.foo" which is provided by "webinfo"
  2550. repository mounted as "nowhere".
  2551. """
  2552. ret = self.get_pillar(
  2553. """\
  2554. file_ignore_regex: []
  2555. file_ignore_glob: []
  2556. git_pillar_provider: pygit2
  2557. cachedir: {cachedir}
  2558. extension_modules: {extmods}
  2559. ext_pillar:
  2560. - git:
  2561. - __env__ {url_extra_repo}:
  2562. - name: gitinfo
  2563. - __env__ {url}:
  2564. - name: webinfo
  2565. - mountpoint: nowhere
  2566. """
  2567. )
  2568. self.assertEqual(
  2569. ret,
  2570. {
  2571. "branch": "master",
  2572. "motd": "The force will be with you. Always.",
  2573. "mylist": ["master"],
  2574. "mydict": {
  2575. "master": True,
  2576. "nested_list": ["master"],
  2577. "nested_dict": {"master": True},
  2578. },
  2579. },
  2580. )
  2581. @skipIf(True, "SLOWTEST skip")
  2582. @skipIf(True, "SLOWTEST skip")
  2583. @skipIf(True, "SLOWTEST skip")
  2584. @skipIf(True, "SLOWTEST skip")
  2585. @skipIf(True, "SLOWTEST skip")
  2586. @skipIf(True, "SLOWTEST skip")
  2587. def test_root_parameter(self):
  2588. """
  2589. Test root parameter
  2590. """
  2591. expected = {"from_subdir": True}
  2592. ret = self.get_pillar(
  2593. """\
  2594. file_ignore_regex: []
  2595. file_ignore_glob: []
  2596. git_pillar_provider: pygit2
  2597. cachedir: {cachedir}
  2598. extension_modules: {extmods}
  2599. ext_pillar:
  2600. - git:
  2601. - master {url}:
  2602. - root: subdir
  2603. - top_only {url}:
  2604. - env: base
  2605. """
  2606. )
  2607. self.assertEqual(ret, expected)
  2608. @skipIf(True, "SLOWTEST skip")
  2609. @skipIf(True, "SLOWTEST skip")
  2610. @skipIf(True, "SLOWTEST skip")
  2611. @skipIf(True, "SLOWTEST skip")
  2612. @skipIf(True, "SLOWTEST skip")
  2613. @skipIf(True, "SLOWTEST skip")
  2614. def test_mountpoint_parameter(self):
  2615. """
  2616. Test mountpoint parameter
  2617. """
  2618. expected = {"included_pillar": True}
  2619. ret = self.get_pillar(
  2620. """\
  2621. file_ignore_regex: []
  2622. file_ignore_glob: []
  2623. git_pillar_provider: pygit2
  2624. cachedir: {cachedir}
  2625. extension_modules: {extmods}
  2626. ext_pillar:
  2627. - git:
  2628. - master {url}:
  2629. - mountpoint: mounted
  2630. - top_mounted {url}:
  2631. - env: base
  2632. """
  2633. )
  2634. self.assertEqual(ret, expected)
  2635. @skipIf(True, "SLOWTEST skip")
  2636. @skipIf(True, "SLOWTEST skip")
  2637. @skipIf(True, "SLOWTEST skip")
  2638. @skipIf(True, "SLOWTEST skip")
  2639. @skipIf(True, "SLOWTEST skip")
  2640. @skipIf(True, "SLOWTEST skip")
  2641. def test_root_and_mountpoint_parameters(self):
  2642. """
  2643. Test root and mountpoint parameters
  2644. """
  2645. expected = {"from_subdir": True}
  2646. ret = self.get_pillar(
  2647. """\
  2648. file_ignore_regex: []
  2649. file_ignore_glob: []
  2650. git_pillar_provider: pygit2
  2651. cachedir: {cachedir}
  2652. extension_modules: {extmods}
  2653. ext_pillar:
  2654. - git:
  2655. - master {url}:
  2656. - mountpoint: mounted
  2657. - root: subdir
  2658. - top_mounted {url}:
  2659. - env: base
  2660. """
  2661. )
  2662. self.assertEqual(ret, expected)
  2663. @skipIf(True, "SLOWTEST skip")
  2664. @skipIf(True, "SLOWTEST skip")
  2665. @skipIf(True, "SLOWTEST skip")
  2666. @skipIf(True, "SLOWTEST skip")
  2667. @skipIf(True, "SLOWTEST skip")
  2668. @skipIf(True, "SLOWTEST skip")
  2669. def test_all_saltenvs(self):
  2670. """
  2671. Test all_saltenvs parameter.
  2672. """
  2673. ret = self.get_pillar(
  2674. """\
  2675. file_ignore_regex: []
  2676. file_ignore_glob: []
  2677. git_pillar_provider: pygit2
  2678. cachedir: {cachedir}
  2679. extension_modules: {extmods}
  2680. pillarenv: dev
  2681. ext_pillar:
  2682. - git:
  2683. - __env__ {url_extra_repo}:
  2684. - all_saltenvs: master
  2685. - __env__ {url}:
  2686. - mountpoint: nowhere
  2687. """
  2688. )
  2689. self.assertEqual(
  2690. ret,
  2691. {
  2692. "branch": "dev",
  2693. "motd": "The force will be with you. Always.",
  2694. "mylist": ["dev"],
  2695. "mydict": {
  2696. "dev": True,
  2697. "nested_list": ["dev"],
  2698. "nested_dict": {"dev": True},
  2699. },
  2700. },
  2701. )
  2702. @skipIf(True, "SLOWTEST skip")
  2703. @skipIf(True, "SLOWTEST skip")
  2704. @skipIf(True, "SLOWTEST skip")
  2705. @skipIf(True, "SLOWTEST skip")
  2706. @skipIf(True, "SLOWTEST skip")
  2707. @skipIf(True, "SLOWTEST skip")
  2708. def test_all_saltenvs_base(self):
  2709. """
  2710. Test all_saltenvs parameter with base pillarenv.
  2711. """
  2712. ret = self.get_pillar(
  2713. """\
  2714. file_ignore_regex: []
  2715. file_ignore_glob: []
  2716. git_pillar_provider: pygit2
  2717. cachedir: {cachedir}
  2718. extension_modules: {extmods}
  2719. ext_pillar:
  2720. - git:
  2721. - __env__ {url_extra_repo}:
  2722. - all_saltenvs: master
  2723. - __env__ {url}:
  2724. - mountpoint: nowhere
  2725. """
  2726. )
  2727. self.assertEqual(
  2728. ret,
  2729. {
  2730. "branch": "master",
  2731. "motd": "The force will be with you. Always.",
  2732. "mylist": ["master"],
  2733. "mydict": {
  2734. "master": True,
  2735. "nested_list": ["master"],
  2736. "nested_dict": {"master": True},
  2737. },
  2738. },
  2739. )
  2740. def test_fallback(self):
  2741. """
  2742. Test fallback parameter.
  2743. """
  2744. ret = self.get_pillar(
  2745. """\
  2746. file_ignore_regex: []
  2747. file_ignore_glob: []
  2748. git_pillar_provider: pygit2
  2749. cachedir: {cachedir}
  2750. extension_modules: {extmods}
  2751. pillarenv: nonexisting
  2752. ext_pillar:
  2753. - git:
  2754. - __env__ {url_extra_repo}:
  2755. - fallback: master
  2756. - __env__ {url}:
  2757. - mountpoint: nowhere
  2758. - fallback: dev
  2759. """
  2760. )
  2761. self.assertEqual(
  2762. ret,
  2763. {
  2764. "branch": "dev",
  2765. "motd": "The force will be with you. Always.",
  2766. "mylist": ["dev"],
  2767. "mydict": {
  2768. "dev": True,
  2769. "nested_list": ["dev"],
  2770. "nested_dict": {"dev": True},
  2771. },
  2772. },
  2773. )
  2774. @skipIf(_windows_or_mac(), "minion is windows or mac")
  2775. @skip_if_not_root
  2776. @skipIf(
  2777. not HAS_PYGIT2,
  2778. "pygit2 >= {0} and libgit2 >= {1} required".format(PYGIT2_MINVER, LIBGIT2_MINVER),
  2779. )
  2780. @skipIf(not HAS_NGINX, "nginx not present")
  2781. @skipIf(not HAS_VIRTUALENV, "virtualenv not present")
  2782. class TestPygit2AuthenticatedHTTP(GitPillarHTTPTestBase):
  2783. """
  2784. Test git_pillar with pygit2 using SSH authentication
  2785. NOTE: Any tests added to this test class should have equivalent tests (if
  2786. possible) in the TestGitPythonSSH class.
  2787. """
  2788. user = USERNAME
  2789. password = PASSWORD
  2790. @skipIf(True, "SLOWTEST skip")
  2791. @skipIf(True, "SLOWTEST skip")
  2792. @skipIf(True, "SLOWTEST skip")
  2793. @skipIf(True, "SLOWTEST skip")
  2794. @skipIf(True, "SLOWTEST skip")
  2795. @skipIf(True, "SLOWTEST skip")
  2796. def test_single_source(self):
  2797. """
  2798. Test using a single ext_pillar repo
  2799. """
  2800. expected = {
  2801. "branch": "master",
  2802. "mylist": ["master"],
  2803. "mydict": {
  2804. "master": True,
  2805. "nested_list": ["master"],
  2806. "nested_dict": {"master": True},
  2807. },
  2808. }
  2809. # Test with global credential options
  2810. ret = self.get_pillar(
  2811. """\
  2812. file_ignore_regex: []
  2813. file_ignore_glob: []
  2814. git_pillar_provider: pygit2
  2815. git_pillar_user: {user}
  2816. git_pillar_password: {password}
  2817. git_pillar_insecure_auth: True
  2818. cachedir: {cachedir}
  2819. extension_modules: {extmods}
  2820. ext_pillar:
  2821. - git:
  2822. - master {url}
  2823. """
  2824. )
  2825. self.assertEqual(ret, expected)
  2826. # Test with per-repo credential options
  2827. ret = self.get_pillar(
  2828. """\
  2829. file_ignore_regex: []
  2830. file_ignore_glob: []
  2831. git_pillar_provider: pygit2
  2832. cachedir: {cachedir}
  2833. extension_modules: {extmods}
  2834. ext_pillar:
  2835. - git:
  2836. - master {url}:
  2837. - user: {user}
  2838. - password: {password}
  2839. - insecure_auth: True
  2840. """
  2841. )
  2842. self.assertEqual(ret, expected)
  2843. @skipIf(True, "SLOWTEST skip")
  2844. @skipIf(True, "SLOWTEST skip")
  2845. @skipIf(True, "SLOWTEST skip")
  2846. @skipIf(True, "SLOWTEST skip")
  2847. @skipIf(True, "SLOWTEST skip")
  2848. @skipIf(True, "SLOWTEST skip")
  2849. def test_multiple_sources_master_dev_no_merge_lists(self):
  2850. """
  2851. Test using two ext_pillar dirs. Since all git_pillar repos are merged
  2852. into a single dictionary, ordering matters.
  2853. This tests with the master branch followed by dev, and with
  2854. pillar_merge_lists disabled.
  2855. """
  2856. expected = {
  2857. "branch": "dev",
  2858. "mylist": ["dev"],
  2859. "mydict": {
  2860. "master": True,
  2861. "dev": True,
  2862. "nested_list": ["dev"],
  2863. "nested_dict": {"master": True, "dev": True},
  2864. },
  2865. }
  2866. # Test with global credential options
  2867. ret = self.get_pillar(
  2868. """\
  2869. file_ignore_regex: []
  2870. file_ignore_glob: []
  2871. git_pillar_provider: pygit2
  2872. git_pillar_user: {user}
  2873. git_pillar_password: {password}
  2874. git_pillar_insecure_auth: True
  2875. cachedir: {cachedir}
  2876. extension_modules: {extmods}
  2877. pillar_merge_lists: False
  2878. ext_pillar:
  2879. - git:
  2880. - master {url}
  2881. - dev {url}
  2882. """
  2883. )
  2884. self.assertEqual(ret, expected)
  2885. # Test with per-repo credential options
  2886. ret = self.get_pillar(
  2887. """\
  2888. file_ignore_regex: []
  2889. file_ignore_glob: []
  2890. git_pillar_provider: pygit2
  2891. cachedir: {cachedir}
  2892. extension_modules: {extmods}
  2893. pillar_merge_lists: False
  2894. ext_pillar:
  2895. - git:
  2896. - master {url}:
  2897. - user: {user}
  2898. - password: {password}
  2899. - insecure_auth: True
  2900. - dev {url}:
  2901. - user: {user}
  2902. - password: {password}
  2903. - insecure_auth: True
  2904. """
  2905. )
  2906. self.assertEqual(ret, expected)
  2907. @skipIf(True, "SLOWTEST skip")
  2908. @skipIf(True, "SLOWTEST skip")
  2909. @skipIf(True, "SLOWTEST skip")
  2910. @skipIf(True, "SLOWTEST skip")
  2911. @skipIf(True, "SLOWTEST skip")
  2912. @skipIf(True, "SLOWTEST skip")
  2913. def test_multiple_sources_dev_master_no_merge_lists(self):
  2914. """
  2915. Test using two ext_pillar dirs. Since all git_pillar repos are merged
  2916. into a single dictionary, ordering matters.
  2917. This tests with the dev branch followed by master, and with
  2918. pillar_merge_lists disabled.
  2919. """
  2920. expected = {
  2921. "branch": "master",
  2922. "mylist": ["master"],
  2923. "mydict": {
  2924. "master": True,
  2925. "dev": True,
  2926. "nested_list": ["master"],
  2927. "nested_dict": {"master": True, "dev": True},
  2928. },
  2929. }
  2930. # Test with global credential options
  2931. ret = self.get_pillar(
  2932. """\
  2933. file_ignore_regex: []
  2934. file_ignore_glob: []
  2935. git_pillar_provider: pygit2
  2936. git_pillar_user: {user}
  2937. git_pillar_password: {password}
  2938. git_pillar_insecure_auth: True
  2939. cachedir: {cachedir}
  2940. extension_modules: {extmods}
  2941. pillar_merge_lists: False
  2942. ext_pillar:
  2943. - git:
  2944. - dev {url}
  2945. - master {url}
  2946. """
  2947. )
  2948. self.assertEqual(ret, expected)
  2949. # Test with per-repo credential options
  2950. ret = self.get_pillar(
  2951. """\
  2952. file_ignore_regex: []
  2953. file_ignore_glob: []
  2954. git_pillar_provider: pygit2
  2955. cachedir: {cachedir}
  2956. extension_modules: {extmods}
  2957. pillar_merge_lists: False
  2958. ext_pillar:
  2959. - git:
  2960. - dev {url}:
  2961. - user: {user}
  2962. - password: {password}
  2963. - insecure_auth: True
  2964. - master {url}:
  2965. - user: {user}
  2966. - password: {password}
  2967. - insecure_auth: True
  2968. """
  2969. )
  2970. self.assertEqual(ret, expected)
  2971. @skipIf(True, "SLOWTEST skip")
  2972. @skipIf(True, "SLOWTEST skip")
  2973. @skipIf(True, "SLOWTEST skip")
  2974. @skipIf(True, "SLOWTEST skip")
  2975. @skipIf(True, "SLOWTEST skip")
  2976. @skipIf(True, "SLOWTEST skip")
  2977. def test_multiple_sources_master_dev_merge_lists(self):
  2978. """
  2979. Test using two ext_pillar dirs. Since all git_pillar repos are merged
  2980. into a single dictionary, ordering matters.
  2981. This tests with the master branch followed by dev, and with
  2982. pillar_merge_lists enabled.
  2983. """
  2984. expected = {
  2985. "branch": "dev",
  2986. "mylist": ["master", "dev"],
  2987. "mydict": {
  2988. "master": True,
  2989. "dev": True,
  2990. "nested_list": ["master", "dev"],
  2991. "nested_dict": {"master": True, "dev": True},
  2992. },
  2993. }
  2994. # Test with global credential options
  2995. ret = self.get_pillar(
  2996. """\
  2997. file_ignore_regex: []
  2998. file_ignore_glob: []
  2999. git_pillar_provider: pygit2
  3000. git_pillar_user: {user}
  3001. git_pillar_password: {password}
  3002. git_pillar_insecure_auth: True
  3003. cachedir: {cachedir}
  3004. extension_modules: {extmods}
  3005. pillar_merge_lists: True
  3006. ext_pillar:
  3007. - git:
  3008. - master {url}
  3009. - dev {url}
  3010. """
  3011. )
  3012. self.assertEqual(ret, expected)
  3013. # Test with per-repo credential options
  3014. ret = self.get_pillar(
  3015. """\
  3016. file_ignore_regex: []
  3017. file_ignore_glob: []
  3018. git_pillar_provider: pygit2
  3019. cachedir: {cachedir}
  3020. extension_modules: {extmods}
  3021. pillar_merge_lists: True
  3022. ext_pillar:
  3023. - git:
  3024. - master {url}:
  3025. - user: {user}
  3026. - password: {password}
  3027. - insecure_auth: True
  3028. - dev {url}:
  3029. - user: {user}
  3030. - password: {password}
  3031. - insecure_auth: True
  3032. """
  3033. )
  3034. self.assertEqual(ret, expected)
  3035. @skipIf(True, "SLOWTEST skip")
  3036. @skipIf(True, "SLOWTEST skip")
  3037. @skipIf(True, "SLOWTEST skip")
  3038. @skipIf(True, "SLOWTEST skip")
  3039. @skipIf(True, "SLOWTEST skip")
  3040. @skipIf(True, "SLOWTEST skip")
  3041. def test_multiple_sources_dev_master_merge_lists(self):
  3042. """
  3043. Test using two ext_pillar dirs. Since all git_pillar repos are merged
  3044. into a single dictionary, ordering matters.
  3045. This tests with the dev branch followed by master, and with
  3046. pillar_merge_lists enabled.
  3047. """
  3048. expected = {
  3049. "branch": "master",
  3050. "mylist": ["dev", "master"],
  3051. "mydict": {
  3052. "master": True,
  3053. "dev": True,
  3054. "nested_list": ["dev", "master"],
  3055. "nested_dict": {"master": True, "dev": True},
  3056. },
  3057. }
  3058. # Test with global credential options
  3059. ret = self.get_pillar(
  3060. """\
  3061. file_ignore_regex: []
  3062. file_ignore_glob: []
  3063. git_pillar_provider: pygit2
  3064. git_pillar_user: {user}
  3065. git_pillar_password: {password}
  3066. git_pillar_insecure_auth: True
  3067. cachedir: {cachedir}
  3068. extension_modules: {extmods}
  3069. pillar_merge_lists: True
  3070. ext_pillar:
  3071. - git:
  3072. - dev {url}
  3073. - master {url}
  3074. """
  3075. )
  3076. self.assertEqual(ret, expected)
  3077. # Test with per-repo credential options
  3078. ret = self.get_pillar(
  3079. """\
  3080. file_ignore_regex: []
  3081. file_ignore_glob: []
  3082. git_pillar_provider: pygit2
  3083. cachedir: {cachedir}
  3084. extension_modules: {extmods}
  3085. pillar_merge_lists: True
  3086. ext_pillar:
  3087. - git:
  3088. - dev {url}:
  3089. - user: {user}
  3090. - password: {password}
  3091. - insecure_auth: True
  3092. - master {url}:
  3093. - user: {user}
  3094. - password: {password}
  3095. - insecure_auth: True
  3096. """
  3097. )
  3098. self.assertEqual(ret, expected)
  3099. @skipIf(True, "SLOWTEST skip")
  3100. @skipIf(True, "SLOWTEST skip")
  3101. @skipIf(True, "SLOWTEST skip")
  3102. @skipIf(True, "SLOWTEST skip")
  3103. @skipIf(True, "SLOWTEST skip")
  3104. @skipIf(True, "SLOWTEST skip")
  3105. def test_multiple_sources_with_pillarenv(self):
  3106. """
  3107. Test using pillarenv to restrict results to those from a single branch
  3108. """
  3109. expected = {
  3110. "branch": "master",
  3111. "mylist": ["master"],
  3112. "mydict": {
  3113. "master": True,
  3114. "nested_list": ["master"],
  3115. "nested_dict": {"master": True},
  3116. },
  3117. }
  3118. # Test with global credential options
  3119. ret = self.get_pillar(
  3120. """\
  3121. file_ignore_regex: []
  3122. file_ignore_glob: []
  3123. git_pillar_provider: pygit2
  3124. git_pillar_user: {user}
  3125. git_pillar_password: {password}
  3126. git_pillar_insecure_auth: True
  3127. cachedir: {cachedir}
  3128. extension_modules: {extmods}
  3129. pillarenv: base
  3130. ext_pillar:
  3131. - git:
  3132. - master {url}
  3133. - dev {url}
  3134. """
  3135. )
  3136. self.assertEqual(ret, expected)
  3137. # Test with per-repo credential options
  3138. ret = self.get_pillar(
  3139. """\
  3140. file_ignore_regex: []
  3141. file_ignore_glob: []
  3142. git_pillar_provider: pygit2
  3143. cachedir: {cachedir}
  3144. extension_modules: {extmods}
  3145. pillarenv: base
  3146. ext_pillar:
  3147. - git:
  3148. - master {url}:
  3149. - user: {user}
  3150. - password: {password}
  3151. - insecure_auth: True
  3152. - dev {url}:
  3153. - user: {user}
  3154. - password: {password}
  3155. - insecure_auth: True
  3156. """
  3157. )
  3158. self.assertEqual(ret, expected)
  3159. @skipIf(True, "SLOWTEST skip")
  3160. @skipIf(True, "SLOWTEST skip")
  3161. @skipIf(True, "SLOWTEST skip")
  3162. @skipIf(True, "SLOWTEST skip")
  3163. @skipIf(True, "SLOWTEST skip")
  3164. @skipIf(True, "SLOWTEST skip")
  3165. def test_includes_enabled(self):
  3166. """
  3167. Test with git_pillar_includes enabled. The top_only branch references
  3168. an SLS file from the master branch, so we should see the
  3169. "included_pillar" key from that SLS file in the compiled pillar data.
  3170. """
  3171. expected = {
  3172. "branch": "master",
  3173. "mylist": ["master"],
  3174. "mydict": {
  3175. "master": True,
  3176. "nested_list": ["master"],
  3177. "nested_dict": {"master": True},
  3178. },
  3179. "included_pillar": True,
  3180. }
  3181. # Test with global credential options
  3182. ret = self.get_pillar(
  3183. """\
  3184. file_ignore_regex: []
  3185. file_ignore_glob: []
  3186. git_pillar_provider: pygit2
  3187. git_pillar_user: {user}
  3188. git_pillar_password: {password}
  3189. git_pillar_insecure_auth: True
  3190. cachedir: {cachedir}
  3191. extension_modules: {extmods}
  3192. ext_pillar:
  3193. - git:
  3194. - master {url}
  3195. - top_only {url}:
  3196. - env: base
  3197. """
  3198. )
  3199. self.assertEqual(ret, expected)
  3200. @skipIf(True, "SLOWTEST skip")
  3201. @skipIf(True, "SLOWTEST skip")
  3202. @skipIf(True, "SLOWTEST skip")
  3203. @skipIf(True, "SLOWTEST skip")
  3204. @skipIf(True, "SLOWTEST skip")
  3205. @skipIf(True, "SLOWTEST skip")
  3206. def test_mountpoint_parameter(self):
  3207. """
  3208. Test mountpoint parameter
  3209. """
  3210. expected = {"included_pillar": True}
  3211. ret = self.get_pillar(
  3212. """\
  3213. file_ignore_regex: []
  3214. file_ignore_glob: []
  3215. git_pillar_provider: pygit2
  3216. git_pillar_user: {user}
  3217. git_pillar_password: {password}
  3218. git_pillar_insecure_auth: True
  3219. cachedir: {cachedir}
  3220. extension_modules: {extmods}
  3221. ext_pillar:
  3222. - git:
  3223. - master {url}:
  3224. - mountpoint: mounted
  3225. - top_mounted {url}:
  3226. - env: base
  3227. """
  3228. )
  3229. self.assertEqual(ret, expected)
  3230. @skipIf(True, "SLOWTEST skip")
  3231. @skipIf(True, "SLOWTEST skip")
  3232. @skipIf(True, "SLOWTEST skip")
  3233. @skipIf(True, "SLOWTEST skip")
  3234. @skipIf(True, "SLOWTEST skip")
  3235. @skipIf(True, "SLOWTEST skip")
  3236. def test_root_parameter(self):
  3237. """
  3238. Test root parameter
  3239. """
  3240. expected = {"from_subdir": True}
  3241. ret = self.get_pillar(
  3242. """\
  3243. file_ignore_regex: []
  3244. file_ignore_glob: []
  3245. git_pillar_provider: pygit2
  3246. git_pillar_user: {user}
  3247. git_pillar_password: {password}
  3248. git_pillar_insecure_auth: True
  3249. cachedir: {cachedir}
  3250. extension_modules: {extmods}
  3251. ext_pillar:
  3252. - git:
  3253. - master {url}:
  3254. - root: subdir
  3255. - top_only {url}:
  3256. - env: base
  3257. """
  3258. )
  3259. self.assertEqual(ret, expected)
  3260. # Test with per-repo credential options
  3261. ret = self.get_pillar(
  3262. """\
  3263. file_ignore_regex: []
  3264. file_ignore_glob: []
  3265. git_pillar_provider: pygit2
  3266. cachedir: {cachedir}
  3267. extension_modules: {extmods}
  3268. ext_pillar:
  3269. - git:
  3270. - master {url}:
  3271. - root: subdir
  3272. - user: {user}
  3273. - password: {password}
  3274. - insecure_auth: True
  3275. - top_only {url}:
  3276. - user: {user}
  3277. - password: {password}
  3278. - insecure_auth: True
  3279. - env: base
  3280. """
  3281. )
  3282. self.assertEqual(ret, expected)
  3283. @skipIf(True, "SLOWTEST skip")
  3284. @skipIf(True, "SLOWTEST skip")
  3285. @skipIf(True, "SLOWTEST skip")
  3286. @skipIf(True, "SLOWTEST skip")
  3287. @skipIf(True, "SLOWTEST skip")
  3288. @skipIf(True, "SLOWTEST skip")
  3289. def test_includes_disabled(self):
  3290. """
  3291. Test with git_pillar_includes enabled. The top_only branch references
  3292. an SLS file from the master branch, but since includes are disabled it
  3293. will not find the SLS file and the "included_pillar" key should not be
  3294. present in the compiled pillar data. We should instead see an error
  3295. message in the compiled data.
  3296. """
  3297. expected = {
  3298. "branch": "master",
  3299. "mylist": ["master"],
  3300. "mydict": {
  3301. "master": True,
  3302. "nested_list": ["master"],
  3303. "nested_dict": {"master": True},
  3304. },
  3305. "_errors": [
  3306. "Specified SLS 'bar' in environment 'base' is not "
  3307. "available on the salt master"
  3308. ],
  3309. }
  3310. # Test with global credential options
  3311. ret = self.get_pillar(
  3312. """\
  3313. file_ignore_regex: []
  3314. file_ignore_glob: []
  3315. git_pillar_provider: pygit2
  3316. git_pillar_includes: False
  3317. git_pillar_user: {user}
  3318. git_pillar_password: {password}
  3319. git_pillar_insecure_auth: True
  3320. cachedir: {cachedir}
  3321. extension_modules: {extmods}
  3322. ext_pillar:
  3323. - git:
  3324. - master {url}
  3325. - top_only {url}:
  3326. - env: base
  3327. """
  3328. )
  3329. self.assertEqual(ret, expected)
  3330. # Test with per-repo credential options
  3331. ret = self.get_pillar(
  3332. """\
  3333. file_ignore_regex: []
  3334. file_ignore_glob: []
  3335. git_pillar_provider: pygit2
  3336. git_pillar_includes: False
  3337. cachedir: {cachedir}
  3338. extension_modules: {extmods}
  3339. ext_pillar:
  3340. - git:
  3341. - master {url}:
  3342. - user: {user}
  3343. - password: {password}
  3344. - insecure_auth: True
  3345. - top_only {url}:
  3346. - user: {user}
  3347. - password: {password}
  3348. - insecure_auth: True
  3349. - env: base
  3350. """
  3351. )
  3352. self.assertEqual(ret, expected)
  3353. @skipIf(True, "SLOWTEST skip")
  3354. @skipIf(True, "SLOWTEST skip")
  3355. @skipIf(True, "SLOWTEST skip")
  3356. @skipIf(True, "SLOWTEST skip")
  3357. @skipIf(True, "SLOWTEST skip")
  3358. @skipIf(True, "SLOWTEST skip")
  3359. def test_includes_enabled_solves___env___with_mountpoint(self):
  3360. """
  3361. Test with git_pillar_includes enabled and using "__env__" as the branch
  3362. name for the configured repositories.
  3363. The "gitinfo" repository contains top.sls file with a local reference
  3364. and also referencing external "nowhere.foo" which is provided by "webinfo"
  3365. repository mounted as "nowhere".
  3366. """
  3367. ret = self.get_pillar(
  3368. """\
  3369. file_ignore_regex: []
  3370. file_ignore_glob: []
  3371. git_pillar_provider: pygit2
  3372. git_pillar_user: {user}
  3373. git_pillar_password: {password}
  3374. git_pillar_insecure_auth: True
  3375. cachedir: {cachedir}
  3376. extension_modules: {extmods}
  3377. ext_pillar:
  3378. - git:
  3379. - __env__ {url_extra_repo}:
  3380. - name: gitinfo
  3381. - user: {user}
  3382. - password: {password}
  3383. - insecure_auth: True
  3384. - __env__ {url}:
  3385. - name: webinfo
  3386. - mountpoint: nowhere
  3387. - user: {user}
  3388. - password: {password}
  3389. - insecure_auth: True
  3390. """
  3391. )
  3392. self.assertEqual(
  3393. ret,
  3394. {
  3395. "branch": "master",
  3396. "motd": "The force will be with you. Always.",
  3397. "mylist": ["master"],
  3398. "mydict": {
  3399. "master": True,
  3400. "nested_list": ["master"],
  3401. "nested_dict": {"master": True},
  3402. },
  3403. },
  3404. )
  3405. @skipIf(True, "SLOWTEST skip")
  3406. @skipIf(True, "SLOWTEST skip")
  3407. @skipIf(True, "SLOWTEST skip")
  3408. @skipIf(True, "SLOWTEST skip")
  3409. @skipIf(True, "SLOWTEST skip")
  3410. @skipIf(True, "SLOWTEST skip")
  3411. def test_root_and_mountpoint_parameters(self):
  3412. """
  3413. Test root and mountpoint parameters
  3414. """
  3415. expected = {"from_subdir": True}
  3416. ret = self.get_pillar(
  3417. """\
  3418. file_ignore_regex: []
  3419. file_ignore_glob: []
  3420. git_pillar_provider: pygit2
  3421. git_pillar_user: {user}
  3422. git_pillar_password: {password}
  3423. git_pillar_insecure_auth: True
  3424. cachedir: {cachedir}
  3425. extension_modules: {extmods}
  3426. ext_pillar:
  3427. - git:
  3428. - master {url}:
  3429. - mountpoint: mounted
  3430. - root: subdir
  3431. - top_mounted {url}:
  3432. - env: base
  3433. """
  3434. )
  3435. self.assertEqual(ret, expected)
  3436. @skipIf(True, "SLOWTEST skip")
  3437. @skipIf(True, "SLOWTEST skip")
  3438. @skipIf(True, "SLOWTEST skip")
  3439. @skipIf(True, "SLOWTEST skip")
  3440. @skipIf(True, "SLOWTEST skip")
  3441. @skipIf(True, "SLOWTEST skip")
  3442. def test_all_saltenvs(self):
  3443. """
  3444. Test all_saltenvs parameter.
  3445. """
  3446. ret = self.get_pillar(
  3447. """\
  3448. file_ignore_regex: []
  3449. file_ignore_glob: []
  3450. git_pillar_provider: pygit2
  3451. git_pillar_user: {user}
  3452. git_pillar_password: {password}
  3453. git_pillar_insecure_auth: True
  3454. cachedir: {cachedir}
  3455. extension_modules: {extmods}
  3456. pillarenv: dev
  3457. ext_pillar:
  3458. - git:
  3459. - __env__ {url_extra_repo}:
  3460. - all_saltenvs: master
  3461. - __env__ {url}:
  3462. - mountpoint: nowhere
  3463. """
  3464. )
  3465. self.assertEqual(
  3466. ret,
  3467. {
  3468. "branch": "dev",
  3469. "motd": "The force will be with you. Always.",
  3470. "mylist": ["dev"],
  3471. "mydict": {
  3472. "dev": True,
  3473. "nested_list": ["dev"],
  3474. "nested_dict": {"dev": True},
  3475. },
  3476. },
  3477. )
  3478. @skipIf(True, "SLOWTEST skip")
  3479. @skipIf(True, "SLOWTEST skip")
  3480. @skipIf(True, "SLOWTEST skip")
  3481. @skipIf(True, "SLOWTEST skip")
  3482. @skipIf(True, "SLOWTEST skip")
  3483. @skipIf(True, "SLOWTEST skip")
  3484. def test_all_saltenvs_base(self):
  3485. """
  3486. Test all_saltenvs parameter with base pillarenv.
  3487. """
  3488. ret = self.get_pillar(
  3489. """\
  3490. file_ignore_regex: []
  3491. file_ignore_glob: []
  3492. git_pillar_provider: pygit2
  3493. git_pillar_user: {user}
  3494. git_pillar_password: {password}
  3495. git_pillar_insecure_auth: True
  3496. cachedir: {cachedir}
  3497. extension_modules: {extmods}
  3498. ext_pillar:
  3499. - git:
  3500. - __env__ {url_extra_repo}:
  3501. - all_saltenvs: master
  3502. - __env__ {url}:
  3503. - mountpoint: nowhere
  3504. """
  3505. )
  3506. self.assertEqual(
  3507. ret,
  3508. {
  3509. "branch": "master",
  3510. "motd": "The force will be with you. Always.",
  3511. "mylist": ["master"],
  3512. "mydict": {
  3513. "master": True,
  3514. "nested_list": ["master"],
  3515. "nested_dict": {"master": True},
  3516. },
  3517. },
  3518. )
  3519. def test_fallback(self):
  3520. """
  3521. Test fallback parameter.
  3522. """
  3523. ret = self.get_pillar(
  3524. """\
  3525. file_ignore_regex: []
  3526. file_ignore_glob: []
  3527. git_pillar_provider: pygit2
  3528. git_pillar_user: {user}
  3529. git_pillar_password: {password}
  3530. git_pillar_insecure_auth: True
  3531. cachedir: {cachedir}
  3532. extension_modules: {extmods}
  3533. pillarenv: nonexisting
  3534. ext_pillar:
  3535. - git:
  3536. - __env__ {url_extra_repo}:
  3537. - fallback: master
  3538. - __env__ {url}:
  3539. - mountpoint: nowhere
  3540. - fallback: dev
  3541. """
  3542. )
  3543. self.assertEqual(
  3544. ret,
  3545. {
  3546. "branch": "dev",
  3547. "motd": "The force will be with you. Always.",
  3548. "mylist": ["dev"],
  3549. "mydict": {
  3550. "dev": True,
  3551. "nested_list": ["dev"],
  3552. "nested_dict": {"dev": True},
  3553. },
  3554. },
  3555. )