blob: b484a41f87e43b2f0d4dd75c07bd6ab56964e752 [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)"
Masayuki Igawa32a4b112019-05-24 17:45:35 +020046
Masayuki Igawaac8ae642019-05-23 11:39:02 +020047BLACKLIST="$(python tools/generate-tempest-plugins-list.py blacklist)"
Chandan Kumarb7affe42017-06-29 13:57:01 +053048
49# Function to clone project using zuul-cloner or from git
Masayuki Igawade1153b2019-07-30 18:02:07 +090050function clone_project {
Chandan Kumarb7affe42017-06-29 13:57:01 +053051 if [ -e /usr/zuul-env/bin/zuul-cloner ]; then
52 /usr/zuul-env/bin/zuul-cloner --cache-dir /opt/git \
caoyuan349ba752019-04-23 19:40:06 +080053 https://opendev.org \
Masayuki Igawae36fe672019-05-23 13:43:46 +020054 "$1"
Chandan Kumarb7affe42017-06-29 13:57:01 +053055
56 elif [ -e /usr/bin/git ]; then
Masayuki Igawae36fe672019-05-23 13:43:46 +020057 /usr/bin/git clone https://opendev.org/"$1" \
58 "$1"
Chandan Kumarb7affe42017-06-29 13:57:01 +053059
60 fi
61}
62
Sphicas, Phil (ps3910)52d70832019-10-21 22:58:02 -070063: ${UPPER_CONSTRAINTS_FILE:="https://releases.openstack.org/constraints/upper/master"}
64DEPS="-c${UPPER_CONSTRAINTS_FILE}"
65
Chandan Kumar97b1ad72017-11-30 18:53:53 +053066# function to create virtualenv to perform sanity operation
Masayuki Igawade1153b2019-07-30 18:02:07 +090067function prepare_workspace {
Chandan Kumar97b1ad72017-11-30 18:53:53 +053068 SANITY_DIR=$(pwd)
Masayuki Igawa8460cb12019-05-16 12:03:23 +090069 virtualenv -p python3 --clear "$SANITY_DIR"/.venv
Chandan Kumar97b1ad72017-11-30 18:53:53 +053070 export TVENV="$SANITY_DIR/tools/with_venv.sh"
71 cd "$SANITY_DIR"
Chandan Kumarb7affe42017-06-29 13:57:01 +053072
Chandan Kumar97b1ad72017-11-30 18:53:53 +053073 # Install tempest with test dependencies in a venv
74 "$TVENV" pip install -e . -r test-requirements.txt
75}
Chandan Kumarb7affe42017-06-29 13:57:01 +053076
77# Function to install project
Masayuki Igawade1153b2019-07-30 18:02:07 +090078function install_project {
Sphicas, Phil (ps3910)52d70832019-10-21 22:58:02 -070079 "$TVENV" pip install $DEPS "$SANITY_DIR"/"$1"
Chandan Kumarb7affe42017-06-29 13:57:01 +053080 # Check for test-requirements.txt file in a project then install it.
Masayuki Igawae36fe672019-05-23 13:43:46 +020081 if [ -e "$SANITY_DIR"/"$1"/test-requirements.txt ]; then
Sphicas, Phil (ps3910)52d70832019-10-21 22:58:02 -070082 "$TVENV" pip install $DEPS -r "$SANITY_DIR"/"$1"/test-requirements.txt
Chandan Kumarb7affe42017-06-29 13:57:01 +053083 fi
84}
85
86# Function to perform sanity checking on Tempest plugin
Masayuki Igawade1153b2019-07-30 18:02:07 +090087function tempest_sanity {
Chandan Kumar97b1ad72017-11-30 18:53:53 +053088 "$TVENV" tempest init "$SANITY_DIR"/tempest_sanity && \
89 cd "$SANITY_DIR"/tempest_sanity && \
90 "$TVENV" tempest list-plugins && \
Chandan Kumarb7affe42017-06-29 13:57:01 +053091 "$TVENV" tempest run -l
Chandan Kumar97b1ad72017-11-30 18:53:53 +053092 retval=$?
Chandan Kumarb7affe42017-06-29 13:57:01 +053093 # Delete tempest workspace
Chandan Kumar97b1ad72017-11-30 18:53:53 +053094 # NOTE: Cleaning should be done even if an error occurs.
Chandan Kumarb7affe42017-06-29 13:57:01 +053095 "$TVENV" tempest workspace remove --name tempest_sanity --rmdir
96 cd "$SANITY_DIR"
Chandan Kumar97b1ad72017-11-30 18:53:53 +053097 # Remove the sanity workspace in case of remaining
98 rm -fr "$SANITY_DIR"/tempest_sanity
Chandan Kumarb7affe42017-06-29 13:57:01 +053099 # Remove the project directory after sanity run
Masayuki Igawae36fe672019-05-23 13:43:46 +0200100 rm -fr "$SANITY_DIR"/"$1"
Chandan Kumar97b1ad72017-11-30 18:53:53 +0530101
102 return $retval
Chandan Kumarb7affe42017-06-29 13:57:01 +0530103}
104
105# Function to run sanity check on each project
Masayuki Igawade1153b2019-07-30 18:02:07 +0900106function plugin_sanity_check {
Chandan Kumar97b1ad72017-11-30 18:53:53 +0530107 prepare_workspace && \
108 clone_project "$1" && \
109 install_project "$1" && \
110 tempest_sanity "$1"
111
112 return $?
Chandan Kumarb7affe42017-06-29 13:57:01 +0530113}
114
115# Log status
116passed_plugin=''
117failed_plugin=''
118# Perform sanity on all tempest plugin projects
119for project in $PROJECT_LIST; do
120 # Remove blacklisted tempest plugins
121 if ! [[ `echo $BLACKLIST | grep -c $project ` -gt 0 ]]; then
122 plugin_sanity_check $project && passed_plugin+=", $project" || \
Chandan Kumar97b1ad72017-11-30 18:53:53 +0530123 failed_plugin+="$project, " > $SANITY_DIR/$project.txt
Chandan Kumarb7affe42017-06-29 13:57:01 +0530124 fi
125done
Chandan Kumarcf576b22017-10-23 17:43:36 +0530126
Masayuki Igawac6b0f142019-05-30 18:38:51 +0900127echo "Passed Plugins: $passed_plugin"
128echo "Failed Plugins: $failed_plugin"
129
Chandan Kumarcf576b22017-10-23 17:43:36 +0530130# Check for failed status
131if [[ -n $failed_plugin ]]; then
132 exit 1
133fi