test_git_pillar.py 105 KB

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