blob: f60beedd8dcaadbc7ca7a4cabbd4227df5b4bd9b [file] [log] [blame]
Bartek Grzybowski87d77c42020-01-17 09:29:15 +01001#!/usr/bin/env bash
Mateusz Pilat9c9be6f2019-05-06 17:12:36 +02002# COPYRIGHT NOTICE STARTS HERE
3#
Bartek Grzybowski87d77c42020-01-17 09:29:15 +01004# Copyright 2018-2020 © Samsung Electronics Co., Ltd.
Mateusz Pilat9c9be6f2019-05-06 17:12:36 +02005#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18# COPYRIGHT NOTICE ENDS HERE
Mateusz Pilatb0f546a2019-05-08 13:33:46 +020019###############################################################################
20# This script performs Jenkins Change Verification for ONAP Offline Installer #
21# No parameters are expected #
22###############################################################################
Mateusz Pilat9c9be6f2019-05-06 17:12:36 +020023
Mateusz Pilatb0f546a2019-05-08 13:33:46 +020024function prep_ubuntu_16_04_for_molecule() {
25 sudo killall apt apt-get
26 sudo apt-get --assume-yes install software-properties-common
27 sudo add-apt-repository --yes ppa:deadsnakes/ppa
28 sudo apt update
29 sudo apt install --assume-yes python3.6
30 sudo apt install --assume-yes python3.6-venv
31}
32
33function run_molecule() {
Mateusz Pilatb0f546a2019-05-08 13:33:46 +020034 local roles=("$@")
35 local MOLECULE_RC
36 for role in ${roles[@]}
37 do
Bartek Grzybowski0ce90bf2020-01-17 14:35:38 +010038 if [ -f ${role}/molecule/default/molecule.yml ]; then
Mateusz Pilatb0f546a2019-05-08 13:33:46 +020039 ./ansible/test/bin/ci-molecule.sh ${role}
40 MOLECULE_RC=$?
41 if [ ${MOLECULE_RC} -ne "0" ]; then FAILED_ROLES+=(${role}); fi
42 else
43 echo "[WARNING] ---------- THERE ARE NO TESTS DEFINED FOR ${role} ----------"
44 fi
45 done
46}
47
48#######################################################################$
49# MAIN #$
50#######################################################################$
Mateusz Pilatf030b062020-05-20 14:58:50 +020051echo "---------- ONAP OFFLINE INSTALLER - CHANGE VERIFICATION START ----------"
Mateusz Pilatb0f546a2019-05-08 13:33:46 +020052FAILED_ROLES=()
Bartek Grzybowski87d77c42020-01-17 09:29:15 +010053ALL_PLAYBOOKS=(`ls -d ansible/test/play-*`) # enumerate all playbook tests for later usage
Bartek Grzybowskif9d95602020-01-17 14:54:11 +010054# Setup environment
Mateusz Pilatf030b062020-05-20 14:58:50 +020055prep_ubuntu_16_04_for_molecule > ubuntu_preparation.log
Mateusz Pilatb0f546a2019-05-08 13:33:46 +020056
Bartek Grzybowski87d77c42020-01-17 09:29:15 +010057# Check for changes in Ansible roles
58ROLE_CHANGES=(`git diff HEAD^ HEAD --name-only ansible/roles | cut -f 1-3 -d "/" | sort -u`)
Mateusz Pilatb0f546a2019-05-08 13:33:46 +020059if [ -z "${ROLE_CHANGES}" ]; then
60 echo "NO ANSIBLE ROLE TESTS REQUIRED"
61else
62 run_molecule "${ROLE_CHANGES[@]}"
63fi
64
Bartek Grzybowski87d77c42020-01-17 09:29:15 +010065# Check for changes in Molecule tests
66if ! $(git diff HEAD^ HEAD --exit-code --quiet ansible/test); then
67 # If there are any changes in ansible/test area
68 MOLECULE_CHANGES=(`git diff HEAD^ HEAD --name-only ansible/test | grep -v "ansible/test/play-.*/"`)
69 if [ ${#MOLECULE_CHANGES[@]} -gt 0 ]; then
70 # If detected changes that affect all playbook tests - run all
71 run_molecule "${ALL_PLAYBOOKS[@]}"
72 # memorize already tested playbooks
73 TESTED_PLAYBOOKS=${ALL_PLAYBOOKS[@]}
74 else
75 # Changes only in ansible/test/play-* area - run tests only for changed playbook tests
76 PLAYBOOKS=(`git diff HEAD^ HEAD --name-only ansible/test | cut -f 1-3 -d "/" | sort -u`)
77 run_molecule "${PLAYBOOKS[@]}"
78 # memorize already tested playbooks
79 TESTED_PLAYBOOKS=${PLAYBOOKS[@]}
80 fi
Mateusz Pilatb0f546a2019-05-08 13:33:46 +020081fi
Mateusz Pilat9c9be6f2019-05-06 17:12:36 +020082
Bartek Grzybowski87d77c42020-01-17 09:29:15 +010083# Check for changes in Ansible playbooks
84PLAYBOOK_CHANGES=(`git diff HEAD^ HEAD --name-only --relative=ansible ansible/*yml | cut -f 1 -d "."`)
85if [ ${#PLAYBOOK_CHANGES[@]} -gt 0 ]; then
86 for playbook in ${PLAYBOOK_CHANGES[@]};
87 do
88 if [ -d ansible/test/play-${playbook} ]; then
89 # If tests for this playbook are defined
90 if [[ ! ${TESTED_PLAYBOOKS[*]} =~ ${playbook} ]]; then
91 # AND weren't already run
92 run_molecule "ansible/test/play-${playbook}"
93 fi
94 else
95 # Warn that no tests are defined for this playbook
96 echo "[WARNING] ---------- THERE ARE NO TESTS DEFINED FOR ${playbook}.yml PLAYBOOK ----------"
97 fi
98 done
99fi
100
101# Check for changes in Ansible group_vars or libraries
102if ! $(git diff HEAD^ HEAD --exit-code --quiet --relative=ansible/group_vars) || \
103 ! $(git diff HEAD^ HEAD --exit-code --quiet --relative=ansible/library); then
104 # If there are any changes in ansible/{group_vars,libraries}
105 # then run all playbook tests except those that've been
106 # already run
107 for playbook in ${ALL_PLAYBOOKS[@]};
108 do
109 if [[ ! ${TESTED_PLAYBOOKS[*]} =~ ${playbook} ]]; then
110 run_molecule "${playbook}"
111 fi
112 done
113fi
114
115# if build was changed
Mateusz Pilat9c9be6f2019-05-06 17:12:36 +0200116
Mateusz Pilatb0f546a2019-05-08 13:33:46 +0200117if `git diff HEAD^ HEAD --name-only | grep -q "build"`; then
118 echo "TO DO: BUILD TEST" ;
119else
120 echo "NO BUILD TEST REQUIRED"
121fi
Mateusz Pilat9c9be6f2019-05-06 17:12:36 +0200122
Bartek Grzybowski87d77c42020-01-17 09:29:15 +0100123# if documentation was changed
Mateusz Pilat9c9be6f2019-05-06 17:12:36 +0200124
Mateusz Pilatb0f546a2019-05-08 13:33:46 +0200125if `git diff HEAD^ HEAD --name-only | grep -q "docs"`; then
126 echo "TO DO: DOC TEST";
127else
128 echo "NO DOC TEST REQUIRED"
129fi
130
Bartek Grzybowski87d77c42020-01-17 09:29:15 +0100131# SUMMARY RESULTS
Mateusz Pilatb0f546a2019-05-08 13:33:46 +0200132
133if [ -z ${FAILED_ROLES} ]; then
134 echo "All verification steps passed"
135else
136 echo "Verification failed for ${FAILED_ROLES[*]}"
137 exit 1
138fi
Mateusz Pilatf030b062020-05-20 14:58:50 +0200139echo "---------- ONAP OFFLINE INSTALLER - CHANGE VERIFICATION END ----------"