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)" |
Chandan Kumar | 97b1ad7 | 2017-11-30 18:53:53 +0530 | [diff] [blame] | 46 | # List of projects having tempest plugin stale or unmaintained for a long time |
| 47 | # (6 months or more) |
| 48 | # TODO(masayukig): Some of these can be removed from BLACKLIST in the future. |
caoyuan | 349ba75 | 2019-04-23 19:40:06 +0800 | [diff] [blame] | 49 | # barbican-tempest-plugin: https://review.opendev.org/#/c/634631/ |
Masayuki Igawa | 7f5dd85 | 2019-05-16 18:48:59 +0900 | [diff] [blame] | 50 | # cyborg-tempest-plugin: https://review.opendev.org/659687 |
caoyuan | 349ba75 | 2019-04-23 19:40:06 +0800 | [diff] [blame] | 51 | # intel-nfv-ci-tests: https://review.opendev.org/#/c/634640/ |
| 52 | # networking-ansible: https://review.opendev.org/#/c/634647/ |
| 53 | # networking-generic-switch: https://review.opendev.org/#/c/634846/ |
| 54 | # networking-l2gw-tempest-plugin: https://review.opendev.org/#/c/635093/ |
| 55 | # networking-midonet: https://review.opendev.org/#/c/635096/ |
| 56 | # networking-plumgrid: https://review.opendev.org/#/c/635096/ |
| 57 | # networking-spp: https://review.opendev.org/#/c/635098/ |
| 58 | # neutron-dynamic-routing: https://review.opendev.org/#/c/637718/ |
| 59 | # neutron-vpnaas: https://review.opendev.org/#/c/637719/ |
| 60 | # nova-lxd: https://review.opendev.org/#/c/638334/ |
| 61 | # valet: https://review.opendev.org/#/c/638339/ |
Masayuki Igawa | 32a4b11 | 2019-05-24 17:45:35 +0200 | [diff] [blame^] | 62 | |
Chandan Kumar | 97b1ad7 | 2017-11-30 18:53:53 +0530 | [diff] [blame] | 63 | BLACKLIST=" |
Chandan Kumar | 97b1ad7 | 2017-11-30 18:53:53 +0530 | [diff] [blame] | 64 | barbican-tempest-plugin |
Masayuki Igawa | 7f5dd85 | 2019-05-16 18:48:59 +0900 | [diff] [blame] | 65 | cyborg-tempest-plugin |
Chandan Kumar | 97b1ad7 | 2017-11-30 18:53:53 +0530 | [diff] [blame] | 66 | intel-nfv-ci-tests |
| 67 | networking-ansible |
| 68 | networking-generic-switch |
| 69 | networking-l2gw-tempest-plugin |
| 70 | networking-midonet |
| 71 | networking-plumgrid |
| 72 | networking-spp |
| 73 | neutron-dynamic-routing |
| 74 | neutron-vpnaas |
| 75 | nova-lxd |
| 76 | valet |
Chandan Kumar | 97b1ad7 | 2017-11-30 18:53:53 +0530 | [diff] [blame] | 77 | " |
Chandan Kumar | b7affe4 | 2017-06-29 13:57:01 +0530 | [diff] [blame] | 78 | |
| 79 | # Function to clone project using zuul-cloner or from git |
| 80 | function clone_project() { |
| 81 | if [ -e /usr/zuul-env/bin/zuul-cloner ]; then |
| 82 | /usr/zuul-env/bin/zuul-cloner --cache-dir /opt/git \ |
caoyuan | 349ba75 | 2019-04-23 19:40:06 +0800 | [diff] [blame] | 83 | https://opendev.org \ |
Chandan Kumar | b7affe4 | 2017-06-29 13:57:01 +0530 | [diff] [blame] | 84 | openstack/"$1" |
| 85 | |
| 86 | elif [ -e /usr/bin/git ]; then |
caoyuan | 349ba75 | 2019-04-23 19:40:06 +0800 | [diff] [blame] | 87 | /usr/bin/git clone https://opendev.org/openstack/"$1" \ |
Chandan Kumar | b7affe4 | 2017-06-29 13:57:01 +0530 | [diff] [blame] | 88 | openstack/"$1" |
| 89 | |
| 90 | fi |
| 91 | } |
| 92 | |
Chandan Kumar | 97b1ad7 | 2017-11-30 18:53:53 +0530 | [diff] [blame] | 93 | # function to create virtualenv to perform sanity operation |
| 94 | function prepare_workspace() { |
| 95 | SANITY_DIR=$(pwd) |
Masayuki Igawa | 8460cb1 | 2019-05-16 12:03:23 +0900 | [diff] [blame] | 96 | virtualenv -p python3 --clear "$SANITY_DIR"/.venv |
Chandan Kumar | 97b1ad7 | 2017-11-30 18:53:53 +0530 | [diff] [blame] | 97 | export TVENV="$SANITY_DIR/tools/with_venv.sh" |
| 98 | cd "$SANITY_DIR" |
Chandan Kumar | b7affe4 | 2017-06-29 13:57:01 +0530 | [diff] [blame] | 99 | |
Chandan Kumar | 97b1ad7 | 2017-11-30 18:53:53 +0530 | [diff] [blame] | 100 | # Install tempest with test dependencies in a venv |
| 101 | "$TVENV" pip install -e . -r test-requirements.txt |
| 102 | } |
Chandan Kumar | b7affe4 | 2017-06-29 13:57:01 +0530 | [diff] [blame] | 103 | |
| 104 | # Function to install project |
| 105 | function install_project() { |
| 106 | "$TVENV" pip install "$SANITY_DIR"/openstack/"$1" |
| 107 | # Check for test-requirements.txt file in a project then install it. |
| 108 | if [ -e "$SANITY_DIR"/openstack/"$1"/test-requirements.txt ]; then |
| 109 | "$TVENV" pip install -r "$SANITY_DIR"/openstack/"$1"/test-requirements.txt |
| 110 | fi |
| 111 | } |
| 112 | |
| 113 | # Function to perform sanity checking on Tempest plugin |
| 114 | function tempest_sanity() { |
Chandan Kumar | 97b1ad7 | 2017-11-30 18:53:53 +0530 | [diff] [blame] | 115 | "$TVENV" tempest init "$SANITY_DIR"/tempest_sanity && \ |
| 116 | cd "$SANITY_DIR"/tempest_sanity && \ |
| 117 | "$TVENV" tempest list-plugins && \ |
Chandan Kumar | b7affe4 | 2017-06-29 13:57:01 +0530 | [diff] [blame] | 118 | "$TVENV" tempest run -l |
Chandan Kumar | 97b1ad7 | 2017-11-30 18:53:53 +0530 | [diff] [blame] | 119 | retval=$? |
Chandan Kumar | b7affe4 | 2017-06-29 13:57:01 +0530 | [diff] [blame] | 120 | # Delete tempest workspace |
Chandan Kumar | 97b1ad7 | 2017-11-30 18:53:53 +0530 | [diff] [blame] | 121 | # NOTE: Cleaning should be done even if an error occurs. |
Chandan Kumar | b7affe4 | 2017-06-29 13:57:01 +0530 | [diff] [blame] | 122 | "$TVENV" tempest workspace remove --name tempest_sanity --rmdir |
| 123 | cd "$SANITY_DIR" |
Chandan Kumar | 97b1ad7 | 2017-11-30 18:53:53 +0530 | [diff] [blame] | 124 | # Remove the sanity workspace in case of remaining |
| 125 | rm -fr "$SANITY_DIR"/tempest_sanity |
Chandan Kumar | b7affe4 | 2017-06-29 13:57:01 +0530 | [diff] [blame] | 126 | # Remove the project directory after sanity run |
| 127 | rm -fr "$SANITY_DIR"/openstack/"$1" |
Chandan Kumar | 97b1ad7 | 2017-11-30 18:53:53 +0530 | [diff] [blame] | 128 | |
| 129 | return $retval |
Chandan Kumar | b7affe4 | 2017-06-29 13:57:01 +0530 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | # Function to run sanity check on each project |
| 133 | function plugin_sanity_check() { |
Chandan Kumar | 97b1ad7 | 2017-11-30 18:53:53 +0530 | [diff] [blame] | 134 | prepare_workspace && \ |
| 135 | clone_project "$1" && \ |
| 136 | install_project "$1" && \ |
| 137 | tempest_sanity "$1" |
| 138 | |
| 139 | return $? |
Chandan Kumar | b7affe4 | 2017-06-29 13:57:01 +0530 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | # Log status |
| 143 | passed_plugin='' |
| 144 | failed_plugin='' |
| 145 | # Perform sanity on all tempest plugin projects |
| 146 | for project in $PROJECT_LIST; do |
| 147 | # Remove blacklisted tempest plugins |
| 148 | if ! [[ `echo $BLACKLIST | grep -c $project ` -gt 0 ]]; then |
| 149 | plugin_sanity_check $project && passed_plugin+=", $project" || \ |
Chandan Kumar | 97b1ad7 | 2017-11-30 18:53:53 +0530 | [diff] [blame] | 150 | failed_plugin+="$project, " > $SANITY_DIR/$project.txt |
Chandan Kumar | b7affe4 | 2017-06-29 13:57:01 +0530 | [diff] [blame] | 151 | fi |
| 152 | done |
Chandan Kumar | cf576b2 | 2017-10-23 17:43:36 +0530 | [diff] [blame] | 153 | |
| 154 | # Check for failed status |
| 155 | if [[ -n $failed_plugin ]]; then |
Chandan Kumar | 97b1ad7 | 2017-11-30 18:53:53 +0530 | [diff] [blame] | 156 | echo "Failed Plugins: $failed_plugin" |
Chandan Kumar | cf576b2 | 2017-10-23 17:43:36 +0530 | [diff] [blame] | 157 | exit 1 |
| 158 | fi |