-
Notifications
You must be signed in to change notification settings - Fork 19
/
functions
189 lines (171 loc) · 6.37 KB
/
functions
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/bin/bash
#
# Copyright 2015 Hewlett-Packard Development Company, L.P.
#
# 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.
#
#
# functions - Grenade-specific functions
#
# The following variables are assumed to be defined by certain functions:
#
# - ``GRENADE_DIR``
# - ``TARGET_DEVSTACK_DIR``
# - ``MYSQL_PASSWORD``
# - ``SAVE_DIR``
# Save trace setting
_XTRACE_GRENADE_FUNCTIONS=$(set +o | grep xtrace)
set +o xtrace
# Include the common functions
GRENADE_DIR=$(cd $(dirname "${BASH_SOURCE:-$0}") && pwd)
source ${TARGET_DEVSTACK_DIR}/functions
source ${TARGET_DEVSTACK_DIR}/lib/stack
source ${GRENADE_DIR}/inc/upgrade
source ${GRENADE_DIR}/inc/plugin
# just like source, except turn off tracing, as it just gets in the way
function source_quiet {
XTRACE=$(set +o | grep xtrace)
set +o xtrace
source $@
$XTRACE
}
# TODO: we'd really like to use the ping_check_functions that exist in
# devstack, however they are all wrapped up in lib/neutron
# gorp. Until that can be cleanly separated we need to keep our own
# copy here.
#
# ping_check_public $ip $timeout [False] - ping an machine on a public
# ip address. Should work with either neutron or nova-net. Also works
# to ensure the guest is not up if you pass False as last parameter.
function ping_check_public {
local ip=$1
local boot_timeout=$2
local expected=${3:-"True"}
local check_command=""
if [[ "$expected" = "True" ]]; then
check_command="while ! ping -c1 -w1 $ip; do sleep 1; done"
else
check_command="while ping -c1 -w1 $ip; do sleep 1; done"
fi
if ! timeout $boot_timeout sh -c "$check_command"; then
if [[ "$expected" = "True" ]]; then
# Dump Console log if ping fails
local fip=$(openstack floating ip list --floating-ip-address $ip -f value -c Port)
local server=$(openstack port show $fip -f value -c device_id)
openstack console log show $server
die $LINENO "[Fail] Couldn't ping server"
else
die $LINENO "[Fail] Could ping server"
fi
fi
}
# save_data() dumps service datastores into SAVE_DIR for base or
# target release.
function save_data {
local release=$1
local dir=$2
echo_summary "Dumping $release databases"
mkdir -p $SAVE_DIR
local db_type=$(
set +o xtrace &&
source $dir/stackrc &&
echo $DATABASE_TYPE)
if [[ "${db_type}" == "mysql" ]]; then
save_mysql_dbs $release $dir
else
echo_summary "TODO: save state for $db_type databases"
fi
}
function worlddump {
local name=$1
if [[ -n "$name" ]]; then
name="-n $name"
fi
if [[ -x $TARGET_DEVSTACK_DIR/tools/worlddump.py ]]; then
$TARGET_DEVSTACK_DIR/tools/worlddump.py $name -d $LOGDIR
sleep 1
else
echo "WARNING: Attempted to worlddump but couldn't find $TARGET_DEVSTACK_DIR/tools/worlddump.py"
fi
}
# Setup Exit Traps for debug purposes
trap exit_trap EXIT
function exit_trap {
# really important that this is the *first* line in this
# function, otherwise we corrupt the exit code
local r=$?
# we don't need tracing during this
set +o xtrace
# we have to turn off errexit at this point, otherwise we're going
# to exit from this function early when the while caller ends
# (with a bad exit)
set +o errexit
if [[ $r -ne 0 ]]; then
# unwind the call stack on failures
local frame=0
while caller $frame; do
((frame++));
done
echo "Exit code: $r"
worlddump
fi
exit $r
}
function run_tempest {
local release_dir
release_dir=$1
cd $release_dir/tempest
# unset the constraints as it might have been set earlier
# by base or target test run
unset TEMPEST_VENV_UPPER_CONSTRAINTS
# NOTE(yoctozepto): Grenade does not know about
# TEMPEST_VENV_UPPER_CONSTRAINTS, only DevStack does.
# This sources that one variable from it.
TEMPEST_VENV_UPPER_CONSTRAINTS=$(set +o xtrace &&
source $release_dir/devstack/stackrc &&
echo $TEMPEST_VENV_UPPER_CONSTRAINTS)
# NOTE(gmann): If gate explicitly set the non master
# constraints to use for Tempest venv then use the same
# while running the tests too otherwise, it will recreate
# the Tempest venv due to constraints mismatch.
# recreation of Tempest venv can flush the initially installed
# tempest plugins and their deps.
if [[ "$TEMPEST_VENV_UPPER_CONSTRAINTS" != "master" ]]; then
echo "Using $TEMPEST_VENV_UPPER_CONSTRAINTS constraints in Tempest virtual env."
# NOTE: setting both tox env var and once Tempest start using new var
# TOX_CONSTRAINTS_FILE then we can remove the old one.
export UPPER_CONSTRAINTS_FILE=$TEMPEST_VENV_UPPER_CONSTRAINTS
export TOX_CONSTRAINTS_FILE=$TEMPEST_VENV_UPPER_CONSTRAINTS
else
# NOTE(gmann): we need to set the below env var pointing to master
# constraints even that is what default in tox.ini. Otherwise it
# can create the issue for grenade run where old and new devstack
# can have different tempest (old and master) to install. For
# detail problem, refer to the
# https://bugs.launchpad.net/devstack/+bug/2003993
export UPPER_CONSTRAINTS_FILE=https://releases.openstack.org/constraints/upper/master
export TOX_CONSTRAINTS_FILE=https://releases.openstack.org/constraints/upper/master
fi
tox -esmoke -- --concurrency=$TEMPEST_CONCURRENCY
}
# Force a shorter connect timeout, if networking has gone off the
# rails we could potentially be hanging around for minutes on every
# ssh attempt due to TCP timeouts/retries.
#
# Don't check or store host keys, which makes it easier for local dev
# when hosts come and go.
#
# Auto-accept whatever we connect to
FSSH="ssh -v -o ConnectTimeout=10 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
# Restore xtrace
$_XTRACE_GRENADE_FUNCTIONS