mirror of
https://github.com/flatcar/scripts.git
synced 2025-09-23 06:31:18 +02:00
Merge pull request #242 from flatcar-linux/t-lo/tapfile-helper-fix-test-output
ci-automation/tapfile_helper_lib.sh: read test output from file
This commit is contained in:
commit
c94315eeba
@ -77,13 +77,13 @@ function __db_init() {
|
|||||||
# 3: <run> - re-run iteration
|
# 3: <run> - re-run iteration
|
||||||
|
|
||||||
function tap_ingest_tapfile() {
|
function tap_ingest_tapfile() {
|
||||||
|
|
||||||
local tapfile="${1}"
|
local tapfile="${1}"
|
||||||
local vendor="${2}"
|
local vendor="${2}"
|
||||||
local run="${3}"
|
local run="${3}"
|
||||||
|
|
||||||
local result=""
|
local result=""
|
||||||
local test_name=""
|
local test_name=""
|
||||||
local error_message=""
|
|
||||||
local in_error_message=false
|
local in_error_message=false
|
||||||
|
|
||||||
if ! [ -f "${TAPFILE_HELPER_DBNAME}" ] ; then
|
if ! [ -f "${TAPFILE_HELPER_DBNAME}" ] ; then
|
||||||
@ -91,55 +91,78 @@ function tap_ingest_tapfile() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Wrap all SQL commands in a transaction to speed up INSERTs
|
# Wrap all SQL commands in a transaction to speed up INSERTs
|
||||||
|
# We will commit intermediately if there's an error message to insert so the
|
||||||
|
# error message file can be reused.
|
||||||
local SQL="BEGIN TRANSACTION;"
|
local SQL="BEGIN TRANSACTION;"
|
||||||
|
local has_error_message="false"
|
||||||
|
|
||||||
# Example TAP input:
|
|
||||||
# ok - coreos.auth.verify
|
|
||||||
# ok - coreos.locksmith.tls
|
|
||||||
# not ok - cl.filesystem
|
|
||||||
# ---
|
|
||||||
# Error: "--- FAIL: cl.filesystem/deadlinks (1.86s)\n files.go:90: Dead symbolic links found: [/var/lib/flatcar-oem-gce/usr/lib64/python3.9/site-packages/certifi-3021.3.16-py3.9.egg-info]"
|
|
||||||
# ...
|
|
||||||
# ok - cl.cloudinit.script
|
|
||||||
# ok - kubeadm.v1.22.0.flannel.base
|
|
||||||
while read -r line; do
|
|
||||||
if [[ "${line}" == "1.."* ]] ; then continue; fi
|
|
||||||
if [ "${line}" = "---" ] ; then # note: read removes leading whitespaces
|
|
||||||
in_error_message=true
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
if $in_error_message ; then
|
# run the parse loop in a subshell and clean up temporary error message file on exit
|
||||||
if [ "${line}" = "..." ] ; then
|
(
|
||||||
in_error_message=false
|
local error_message_file="$(mktemp)"
|
||||||
else
|
trap "rm -f '${error_message_file}'" EXIT
|
||||||
error_message="$(echo -e "$line" \
|
# Example TAP input:
|
||||||
| sed -e 's/^Error: "--- FAIL: /"/' -e 's/^[[:space:]]*//' \
|
# ok - coreos.auth.verify
|
||||||
| sed -e "s/[>\"']/_/g" -e 's/[[:space:]]/ /g')"
|
# ok - coreos.locksmith.tls
|
||||||
|
# not ok - cl.filesystem
|
||||||
|
# ---
|
||||||
|
# Error: "--- FAIL: cl.filesystem/deadlinks (1.86s)\n files.go:90: Dead symbolic links found: [/var/lib/flatcar-oem-gce/usr/lib64/python3.9/site-packages/certifi-3021.3.16-py3.9.egg-info]"
|
||||||
|
# ...
|
||||||
|
# ok - cl.cloudinit.script
|
||||||
|
# ok - kubeadm.v1.22.0.flannel.base
|
||||||
|
while read -r line; do
|
||||||
|
if [[ "${line}" == "1.."* ]] ; then continue; fi
|
||||||
|
if [ "${line}" = "---" ] ; then # note: read removes leading whitespaces
|
||||||
|
in_error_message=true
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
test_name="$(echo "${line}" | sed 's/^[^-]* - //')"
|
if $in_error_message ; then
|
||||||
local result_string
|
if [ "${line}" = "..." ] ; then
|
||||||
result_string="$(echo "${line}" | sed 's/ - .*//')"
|
in_error_message=false
|
||||||
result=0
|
has_error_message="true"
|
||||||
if [ "${result_string}" = "ok" ] ; then
|
else
|
||||||
result=1
|
echo -e "$line" \
|
||||||
|
| sed -e 's/^Error: "--- FAIL: /"/' -e 's/^[[:space:]]*//' \
|
||||||
|
-e "s/[>\"']/_/g" -e 's/[[:space:]]/ /g' \
|
||||||
|
-e 's/.\{200\}/&\n/g' \
|
||||||
|
>> "${error_message_file}"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
test_name="$(echo "${line}" | sed 's/^[^-]* - //')"
|
||||||
|
local result_string
|
||||||
|
result_string="$(echo "${line}" | sed 's/ - .*//')"
|
||||||
|
result=0
|
||||||
|
if [ "${result_string}" = "ok" ] ; then
|
||||||
|
result=1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
SQL="${SQL}INSERT OR IGNORE INTO test_case(name) VALUES ('${test_name}');"
|
local test_output="/dev/null"
|
||||||
SQL="${SQL}INSERT OR IGNORE INTO vendor(name) VALUES ('${vendor}');"
|
if [ "${has_error_message}" = "true" ] ; then
|
||||||
|
test_output="${error_message_file}"
|
||||||
|
fi
|
||||||
|
SQL="${SQL}INSERT OR IGNORE INTO test_case(name) VALUES ('${test_name}');"
|
||||||
|
SQL="${SQL}INSERT OR IGNORE INTO vendor(name) VALUES ('${vendor}');"
|
||||||
|
|
||||||
SQL="${SQL}INSERT OR REPLACE INTO test_run(run,result,output,case_id,vendor_id)
|
SQL="${SQL}INSERT OR REPLACE INTO test_run(run,result,output,case_id,vendor_id)
|
||||||
VALUES ('${run}','${result}', '${error_message}',
|
VALUES ('${run}','${result}', readfile('${test_output}'),
|
||||||
(SELECT id FROM test_case WHERE name='${test_name}'),
|
(SELECT id FROM test_case WHERE name='${test_name}'),
|
||||||
(SELECT id FROM vendor WHERE name='${vendor}'));"
|
(SELECT id FROM vendor WHERE name='${vendor}'));"
|
||||||
error_message=""
|
|
||||||
done < "$tapfile"
|
|
||||||
|
|
||||||
local SQL="${SQL}COMMIT;"
|
if [ "${has_error_message}" = "true" ] ; then
|
||||||
|
SQL="${SQL}COMMIT;"
|
||||||
|
__sqlite3_wrapper "${SQL}"
|
||||||
|
truncate --size 0 "${error_message_file}"
|
||||||
|
has_error_message="false"
|
||||||
|
SQL="BEGIN TRANSACTION;"
|
||||||
|
fi
|
||||||
|
|
||||||
|
done < "$tapfile"
|
||||||
|
)
|
||||||
|
|
||||||
|
SQL="${SQL}COMMIT;"
|
||||||
__sqlite3_wrapper "${SQL}"
|
__sqlite3_wrapper "${SQL}"
|
||||||
}
|
}
|
||||||
# --
|
# --
|
||||||
|
Loading…
x
Reference in New Issue
Block a user