1
0

test_git_pillar.py 115 KB

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