update(test): make run_regression_tests.sh script accept different

options

The following options have been added:
* -v (verbose)
* -p (prepare falco_traces test suite)
* -b (specify custom branch for downloading trace files)
* -d (specify the build directory)

Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
This commit is contained in:
Leonardo Di Donato 2020-07-14 13:33:39 +00:00 committed by poiana
parent 8f07189ede
commit bb1282c7be
3 changed files with 97 additions and 48 deletions

View File

@ -20,17 +20,17 @@ set -euo pipefail
BUILD_DIR=$1 BUILD_DIR=$1
SCRIPT=$(readlink -f $0) SCRIPT=$(readlink -f $0)
SCRIPTDIR=$(dirname $SCRIPT) SCRIPTDIR=$(dirname "$SCRIPT")
RUNNERDIR="${SCRIPTDIR}/runner" RUNNERDIR="${SCRIPTDIR}/runner"
FALCO_VERSION=$(cat ${BUILD_DIR}/userspace/falco/config_falco.h | grep 'FALCO_VERSION ' | cut -d' ' -f3 | sed -e 's/^"//' -e 's/"$//') FALCO_VERSION=$(cat ${BUILD_DIR}/userspace/falco/config_falco.h | grep 'FALCO_VERSION ' | cut -d' ' -f3 | sed -e 's/^"//' -e 's/"$//')
DRIVER_VERSION=$(cat ${BUILD_DIR}/userspace/falco/config_falco.h | grep 'DRIVER_VERSION ' | cut -d' ' -f3 | sed -e 's/^"//' -e 's/"$//') DRIVER_VERSION=$(cat ${BUILD_DIR}/userspace/falco/config_falco.h | grep 'DRIVER_VERSION ' | cut -d' ' -f3 | sed -e 's/^"//' -e 's/"$//')
FALCO_PACKAGE="falco-${FALCO_VERSION}-x86_64.tar.gz" FALCO_PACKAGE="falco-${FALCO_VERSION}-x86_64.tar.gz"
cp "${BUILD_DIR}/${FALCO_PACKAGE}" "${RUNNERDIR}" cp "${BUILD_DIR}/${FALCO_PACKAGE}" "${RUNNERDIR}"
pushd ${RUNNERDIR} pushd "${RUNNERDIR}"
docker build --build-arg FALCO_VERSION="$FALCO_VERSION" \ docker build --build-arg FALCO_VERSION="$FALCO_VERSION" \
-t falcosecurity/falco:test-driver-loader \ -t falcosecurity/falco:test-driver-loader \
-f "${RUNNERDIR}/Dockerfile" ${RUNNERDIR} -f "${RUNNERDIR}/Dockerfile" "${RUNNERDIR}"
popd popd
rm -f "${RUNNERDIR}/${FALCO_PACKAGE}" rm -f "${RUNNERDIR}/${FALCO_PACKAGE}"

View File

