-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathngcp-system-tests
executable file
·113 lines (97 loc) · 2.2 KB
/
ngcp-system-tests
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
#!/bin/bash
set -e
set -E
declare -r ME="$(basename "$0")"
declare -r OPTS=("$@")
declare -a PROVE_OPTS=()
NGCP_TESTS_MODE=${NGCP_TESTS_MODE:=prove}
error() {
if [ "${NGCP_TESTS_MODE}" = 'tap' ]; then
echo "Bail out! $*" >&2
else
echo "$ME: error: $*" >&2
fi
exit 1
}
usage() {
cat <<HELP
Usage: ${ME} [<option>...]
Options:
--mode <name> Operation mode to use. Values: jenkins, tap, prove.
-h, --help Print this help message and exit.
HELP
}
get_options() {
local _cmdline_opts="help,mode:"
local _opt_temp
_opt_temp=$(getopt -n "${ME}" -o 'h' -l "${_cmdline_opts}" -- "${OPTS[@]}")
eval set -- "${_opt_temp}"
while :; do
case "$1" in
--help|-h)
usage
exit 0
;;
--mode)
shift
NGCP_TESTS_MODE="$1"
;;
--)
shift
break
;;
*)
error "Internal getopt error! $1"
;;
esac
shift
done
PROVE_OPTS=("$@")
}
if ! [ -d /etc/ngcp-system-tests/ ]; then
error "Missing system test suite files, please run 'ngcpcfg build'"
fi
get_options "$@"
case "${NGCP_TESTS_MODE}" in
jenkins)
export GOSS_NOCOLOR=true
$0 --mode=tap
;;
prove)
export NGCP_TESTS_MODE=tap
prove "${PROVE_OPTS[@]}" -f "$0"
;;
*)
DEBIAN_RELEASE=$(sed -e 's/\([0-9]*\)\..*/\1/' /etc/debian_version)
# Translate Debian codenames that don't have a version number (yet) into
# according numbers
case "${DEBIAN_RELEASE}" in
bullseye*)
DEBIAN_RELEASE=11
;;
bookworm*)
DEBIAN_RELEASE=12
;;
trixie*)
DEBIAN_RELEASE=13
;;
esac
export DEBIAN_RELEASE
# Use an actual variable so that the values do not evaluate as strings,
# and thus as always true.
if [ "$(ngcp-check-active -v)" = 'active' ]; then
NODE_ACTIVE=true
else
NODE_ACTIVE=false
fi
VARS=$(mktemp --tmpdir ngcp-system-tests.XXXXXXXXXX.yaml)
trap 'rm -f "${VARS}"' EXIT
cat >"${VARS}" <<-EOF
SKIP_DNS_CHECK_TEST: ${SKIP_DNS_CHECK_TEST:-false}
NODE_ACTIVE: ${NODE_ACTIVE}
EOF
PLAN='/etc/ngcp-system-tests/goss.yaml'
goss --gossfile "${PLAN}" --vars "${VARS}" \
validate --format "${NGCP_TESTS_MODE}"
;;
esac