Chandan Kumar | b7affe4 | 2017-06-29 13:57:01 +0530 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # Copyright 2017 Red Hat, Inc. |
| 4 | # All Rights Reserved. |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 7 | # not use this file except in compliance with the License. You may obtain |
| 8 | # 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, WITHOUT |
| 14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 15 | # License for the specific language governing permissions and limitations |
| 16 | # under the License. |
| 17 | |
| 18 | # This script is intended to check the sanity of tempest plugins against |
| 19 | # tempest master. |
| 20 | # What it does: |
Momoka Toyota | fe879ea | 2017-09-15 10:56:42 +0900 | [diff] [blame] | 21 | # * Retrieve the project lists having tempest plugin if project name is |
Chandan Kumar | b7affe4 | 2017-06-29 13:57:01 +0530 | [diff] [blame] | 22 | # given. |
Chandan Kumar | 97b1ad7 | 2017-11-30 18:53:53 +0530 | [diff] [blame] | 23 | # * For each project in a list, it does: |
| 24 | # * Create virtualenv and install tempest in it |
Chandan Kumar | b7affe4 | 2017-06-29 13:57:01 +0530 | [diff] [blame] | 25 | # * Clone the Project |
| 26 | # * Install the Project and also installs dependencies from |
| 27 | # test-requirements.txt. |
| 28 | # * Create Tempest workspace |
| 29 | # * List tempest plugins |
| 30 | # * List tempest plugins tests |
Chandan Kumar | 97b1ad7 | 2017-11-30 18:53:53 +0530 | [diff] [blame] | 31 | # * Delete virtualenv and project repo |
Chandan Kumar | b7affe4 | 2017-06-29 13:57:01 +0530 | [diff] [blame] | 32 | # |
| 33 | # If one of the step fails, The script will exit with failure. |
| 34 | |
| 35 | if [ "$1" == "-h" ]; then |
| 36 | echo -e "This script performs the sanity of tempest plugins to find |
| 37 | configuration and dependency issues with the tempest.\n |
| 38 | Usage: sh ./tools/tempest-plugin-sanity.sh [Run sanity on tempest plugins]" |
| 39 | exit 0 |
| 40 | fi |
| 41 | |
| 42 | set -ex |
| 43 | |
| 44 | # retrieve a list of projects having tempest plugins |
| 45 | PROJECT_LIST="$(python tools/generate-tempest-plugins-list.py)" |
Masayuki Igawa | 32a4b11 | 2019-05-24 17:45:35 +0200 | [diff] [blame] | 46 | |
Martin Kopec | dc84423 | 2020-12-24 15:57:53 +0000 | [diff] [blame] | 47 | NON_ACTIVE_LIST="$(python tools/generate-tempest-plugins-list.py nonactivelist)" |
Chandan Kumar | b7affe4 | 2017-06-29 13:57:01 +0530 | [diff] [blame] | 48 | |
| 49 | # Function to clone project using zuul-cloner or from git |
Masayuki Igawa | de1153b | 2019-07-30 18:02:07 +0900 | [diff] [blame] | 50 | function clone_project { |
Chandan Kumar | b7affe4 | 2017-06-29 13:57:01 +0530 | [diff] [blame] | 51 | if [ -e /usr/zuul-env/bin/zuul-cloner ]; then |
| 52 | /usr/zuul-env/bin/zuul-cloner --cache-dir /opt/git \ |
caoyuan | 349ba75 | 2019-04-23 19:40:06 +0800 | [diff] [blame] | 53 | https://opendev.org \ |
Masayuki Igawa | e36fe67 | 2019-05-23 13:43:46 +0200 | [diff] [blame] | 54 | "$1" |
Chandan Kumar | b7affe4 | 2017-06-29 13:57:01 +0530 | [diff] [blame] | 55 | |
| 56 | elif [ -e /usr/bin/git ]; then |
Masayuki Igawa | e36fe67 | 2019-05-23 13:43:46 +0200 | [diff] [blame] | 57 | /usr/bin/git clone https://opendev.org/"$1" \ |
| 58 | "$1" |
Chandan Kumar | b7affe4 | 2017-06-29 13:57:01 +0530 | [diff] [blame] | 59 | |
| 60 | fi |
| 61 | } |
| 62 | |
Andreas Jaeger | 99b085b | 2020-04-21 15:00:14 +0200 | [diff] [blame] | 63 | : ${TOX_CONSTRAINTS_FILE:="https://releases.openstack.org/constraints/upper/master"} |
| 64 | DEPS="-c${TOX_CONSTRAINTS_FILE}" |
Sphicas, Phil (ps3910) | 52d7083 | 2019-10-21 22:58:02 -0700 | [diff] [blame] | 65 | |
Chandan Kumar | 97b1ad7 | 2017-11-30 18:53:53 +0530 | [diff] [blame] | 66 | # function to create virtualenv to perform sanity operation |
Masayuki Igawa | de1153b | 2019-07-30 18:02:07 +0900 | [diff] [blame] | 67 | function prepare_workspace { |
Chandan Kumar | 97b1ad7 | 2017-11-30 18:53:53 +0530 | [diff] [blame] | 68 | SANITY_DIR=$(pwd) |
Martin Kopec | 4c709ec | 2020-06-19 08:27:46 +0000 | [diff] [blame] | 69 | python3 -m venv "$SANITY_DIR"/.venv |
Chandan Kumar | 97b1ad7 | 2017-11-30 18:53:53 +0530 | [diff] [blame] | 70 | export TVENV="$SANITY_DIR/tools/with_venv.sh" |
| 71 | cd "$SANITY_DIR" |
Chandan Kumar | b7affe4 | 2017-06-29 13:57:01 +0530 | [diff] [blame] | 72 | |
Chandan Kumar | 97b1ad7 | 2017-11-30 18:53:53 +0530 | [diff] [blame] | 73 | # Install tempest with test dependencies in a venv |
| 74 | "$TVENV" pip install -e . -r test-requirements.txt |
| 75 | } |
Chandan Kumar | b7affe4 | 2017-06-29 13:57:01 +0530 | [diff] [blame] | 76 | |
| 77 | # Function to install project |
Masayuki Igawa | de1153b | 2019-07-30 18:02:07 +0900 | [diff] [blame] | 78 | function install_project { |
Sphicas, Phil (ps3910) | 52d7083 | 2019-10-21 22:58:02 -0700 | [diff] [blame] | 79 | "$TVENV" pip install $DEPS "$SANITY_DIR"/"$1" |
Chandan Kumar | b7affe4 | 2017-06-29 13:57:01 +0530 | [diff] [blame] | 80 | # Check for test-requirements.txt file in a project then install it. |
Masayuki Igawa | e36fe67 | 2019-05-23 13:43:46 +0200 | [diff] [blame] | 81 | if [ -e "$SANITY_DIR"/"$1"/test-requirements.txt ]; then |
Sphicas, Phil (ps3910) | 52d7083 | 2019-10-21 22:58:02 -0700 | [diff] [blame] | 82 | "$TVENV" pip install $DEPS -r "$SANITY_DIR"/"$1"/test-requirements.txt |
Chandan Kumar | b7affe4 | 2017-06-29 13:57:01 +0530 | [diff] [blame] | 83 | fi |
| 84 | } |
| 85 | |
| 86 | # Function to perform sanity checking on Tempest plugin |
Masayuki Igawa | de1153b | 2019-07-30 18:02:07 +0900 | [diff] [blame] | 87 | function tempest_sanity { |
Chandan Kumar | 97b1ad7 | 2017-11-30 18:53:53 +0530 | [diff] [blame] | 88 | "$TVENV" tempest init "$SANITY_DIR"/tempest_sanity && \ |
| 89 | cd "$SANITY_DIR"/tempest_sanity && \ |
| 90 | "$TVENV" tempest list-plugins && \ |
Chandan Kumar | b7affe4 | 2017-06-29 13:57:01 +0530 | [diff] [blame] | 91 | "$TVENV" tempest run -l |
Chandan Kumar | 97b1ad7 | 2017-11-30 18:53:53 +0530 | [diff] [blame] | 92 | retval=$? |
Chandan Kumar | b7affe4 | 2017-06-29 13:57:01 +0530 | [diff] [blame] | 93 | # Delete tempest workspace |
Chandan Kumar | 97b1ad7 | 2017-11-30 18:53:53 +0530 | [diff] [blame] | 94 | # NOTE: Cleaning should be done even if an error occurs. |
Chandan Kumar | b7affe4 | 2017-06-29 13:57:01 +0530 | [diff] [blame] | 95 | "$TVENV" tempest workspace remove --name tempest_sanity --rmdir |
| 96 | cd "$SANITY_DIR" |
Chandan Kumar | 97b1ad7 | 2017-11-30 18:53:53 +0530 | [diff] [blame] | 97 | # Remove the sanity workspace in case of remaining |
| 98 | rm -fr "$SANITY_DIR"/tempest_sanity |
Chandan Kumar | b7affe4 | 2017-06-29 13:57:01 +0530 | [diff] [blame] | 99 | # Remove the project directory after sanity run |
Masayuki Igawa | e36fe67 | 2019-05-23 13:43:46 +0200 | [diff] [blame] | 100 | rm -fr "$SANITY_DIR"/"$1" |
Chandan Kumar | 97b1ad7 | 2017-11-30 18:53:53 +0530 | [diff] [blame] | 101 | |
| 102 | return $retval |
Chandan Kumar | b7affe4 | 2017-06-29 13:57:01 +0530 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | # Function to run sanity check on each project |
Masayuki Igawa | de1153b | 2019-07-30 18:02:07 +0900 | [diff] [blame] | 106 | function plugin_sanity_check { |
Chandan Kumar | 97b1ad7 | 2017-11-30 18:53:53 +0530 | [diff] [blame] | 107 | prepare_workspace && \ |
| 108 | clone_project "$1" && \ |
| 109 | install_project "$1" && \ |
| 110 | tempest_sanity "$1" |
| 111 | |
| 112 | return $? |
Chandan Kumar | b7affe4 | 2017-06-29 13:57:01 +0530 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | # Log status |
| 116 | passed_plugin='' |
| 117 | failed_plugin='' |
| 118 | # Perform sanity on all tempest plugin projects |
| 119 | for project in $PROJECT_LIST; do |
Martin Kopec | dc84423 | 2020-12-24 15:57:53 +0000 | [diff] [blame] | 120 | # Remove non-active tempest plugins |
| 121 | if ! [[ `echo $NON_ACTIVE_LIST | grep -c $project ` -gt 0 ]]; then |
Chandan Kumar | b7affe4 | 2017-06-29 13:57:01 +0530 | [diff] [blame] | 122 | plugin_sanity_check $project && passed_plugin+=", $project" || \ |
Chandan Kumar | 97b1ad7 | 2017-11-30 18:53:53 +0530 | [diff] [blame] | 123 | failed_plugin+="$project, " > $SANITY_DIR/$project.txt |
Chandan Kumar | b7affe4 | 2017-06-29 13:57:01 +0530 | [diff] [blame] | 124 | fi |
| 125 | done |
Chandan Kumar | cf576b2 | 2017-10-23 17:43:36 +0530 | [diff] [blame] | 126 | |
Masayuki Igawa | c6b0f14 | 2019-05-30 18:38:51 +0900 | [diff] [blame] | 127 | echo "Passed Plugins: $passed_plugin" |
| 128 | echo "Failed Plugins: $failed_plugin" |
| 129 | |
Chandan Kumar | cf576b2 | 2017-10-23 17:43:36 +0530 | [diff] [blame] | 130 | # Check for failed status |
| 131 | if [[ -n $failed_plugin ]]; then |
| 132 | exit 1 |
| 133 | fi |