1
0

test_git_pillar.py 105 KB

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