This repository has been archived by the owner on Feb 8, 2021. It is now read-only.
/
test-cmd.sh
executable file
·195 lines (163 loc) · 4.51 KB
/
test-cmd.sh
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
#!/bin/bash
# This command checks that the built commands can function together for
# simple scenarios. It does not require Docker so it can run in travis.
set -o errexit
set -o nounset
set -o pipefail
HYPER_ROOT=$(readlink -f $(dirname "${BASH_SOURCE}")/..)
source "${HYPER_ROOT}/hack/lib/init.sh"
function cleanup()
{
stop_hyperd
rm -rf "${HYPER_TEMP}"
hyper::log::status "Clean up complete"
}
# Executes curl against the proxy. $1 is the path to use, $2 is the desired
# return code. Prints a helpful message on failure.
function check-curl-access-code()
{
local status
local -r address=$1
local -r desired=$2
local -r full_address="${API_HOST}:${API_PORT}${address}"
status=$(curl -w "%{http_code}" --silent --output /dev/null "${full_address}")
if [ "${status}" == "${desired}" ]; then
return 0
fi
echo "For address ${full_address}, got ${status} but wanted ${desired}"
return 1
}
function start_hyperd()
{
config="$1"
sdriver="$2"
if [[ -z "${config}" ]]; then
echo "no configuration file provided!"
return 1
fi
# Start hyperd
hyper::log::status "Starting hyperd"
sudo "${HYPER_OUTPUT_HOSTBIN}/hyperd" \
--host="tcp://127.0.0.1:${API_PORT}" \
--v=3 \
--config="${config}" 1>&2 &
HYPERD_PID=$!
if [ "$sdriver" == "devicemapper" ]; then
echo "waiting hyperd start up"
sleep 600
fi
hyper::util::wait_for_url "http://127.0.0.1:${API_PORT}/info" "hyper-info"
# Check hyperctl
hyper::log::status "Running hyperctl command with no options"
"${HYPER_OUTPUT_HOSTBIN}/hyperctl"
}
function stop_hyperd()
{
if ps --ppid ${HYPERD_PID} > /dev/null 2>&1 ; then
read HYPERD_PID other < <(ps --ppid ${HYPERD_PID}|grep hyperd)
fi
[[ -n "${HYPERD_PID-}" ]] && sudo kill "${HYPERD_PID}" 1>&2 2>/dev/null
t=1
while ps -p ${HYPERD_PID} >/dev/null 2>&1 ; do
echo "wait hyperd(${HYPERD_PID}) stop"
sleep 1
[ $((t++)) -ge 15 ] && break
done
HYPERD_PID=
}
function setup_libvirtd() {
(cat <<EOF
user = "root"
group = "root"
clear_emulator_capabilities = 0
EOF
) | sudo tee /etc/libvirt/qemu.conf
sudo /etc/init.d/libvirt-bin restart
}
hyper::util::trap_add cleanup EXIT SIGINT
hyper::util::ensure-temp-dir
API_PORT=${API_PORT:-12345}
API_HOST=${API_HOST:-127.0.0.1}
HYPER_TEMP=${HYPER_TEMP:-/tmp}
# ensure ~/.hyper/config isn't loaded by tests
HOME="${HYPER_TEMP}"
if [ "x${HYPER_RUNTIME:-}" = "x" ] ; then
# build hyperstart Kernel and Initrd
echo "Build Kernel and Initrd by hyperstart"
hyper::hyperstart::build
else
KERNEL_PATH=${HYPER_RUNTIME}/kernel
INITRD_PATH=${HYPER_RUNTIME}/hyper-initrd.img
fi
runTests() {
execdriver="$1"
stordriver="$2"
echo "Testing hyperd with execdriver: $1, storage driver: $2"
if [ -z "${stordriver}" ]; then
echo "no storage driver provided!"
return 1
else
# add the execdriver and storage driver items into configuration file
cat > ${HYPER_TEMP}/config << __EOF__
Kernel=${KERNEL_PATH}
Initrd=${INITRD_PATH}
StorageDriver=${stordriver}
Hypervisor=${execdriver}
gRPCHost=0.0.0.0:22318
__EOF__
fi
# setup libvirtd
[ "$execdriver" = "libvirt" ] && setup_libvirtd
# Start 'hyperd'
start_hyperd "${HYPER_TEMP}/config" $stordriver
# Passing no arguments to 'create' is an error
! sudo hyperctl create
# Passing no arguments to 'info' is right
sudo hyperctl info
#######################
# API status check #
#######################
######################
# Image management #
######################
hyper::test::check_image busybox || hyper::test::pull_image busybox
hyper::test::check_image busybox
hyper::test::remove_image busybox
! hyper::test::check_image busybox
hyper::test::pull_image busybox
hyper::test::check_image busybox
hyper::test::pull_image "haproxy:1.4"
hyper::test::check_image "haproxy" "1.4"
########################
# gRPC API integration #
########################
hyper::test::integration
###########################
# POD creation / deletion #
###########################
hyper::test::command
hyper::test::exitcode
hyper::test::exec
hyper::test::hostname
hyper::test::insert_file
hyper::test::map_file
hyper::test::with_volume
hyper::test::service
stop_hyperd
}
# devicemapper storage driver takes too much time to init
hyper_storage_drivers=(
"aufs"
)
hyper_exec_drivers=(
""
"qemu"
"libvirt"
)
for sdriver in "${hyper_storage_drivers[@]}"; do
for edriver in "${hyper_exec_drivers[@]}"; do
runTests "${edriver}" "${sdriver}"
done
done
hyper::test::clear_all
hyper::log::status "TEST PASSED"