Run DevStack in the gate
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test-functions.sh 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. #!/bin/bash
  2. # Copyright (C) 2013 OpenStack Foundation
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  13. # implied.
  14. #
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. # This script tests the checkout functions defined in functions.sh.
  18. source functions.sh
  19. SUDO=""
  20. LOCAL_AAR_VARS="TEST_GIT_CHECKOUTS TEST_ZUUL_REFS GIT_CLONE_AND_CD_ARG"
  21. # Mock out the checkout function since the refs we're checking out do
  22. # not exist.
  23. function git_checkout_branch {
  24. local project=$1
  25. local branch=$2
  26. project=`basename $project`
  27. if [[ "$branch" == "FETCH_HEAD" ]]; then
  28. branch=$FETCH_HEAD
  29. fi
  30. TEST_GIT_CHECKOUTS[$project]=$branch
  31. }
  32. # Mock out the fetch function since the refs we're fetching do not
  33. # exist.
  34. function git_fetch_at_ref {
  35. local project=$1
  36. local ref=$2
  37. project=`basename $project`
  38. if [ "$ref" != "" ]; then
  39. if [[ "${TEST_ZUUL_REFS[$project]}" =~ "$ref" ]]; then
  40. FETCH_HEAD="$ref"
  41. return 0
  42. fi
  43. return 1
  44. else
  45. # return failing
  46. return 1
  47. fi
  48. }
  49. # Mock out git repo functions so the git repos don't have to exist.
  50. function git_has_branch {
  51. local project=$1
  52. local branch=$2
  53. case $branch in
  54. master) return 0 ;;
  55. stable/havana)
  56. case $project in
  57. openstack/glance) return 0 ;;
  58. openstack/swift) return 0 ;;
  59. openstack/nova) return 0 ;;
  60. openstack/keystone) return 0 ;;
  61. opestnack/tempest) return 0 ;;
  62. esac
  63. esac
  64. return 1
  65. }
  66. function git_prune {
  67. return 0
  68. }
  69. function git_remote_update {
  70. return 0
  71. }
  72. function git_remote_set_url {
  73. return 0
  74. }
  75. function git_clone_and_cd {
  76. if [[ "x${2}" == "x" ]]; then
  77. GIT_CLONE_AND_CD_ARG["ERROR"]="ERROR"
  78. return 1
  79. else
  80. GIT_CLONE_AND_CD_ARG[$2]="$1,$3"
  81. fi
  82. return 0
  83. }
  84. # Utility function for tests
  85. function assert_equal {
  86. local lineno
  87. local function
  88. lineno=$(caller 0 | awk '{print $1}')
  89. function=$(caller 0 | awk '{print $2}')
  90. if [[ "$1" != "$2" ]]; then
  91. echo "ERROR: $1 != $2 in $function:L$lineno!"
  92. ERROR=1
  93. else
  94. echo "$function:L$lineno - ok"
  95. fi
  96. }
  97. function assert_raises {
  98. local lineno
  99. local function
  100. lineno=$(caller 0 | awk '{print $1}')
  101. function=$(caller 0 | awk '{print $2}')
  102. eval "$@" &>/dev/null
  103. if [[ $? -eq 0 ]]; then
  104. ERROR=1
  105. echo "ERROR: \`\`$@\`\` returned OK instead of error in $function:L$lineno!"
  106. fi
  107. }
  108. # Tests follow:
  109. function test_one_on_master {
  110. # devstack-gate master ZA
  111. for aar_var in $LOCAL_AAR_VARS; do
  112. eval `echo "declare -A $aar_var"`
  113. done
  114. local ZUUL_PROJECT='openstack/devstack-gate'
  115. local ZUUL_BRANCH='master'
  116. local ZUUL_REF='refs/zuul/master/ZA'
  117. TEST_ZUUL_REFS[devstack-gate]+=' refs/zuul/master/ZA'
  118. setup_project openstack/devstack-gate $ZUUL_BRANCH
  119. assert_equal "${TEST_GIT_CHECKOUTS[devstack-gate]}" 'refs/zuul/master/ZA'
  120. }
  121. function test_two_on_master {
  122. # devstack-gate master ZA
  123. # glance master ZB
  124. for aar_var in $LOCAL_AAR_VARS; do
  125. eval `echo "declare -A $aar_var"`
  126. done
  127. local ZUUL_PROJECT='openstack/glance'
  128. local ZUUL_BRANCH='master'
  129. local ZUUL_REF='refs/zuul/master/ZB'
  130. TEST_ZUUL_REFS[devstack-gate]+=' refs/zuul/master/ZA'
  131. TEST_ZUUL_REFS[devstack-gate]+=' refs/zuul/master/ZB'
  132. TEST_ZUUL_REFS[glance]+=' refs/zuul/master/ZB'
  133. setup_project openstack/devstack-gate $ZUUL_BRANCH
  134. setup_project openstack/glance $ZUUL_BRANCH
  135. assert_equal "${TEST_GIT_CHECKOUTS[devstack-gate]}" 'refs/zuul/master/ZB'
  136. assert_equal "${TEST_GIT_CHECKOUTS[glance]}" 'refs/zuul/master/ZB'
  137. }
  138. function test_multi_branch_on_master {
  139. # devstack-gate master ZA
  140. # glance stable/havana ZB
  141. # python-glanceclient master ZC
  142. for aar_var in $LOCAL_AAR_VARS; do
  143. eval `echo "declare -A $aar_var"`
  144. done
  145. local ZUUL_PROJECT='openstack/python-glanceclient'
  146. local ZUUL_BRANCH='master'
  147. local ZUUL_REF='refs/zuul/master/ZC'
  148. TEST_ZUUL_REFS[devstack-gate]+=' refs/zuul/master/ZA'
  149. TEST_ZUUL_REFS[devstack-gate]+=' refs/zuul/master/ZB'
  150. TEST_ZUUL_REFS[devstack-gate]+=' refs/zuul/master/ZC'
  151. TEST_ZUUL_REFS[glance]+=' refs/zuul/stable/havana/ZB'
  152. TEST_ZUUL_REFS[glance]+=' refs/zuul/stable/havana/ZC'
  153. TEST_ZUUL_REFS[python-glanceclient]+=' refs/zuul/master/ZC'
  154. setup_project openstack/devstack-gate $ZUUL_BRANCH
  155. setup_project openstack/glance $ZUUL_BRANCH
  156. setup_project openstack/python-glanceclient $ZUUL_BRANCH
  157. assert_equal "${TEST_GIT_CHECKOUTS[devstack-gate]}" 'refs/zuul/master/ZC'
  158. assert_equal "${TEST_GIT_CHECKOUTS[glance]}" 'master'
  159. assert_equal "${TEST_GIT_CHECKOUTS[python-glanceclient]}" 'refs/zuul/master/ZC'
  160. }
  161. function test_multi_branch_project_override {
  162. # main branch is stable/havana
  163. # devstack-gate master ZA
  164. # devstack-gate master ZB
  165. # python-glanceclient master ZC
  166. # glance stable/havana ZD
  167. # tempest not in queue (override to master)
  168. # oslo.config not in queue (master because no stable/havana branch)
  169. # nova not in queue (stable/havana)
  170. for aar_var in $LOCAL_AAR_VARS; do
  171. eval `echo "declare -A $aar_var"`
  172. done
  173. local ZUUL_PROJECT='openstack/glance'
  174. local ZUUL_BRANCH='stable/havana'
  175. local OVERRIDE_TEMPEST_PROJECT_BRANCH='master'
  176. local ZUUL_REF='refs/zuul/stable/havana/ZD'
  177. TEST_ZUUL_REFS[devstack-gate]+=' refs/zuul/master/ZA'
  178. TEST_ZUUL_REFS[devstack-gate]+=' refs/zuul/master/ZB'
  179. TEST_ZUUL_REFS[devstack-gate]+=' refs/zuul/master/ZC'
  180. TEST_ZUUL_REFS[devstack-gate]+=' refs/zuul/master/ZD'
  181. TEST_ZUUL_REFS[python-glanceclient]+=' refs/zuul/master/ZC'
  182. TEST_ZUUL_REFS[python-glanceclient]+=' refs/zuul/master/ZD'
  183. TEST_ZUUL_REFS[glance]+=' refs/zuul/stable/havana/ZD'
  184. setup_project openstack/devstack-gate $ZUUL_BRANCH
  185. setup_project openstack/glance $ZUUL_BRANCH
  186. setup_project openstack/python-glanceclient $ZUUL_BRANCH
  187. setup_project openstack/tempest $ZUUL_BRANCH
  188. setup_project openstack/nova $ZUUL_BRANCH
  189. setup_project openstack/oslo.config $ZUUL_BRANCH
  190. assert_equal "${TEST_GIT_CHECKOUTS[devstack-gate]}" 'refs/zuul/master/ZD'
  191. assert_equal "${TEST_GIT_CHECKOUTS[glance]}" 'refs/zuul/stable/havana/ZD'
  192. assert_equal "${TEST_GIT_CHECKOUTS[tempest]}" 'master'
  193. assert_equal "${TEST_GIT_CHECKOUTS[nova]}" 'stable/havana'
  194. assert_equal "${TEST_GIT_CHECKOUTS[oslo.config]}" 'master'
  195. assert_equal "${TEST_GIT_CHECKOUTS[python-glanceclient]}" 'refs/zuul/master/ZD'
  196. }
  197. function test_multi_branch_on_stable {
  198. # devstack-gate master ZA
  199. # glance stable/havana ZB
  200. # python-glanceclient not in queue
  201. for aar_var in $LOCAL_AAR_VARS; do
  202. eval `echo "declare -A $aar_var"`
  203. done
  204. local ZUUL_PROJECT='openstack/glance'
  205. local ZUUL_BRANCH='stable/havana'
  206. local ZUUL_REF='refs/zuul/stable/havana/ZB'
  207. TEST_ZUUL_REFS[devstack-gate]+=' refs/zuul/master/ZA'
  208. TEST_ZUUL_REFS[devstack-gate]+=' refs/zuul/master/ZB'
  209. TEST_ZUUL_REFS[glance]+=' refs/zuul/stable/havana/ZB'
  210. setup_project openstack/devstack-gate $ZUUL_BRANCH
  211. setup_project openstack/glance $ZUUL_BRANCH
  212. setup_project openstack/python-glanceclient $ZUUL_BRANCH
  213. assert_equal "${TEST_GIT_CHECKOUTS[devstack-gate]}" 'refs/zuul/master/ZB'
  214. assert_equal "${TEST_GIT_CHECKOUTS[glance]}" 'refs/zuul/stable/havana/ZB'
  215. assert_equal "${TEST_GIT_CHECKOUTS[python-glanceclient]}" 'master'
  216. }
  217. function test_multi_git_base_project_override {
  218. # osrg/ryu https://github.com
  219. # test/devstack-gate https://example.com
  220. # openstack/keystone https://opendev.org
  221. # openstack/glance http://tarballs.openstack.org
  222. for aar_var in $LOCAL_AAR_VARS; do
  223. eval `echo "declare -A $aar_var"`
  224. done
  225. GIT_CLONE_AND_CD_ARG["ERROR"]="NULL"
  226. local ZUUL_PROJECT='openstack/neutron'
  227. local ZUUL_BRANCH='master'
  228. local ZUUL_REF='refs/zuul/master/ZA'
  229. local GIT_BASE=""
  230. local GIT_BASE_DEF="https://opendev.org"
  231. local OVERRIDE_RYU_GIT_BASE='https://github.com'
  232. setup_project "osrg/ryu" $ZUUL_BRANCH
  233. local OVERRIDE_DEVSTACK_GATE_GIT_BASE='https://example.com'
  234. setup_project "test/devstack-gate" $ZUUL_BRANCH
  235. setup_project "openstack/keystone" $ZUUL_BRANCH
  236. local GIT_BASE="http://tarballs.openstack.org"
  237. setup_project "openstack/glance" $ZUUL_BRANCH
  238. assert_equal "${GIT_CLONE_AND_CD_ARG["ryu"]}" "osrg/ryu,$OVERRIDE_RYU_GIT_BASE"
  239. assert_equal "${GIT_CLONE_AND_CD_ARG["devstack-gate"]}" "test/devstack-gate,$OVERRIDE_DEVSTACK_GATE_GIT_BASE"
  240. assert_equal "${GIT_CLONE_AND_CD_ARG["keystone"]}" "openstack/keystone,$GIT_BASE_DEF"
  241. assert_equal "${GIT_CLONE_AND_CD_ARG["glance"]}" "openstack/glance,$GIT_BASE"
  242. assert_equal "${GIT_CLONE_AND_CD_ARG["ERROR"]}" "NULL"
  243. }
  244. function test_grenade_backward {
  245. # devstack-gate master ZA
  246. # nova stable/havana ZB
  247. # keystone stable/havana ZC
  248. # keystone master ZD
  249. # glance master ZE
  250. # swift not in queue
  251. # python-glanceclient not in queue
  252. # havana -> master (with changes)
  253. for aar_var in $LOCAL_AAR_VARS; do
  254. eval `echo "declare -A $aar_var"`
  255. done
  256. local ZUUL_PROJECT='openstack/glance'
  257. local ZUUL_BRANCH='master'
  258. local ZUUL_REF='refs/zuul/master/ZE'
  259. local GRENADE_OLD_BRANCH='stable/havana'
  260. local GRENADE_NEW_BRANCH='master'
  261. TEST_ZUUL_REFS[devstack-gate]+=' refs/zuul/master/ZA'
  262. TEST_ZUUL_REFS[devstack-gate]+=' refs/zuul/master/ZB'
  263. TEST_ZUUL_REFS[devstack-gate]+=' refs/zuul/master/ZC'
  264. TEST_ZUUL_REFS[devstack-gate]+=' refs/zuul/master/ZD'
  265. TEST_ZUUL_REFS[devstack-gate]+=' refs/zuul/master/ZE'
  266. TEST_ZUUL_REFS[nova]+=' refs/zuul/stable/havana/ZB'
  267. TEST_ZUUL_REFS[nova]+=' refs/zuul/stable/havana/ZC'
  268. TEST_ZUUL_REFS[nova]+=' refs/zuul/stable/havana/ZD'
  269. TEST_ZUUL_REFS[nova]+=' refs/zuul/stable/havana/ZE'
  270. TEST_ZUUL_REFS[keystone]+=' refs/zuul/stable/havana/ZC'
  271. TEST_ZUUL_REFS[keystone]+=' refs/zuul/stable/havana/ZD'
  272. TEST_ZUUL_REFS[keystone]+=' refs/zuul/stable/havana/ZE'
  273. TEST_ZUUL_REFS[keystone]+=' refs/zuul/master/ZD'
  274. TEST_ZUUL_REFS[keystone]+=' refs/zuul/master/ZE'
  275. TEST_ZUUL_REFS[glance]+=' refs/zuul/master/ZE'
  276. setup_project openstack/devstack-gate $GRENADE_OLD_BRANCH
  277. setup_project openstack/nova $GRENADE_OLD_BRANCH
  278. setup_project openstack/keystone $GRENADE_OLD_BRANCH
  279. setup_project openstack/glance $GRENADE_OLD_BRANCH
  280. setup_project openstack/swift $GRENADE_OLD_BRANCH
  281. setup_project openstack/python-glanceclient $GRENADE_OLD_BRANCH
  282. assert_equal "${TEST_GIT_CHECKOUTS[devstack-gate]}" 'refs/zuul/master/ZE'
  283. assert_equal "${TEST_GIT_CHECKOUTS[nova]}" 'refs/zuul/stable/havana/ZE'
  284. assert_equal "${TEST_GIT_CHECKOUTS[keystone]}" 'refs/zuul/stable/havana/ZE'
  285. assert_equal "${TEST_GIT_CHECKOUTS[glance]}" 'stable/havana'
  286. assert_equal "${TEST_GIT_CHECKOUTS[swift]}" 'stable/havana'
  287. assert_equal "${TEST_GIT_CHECKOUTS[python-glanceclient]}" 'master'
  288. declare -A TEST_GIT_CHECKOUTS
  289. setup_project openstack/devstack-gate $GRENADE_NEW_BRANCH
  290. setup_project openstack/nova $GRENADE_NEW_BRANCH
  291. setup_project openstack/keystone $GRENADE_NEW_BRANCH
  292. setup_project openstack/glance $GRENADE_NEW_BRANCH
  293. setup_project openstack/swift $GRENADE_NEW_BRANCH
  294. setup_project openstack/python-glanceclient $GRENADE_NEW_BRANCH
  295. assert_equal "${TEST_GIT_CHECKOUTS[devstack-gate]}" 'refs/zuul/master/ZE'
  296. assert_equal "${TEST_GIT_CHECKOUTS[nova]}" 'master'
  297. assert_equal "${TEST_GIT_CHECKOUTS[keystone]}" 'refs/zuul/master/ZE'
  298. assert_equal "${TEST_GIT_CHECKOUTS[glance]}" 'refs/zuul/master/ZE'
  299. assert_equal "${TEST_GIT_CHECKOUTS[swift]}" 'master'
  300. assert_equal "${TEST_GIT_CHECKOUTS[python-glanceclient]}" 'master'
  301. }
  302. function test_grenade_forward {
  303. # devstack-gate master ZA
  304. # nova master ZB
  305. # keystone stable/havana ZC
  306. # keystone master ZD
  307. # glance stable/havana ZE
  308. # swift not in queue
  309. # python-glanceclient not in queue
  310. # havana (with changes) -> master
  311. for aar_var in $LOCAL_AAR_VARS; do
  312. eval `echo "declare -A $aar_var"`
  313. done
  314. local ZUUL_PROJECT='openstack/glance'
  315. local ZUUL_BRANCH='stable/havana'
  316. local ZUUL_REF='refs/zuul/stable/havana/ZE'
  317. local GRENADE_OLD_BRANCH='stable/havana'
  318. local GRENADE_NEW_BRANCH='master'
  319. TEST_ZUUL_REFS[devstack-gate]+=' refs/zuul/master/ZA'
  320. TEST_ZUUL_REFS[devstack-gate]+=' refs/zuul/master/ZB'
  321. TEST_ZUUL_REFS[devstack-gate]+=' refs/zuul/master/ZC'
  322. TEST_ZUUL_REFS[devstack-gate]+=' refs/zuul/master/ZD'
  323. TEST_ZUUL_REFS[devstack-gate]+=' refs/zuul/master/ZE'
  324. TEST_ZUUL_REFS[nova]+=' refs/zuul/master/ZB'
  325. TEST_ZUUL_REFS[nova]+=' refs/zuul/master/ZC'
  326. TEST_ZUUL_REFS[nova]+=' refs/zuul/master/ZD'
  327. TEST_ZUUL_REFS[nova]+=' refs/zuul/master/ZE'
  328. TEST_ZUUL_REFS[keystone]+=' refs/zuul/stable/havana/ZC'
  329. TEST_ZUUL_REFS[keystone]+=' refs/zuul/stable/havana/ZD'
  330. TEST_ZUUL_REFS[keystone]+=' refs/zuul/stable/havana/ZE'
  331. TEST_ZUUL_REFS[keystone]+=' refs/zuul/master/ZD'
  332. TEST_ZUUL_REFS[keystone]+=' refs/zuul/master/ZE'
  333. TEST_ZUUL_REFS[glance]+=' refs/zuul/stable/havana/ZE'
  334. setup_project openstack/devstack-gate $GRENADE_OLD_BRANCH
  335. setup_project openstack/nova $GRENADE_OLD_BRANCH
  336. setup_project openstack/keystone $GRENADE_OLD_BRANCH
  337. setup_project openstack/glance $GRENADE_OLD_BRANCH
  338. setup_project openstack/swift $GRENADE_OLD_BRANCH
  339. setup_project openstack/python-glanceclient $GRENADE_OLD_BRANCH
  340. assert_equal "${TEST_GIT_CHECKOUTS[devstack-gate]}" 'refs/zuul/master/ZE'
  341. assert_equal "${TEST_GIT_CHECKOUTS[nova]}" 'stable/havana'
  342. assert_equal "${TEST_GIT_CHECKOUTS[keystone]}" 'refs/zuul/stable/havana/ZE'
  343. assert_equal "${TEST_GIT_CHECKOUTS[glance]}" 'refs/zuul/stable/havana/ZE'
  344. assert_equal "${TEST_GIT_CHECKOUTS[swift]}" 'stable/havana'
  345. assert_equal "${TEST_GIT_CHECKOUTS[python-glanceclient]}" 'master'
  346. declare -A TEST_GIT_CHECKOUTS
  347. setup_project openstack/devstack-gate $GRENADE_NEW_BRANCH
  348. setup_project openstack/nova $GRENADE_NEW_BRANCH
  349. setup_project openstack/keystone $GRENADE_NEW_BRANCH
  350. setup_project openstack/glance $GRENADE_NEW_BRANCH
  351. setup_project openstack/swift $GRENADE_NEW_BRANCH
  352. setup_project openstack/python-glanceclient $GRENADE_NEW_BRANCH
  353. assert_equal "${TEST_GIT_CHECKOUTS[devstack-gate]}" 'refs/zuul/master/ZE'
  354. assert_equal "${TEST_GIT_CHECKOUTS[nova]}" 'refs/zuul/master/ZE'
  355. assert_equal "${TEST_GIT_CHECKOUTS[keystone]}" 'refs/zuul/master/ZE'
  356. assert_equal "${TEST_GIT_CHECKOUTS[glance]}" 'master'
  357. assert_equal "${TEST_GIT_CHECKOUTS[swift]}" 'master'
  358. assert_equal "${TEST_GIT_CHECKOUTS[python-glanceclient]}" 'master'
  359. }
  360. function test_branch_override {
  361. # glance stable/havana ZA
  362. # devstack-gate master ZB
  363. # swift not in queue
  364. # python-glanceclient not in queue
  365. for aar_var in $LOCAL_AAR_VARS; do
  366. eval `echo "declare -A $aar_var"`
  367. done
  368. local ZUUL_PROJECT='openstack/devstack-gate'
  369. local ZUUL_BRANCH='master'
  370. local ZUUL_REF='refs/zuul/master/ZB'
  371. local OVERRIDE_ZUUL_BRANCH='stable/havana'
  372. TEST_ZUUL_REFS[devstack-gate]+=' refs/zuul/master/ZB'
  373. TEST_ZUUL_REFS[glance]+=' refs/zuul/stable/havana/ZA'
  374. TEST_ZUUL_REFS[glance]+=' refs/zuul/stable/havana/ZB'
  375. setup_project openstack/devstack-gate $OVERRIDE_ZUUL_BRANCH
  376. setup_project openstack/glance $OVERRIDE_ZUUL_BRANCH
  377. setup_project openstack/swift $OVERRIDE_ZUUL_BRANCH
  378. setup_project openstack/python-glanceclient $OVERRIDE_ZUUL_BRANCH
  379. assert_equal "${TEST_GIT_CHECKOUTS[devstack-gate]}" 'refs/zuul/master/ZB'
  380. assert_equal "${TEST_GIT_CHECKOUTS[glance]}" 'refs/zuul/stable/havana/ZB'
  381. assert_equal "${TEST_GIT_CHECKOUTS[swift]}" 'stable/havana'
  382. assert_equal "${TEST_GIT_CHECKOUTS[python-glanceclient]}" 'master'
  383. }
  384. function test_periodic {
  385. # No queue
  386. for aar_var in $LOCAL_AAR_VARS; do
  387. eval `echo "declare -A $aar_var"`
  388. done
  389. local ZUUL_BRANCH='stable/havana'
  390. local ZUUL_PROJECT='openstack/glance'
  391. setup_project openstack/glance $ZUUL_BRANCH
  392. assert_equal "${TEST_GIT_CHECKOUTS[glance]}" 'stable/havana'
  393. }
  394. # Run setup_project without setting a ZUUL_BRANCH which is how a subset of
  395. # periodic jobs operate
  396. function test_periodic_no_branch {
  397. declare -A TEST_GIT_CHECKOUTS
  398. declare -A TEST_ZUUL_REF
  399. local ZUUL_PROJECT='openstack/glance'
  400. setup_project openstack/glance 'master'
  401. assert_equal "${TEST_GIT_CHECKOUTS[glance]}" 'master'
  402. }
  403. # setup_workspace fails without argument
  404. function test_workspace_branch_arg {
  405. assert_raises setup_workspace
  406. }
  407. function test_call_hook_if_defined {
  408. local filename=test_call_hook_if_defined.txt
  409. local save_dir
  410. save_dir=$(pwd)/tmp
  411. mkdir -p $save_dir
  412. function demo_script {
  413. local filename=$1
  414. local save_dir=$2
  415. # Clean up any files from previous tests
  416. rm -f $save_dir/$filename
  417. call_hook_if_defined test_hook $filename $save_dir
  418. ret_val=$?
  419. return $ret_val
  420. }
  421. # No hook defined returns success 0 & no file created
  422. demo_script $filename $save_dir
  423. ret_val=$?
  424. assert_equal "$ret_val" "0"
  425. [[ -e $save_dir/$filename ]]
  426. file_exists=$?
  427. assert_equal $file_exists 1
  428. # Hook defined returns its error code and file with output
  429. function test_hook {
  430. echo "hello test_hook"
  431. return 123
  432. }
  433. demo_script $filename $save_dir
  434. ret_val=$?
  435. assert_equal "$ret_val" "123"
  436. [[ -e $save_dir/$filename ]]
  437. file_exists=$?
  438. assert_equal $file_exists 0
  439. # Make sure the expected contents has length > 0
  440. result_expected=`cat $save_dir/$filename | grep "hello test_hook"`
  441. [[ ${#result_expected} -eq "0" ]]
  442. assert_equal $? 1
  443. # Hook defined with invalid file fails
  444. demo_script /invalid/file.txt $save_dir
  445. ret_val=$?
  446. assert_equal "$ret_val" "1"
  447. # Clean up
  448. rm -rf $save_dir
  449. }
  450. # test that reproduce file is populated correctly
  451. function test_reproduce {
  452. # expected result
  453. read -d '' EXPECTED_VARS << EOF
  454. declare -x ZUUL_VAR="zuul-var"
  455. declare -x DEVSTACK_VAR="devstack-var"
  456. declare -x ZUUL_VAR_MULTILINE="zuul-var-setting1
  457. zuul-var-setting2"
  458. declare -x DEVSTACK_VAR_MULTILINE="devstack-var-setting1
  459. devstack-var-setting2"
  460. gate_hook ()
  461. {
  462. echo "The cake is a lie"
  463. }
  464. declare -fx gate_hook
  465. EOF
  466. # prepare environment for test
  467. WORKSPACE=.
  468. export DEVSTACK_VAR=devstack-var
  469. export DEVSTACK_VAR_MULTILINE="devstack-var-setting1
  470. devstack-var-setting2"
  471. export ZUUL_VAR=zuul-var
  472. export ZUUL_VAR_MULTILINE="zuul-var-setting1
  473. zuul-var-setting2"
  474. function gate_hook {
  475. echo "The cake is a lie"
  476. }
  477. export -f gate_hook
  478. mkdir $WORKSPACE/logs
  479. # execute call and assert
  480. reproduce
  481. [[ -e $WORKSPACE/logs/reproduce.sh ]]
  482. file_exists=$?
  483. assert_equal $file_exists 0
  484. result_expected=`cat $WORKSPACE/logs/reproduce.sh | grep "$EXPECTED_VARS"`
  485. [[ ${#result_expected} -eq "0" ]]
  486. assert_equal $? 1
  487. # clean up environment
  488. rm -rf $WORKSPACE/logs
  489. rm -rf $WORKSPACE/workspace
  490. unset WORKSPACE
  491. unset DEVSTACK_VAR
  492. unset DEVSTACK_VAR_MULTILINE
  493. unset ZUUL_VAR
  494. unset ZUUL_VAR_MULTILINE
  495. unset gate_hook
  496. }
  497. # Run tests:
  498. #set -o xtrace
  499. test_branch_override
  500. test_grenade_backward
  501. test_grenade_forward
  502. test_multi_branch_on_master
  503. test_multi_branch_on_stable
  504. test_multi_branch_project_override
  505. test_multi_git_base_project_override
  506. test_one_on_master
  507. test_periodic
  508. test_periodic_no_branch
  509. test_two_on_master
  510. test_workspace_branch_arg
  511. test_call_hook_if_defined
  512. test_reproduce
  513. if [[ ! -z "$ERROR" ]]; then
  514. echo
  515. echo "FAIL: Tests have errors! See output above."
  516. echo
  517. exit 1
  518. else
  519. echo
  520. echo "Tests completed successfully!"
  521. echo
  522. fi