blob: 500ff026b714f12013ecd8e42ba5bee549cd991b [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.
Chandan Kumar97b1ad72017-11-30 18:53:53 +053049# barbican-tempest-plugin: https://review.openstack.org/#/c/634631/
50# intel-nfv-ci-tests: https://review.openstack.org/#/c/634640/
51# networking-ansible: https://review.openstack.org/#/c/634647/
52# networking-generic-switch: https://review.openstack.org/#/c/634846/
53# networking-l2gw-tempest-plugin: https://review.openstack.org/#/c/635093/
54# networking-midonet: https://review.openstack.org/#/c/635096/
55# networking-plumgrid: https://review.openstack.org/#/c/635096/
56# networking-spp: https://review.openstack.org/#/c/635098/
57# neutron-dynamic-routing: https://review.openstack.org/#/c/637718/
58# neutron-vpnaas: https://review.openstack.org/#/c/637719/
59# nova-lxd: https://review.openstack.org/#/c/638334/
60# valet: https://review.openstack.org/#/c/638339/
61# vitrage-tempest-plugin: https://review.openstack.org/#/c/639003/
62BLACKLIST="
Chandan Kumar97b1ad72017-11-30 18:53:53 +053063barbican-tempest-plugin
64intel-nfv-ci-tests
65networking-ansible
66networking-generic-switch
67networking-l2gw-tempest-plugin
68networking-midonet
69networking-plumgrid
70networking-spp
71neutron-dynamic-routing
72neutron-vpnaas
73nova-lxd
74valet
75vitrage-tempest-plugin
76"
Chandan Kumarb7affe42017-06-29 13:57:01 +053077
78# Function to clone project using zuul-cloner or from git
79function clone_project() {
80 if [ -e /usr/zuul-env/bin/zuul-cloner ]; then
81 /usr/zuul-env/bin/zuul-cloner --cache-dir /opt/git \
Ian Wienandff3851b2019-03-24 20:36:15 +000082 https://git.openstack.org \
Chandan Kumarb7affe42017-06-29 13:57:01 +053083 openstack/"$1"
84
85 elif [ -e /usr/bin/git ]; then
Ian Wienandff3851b2019-03-24 20:36:15 +000086 /usr/bin/git clone https://git.openstack.org/openstack/"$1" \
Chandan Kumarb7affe42017-06-29 13:57:01 +053087 openstack/"$1"
88
89 fi
90}
91
Chandan Kumar97b1ad72017-11-30 18:53:53 +053092# function to create virtualenv to perform sanity operation
93function prepare_workspace() {
94 SANITY_DIR=$(pwd)
Masayuki Igawa8460cb12019-05-16 12:03:23 +090095 virtualenv -p python3 --clear "$SANITY_DIR"/.venv
Chandan Kumar97b1ad72017-11-30 18:53:53 +053096 export TVENV="$SANITY_DIR/tools/with_venv.sh"
97 cd "$SANITY_DIR"
Chandan Kumarb7affe42017-06-29 13:57:01 +053098
Chandan Kumar97b1ad72017-11-30 18:53:53 +053099 # Install tempest with test dependencies in a venv
100 "$TVENV" pip install -e . -r test-requirements.txt
101}
Chandan Kumarb7affe42017-06-29 13:57:01 +0530102
103# Function to install project
104function install_project() {
105 "$TVENV" pip install "$SANITY_DIR"/openstack/"$1"
106 # Check for test-requirements.txt file in a project then install it.
107 if [ -e "$SANITY_DIR"/openstack/"$1"/test-requirements.txt ]; then
108 "$TVENV" pip install -r "$SANITY_DIR"/openstack/"$1"/test-requirements.txt
109 fi
110}
111
112# Function to perform sanity checking on Tempest plugin
113function tempest_sanity() {
Chandan Kumar97b1ad72017-11-30 18:53:53 +0530114 "$TVENV" tempest init "$SANITY_DIR"/tempest_sanity && \
115 cd "$SANITY_DIR"/tempest_sanity && \
116 "$TVENV" tempest list-plugins && \
Chandan Kumarb7affe42017-06-29 13:57:01 +0530117 "$TVENV" tempest run -l
Chandan Kumar97b1ad72017-11-30 18:53:53 +0530118 retval=$?
Chandan Kumarb7affe42017-06-29 13:57:01 +0530119 # Delete tempest workspace
Chandan Kumar97b1ad72017-11-30 18:53:53 +0530120 # NOTE: Cleaning should be done even if an error occurs.
Chandan Kumarb7affe42017-06-29 13:57:01 +0530121 "$TVENV" tempest workspace remove --name tempest_sanity --rmdir
122 cd "$SANITY_DIR"
Chandan Kumar97b1ad72017-11-30 18:53:53 +0530123 # Remove the sanity workspace in case of remaining
124 rm -fr "$SANITY_DIR"/tempest_sanity
Chandan Kumarb7affe42017-06-29 13:57:01 +0530125 # Remove the project directory after sanity run
126 rm -fr "$SANITY_DIR"/openstack/"$1"
Chandan Kumar97b1ad72017-11-30 18:53:53 +0530127
128 return $retval
Chandan Kumarb7affe42017-06-29 13:57:01 +0530129}
130
131# Function to run sanity check on each project
132function plugin_sanity_check() {
Chandan Kumar97b1ad72017-11-30 18:53:53 +0530133 prepare_workspace && \
134 clone_project "$1" && \
135 install_project "$1" && \
136 tempest_sanity "$1"
137
138 return $?
Chandan Kumarb7affe42017-06-29 13:57:01 +0530139}
140
141# Log status
142passed_plugin=''
143failed_plugin=''
144# Perform sanity on all tempest plugin projects
145for project in $PROJECT_LIST; do
146 # Remove blacklisted tempest plugins
147 if ! [[ `echo $BLACKLIST | grep -c $project ` -gt 0 ]]; then
148 plugin_sanity_check $project && passed_plugin+=", $project" || \
Chandan Kumar97b1ad72017-11-30 18:53:53 +0530149 failed_plugin+="$project, " > $SANITY_DIR/$project.txt
Chandan Kumarb7affe42017-06-29 13:57:01 +0530150 fi
151done
Chandan Kumarcf576b22017-10-23 17:43:36 +0530152
153# Check for failed status
154if [[ -n $failed_plugin ]]; then
Chandan Kumar97b1ad72017-11-30 18:53:53 +0530155 echo "Failed Plugins: $failed_plugin"
Chandan Kumarcf576b22017-10-23 17:43:36 +0530156 exit 1
157fi