forked from openstack-archive/fuel-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_tests.sh
More file actions
executable file
·151 lines (119 loc) · 3.53 KB
/
Copy pathrun_tests.sh
File metadata and controls
executable file
·151 lines (119 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/bash
# Copyright 2014 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
set -eu
function usage {
echo "Usage: $0 [OPTION]..."
echo "Run fuel plugin building"
echo ""
echo " -b, --build Builds all of the plugins"
echo " -B, --no-build Don't run plugins build"
echo " -f, --fpb Run tests for fpb"
echo " -F, --no-fpb Don't run tests for fpb"
echo " -h, --help Print this usage message"
echo ""
echo "Note: with no options specified, the script will try to run "
echo " all available tests with all available checks."
exit
}
function process_options {
for arg in $@; do
case "$arg" in
-h|--help) usage;;
-b|--build) plugins_build=1;;
-B|--no-build) no_plugins_build=1;;
-f|--fpb) fpb_tests=1;;
-F|--no-fpb) no_fpb_tests=1;;
-*) testropts="$testropts $arg";;
*) testrargs="$testrargs $arg"
esac
done
}
# Settings
ROOT=$(dirname `readlink -f $0`)
FPB_VENV_PATH=${FPB_VENV_PATH:-"${ROOT}/fpb_venv"}
BUILT_PLUGINS_PATH=${BUILT_PLUGINS_PATH:-"${ROOT}/built_plugins"}
# Initialize global variables
plugins_build=0
no_plugins_build=0
fpb_tests=0
no_fpb_tests=0
function run_tests {
run_cleanup
# This variable collects all failed tests. It'll be printed in
# the end of this function as a small statistic for user.
local errors=""
# Enable all tests if none was specified skipping all explicitly
# disabled tests.
if [[ $plugins_build -eq 0 && \
$fpb_tests -eq 0 ]]; then
if [ $no_plugins_build -ne 1 ]; then plugins_build=1; fi
if [ $no_fpb_tests -ne 1 ]; then fpb_tests=1; fi
fi
# Run all enabled tests
if [ $plugins_build -eq 1 ]; then
echo "Starting plugins build..."
run_build || errors+=" plugins_build"
fi
if [ $fpb_tests -eq 1 ]; then
echo "Starting fpb testing..."
run_fpb || errors+=" fpb_tests"
fi
if [ -n "$errors" ]; then
echo Failed tests: $errors
exit 1
fi
exit
}
function run_cleanup {
find ${ROOT} -type f -name *.pyc -delete
}
function run_fpb {
local result=0
pushd "${ROOT}/fuel_plugin_builder" >> /dev/null
tox || result=1
popd >> /dev/null
return $result
}
# Build all of the plugins with current version of plugins builder
function run_build {
virtualenv $FPB_VENV_PATH
# virtualenv has unbound variables
# disable it during virtualenv usage
set +u
source $FPB_VENV_PATH/bin/activate || return 1
fpb_path="${ROOT}/fuel_plugin_builder/"
pushd $fpb_path
python setup.py install
popd
mkdir -p $BUILT_PLUGINS_PATH
rm -f $BUILT_PLUGINS_PATH/*.fp
rm -f $BUILT_PLUGINS_PATH/*.rpm
# Find plugins
for dir in $ROOT/*/metadata.yaml;
do
plugin_dir=$(dirname "${dir}");
pushd "${plugin_dir}"
fpb --build "${plugin_dir}" --debug || return 1
cp *.fp $BUILT_PLUGINS_PATH/
cp *.rpm $BUILT_PLUGINS_PATH/
popd
done
deactivate
set -u
return 0
}
# Parse command line arguments and run the tests
process_options $@
run_tests