blob: d38687e9a2dc00f7ada6fe0a70af1192ad76eb6c [file] [log] [blame]
Chandan Kumarb7affe42017-06-29 13:57:01 +05301#!/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 Toyotafe879ea2017-09-15 10:56:42 +090021# * Retrieve the project lists having tempest plugin if project name is
Chandan Kumarb7affe42017-06-29 13:57:01 +053022# given.
Chandan Kumar97b1ad72017-11-30 18:53:53 +053023# * For each project in a list, it does:
24# * Create virtualenv and install tempest in it
Chandan Kumarb7affe42017-06-29 13:57:01 +053025# * 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 Kumar97b1ad72017-11-30 18:53:53 +053031# * Delete virtualenv and project repo
Chandan Kumarb7affe42017-06-29 13:57:01 +053032#
33# If one of the step fails, The script will exit with failure.
34
35if [ "$1" == "-h" ]; then
36 echo -e "This script performs the sanity of tempest plugins to find
37configuration and dependency issues with the tempest.\n
38Usage: sh ./tools/tempest-plugin-sanity.sh [Run sanity on tempest plugins]"
39 exit 0
40fi
41
42set -ex
43
44# retrieve a list of projects having tempest plugins
45PROJECT_LIST="$(python tools/generate-tempest-plugins-list.py)"
Chandan Kumar97b1ad72017-11-30 18:53:53 +053046# 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.
caoyuan349ba752019-04-23 19:40:06 +080049# barbican-tempest-plugin: https://review.opendev.org/#/c/634631/
Masayuki Igawa7f5dd852019-05-16 18:48:59 +090050# cyborg-tempest-plugin: https://review.opendev.org/659687
Masayuki Igawae36fe672019-05-23 13:43:46 +020051# gce-api: It looks gce-api doesn't support python3 yet.
caoyuan349ba752019-04-23 19:40:06 +080052# intel-nfv-ci-tests: https://review.opendev.org/#/c/634640/
53# networking-ansible: https://review.opendev.org/#/c/634647/
Masayuki Igawae36fe672019-05-23 13:43:46 +020054# networking-bgpvpn: https://review.opendev.org/#/c/662142/
caoyuan349ba752019-04-23 19:40:06 +080055# networking-generic-switch: https://review.opendev.org/#/c/634846/
56# networking-l2gw-tempest-plugin: https://review.opendev.org/#/c/635093/
57# networking-midonet: https://review.opendev.org/#/c/635096/
58# networking-plumgrid: https://review.opendev.org/#/c/635096/
59# networking-spp: https://review.opendev.org/#/c/635098/
60# neutron-dynamic-routing: https://review.opendev.org/#/c/637718/
61# neutron-vpnaas: https://review.opendev.org/#/c/637719/
62# nova-lxd: https://review.opendev.org/#/c/638334/
63# valet: https://review.opendev.org/#/c/638339/
Masayuki Igawa32a4b112019-05-24 17:45:35 +020064
Chandan Kumar97b1ad72017-11-30 18:53:53 +053065BLACKLIST="
Masayuki Igawae36fe672019-05-23 13:43:46 +020066openstack/barbican-tempest-plugin
67openstack/cyborg-tempest-plugin
68x/gce-api
69x/intel-nfv-ci-tests
70x/networking-ansible
71openstack/networking-bgpvpn
72openstack/networking-generic-switch
73openstack/networking-l2gw-tempest-plugin
74openstack/networking-midonet
75x/networking-plumgrid
76x/networking-spp
77openstack/neutron-dynamic-routing
78openstack/neutron-vpnaas
79x/nova-lxd
80x/valet
Chandan Kumar97b1ad72017-11-30 18:53:53 +053081"
Chandan Kumarb7affe42017-06-29 13:57:01 +053082
83# Function to clone project using zuul-cloner or from git
84function clone_project() {
85 if [ -e /usr/zuul-env/bin/zuul-cloner ]; then
86 /usr/zuul-env/bin/zuul-cloner --cache-dir /opt/git \
caoyuan349ba752019-04-23 19:40:06 +080087 https://opendev.org \
Masayuki Igawae36fe672019-05-23 13:43:46 +020088 "$1"
Chandan Kumarb7affe42017-06-29 13:57:01 +053089
90 elif [ -e /usr/bin/git ]; then
Masayuki Igawae36fe672019-05-23 13:43:46 +020091 /usr/bin/git clone https://opendev.org/"$1" \
92 "$1"
Chandan Kumarb7affe42017-06-29 13:57:01 +053093
94 fi
95}
96
Chandan Kumar97b1ad72017-11-30 18:53:53 +053097# function to create virtualenv to perform sanity operation
98function prepare_workspace() {
99 SANITY_DIR=$(pwd)
Masayuki Igawa8460cb12019-05-16 12:03:23 +0900100 virtualenv -p python3 --clear "$SANITY_DIR"/.venv
Chandan Kumar97b1ad72017-11-30 18:53:53 +0530101 export TVENV="$SANITY_DIR/tools/with_venv.sh"
102 cd "$SANITY_DIR"
Chandan Kumarb7affe42017-06-29 13:57:01 +0530103
Chandan Kumar97b1ad72017-11-30 18:53:53 +0530104 # Install tempest with test dependencies in a venv
105 "$TVENV" pip install -e . -r test-requirements.txt
106}
Chandan Kumarb7affe42017-06-29 13:57:01 +0530107
108# Function to install project
109function install_project() {
Masayuki Igawae36fe672019-05-23 13:43:46 +0200110 "$TVENV" pip install "$SANITY_DIR"/"$1"
Chandan Kumarb7affe42017-06-29 13:57:01 +0530111 # Check for test-requirements.txt file in a project then install it.
Masayuki Igawae36fe672019-05-23 13:43:46 +0200112 if [ -e "$SANITY_DIR"/"$1"/test-requirements.txt ]; then
113 "$TVENV" pip install -r "$SANITY_DIR"/"$1"/test-requirements.txt
Chandan Kumarb7affe42017-06-29 13:57:01 +0530114 fi
115}
116
117# Function to perform sanity checking on Tempest plugin
118function tempest_sanity() {
Chandan Kumar97b1ad72017-11-30 18:53:53 +0530119 "$TVENV" tempest init "$SANITY_DIR"/tempest_sanity && \
120 cd "$SANITY_DIR"/tempest_sanity && \
121 "$TVENV" tempest list-plugins && \
Chandan Kumarb7affe42017-06-29 13:57:01 +0530122 "$TVENV" tempest run -l
Chandan Kumar97b1ad72017-11-30 18:53:53 +0530123 retval=$?
Chandan Kumarb7affe42017-06-29 13:57:01 +0530124 # Delete tempest workspace
Chandan Kumar97b1ad72017-11-30 18:53:53 +0530125 # NOTE: Cleaning should be done even if an error occurs.
Chandan Kumarb7affe42017-06-29 13:57:01 +0530126 "$TVENV" tempest workspace remove --name tempest_sanity --rmdir
127 cd "$SANITY_DIR"
Chandan Kumar97b1ad72017-11-30 18:53:53 +0530128 # Remove the sanity workspace in case of remaining
129 rm -fr "$SANITY_DIR"/tempest_sanity
Chandan Kumarb7affe42017-06-29 13:57:01 +0530130 # Remove the project directory after sanity run
Masayuki Igawae36fe672019-05-23 13:43:46 +0200131 rm -fr "$SANITY_DIR"/"$1"
Chandan Kumar97b1ad72017-11-30 18:53:53 +0530132
133 return $retval
Chandan Kumarb7affe42017-06-29 13:57:01 +0530134}
135
136# Function to run sanity check on each project
137function plugin_sanity_check() {
Chandan Kumar97b1ad72017-11-30 18:53:53 +0530138 prepare_workspace && \
139 clone_project "$1" && \
140 install_project "$1" && \
141 tempest_sanity "$1"
142
143 return $?
Chandan Kumarb7affe42017-06-29 13:57:01 +0530144}
145
146# Log status
147passed_plugin=''
148failed_plugin=''
149# Perform sanity on all tempest plugin projects
150for project in $PROJECT_LIST; do
151 # Remove blacklisted tempest plugins
152 if ! [[ `echo $BLACKLIST | grep -c $project ` -gt 0 ]]; then
153 plugin_sanity_check $project && passed_plugin+=", $project" || \
Chandan Kumar97b1ad72017-11-30 18:53:53 +0530154 failed_plugin+="$project, " > $SANITY_DIR/$project.txt
Chandan Kumarb7affe42017-06-29 13:57:01 +0530155 fi
156done
Chandan Kumarcf576b22017-10-23 17:43:36 +0530157
Masayuki Igawac6b0f142019-05-30 18:38:51 +0900158echo "Passed Plugins: $passed_plugin"
159echo "Failed Plugins: $failed_plugin"
160
Chandan Kumarcf576b22017-10-23 17:43:36 +0530161# Check for failed status
162if [[ -n $failed_plugin ]]; then
163 exit 1
164fi