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 ##############################################################################
14 #----------------------------------------------------------------------
15 # This script is used by CI and executed by Jenkins jobs.
16 # You are not supposed to use this script manually if you don't know
18 #----------------------------------------------------------------------
20 # This function will determine the impacted generic scenario by processing the
21 # change and using diff to see what changed.
22 # It currently sets the scenario to os-nosdn-nofeature.
23 function determine_generic_scenario() {
24 echo "Processing $GERRIT_PROJECT $GERRIT_REFSPEC"
26 # set the default scenario
27 DEPLOY_SCENARIO="os-nosdn-nofeature"
30 # This function determines the impacted external scenario by processing the Gerrit
31 # change and using diff to see what changed. If changed files belong to a scenario
32 # its name gets recorded for deploying and testing the right scenario.
35 # <project-repo>/scenarios/<scenario>/<impacted files>: <scenario>
36 function determine_external_scenario() {
37 echo "Processing $GERRIT_PROJECT $GERRIT_REFSPEC"
39 # remove the clone that is done via jenkins and place releng-xci there so the
40 # things continue functioning properly
41 cd $HOME && /bin/rm -rf $WORKSPACE
42 git clone -q https://gerrit.opnfv.org/gerrit/releng-xci $WORKSPACE && cd $WORKSPACE
44 # fix the permissions so ssh doesn't complain due to having world-readable keyfiles
45 chmod -R go-rwx $WORKSPACE/xci/scripts/vm
47 # clone the project repo and fetch the patchset to process for further processing
48 git clone -q https://gerrit.opnfv.org/gerrit/$GERRIT_PROJECT $WORK_DIRECTORY/$GERRIT_PROJECT
49 cd $WORK_DIRECTORY/$GERRIT_PROJECT
50 git fetch -q https://gerrit.opnfv.org/gerrit/$GERRIT_PROJECT $GERRIT_REFSPEC && git checkout -q FETCH_HEAD
52 # process the diff to find out what scenario(s) are impacted - there should only be 1
53 DEPLOY_SCENARIO=$(git diff HEAD^..HEAD --name-only | grep scenarios | awk -F '[/|/]' '{print $2}' | uniq)
56 echo "Determining the impacted scenario"
58 # ensure GERRIT_TOPIC is set
59 GERRIT_TOPIC="${GERRIT_TOPIC:-''}"
61 # this directory is where the temporary clones and files are created
62 # while extracting the impacted scenario
63 WORK_DIRECTORY=/tmp/$GERRIT_CHANGE_NUMBER/$DISTRO
64 /bin/rm -rf $WORK_DIRECTORY && mkdir -p $WORK_DIRECTORY
66 # skip the healthcheck if the patch doesn't impact the deployment
67 if [[ "$GERRIT_TOPIC" =~ skip-verify|skip-deployment ]]; then
68 echo "Skipping verify!"
69 echo "DEPLOY_SCENARIO=os-nosdn-nofeature" > $WORK_DIRECTORY/scenario.properties
73 if [[ $GERRIT_PROJECT == "releng-xci" ]]; then
74 determine_generic_scenario
76 determine_external_scenario
79 # ensure single scenario is impacted
80 if [[ $(echo $DEPLOY_SCENARIO | wc -w) != 1 ]]; then
81 echo "Change impacts multiple scenarios!"
82 echo "XCI doesn't support testing of changes that impact multiple scenarios currently."
83 echo "Please split your change into multiple different/dependent changes, each modifying single scenario."
88 case $DEPLOY_SCENARIO in
93 XCI_INSTALLER=kubespray
96 echo "Unable to determine the installer. Exiting!"
101 # save the installer and scenario names into java properties file
102 # so they can be injected to downstream jobs via envInject
103 echo "Recording the installer '$XCI_INSTALLER' and scenario '$DEPLOY_SCENARIO' for downstream jobs"
104 echo "XCI_INSTALLER=$XCI_INSTALLER" > $WORK_DIRECTORY/scenario.properties
105 echo "DEPLOY_SCENARIO=$DEPLOY_SCENARIO" >> $WORK_DIRECTORY/scenario.properties
107 # skip the deployment if the scenario is not supported on this distro
108 OPNFV_SCENARIO_REQUIREMENTS=$WORKSPACE/xci/opnfv-scenario-requirements.yml
109 if ! sed -n "/^- scenario: $DEPLOY_SCENARIO$/,/^$/p" $OPNFV_SCENARIO_REQUIREMENTS | grep -q $DISTRO; then
110 echo "# SKIPPED: Scenario $DEPLOY_SCENARIO is NOT supported on $DISTRO"