f-70: e2e: runner par couche, bibliothèque découpée, nettoyage et assert_clean par test #70
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
c090607785
commit
0932f5d157
9 changed files with 1095 additions and 292 deletions
108
test/e2e/run.sh
108
test/e2e/run.sh
|
|
@ -2,16 +2,22 @@
|
|||
|
||||
LAB_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
LAB_HOST="${LAB_HOST:-${LAB_DIR}/labctl.sh}"
|
||||
SCENARIO_DIR="${SCENARIO_DIR:-${LAB_DIR}/scenarios}"
|
||||
SUITE_DIR="${SUITE_DIR:-${LAB_DIR}/suite}"
|
||||
LIBS=(core vm net evpn fixture)
|
||||
SCENARIO_LOG=""
|
||||
|
||||
usage () {
|
||||
cat >&2 <<USAGE
|
||||
usage: ${0##*/} <scénario>... | all
|
||||
usage: ${0##*/} [--continue] all | --from <NN> | <couche N0>... | <test>...
|
||||
${0##*/} --matrice
|
||||
|
||||
scénarios : $(cd "${SCENARIO_DIR}" && ls -- *.sh | sed 's/\.sh$//' | tr '\n' ' ')
|
||||
tests : $(cd "${SUITE_DIR}" && ls -- *.sh 2>/dev/null | sed 's/\.sh$//' | tr '\n' ' ')
|
||||
|
||||
Chaque scénario s'exécute depuis le Mac sur le lab en cours (labctl.sh up, push, ./labctl up).
|
||||
Chaque test s'exécute depuis le Mac sur le lab en cours (labctl.sh up, push, ./labctl up).
|
||||
Une couche se désigne par son numéro (00, 10, …, 70), un test par son numéro ou son nom.
|
||||
Avant un test, ses ressources t<NN> restantes sont supprimées et l'état de chaque hôte de
|
||||
l'en-tête « # hôtes: » est relevé ; après, ses ressources sont supprimées et l'hôte doit être
|
||||
revenu à cet état. Avec all ou --from, une couche en échec arrête la suite (--continue : non).
|
||||
Une ligne RÉUSSI ou ÉCHOUÉ par vérification ; code de sortie 1 si une vérification échoue ou
|
||||
si aucune n'a été faite.
|
||||
USAGE
|
||||
|
|
@ -19,23 +25,43 @@ USAGE
|
|||
}
|
||||
|
||||
on () {
|
||||
local node="${1}" assignment
|
||||
local node="${1}" assignment lib
|
||||
shift
|
||||
{
|
||||
for assignment in "$@"; do
|
||||
printf 'export %q=%q\n' "${assignment%%=*}" "${assignment#*=}"
|
||||
done
|
||||
cat "${LAB_DIR}/lib/node.sh"
|
||||
for lib in "${LIBS[@]}"; do
|
||||
cat "${LAB_DIR}/lib/${lib}.sh"
|
||||
done
|
||||
cat
|
||||
} | "${LAB_HOST}" ssh "./labctl ssh ${node} 'sudo bash -s'" 2>&1 | tee -a "${SCENARIO_LOG}"
|
||||
}
|
||||
|
||||
header () {
|
||||
sed -n "s/^# ${2}: *//p" "${1}" | head -n 1
|
||||
}
|
||||
|
||||
number () {
|
||||
local name
|
||||
name=$(basename "${1}")
|
||||
echo "${name%%-*}"
|
||||
}
|
||||
|
||||
run_scenario () {
|
||||
local file="${1}" name passed failed
|
||||
local file="${1}" name passed failed host hosts num
|
||||
name="$(basename "${file}" .sh)"
|
||||
num=$(number "${file}")
|
||||
hosts=$(header "${file}" hôtes)
|
||||
SCENARIO_LOG="$(mktemp)"
|
||||
echo "=== ${name}"
|
||||
for host in ${hosts}; do
|
||||
on "${host}" "T=${num}" "HOST=${host}" <<< 'prepare_test'
|
||||
done
|
||||
( . "${file}" )
|
||||
for host in ${hosts}; do
|
||||
on "${host}" "T=${num}" "HOST=${host}" <<< 'finish_test'
|
||||
done
|
||||
passed=$(grep -c '^RÉUSSI: ' "${SCENARIO_LOG}")
|
||||
failed=$(grep -c '^ÉCHOUÉ: ' "${SCENARIO_LOG}")
|
||||
rm -f "${SCENARIO_LOG}"
|
||||
|
|
@ -43,21 +69,63 @@ run_scenario () {
|
|||
[[ "${failed}" -eq 0 && "${passed}" -gt 0 ]]
|
||||
}
|
||||
|
||||
main () {
|
||||
local -a files=()
|
||||
local arg file rc=0
|
||||
[[ $# -gt 0 ]] || usage
|
||||
for arg in "$@"; do
|
||||
if [[ "${arg}" == all ]]; then
|
||||
files+=("${SCENARIO_DIR}"/*.sh)
|
||||
continue
|
||||
fi
|
||||
file=$(ls "${SCENARIO_DIR}/${arg}"*.sh 2>/dev/null | head -n 1)
|
||||
[[ -n "${file}" ]] || { echo "scénario inconnu : ${arg}" >&2; usage; }
|
||||
files+=("${file}")
|
||||
matrix () {
|
||||
local file
|
||||
printf '%s\n' '.. list-table::' ' :header-rows: 1' '' \
|
||||
' * - Test' ' - Fonctionnalité' ' - Hôtes' ' - Tickets'
|
||||
for file in "${SUITE_DIR}"/*.sh; do
|
||||
printf ' * - ``%s``\n - %s\n - %s\n - %s\n' "$(basename "${file}" .sh)" \
|
||||
"$(header "${file}" fonctionnalité)" "$(header "${file}" hôtes)" "$(header "${file}" tickets)"
|
||||
done
|
||||
}
|
||||
|
||||
select_files () {
|
||||
local arg file from=""
|
||||
for arg in "$@"; do
|
||||
if [[ -n "${from}" ]]; then
|
||||
[[ "${arg}" =~ ^[0-9]{2}$ ]] || { echo "--from : numéro à deux chiffres attendu" >&2; return 1; }
|
||||
for file in "${SUITE_DIR}"/*.sh; do
|
||||
[[ "$(number "${file}")" > "${arg}" || "$(number "${file}")" == "${arg}" ]] && echo "${file}"
|
||||
done
|
||||
from=""
|
||||
elif [[ "${arg}" == --from ]]; then
|
||||
from=1
|
||||
elif [[ "${arg}" == all ]]; then
|
||||
ls "${SUITE_DIR}"/*.sh
|
||||
elif [[ "${arg}" =~ ^[0-9]0$ ]]; then
|
||||
ls "${SUITE_DIR}/${arg:0:1}"[0-9]-*.sh 2>/dev/null || { echo "couche vide : ${arg}" >&2; return 1; }
|
||||
else
|
||||
file=$(ls "${SUITE_DIR}/${arg}"*.sh 2>/dev/null | head -n 1)
|
||||
[[ -n "${file}" ]] || { echo "test inconnu : ${arg}" >&2; return 1; }
|
||||
echo "${file}"
|
||||
fi
|
||||
done
|
||||
[[ -z "${from}" ]] || { echo "--from sans numéro" >&2; return 1; }
|
||||
}
|
||||
|
||||
main () {
|
||||
local -a files=() args=()
|
||||
local arg file rc=0 layer="" layer_rc=0 stop=1 sweep=0 out
|
||||
for arg in "$@"; do
|
||||
case "${arg}" in
|
||||
--continue) stop=0 ;;
|
||||
--matrice) matrix; return 0 ;;
|
||||
all|--from) sweep=1; args+=("${arg}") ;;
|
||||
*) args+=("${arg}") ;;
|
||||
esac
|
||||
done
|
||||
[[ ${#args[@]} -gt 0 ]] || usage
|
||||
out=$(select_files "${args[@]}") || usage
|
||||
while IFS= read -r file; do files+=("${file}"); done <<< "${out}"
|
||||
[[ ${#files[@]} -gt 0 && -n "${files[0]}" ]] || usage
|
||||
for file in "${files[@]}"; do
|
||||
run_scenario "${file}" || rc=1
|
||||
[[ "$(number "${file}")" =~ ^[0-9]{2}$ ]] || sweep=0
|
||||
if [[ "${sweep}" -eq 1 && "${stop}" -eq 1 && -n "${layer}" && "$(number "${file}" | cut -c1)" != "${layer}" && "${layer_rc}" -ne 0 ]]; then
|
||||
echo "=== couche ${layer}0 en échec : arrêt de la suite (--continue pour poursuivre)"
|
||||
return 1
|
||||
fi
|
||||
[[ "$(number "${file}" | cut -c1)" != "${layer}" ]] && { layer=$(number "${file}" | cut -c1); layer_rc=0; }
|
||||
run_scenario "${file}" || { rc=1; layer_rc=1; }
|
||||
done
|
||||
return "${rc}"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue