CI for the TripleO project
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.

common_functions.sh 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/bin/bash
  2. # Tripleo CI functions
  3. # Revert a commit for tripleo ci
  4. # $1 : project name e.g. nova
  5. # $2 : hash id of commit to revert
  6. # $3 : bug id of reason for revert (used to skip revert if found in commit
  7. # that triggers ci).
  8. function temprevert {
  9. # Before reverting check to ensure this isn't the related fix
  10. if git --git-dir=$TRIPLEO_ROOT/${ZUUL_PROJECT#*/}/.git log -1 | grep -iE "bug.*$3" ; then
  11. echo "Skipping temprevert because bug fix $3 was found in git message."
  12. return 0
  13. fi
  14. pushd $TRIPLEO_ROOT/$1
  15. # Abort on fail so we're not left in a conflict state
  16. git revert --no-edit $2 || git revert --abort || true
  17. popd
  18. DELOREAN_BUILD_REFS="${DELOREAN_BUILD_REFS:-} $1"
  19. }
  20. # Pin to a commit for tripleo ci
  21. # $1 : project name e.g. nova
  22. # $2 : hash id of commit to pin too
  23. # $3 : bug id of reason for the pin (used to skip revert if found in commit
  24. # that triggers ci).
  25. function pin {
  26. # Before reverting check to ensure this isn't the related fix
  27. if git --git-dir=$TRIPLEO_ROOT/${ZUUL_PROJECT#*/}/.git log -1 | grep -iE "bug.*$3" ; then
  28. echo "Skipping pin because bug fix $3 was found in git message."
  29. return 0
  30. fi
  31. pushd $TRIPLEO_ROOT/$1
  32. git reset --hard $2
  33. popd
  34. DELOREAN_BUILD_REFS="${DELOREAN_BUILD_REFS:-} $1"
  35. }
  36. # Cherry-pick a commit for tripleo ci
  37. # $1 : project name e.g. nova
  38. # $2 : Gerrit refspec to cherry pick
  39. # $3 : bug id of reason for the cherry pick (used to skip cherry pick if found
  40. # in commit that triggers ci).
  41. function cherrypick {
  42. local PROJ_NAME=$1
  43. local REFSPEC=$2
  44. # Before cherrypicking check to ensure this isn't the related fix
  45. if git --git-dir=$TRIPLEO_ROOT/${ZUUL_PROJECT#*/}/.git log -1 | grep -iE "bug.*$3" ; then
  46. echo "Skipping cherrypick because bug fix $3 was found in git message."
  47. return 0
  48. fi
  49. pushd $TRIPLEO_ROOT/$PROJ_NAME
  50. git fetch https://review.opendev.org/openstack/$PROJ_NAME "$REFSPEC"
  51. # Abort on fail so we're not left in a conflict state
  52. git cherry-pick FETCH_HEAD || git cherry-pick --abort
  53. popd
  54. DELOREAN_BUILD_REFS="${DELOREAN_BUILD_REFS:-} $1"
  55. # Export a DIB_REPOREF variable as well
  56. export DIB_REPOREF_${PROJ_NAME//-/_}=$REFSPEC
  57. }
  58. # echo's out a project name from a ref
  59. # $1 : e.g. openstack/nova:master:refs/changes/87/64787/3 returns nova
  60. function filterref {
  61. PROJ=${1%%:*}
  62. PROJ=${PROJ##*/}
  63. echo $PROJ
  64. }
  65. function layer_ci_repo {
  66. # Find the path to the trunk repository used
  67. TRUNKREPOUSED=$(grep -Eo "[0-9a-z]{2}/[0-9a-z]{2}/[0-9a-z]{40}_[0-9a-z]+" /etc/yum.repos.d/delorean.repo)
  68. # Layer the ci repository on top of it
  69. sudo wget http://$MY_IP:8766/current/delorean-ci.repo -O /etc/yum.repos.d/delorean-ci.repo
  70. # rewrite the baseurl in delorean-ci.repo as its currently pointing a https://trunk.rdoproject.org/..
  71. sudo sed -i -e "s%baseurl=.*%baseurl=http://$MY_IP:8766/current/%" /etc/yum.repos.d/delorean-ci.repo
  72. sudo sed -i -e 's%priority=.*%priority=1%' /etc/yum.repos.d/delorean-ci.repo
  73. }
  74. function echo_vars_to_deploy_env {
  75. CALLER=$(caller)
  76. echo "# Written via echo_vars_to_deploy_env from $CALLER" >> $TRIPLEO_ROOT/tripleo-ci/deploy.env
  77. for VAR in NODEPOOL_CBS_CENTOS_PROXY NODEPOOL_CENTOS_MIRROR http_proxy INTROSPECT MY_IP no_proxy NODECOUNT OVERCLOUD_DEPLOY_ARGS OVERCLOUD_UPDATE_ARGS PACEMAKER SSH_OPTIONS STABLE_RELEASE TRIPLEO_ROOT TRIPLEO_SH_ARGS NETISO_V4 NETISO_V6 TOCI_JOBTYPE UNDERCLOUD_SSL UNDERCLOUD_HEAT_CONVERGENCE RUN_TEMPEST_TESTS RUN_PING_TEST JOB_NAME OVB UNDERCLOUD_IDEMPOTENT MULTINODE CONTROLLER_HOSTS COMPUTE_HOSTS SUBNODES_SSH_KEY TEST_OVERCLOUD_DELETE OVERCLOUD OSINFRA UNDERCLOUD_SANITY_CHECK OVERCLOUD_PINGTEST_ARGS FEATURE_BRANCH OVERCLOUD_ROLES UPGRADE_RELEASE OVERCLOUD_MAJOR_UPGRADE MAJOR_UPGRADE UNDERCLOUD_MAJOR_UPGRADE CA_SERVER UNDERCLOUD_TELEMETRY UNDERCLOUD_UI UNDERCLOUD_VALIDATIONS PREDICTABLE_PLACEMENT OPSTOOLS_REPO_ENABLED UPGRADE_ENV BOOTSTRAP_SUBNODES_MINIMAL MULTINODE_ENV_PATH; do
  78. if [ -n "${!VAR:+x}" ]; then
  79. echo "export $VAR=\"${!VAR}\"" >> $TRIPLEO_ROOT/tripleo-ci/deploy.env
  80. fi
  81. done
  82. for role in $OVERCLOUD_ROLES; do
  83. eval hosts=\${${role}_hosts}
  84. echo "export ${role}_hosts=\"${hosts}\"" >> $TRIPLEO_ROOT/tripleo-ci/deploy.env
  85. done
  86. }