test_git_pillar.py 108 KB

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