forked from Telmate/proxmox-api-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testsetups
99 lines (82 loc) · 2.91 KB
/
testsetups
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
#!/bin/bash
# TEST SETUP FUNCTIONS
# These functions perform housekeeping around the go test actions, adding logics
# needed for sequencing, combination, dependency, and interaction with the shell.
#
# Their names must begin with $setup_prefix, followed by the name of an action
# defined in the testActions Go map. $setup_prefix is defined in CONFIGURATION,
# in runtests.sh
#
# They generally:
# - receive (currently) a single parameter from runSequence: the number of
# times each one has been called
# - obtain the target action name as a parameter or by reading their own name
# - prepare any inputs and perform any interactions needed before the call
# - run the target action through runAction (or fake the run, or omit it)
# - read any outputs and perform any interactions needed after a test action
# - call setActionResult to conclude something about what was tested
# - return back the setActionResult exit status
# Generic setups - these capture common behaviour
testsetup_null() {
return
}
testsetup_stub() {
local target=${FUNCNAME[1]##*${setup_prefix}}
debugMessage "SETUP TARGET: $target"
setActionResult $target STUB
}
# FIXME: be able to accept target and flags from handlers
testsetup_simple() {
local target="${FUNCNAME[1]##*${setup_prefix}}"
# if caller is not a setup handler the target comes in the first argument
if [[ "$target" == "${FUNCNAME[1]}" ]]; then
target="$1" ; shift
fi
debugMessage "SETUP TARGET: $target"
runAction $target $@
setActionResult $target $?
}
testsetup_loop_vm() {
local target="${FUNCNAME[1]##*${setup_prefix}}" ; debugMessage "SETUP TARGET: $target"
local message="$1"
[[ -n $message ]] && echo "$message"
local flags result
for vmid in "${!vms[@]}"; do
flags="-vmid ${vmid}"
runAction $flags $target
result=$?
setActionResult $target $result
(( result )) && break
done
return $result
}
testsetup_loop_node() {
local target="${FUNCNAME[1]##*${setup_prefix}}" ; debugMessage "SETUP TARGET: $target"
local message="$1"
[[ -n $message ]] && echo "$message"
local result node
for node in "${nodes[@]}"; do
runAction $target $node
result=$?
setActionResult $target $result
(( result )) && break
done
return $result
}
testsetup_loop_storage() {
local target="${FUNCNAME[1]##*${setup_prefix}}" ; debugMessage "SETUP TARGET: $target"
local message="$1"
[[ -n $message ]] && echo "$message"
local result storage
for storage in "${storages[@]}"; do
runAction $target $storage
result=$?
setActionResult $target $result
(( result )) && break
done
return $result
}
# Concrete setups - these map to a single target Go test action to perform
for unit in node storage vm vmdevice configlxc configqemu client session; do
. "$scriptdir/testsetups_$unit"
done