2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2018 SUSE and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
12 #----------------------------------------------------------------------
13 # This script is used by CI and executed by Jenkins jobs.
14 # You are not supposed to use this script manually if you don't know
16 #----------------------------------------------------------------------
18 # This function allows developers to specify the impacted scenario by adding
19 # the info about installer and scenario into the commit message or using
20 # the topic branch names. This results in either skipping the real verification
21 # totally or skipping the determining the installer and scenario programmatically.
22 # It is important to note that this feature is only available to generic scenarios
23 # and only single installer/scenario pair is allowed.
24 # The input in commit message should be placed at the end of the commit message body,
25 # before the signed-off and change-id lines.
27 # Pattern to be searched in Commit Message
28 # deploy-scenario:<scenario-name>
29 # installer-type:<installer-type>
31 # deploy-scenario:os-odl-nofeature
34 # deploy-scenario:k8-nosdn-nofeature
35 # installer-type:kubespray
37 # Patterns to be searched in topic branch name
41 function override_scenario() {
42 echo "Processing $GERRIT_PROJECT patchset $GERRIT_REFSPEC"
44 # ensure the metadata we record is consistent for all types of patches including skipped ones
45 # extract releng-xci sha
46 XCI_SHA=$(cd $WORKSPACE && git rev-parse HEAD)
48 # extract scenario sha which is same as releng-xci sha for generic scenarios
51 # process topic branch names
52 if [[ "$GERRIT_TOPIC" =~ skip-verify|skip-deployment|force-verify ]]; then
53 [[ "$GERRIT_TOPIC" =~ force-verify ]] && echo "Forcing CI verification using default scenario and installer!"
54 [[ "$GERRIT_TOPIC" =~ skip-verify|skip-deployment ]] && echo "Skipping verification!"
55 echo "INSTALLER_TYPE=osa" > $WORK_DIRECTORY/scenario.properties
56 echo "DEPLOY_SCENARIO=os-nosdn-nofeature" >> $WORK_DIRECTORY/scenario.properties
57 echo "XCI_SHA=$XCI_SHA" >> $WORK_DIRECTORY/scenario.properties
58 echo "SCENARIO_SHA=$SCENARIO_SHA" >> $WORK_DIRECTORY/scenario.properties
59 echo "PROJECT_NAME=$GERRIT_PROJECT" >> $WORK_DIRECTORY/scenario.properties
63 # process commit message
64 if [[ "$GERRIT_CHANGE_COMMIT_MESSAGE" =~ "installer-type:" && "$GERRIT_CHANGE_COMMIT_MESSAGE" =~ "deploy-scenario:" ]]; then
65 INSTALLER_TYPE=$(echo $GERRIT_CHANGE_COMMIT_MESSAGE | awk '/installer-type:/' RS=" " | cut -d":" -f2)
66 DEPLOY_SCENARIO=$(echo $GERRIT_CHANGE_COMMIT_MESSAGE | awk '/deploy-scenario:/' RS=" " | cut -d":" -f2)
68 if [[ -z "$INSTALLER_TYPE" || -z "$DEPLOY_SCENARIO" ]]; then
69 echo "Installer type or deploy scenario is not specified. Falling back to programmatically determining them."
71 echo "Recording the installer '$INSTALLER_TYPE' and scenario '$DEPLOY_SCENARIO' for downstream jobs"
72 echo "INSTALLER_TYPE=$INSTALLER_TYPE" > $WORK_DIRECTORY/scenario.properties
73 echo "DEPLOY_SCENARIO=$DEPLOY_SCENARIO" >> $WORK_DIRECTORY/scenario.properties
74 echo "XCI_SHA=$XCI_SHA" >> $WORK_DIRECTORY/scenario.properties
75 echo "SCENARIO_SHA=$SCENARIO_SHA" >> $WORK_DIRECTORY/scenario.properties
76 echo "PROJECT_NAME=$GERRIT_PROJECT" >> $WORK_DIRECTORY/scenario.properties
80 echo "Installer type or deploy scenario is not specified. Falling back to programmatically determining them."
84 # This function determines the default scenario for changes coming to releng-xci
85 # by processing the Gerrit change and using diff to see what changed.
87 # The stuff in releng-xci is for the installer and other common things so the
88 # determination is based on those.
91 # releng-xci/installer/<installer_type>/<impacted files>: <scenario>
92 function determine_default_scenario() {
93 echo "Processing $GERRIT_PROJECT patchset $GERRIT_REFSPEC"
97 # We need to set default scenario for changes that mess with installers
98 INSTALLERS=$(git diff HEAD^..HEAD --name-only -- 'xci/installer' | cut -d "/" -f 3 | uniq)
99 for CHANGED_INSTALLER in $INSTALLERS; do
100 case $CHANGED_INSTALLER in
102 DEPLOY_SCENARIO[${#DEPLOY_SCENARIO[@]}]='k8-nosdn-nofeature'
104 # Default case (including OSA changes)
106 DEPLOY_SCENARIO[${#DEPLOY_SCENARIO[@]}]='os-nosdn-nofeature'
110 # For all other changes, we only need to set a default scenario if it's not set already
111 if git diff HEAD^..HEAD --name-only | grep -q -v 'xci/installer'; then
112 [[ ${#DEPLOY_SCENARIO[@]} -eq 0 ]] && DEPLOY_SCENARIO[${#DEPLOY_SCENARIO[@]}]='os-nosdn-nofeature'
115 # extract releng-xci sha
116 XCI_SHA=$(cd $WORKSPACE && git rev-parse HEAD)
118 # TODO: we need to fix this so we actually extract the scenario sha by cloning releng-xci-scenarios
119 # for the determined scenario. it is crucial for promotion...
120 SCENARIO_SHA=$XCI_SHA
123 # This function determines the impacted scenario by processing the Gerrit
124 # change and using diff to see what changed. If changed files belong to a scenario
125 # its name gets recorded for deploying and testing the right scenario.
128 # <project-repo>/scenarios/<scenario>/<impacted files>: <scenario>
129 function determine_scenario() {
130 echo "Processing $GERRIT_PROJECT patchset $GERRIT_REFSPEC"
132 # remove the clone that is done via jenkins and place releng-xci there so the
133 # things continue functioning properly
134 cd $HOME && /bin/rm -rf $WORKSPACE
135 git clone -q https://gerrit.opnfv.org/gerrit/releng-xci $WORKSPACE && cd $WORKSPACE
137 # fix the permissions so ssh doesn't complain due to having world-readable keyfiles
138 chmod -R go-rwx $WORKSPACE/xci/scripts/vm
140 # clone the project repo and fetch the patchset to process for further processing
141 git clone -q https://gerrit.opnfv.org/gerrit/$GERRIT_PROJECT $WORK_DIRECTORY/$GERRIT_PROJECT
142 cd $WORK_DIRECTORY/$GERRIT_PROJECT
143 git fetch -q https://gerrit.opnfv.org/gerrit/$GERRIT_PROJECT $GERRIT_REFSPEC && git checkout -q FETCH_HEAD
145 # process the diff to find out what scenario(s) are impacted - there should only be 1
146 DEPLOY_SCENARIO+=$(git diff HEAD^..HEAD --name-only | grep scenarios | awk -F '[/|/]' '{print $2}' | uniq)
148 # extract releng-xci sha
149 XCI_SHA=$(cd $WORKSPACE && git rev-parse HEAD)
151 # extract scenario sha
152 SCENARIO_SHA=$(cd $WORK_DIRECTORY/$GERRIT_PROJECT && git rev-parse HEAD)
155 echo "Determining the impacted scenario"
157 declare -a DEPLOY_SCENARIO
159 # ensure GERRIT_TOPIC is set
160 GERRIT_TOPIC="${GERRIT_TOPIC:-''}"
162 # this directory is where the temporary clones and files are created
163 # while extracting the impacted scenario
164 WORK_DIRECTORY=/tmp/$GERRIT_CHANGE_NUMBER/$DISTRO
165 /bin/rm -rf $WORK_DIRECTORY && mkdir -p $WORK_DIRECTORY
167 if [[ $GERRIT_PROJECT == "releng-xci" ]]; then
168 determine_default_scenario
173 # ensure single scenario is impacted
174 if [[ $(IFS=$'\n' echo ${DEPLOY_SCENARIO[@]} | wc -w) != 1 ]]; then
175 echo "Change impacts multiple scenarios!"
176 echo "XCI doesn't support testing of changes that impact multiple scenarios currently."
177 echo "Please split your change into multiple different/dependent changes, each modifying single scenario."
182 case ${DEPLOY_SCENARIO[0]} in
187 INSTALLER_TYPE=kubespray
190 echo "Unable to determine the installer. Exiting!"
195 # save the installer and scenario names into java properties file
196 # so they can be injected to downstream jobs via envInject
197 echo "Recording the installer '$INSTALLER_TYPE' and scenario '${DEPLOY_SCENARIO[0]}' and SHAs for downstream jobs"
198 echo "INSTALLER_TYPE=$INSTALLER_TYPE" > $WORK_DIRECTORY/scenario.properties
199 echo "DEPLOY_SCENARIO=$DEPLOY_SCENARIO" >> $WORK_DIRECTORY/scenario.properties
200 echo "XCI_SHA=$XCI_SHA" >> $WORK_DIRECTORY/scenario.properties
201 echo "SCENARIO_SHA=$SCENARIO_SHA" >> $WORK_DIRECTORY/scenario.properties
202 echo "PROJECT_NAME=$GERRIT_PROJECT" >> $WORK_DIRECTORY/scenario.properties
204 # skip scenario support check if the job is promotion job
205 if [[ "$JOB_NAME" =~ (os|k8) ]]; then
209 # skip the deployment if the scenario is not supported on this distro
210 OPNFV_SCENARIO_REQUIREMENTS=$WORKSPACE/xci/opnfv-scenario-requirements.yml
211 if ! sed -n "/^- scenario: ${DEPLOY_SCENARIO[0]}$/,/^$/p" $OPNFV_SCENARIO_REQUIREMENTS | grep -q $DISTRO; then
212 echo "# SKIPPED: Scenario ${DEPLOY_SCENARIO[0]} is NOT supported on $DISTRO"