755ad730c9a99fa994fa7d9692b624cea8236f2a
[infra/cicd.git] / jjb / cloud-infra / cloud-infra-scenario-test.sh
1 #!/bin/bash
2
3
4 # vim: set ts=2 sw=2 expandtab:
5 #!/bin/bash
6
7 # ============LICENSE_START=======================================================
8 #  Copyright (C) 2019 The Nordix Foundation. All rights reserved.
9 # ================================================================================
10 # Licensed under the Apache License, Version 2.0 (the "License");
11 # you may not use this file except in compliance with the License.
12 # You may obtain a copy of the License at
13 #
14 #      http://www.apache.org/licenses/LICENSE-2.0
15 #
16 # Unless required by applicable law or agreed to in writing, software
17 # distributed under the License is distributed on an "AS IS" BASIS,
18 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 # See the License for the specific language governing permissions and
20 # limitations under the License.
21 #
22 # SPDX-License-Identifier: Apache-2.0
23 # ============LICENSE_END=========================================================
24
25 set -o errexit
26 set -o nounset
27 set -o pipefail
28
29 # this function processes commit message to determine the impacted scenario
30 # using the input provided by the committer.
31 #
32 # installer type and scenario should be placed at the beginning of lines
33 # separately and the format of the entry in commit message is as below
34 #
35 # installer-type: <installer type>
36 # deploy-scenario: <scenario name>
37 #
38 # example is
39 #
40 # installer-type: kubespray
41 # deploy-scenario: k8-calico-nofeature
42 function override_installer_scenario() {
43   echo "Processing $GERRIT_PROJECT patchset $GERRIT_REFSPEC to determine the installer and the scenario"
44   cd $WORKSPACE
45   COMMIT_MESSAGE=$(git show -s --format=%B)
46
47   if [[ "$COMMIT_MESSAGE" =~ "deploy-scenario:" && "$COMMIT_MESSAGE" =~ "installer-type:" ]]; then
48     export INSTALLER_TYPE=$(echo "$COMMIT_MESSAGE" | grep '^installer-type:' | cut -d":" -f2 | sed 's/\s*//g')
49     export DEPLOY_SCENARIO=$(echo "$COMMIT_MESSAGE" | grep '^deploy-scenario:' | cut -d":" -f2 | sed 's/\s*//g')
50     generate_temporary_sdf
51   else
52     echo "Installer type or deploy scenario is not specified."
53     echo "Falling back to programmatically determining them."
54     determine_scenario
55   fi
56 }
57
58 # this function will process the changed files to determine the impacted scenario
59 # if it is no specified by the committer. only one scenario per change should be
60 # touched.
61 # TODO: this is not implented yet.
62 function determine_scenario() {
63   echo "Processing $GERRIT_PROJECT patchset $GERRIT_REFSPEC"
64   cd $WORKSPACE
65   COMMIT_MESSAGE=$(git show -s --format=%B)
66   echo "Not implemented!"
67   exit 1
68 }
69
70 # this function generates temporary sdf file with the details of the impacted
71 # scenario.
72 function generate_temporary_sdf() {
73 echo "Generating temporary SDF to use for verification"
74   cat << EOF > $WORKSPACE/sdf.yml
75 scenario:
76   $DEPLOY_SCENARIO:
77     scm: git
78     src: $PROJECT_GIT_URL
79     version: $GERRIT_PATCHSET_REVISION
80     refspec: $GERRIT_REFSPEC
81     installers:
82       $INSTALLER_TYPE:
83         role: scenarios/$DEPLOY_SCENARIO/$INSTALLER_TYPE/role/$DEPLOY_SCENARIO
84         distros:
85           - ubuntu
86 EOF
87 }
88
89 echo "Determining the impacted scenario"
90
91 declare -a DEPLOY_SCENARIO
92
93 override_installer_scenario
94 generate_temporary_sdf
95
96 # execute cloud engine test.sh script with arguments
97 echo "Testing scenario $DEPLOY_SCENARIO deployed using $INSTALLER_TYPE"
98 cd $WORKSPACE && git clone -q $TEST_REPO_URL
99 cd test
100 ./test/test.sh -c -f $TEST_FW -t $TEST_SUITE -s $DEPLOY_SCENARIO
101
102 # vim: set ts=2 sw=2 expandtab: