From 22af2876e6c485d145704bdbf1ece3e97fadf0e7 Mon Sep 17 00:00:00 2001 From: Thilo Fromm Date: Wed, 2 Mar 2022 13:02:52 +0100 Subject: [PATCH 1/2] ci-automation/tapfile_helper_lib.sh: read test output from file This change updates the tapfile helper to read test output from a file instead of passig it inline in the SQL INSERT statement. This fixes an issue with large error output from tests, which breaks tap_ingest_tapfile(): ci-automation/tapfile_helper_lib.sh: line 31: /usr/bin/sqlite3: Argument list too long Error observed with the cl.toolbox.dnf-install test, which can generate 8000 lines of output. Fix tested with the same output. Signed-off-by: Thilo Fromm --- ci-automation/tapfile_helper_lib.sh | 34 +++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/ci-automation/tapfile_helper_lib.sh b/ci-automation/tapfile_helper_lib.sh index 650f11441e..bac12c3006 100644 --- a/ci-automation/tapfile_helper_lib.sh +++ b/ci-automation/tapfile_helper_lib.sh @@ -77,13 +77,14 @@ function __db_init() { # 3: - re-run iteration function tap_ingest_tapfile() { + local tapfile="${1}" local vendor="${2}" local run="${3}" local result="" local test_name="" - local error_message="" + local error_message_file="$(mktemp)" local in_error_message=false if ! [ -f "${TAPFILE_HELPER_DBNAME}" ] ; then @@ -91,7 +92,10 @@ function tap_ingest_tapfile() { fi # 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 has_error_message="false" # Example TAP input: # ok - coreos.auth.verify @@ -112,10 +116,12 @@ function tap_ingest_tapfile() { if $in_error_message ; then if [ "${line}" = "..." ] ; then in_error_message=false + has_error_message="true" else - error_message="$(echo -e "$line" \ - | sed -e 's/^Error: "--- FAIL: /"/' -e 's/^[[:space:]]*//' \ - | sed -e "s/[>\"']/_/g" -e 's/[[:space:]]/ /g')" + echo -e "$line" \ + | sed -e 's/^Error: "--- FAIL: /"/' -e 's/^[[:space:]]*//' \ + | sed -e "s/[>\"']/_/g" -e 's/[[:space:]]/ /g' \ + >> "${error_message_file}" continue fi else @@ -128,18 +134,32 @@ function tap_ingest_tapfile() { fi fi + local test_output="/dev/null" + 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) - VALUES ('${run}','${result}', '${error_message}', + VALUES ('${run}','${result}', readfile('${test_output}'), (SELECT id FROM test_case WHERE name='${test_name}'), (SELECT id FROM vendor WHERE name='${vendor}'));" - error_message="" + + 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" - local SQL="${SQL}COMMIT;" + rm -f "${error_message_file}" + SQL="${SQL}COMMIT;" __sqlite3_wrapper "${SQL}" } # -- From 2b2bfad5e1b501ac4328889a0cc51886870c9a33 Mon Sep 17 00:00:00 2001 From: Thilo Fromm Date: Wed, 2 Mar 2022 15:35:57 +0100 Subject: [PATCH 2/2] ci-automation/tapfile_helper_lib.sh: use subshell, break lines after 200 Signed-off-by: Thilo Fromm --- ci-automation/tapfile_helper_lib.sh | 111 ++++++++++++++-------------- 1 file changed, 57 insertions(+), 54 deletions(-) diff --git a/ci-automation/tapfile_helper_lib.sh b/ci-automation/tapfile_helper_lib.sh index bac12c3006..55589ecde5 100644 --- a/ci-automation/tapfile_helper_lib.sh +++ b/ci-automation/tapfile_helper_lib.sh @@ -84,7 +84,6 @@ function tap_ingest_tapfile() { local result="" local test_name="" - local error_message_file="$(mktemp)" local in_error_message=false if ! [ -f "${TAPFILE_HELPER_DBNAME}" ] ; then @@ -97,67 +96,71 @@ function tap_ingest_tapfile() { 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 - if [ "${line}" = "..." ] ; then - in_error_message=false - has_error_message="true" - else - echo -e "$line" \ - | sed -e 's/^Error: "--- FAIL: /"/' -e 's/^[[:space:]]*//' \ - | sed -e "s/[>\"']/_/g" -e 's/[[:space:]]/ /g' \ - >> "${error_message_file}" + # run the parse loop in a subshell and clean up temporary error message file on exit + ( + local error_message_file="$(mktemp)" + trap "rm -f '${error_message_file}'" EXIT + # 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 - 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 + + if $in_error_message ; then + if [ "${line}" = "..." ] ; then + in_error_message=false + has_error_message="true" + else + 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 - local test_output="/dev/null" - 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}');" + local test_output="/dev/null" + 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) - VALUES ('${run}','${result}', readfile('${test_output}'), - (SELECT id FROM test_case WHERE name='${test_name}'), - (SELECT id FROM vendor WHERE name='${vendor}'));" + SQL="${SQL}INSERT OR REPLACE INTO test_run(run,result,output,case_id,vendor_id) + VALUES ('${run}','${result}', readfile('${test_output}'), + (SELECT id FROM test_case WHERE name='${test_name}'), + (SELECT id FROM vendor WHERE name='${vendor}'));" - 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 + 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" - - rm -f "${error_message_file}" + done < "$tapfile" + ) SQL="${SQL}COMMIT;" __sqlite3_wrapper "${SQL}"