X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=offline-installer-review.sh;h=f60beedd8dcaadbc7ca7a4cabbd4227df5b4bd9b;hb=e05179d49e04bc5705e1617601c50bd020910ded;hp=3530d8f8eba6a29ae2662b2a57299a1565e21fd8;hpb=b7f4912590d581d2a2e77e0126a487f428e8e5bd;p=oom%2Foffline-installer.git diff --git a/offline-installer-review.sh b/offline-installer-review.sh index 3530d8f8..f60beedd 100755 --- a/offline-installer-review.sh +++ b/offline-installer-review.sh @@ -1,7 +1,7 @@ -#! /usr/bin/env bash +#!/usr/bin/env bash # COPYRIGHT NOTICE STARTS HERE # -# Copyright 2018 © Samsung Electronics Co., Ltd. +# Copyright 2018-2020 © Samsung Electronics Co., Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -31,12 +31,11 @@ function prep_ubuntu_16_04_for_molecule() { } function run_molecule() { - prep_ubuntu_16_04_for_molecule local roles=("$@") local MOLECULE_RC for role in ${roles[@]} do - if `find ${role} -name molecule.yml | grep -q '.*'`; then + if [ -f ${role}/molecule/default/molecule.yml ]; then ./ansible/test/bin/ci-molecule.sh ${role} MOLECULE_RC=$? if [ ${MOLECULE_RC} -ne "0" ]; then FAILED_ROLES+=(${role}); fi @@ -49,26 +48,71 @@ function run_molecule() { #######################################################################$ # MAIN #$ #######################################################################$ +echo "---------- ONAP OFFLINE INSTALLER - CHANGE VERIFICATION START ----------" FAILED_ROLES=() +ALL_PLAYBOOKS=(`ls -d ansible/test/play-*`) # enumerate all playbook tests for later usage +# Setup environment +prep_ubuntu_16_04_for_molecule > ubuntu_preparation.log -#if ansible role was changed$$ -ROLE_CHANGES=(`git diff HEAD^ HEAD --name-only | grep "ansible/role" | cut -f 1-3 -d "/" | sort -u`) +# Check for changes in Ansible roles +ROLE_CHANGES=(`git diff HEAD^ HEAD --name-only ansible/roles | cut -f 1-3 -d "/" | sort -u`) if [ -z "${ROLE_CHANGES}" ]; then echo "NO ANSIBLE ROLE TESTS REQUIRED" else run_molecule "${ROLE_CHANGES[@]}" fi -#if ansible was changed +# Check for changes in Molecule tests +if ! $(git diff HEAD^ HEAD --exit-code --quiet ansible/test); then + # If there are any changes in ansible/test area + MOLECULE_CHANGES=(`git diff HEAD^ HEAD --name-only ansible/test | grep -v "ansible/test/play-.*/"`) + if [ ${#MOLECULE_CHANGES[@]} -gt 0 ]; then + # If detected changes that affect all playbook tests - run all + run_molecule "${ALL_PLAYBOOKS[@]}" + # memorize already tested playbooks + TESTED_PLAYBOOKS=${ALL_PLAYBOOKS[@]} + else + # Changes only in ansible/test/play-* area - run tests only for changed playbook tests + PLAYBOOKS=(`git diff HEAD^ HEAD --name-only ansible/test | cut -f 1-3 -d "/" | sort -u`) + run_molecule "${PLAYBOOKS[@]}" + # memorize already tested playbooks + TESTED_PLAYBOOKS=${PLAYBOOKS[@]} + fi +fi -if `git diff HEAD^ HEAD --name-only | grep -q "ansible/test"`; then - PLAYBOOKS=(`find ansible/test -name "play-*"`) - run_molecule "${PLAYBOOKS[@]}" -else - echo "NO FULL ANSIBLE TEST REQUIRED"; +# Check for changes in Ansible playbooks +PLAYBOOK_CHANGES=(`git diff HEAD^ HEAD --name-only --relative=ansible ansible/*yml | cut -f 1 -d "."`) +if [ ${#PLAYBOOK_CHANGES[@]} -gt 0 ]; then + for playbook in ${PLAYBOOK_CHANGES[@]}; + do + if [ -d ansible/test/play-${playbook} ]; then + # If tests for this playbook are defined + if [[ ! ${TESTED_PLAYBOOKS[*]} =~ ${playbook} ]]; then + # AND weren't already run + run_molecule "ansible/test/play-${playbook}" + fi + else + # Warn that no tests are defined for this playbook + echo "[WARNING] ---------- THERE ARE NO TESTS DEFINED FOR ${playbook}.yml PLAYBOOK ----------" + fi + done fi -#if build was changed +# Check for changes in Ansible group_vars or libraries +if ! $(git diff HEAD^ HEAD --exit-code --quiet --relative=ansible/group_vars) || \ + ! $(git diff HEAD^ HEAD --exit-code --quiet --relative=ansible/library); then + # If there are any changes in ansible/{group_vars,libraries} + # then run all playbook tests except those that've been + # already run + for playbook in ${ALL_PLAYBOOKS[@]}; + do + if [[ ! ${TESTED_PLAYBOOKS[*]} =~ ${playbook} ]]; then + run_molecule "${playbook}" + fi + done +fi + +# if build was changed if `git diff HEAD^ HEAD --name-only | grep -q "build"`; then echo "TO DO: BUILD TEST" ; @@ -76,7 +120,7 @@ else echo "NO BUILD TEST REQUIRED" fi -#if documentation was changed +# if documentation was changed if `git diff HEAD^ HEAD --name-only | grep -q "docs"`; then echo "TO DO: DOC TEST"; @@ -84,7 +128,7 @@ else echo "NO DOC TEST REQUIRED" fi -#SUMMARY RESULTS +# SUMMARY RESULTS if [ -z ${FAILED_ROLES} ]; then echo "All verification steps passed" @@ -92,4 +136,4 @@ else echo "Verification failed for ${FAILED_ROLES[*]}" exit 1 fi - +echo "---------- ONAP OFFLINE INSTALLER - CHANGE VERIFICATION END ----------"