@ -1,5 +1,5 @@
# #
# Copyright (C) 2019 The Falco Authors. # Copyright (C) 2020 The Falco Authors.
# #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# #
# Copyright (C) 2019 The Falco Authors. # Copyright (C) 2020 The Falco Authors.
# #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
@ -18,45 +18,46 @@
set -euo pipefail set -euo pipefail
SCRIPT=$(readlink -f $0) SCRIPT=$(readlink -f $0)
SCRIPTDIR=$(dirname $SCRIPT) SCRIPTDIR=$(dirname "$SCRIPT")
BUILD_DIR=$1
BRANCH=${2:-none}
TRACE_DIR=$BUILD_DIR/test
mkdir -p $TRACE_DIR
function download_trace_files() { function download_trace_files() {
echo "branch=$BRANCH"
for TRACE in traces-positive traces-negative traces-info ; do for TRACE in traces-positive traces-negative traces-info ; do
if [ ! -e $TRACE_DIR/$TRACE ]; then if [ ! -e "$TRACE_DIR/$TRACE" ]; then
if [ $BRANCH != "none" ]; then if [ "$OPT_BRANCH" != "none" ]; then
curl -fso $TRACE_DIR/$TRACE.zip https://s3.amazonaws.com/download.draios.com/falco-tests/$TRACE-$BRANCH.zip curl -fso "$TRACE_DIR/$TRACE.zip" https://s3.amazonaws.com/download.draios.com/falco-tests/$TRACE-$OPT_BRANCH.zip
else else
curl -fso $TRACE_DIR/$TRACE.zip https://s3.amazonaws.com/download.draios.com/falco-tests/$TRACE.zip curl -fso "$TRACE_DIR/$TRACE.zip" https://s3.amazonaws.com/download.draios.com/falco-tests/$TRACE.zip
fi fi
unzip -d $TRACE_DIR $TRACE_DIR/$TRACE.zip unzip -d "$TRACE_DIR" "$TRACE_DIR/$TRACE.zip"
rm -rf $TRACE_DIR/$TRACE.zip rm -rf "$TRACE_DIR/$TRACE.zip"
fi else
if ${OPT_VERBOSE}; then
echo "Trace directory $TRACE_DIR/$TRACE already exist: skipping"
fi
fi
done done
} }
function prepare_multiplex_fileset() { function prepare_multiplex_fileset() {
dir=$1 dir=$1
detect=$2 detect=$2
for trace in $TRACE_DIR/$dir/*.scap ; do for trace in "$TRACE_DIR/$dir"/*.scap ; do
[ -e "$trace" ] || continue [ -e "$trace" ] || continue
NAME=`basename $trace .scap` NAME=$(basename "$trace" .scap)
# falco_traces.yaml might already have an entry for this trace # falco_traces.yaml might already have an entry for this trace file, with specific detection levels and counts.
# file, with specific detection levels and counts. If so, skip # If so, skip it.
# it. Otherwise, add a generic entry showing whether or not to # Otherwise, add a generic entry showing whether or not to detect anything.
# detect anything. if grep -q "$NAME:" "$SCRIPTDIR/falco_traces.yaml"; then
grep -q "$NAME:" $SCRIPTDIR/falco_traces.yaml && continue if ${OPT_VERBOSE}; then
echo "Entry $NAME already exist: skipping"
fi
continue
fi
cat << EOF >> "$SCRIPTDIR/falco_traces.yaml"
cat << EOF >> $SCRIPTDIR/falco_traces.yaml
$NAME: $NAME:
detect: $detect detect: $detect
detect_level: WARNING detect_level: WARNING
@ -66,41 +67,89 @@ EOF
} }
function prepare_multiplex_file() { function prepare_multiplex_file() {
cp $SCRIPTDIR/falco_traces.yaml.in $SCRIPTDIR/falco_traces.yaml cp "$SCRIPTDIR/falco_traces.yaml.in" "$SCRIPTDIR/falco_traces.yaml"
prepare_multiplex_fileset traces-positive True prepare_multiplex_fileset traces-positive True
prepare_multiplex_fileset traces-negative False prepare_multiplex_fileset traces-negative False
prepare_multiplex_fileset traces-info True prepare_multiplex_fileset traces-info True
echo "Contents of $SCRIPTDIR/falco_traces.yaml:" if ${OPT_VERBOSE}; then
cat $SCRIPTDIR/falco_traces.yaml echo "Contents of $SCRIPTDIR/falco_traces.yaml"
cat "$SCRIPTDIR/falco_traces.yaml"
fi
} }
function print_test_failure_details() { function print_test_failure_details() {
echo "Showing full job logs for any tests that failed:" echo "Showing full job logs for any tests that failed:"
jq '.tests[] | select(.status != "PASS") | .logfile' $SCRIPTDIR/job-results/latest/results.json | xargs cat jq '.tests[] | select(.status != "PASS") | .logfile' "$SCRIPTDIR/job-results/latest/results.json" | xargs cat
} }
function run_tests() { function run_tests() {
rm -rf /tmp/falco_outputs rm -rf /tmp/falco_outputs
mkdir /tmp/falco_outputs mkdir /tmp/falco_outputs
# If we got this far, we can undo set -e, as we're watching the # If we got this far, we can undo set -e,
# return status when running avocado. # as we're watching the return status when running avocado.
set +e set +e
TEST_RC=0 TEST_RC=0
for mult in $SCRIPTDIR/falco_traces.yaml $SCRIPTDIR/falco_tests.yaml $SCRIPTDIR/falco_tests_package.yaml $SCRIPTDIR/falco_k8s_audit_tests.yaml $SCRIPTDIR/falco_tests_psp.yaml; do for mult in $SCRIPTDIR/falco_traces.yaml $SCRIPTDIR/falco_tests.yaml $SCRIPTDIR/falco_tests_package.yaml $SCRIPTDIR/falco_k8s_audit_tests.yaml $SCRIPTDIR/falco_tests_psp.yaml; do
CMD="avocado run --mux-yaml $mult --job-results-dir $SCRIPTDIR/job-results -- $SCRIPTDIR/falco_test.py" CMD="avocado run --mux-yaml $mult --job-results-dir $SCRIPTDIR/job-results -- $SCRIPTDIR/falco_test.py"
echo "Running: $CMD" echo "Running $CMD"
BUILD_DIR=${BUILD_DIR} $CMD BUILD_DIR=${OPT_BUILD_DIR} $CMD
RC=$? RC=$?
TEST_RC=$((TEST_RC+$RC)) TEST_RC=$((TEST_RC+RC))
if [ $RC -ne 0 ]; then if [ $RC -ne 0 ]; then
print_test_failure_details print_test_failure_details
fi fi
done done
} }
OPT_ONLY_PREPARE="false"
OPT_VERBOSE="false"
OPT_BUILD_DIR="$(dirname "$SCRIPTDIR")/build"
OPT_BRANCH="none"
while getopts ':p :v :b: :d:' 'OPTKEY'; do
case ${OPTKEY} in
'p')
OPT_ONLY_PREPARE="true"
;;
'v')
OPT_VERBOSE="true"
;;
'd')
OPT_BUILD_DIR=${OPTARG}
;;
'b')
OPT_BRANCH=${OPTARG}
;;
'?')
echo "Invalid option -- ${OPTARG}" >&2
exit 1
;;
':')
echo "Missing argument for option -- ${OPTARG}" >&2
exit 1
;;
*)
echo "Unimplemented option -- ${OPTKEY}" >&2
exit 1
;;
esac
done
TRACE_DIR=$OPT_BUILD_DIR/test
if ${OPT_VERBOSE}; then
echo "Build directory = $OPT_BUILD_DIR"
echo "Trace directory = $TRACE_DIR (creating...)"
echo "Custom branch = $OPT_BRANCH"
fi
mkdir -p "$TRACE_DIR"
download_trace_files download_trace_files
prepare_multiplex_file prepare_multiplex_file
run_tests
exit $TEST_RC if ! ${OPT_ONLY_PREPARE}; then
run_tests
exit $TEST_RC
fi