forked from redhat-openstack/khaleesi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.bash
251 lines (212 loc) · 6.95 KB
/
functions.bash
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
if [ -z ${FUNCTIONS_SOURCED+xxx} ]; then
FUNCTIONS_SOURCED=true
set -e -u
declare -a __init_exit_todo_list=()
declare -i __init_script_exit_code=0
declare -r SCRIPT_CMD="$0"
declare -r SCRIPT_PATH=$(readlink -f "$0")
declare -r TOP_DIR=$(cd $(dirname "$0") && pwd)
debug.print_callstack() {
local i=0;
local cs_frames=${#BASH_SOURCE[@]}
echo "Traceback ... "
for (( i=$cs_frames - 1; i >= 2; i-- )); do
local cs_file=${BASH_SOURCE[i]}
local cs_fn=${FUNCNAME[i]}
local cs_line=${BASH_LINENO[i-1]}
# extract the line from the file
local line=$(sed -n "${cs_line}{s/^ *//;p}" "$cs_file")
echo -e " $cs_file[$cs_line]:" \
"$cs_fn:\t" \
"$line"
done
echo "--------------------------------------------------"
}
# on_exit_handler <exit-value>
on_exit_handler() {
# store the script exit code to be used later
__init_script_exit_code=${1:-0}
# print callstack
test $__init_script_exit_code -eq 0 || debug.print_callstack
echo "Exit cleanup ... ${__init_exit_todo_list[@]} "
for cmd in "${__init_exit_todo_list[@]}" ; do
echo " running: $cmd"
# run commands in a subshell so that the failures
# can be ignored
($cmd) || {
local cmd_type=$(type -t $cmd)
local cmd_text="$cmd"
local failed="FAILED"
echo " $cmd_type: $cmd_text - $failed to execute ..."
}
done
}
on_exit() {
local cmd="$*"
local n=${#__init_exit_todo_list[*]}
if [[ $n -eq 0 ]]; then
trap 'on_exit_handler $?' EXIT
__init_exit_todo_list=("$cmd")
else
__init_exit_todo_list=("$cmd" "${__init_exit_todo_list[@]}") #execute in reverse order
fi
}
init.print_result() {
local exit_code=$__init_script_exit_code
if [[ $exit_code == 0 ]]; then
echo "$SCRIPT_CMD: PASSED"
else
echo "$SCRIPT_CMD: FAILED" \
" - exit code: [ $exit_code ]"
fi
}
execute() {
echo "Execute Command:"
echo "$@"
"$@"
}
generate_settings_file() {
local out_file=${1:-'settings.yml'}
local OS_NETWORK_TYPE=${OS_NETWORK_TYPE:-'neutron'}
local default_floating_nw_name='external'
local default_flavor_id=4
local default_tempest_flavor_id=2
local default_tempest_image_id='10a4092c-6ec9-4ddf-b97c-b0f8dff0958e'
local default_tempest_repo='git://github.com/openstack/tempest.git'
local wait_for_boot=${WAIT_FOR_BOOT:-'180'}
local key_file=${KEY_FILE:-/key.pem }
local key_name=${SSH_KEY_NAME:-'key'}
chmod 600 $key_file
local job_name=${JOB_NAME}
local node_prefix=${NODE_PREFIX:-''}
local flavor_id=${FLAVOR_ID:-$default_flavor_id}
local floating_nw_name=${FLOATING_NETWORK_NAME:-'external'}
local image_id=$IMAGE_ID
local tempest_image_id=${TEMPEST_IMAGE_ID:-$default_tempest_image_id}
local tempest_flavor_id=${TEMPEST_FLAVOR_ID:-$default_tempest_flavor_id}
local foreman_image_id=${FOREMAN_IMAGE_ID:-$IMAGE_ID}
local foreman_flavor_id=${FOREMAN_FLAVOR_ID:-$default_flavor_id}
local net_1=${NET_1:-'CHANGE_ME'}
local net_2=${NET_2:-''}
local net_2_name=${NET_2_NAME:-'packstack_int'}
local net_3=${NET_3:-''}
local net_3_name=${NET_3_NAME:-'foreman_ext'}
local tags=${TAGS:-''}
local skip_tags=${SKIP_TAGS:-''}
local skip_tags_collect=${SKIP_TAGS_COLLECT:-''}
local tempest_tests=${TEMPEST_TEST_NAME:-'tempest.scenario.test_network_basic_ops'}
local remote_user=${REMOTE_USER:-'cloud-user'}
local tempest_repo=${TEMPEST_REPO:-$default_tempest_repo}
local tempest_branch=${TEMPEST_BRANCH:-'master'}
local tempest_remote_user=${TEMPEST_REMOTE_USER:-'fedora'}
local tempest_setup_method=${TEMPEST_SETUP_METHOD:-'packstack/provision'}
local foreman_remote_user=${FOREMAN_REMOTE_USER:-$REMOTE_USER}
local sm_username=${SM_USERNAME:-''}
local sm_password=${SM_PASSWORD:-''}
local host_env=${HOST_ENV:-'neutron'}
local product=${PRODUCT:-'rdo'} #product
local productrelease=${PRODUCTRELEASE:-'icehouse'} #rdo_release
local productreleaserepo=${PRODUCTRELEASEREPO:-'production'} #rdo_repo
local netplugin=${NETPLUGIN:-'neutron'} #network_driver
local selinux=${SELINUX:-'enforcing'} #enforcing, permissive
local update_rpms_tarball=${UPDATE_RPMS_TARBALL:-''}
local net_ids="[{ net-id: '$net_1' }"
if [[ ! -z $net_2 ]]; then
net_ids="$net_ids, { net-id: '$net_2' }"
fi
if [[ ! -z $net_3 ]]; then
net_ids="$net_ids, { net-id: '$net_3' }"
fi
net_ids="$net_ids ]"
cat > $out_file <<-EOF
# job config
selinux: $selinux
packstack_int: whayutin
config:
product: $product
version: $productrelease
repo: $productreleaserepo
netplugin: $netplugin
verbosity:
- info
# OpenStack controller settings, can be set by sourcing a keystonerc file
os_auth_url: '$OS_AUTH_URL'
os_username: $OS_USERNAME
os_password: $OS_PASSWORD
os_tenant_name: $OS_TENANT_NAME
os_network_type: $OS_NETWORK_TYPE
# instance settings
job_name: $job_name
node_prefix: $node_prefix
network_ids: $net_ids
net_2_name: $net_2_name
net_3_name: $net_3_name
image_id: $image_id
ssh_private_key: $key_file
ssh_key_name: $key_name
flavor_id: $flavor_id
floating_network_name: $floating_nw_name
tempest_image_id: $tempest_image_id
tempest_flavor_id: $tempest_flavor_id
tempest_remote_user: $tempest_remote_user
foreman_image_id: $foreman_image_id
foreman_flavor_id: $foreman_flavor_id
foreman_remote_user: $foreman_remote_user
sm_username: $sm_username
sm_password: $sm_password
cleanup_nodes: "{{ nodes }}"
#VM settings
epel_repo: download.fedoraproject.org/pub/epel/6/
gpg_check: 0
ntp_server: clock.redhat.com
reboot_delay: +1
wait_for_boot: $wait_for_boot
update_rpms_tarball: $update_rpms_tarball
# Currently sudo w/ NOPASSWD must be enabled in /etc/sudoers for sudo to work
# running w/ -u $remote_user and -s will override these options
remote_user: $remote_user
tempest:
setup_method: $tempest_setup_method
repo: $tempest_repo
revision: $tempest_branch
checkout_dir: /var/lib/tempest
puppet_file: /tmp/tempest_init.pp
test_name: $tempest_tests
exclude:
files:
- test_server_rescue
- test_server_actions
- test_load_balancer
- test_vpnaas_extensions
tests:
- test_rescue_unrescue_instance
- test_create_get_delete_object
- test_create_volume_from_snapshot
- test_service_provider_list
- test_ec2_
- test_stack_crud_no_resources
- test_stack_list_responds
log_files:
- /var/tmp/packstack
- /root/
- /var/lib/tempest/etc/
- /var/lib/tempest/run.log
- /var/lib/tempest/tempest.log
- /var/lib/tempest/*.log
- /var/lib/tempest/*.xml
- /var/log/
- /etc/nova
- /etc/ceilometer
- /etc/cinder
- /etc/glance
- /etc/keystone
- /etc/neutron
- /etc/ntp
- /etc/puppet
- /etc/qpid
- /etc/qpidd.conf
- /etc/selinux
- /etc/yum.repos.d
EOF
}
fi # FUNCTIONS_SOURCED