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: |
| 21 | # * Creates the virtualenv |
| 22 | # * Install tempest |
Momoka Toyota | fe879ea | 2017-09-15 10:56:42 +0900 | [diff] [blame^] | 23 | # * Retrieve the project lists having tempest plugin if project name is |
Chandan Kumar | b7affe4 | 2017-06-29 13:57:01 +0530 | [diff] [blame] | 24 | # given. |
| 25 | # * For each project in a list, It does: |
| 26 | # * Clone the Project |
| 27 | # * Install the Project and also installs dependencies from |
| 28 | # test-requirements.txt. |
| 29 | # * Create Tempest workspace |
| 30 | # * List tempest plugins |
| 31 | # * List tempest plugins tests |
| 32 | # * Uninstall the project and its dependencies |
| 33 | # * Again Install tempest |
| 34 | # * Again repeat the step from cloning project |
| 35 | # |
| 36 | # If one of the step fails, The script will exit with failure. |
| 37 | |
| 38 | if [ "$1" == "-h" ]; then |
| 39 | echo -e "This script performs the sanity of tempest plugins to find |
| 40 | configuration and dependency issues with the tempest.\n |
| 41 | Usage: sh ./tools/tempest-plugin-sanity.sh [Run sanity on tempest plugins]" |
| 42 | exit 0 |
| 43 | fi |
| 44 | |
| 45 | set -ex |
| 46 | |
| 47 | # retrieve a list of projects having tempest plugins |
| 48 | PROJECT_LIST="$(python tools/generate-tempest-plugins-list.py)" |
| 49 | # List of projects having tempest plugin stale or unmaintained from long time |
| 50 | BLACKLIST="trio2o" |
| 51 | |
| 52 | # Function to clone project using zuul-cloner or from git |
| 53 | function clone_project() { |
| 54 | if [ -e /usr/zuul-env/bin/zuul-cloner ]; then |
| 55 | /usr/zuul-env/bin/zuul-cloner --cache-dir /opt/git \ |
| 56 | git://git.openstack.org \ |
| 57 | openstack/"$1" |
| 58 | |
| 59 | elif [ -e /usr/bin/git ]; then |
| 60 | /usr/bin/git clone git://git.openstack.org/openstack/"$1" \ |
| 61 | openstack/"$1" |
| 62 | |
| 63 | fi |
| 64 | } |
| 65 | |
| 66 | # Create virtualenv to perform sanity operation |
| 67 | SANITY_DIR=$(pwd) |
| 68 | virtualenv "$SANITY_DIR"/.venv |
| 69 | export TVENV="$SANITY_DIR/tools/with_venv.sh" |
| 70 | cd "$SANITY_DIR" |
| 71 | |
| 72 | # Install tempest in a venv |
| 73 | "$TVENV" pip install . |
| 74 | |
| 75 | # Function to install project |
| 76 | function install_project() { |
| 77 | "$TVENV" pip install "$SANITY_DIR"/openstack/"$1" |
| 78 | # Check for test-requirements.txt file in a project then install it. |
| 79 | if [ -e "$SANITY_DIR"/openstack/"$1"/test-requirements.txt ]; then |
| 80 | "$TVENV" pip install -r "$SANITY_DIR"/openstack/"$1"/test-requirements.txt |
| 81 | fi |
| 82 | } |
| 83 | |
| 84 | # Function to perform sanity checking on Tempest plugin |
| 85 | function tempest_sanity() { |
| 86 | "$TVENV" tempest init "$SANITY_DIR"/tempest_sanity |
| 87 | cd "$SANITY_DIR"/tempest_sanity |
| 88 | "$TVENV" tempest list-plugins |
| 89 | "$TVENV" tempest run -l |
| 90 | # Delete tempest workspace |
| 91 | "$TVENV" tempest workspace remove --name tempest_sanity --rmdir |
| 92 | cd "$SANITY_DIR" |
| 93 | } |
| 94 | |
| 95 | # Function to uninstall project |
| 96 | function uninstall_project() { |
| 97 | "$TVENV" pip uninstall -y "$SANITY_DIR"/openstack/"$1" |
| 98 | # Check for *requirements.txt file in a project then uninstall it. |
| 99 | if [ -e "$SANITY_DIR"/openstack/"$1"/*requirements.txt ]; then |
| 100 | "$TVENV" pip uninstall -y -r "$SANITY_DIR"/openstack/"$1"/*requirements.txt |
| 101 | fi |
| 102 | # Remove the project directory after sanity run |
| 103 | rm -fr "$SANITY_DIR"/openstack/"$1" |
| 104 | } |
| 105 | |
| 106 | # Function to run sanity check on each project |
| 107 | function plugin_sanity_check() { |
| 108 | clone_project "$1" && install_project "$1" && tempest_sanity "$1" \ |
| 109 | && uninstall_project "$1" && "$TVENV" pip install . |
| 110 | } |
| 111 | |
| 112 | # Log status |
| 113 | passed_plugin='' |
| 114 | failed_plugin='' |
| 115 | # Perform sanity on all tempest plugin projects |
| 116 | for project in $PROJECT_LIST; do |
| 117 | # Remove blacklisted tempest plugins |
| 118 | if ! [[ `echo $BLACKLIST | grep -c $project ` -gt 0 ]]; then |
| 119 | plugin_sanity_check $project && passed_plugin+=", $project" || \ |
| 120 | failed_plugin+=", $project" |
| 121 | fi |
| 122 | done |