From bf3ce384e5a84ffbbc08d6b63d8ff764a3a62626 Mon Sep 17 00:00:00 2001 From: Kay0u Date: Tue, 12 Oct 2021 18:09:08 +0200 Subject: [PATCH 1/5] handle multi worker --- lib/common.sh | 5 +++-- lib/tests_coordination.sh | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/common.sh b/lib/common.sh index 931db29..9663a64 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -14,10 +14,11 @@ DIST=${DIST:-buster} # Yunohost version: stable, testing or unstable YNH_BRANCH=${YNH_BRANCH:-stable} +WORKER_ID=${WORKER_ID:-0} LXC_BASE="ynh-appci-$DIST-$ARCH-$YNH_BRANCH-base" -LXC_NAME="ynh-appci-$DIST-$ARCH-$YNH_BRANCH-test" +LXC_NAME="ynh-appci-$DIST-$ARCH-$YNH_BRANCH-test-${WORKER_ID}" -readonly lock_file="./pcheck.lock" +readonly lock_file="./pcheck-${WORKER_ID}.lock" DEFAULT_PHP_VERSION="7.3" [[ "$DIST" == "bullseye" ]] && DEFAULT_PHP_VERSION="7.4" diff --git a/lib/tests_coordination.sh b/lib/tests_coordination.sh index 1e81022..9861f03 100644 --- a/lib/tests_coordination.sh +++ b/lib/tests_coordination.sh @@ -4,7 +4,7 @@ source lib/lxc.sh source lib/tests.sh source lib/witness.sh -complete_log="./Complete.log" +readonly complete_log="./Complete-${LXC_NAME}.log" # Purge some log files rm -f "$complete_log" && touch "$complete_log" @@ -295,7 +295,7 @@ run_all_tests() { # Print the final results of the tests log_title "Tests summary" - python3 lib/analyze_test_results.py $TEST_CONTEXT 2>./results.json + python3 lib/analyze_test_results.py $TEST_CONTEXT 2> ./results-${LXC_NAME}.json [[ -e "$TEST_CONTEXT/summary.png" ]] && cp "$TEST_CONTEXT/summary.png" ./summary.png || rm -f summary.png # Restore the started time for the timer From ef2c602d4a1b5e0086e847dc24bf51b2e7c21afc Mon Sep 17 00:00:00 2001 From: Kay0u Date: Wed, 13 Oct 2021 13:26:57 +0200 Subject: [PATCH 2/5] curl_print in TEST_CONTEXT folder --- lib/tests.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/tests.sh b/lib/tests.sh index 267bd4f..6a457e7 100644 --- a/lib/tests.sh +++ b/lib/tests.sh @@ -196,7 +196,7 @@ _VALIDATE_THAT_APP_CAN_BE_ACCESSED () { --write-out "%{http_code};%{url_effective}\n" \ --output "$curl_output" \ $check_domain$curl_check_path \ - > "./curl_print" + > "$TEST_CONTEXT/curl_print" # Analyze the result of curl command if [ $? -ne 0 ] @@ -205,7 +205,7 @@ _VALIDATE_THAT_APP_CAN_BE_ACCESSED () { curl_error=1 fi - http_code=$(cat "./curl_print" | cut -d ';' -f1) + http_code=$(cat "$TEST_CONTEXT/curl_print" | cut -d ';' -f1) log_debug "HTTP code: $http_code" @@ -245,7 +245,7 @@ _VALIDATE_THAT_APP_CAN_BE_ACCESSED () { fi echo -e "Test URL: $check_domain$curl_check_path -Real URL: $(cat "./curl_print" | cut --delimiter=';' --fields=2) +Real URL: $(cat "$TEST_CONTEXT/curl_print" | cut --delimiter=';' --fields=2) HTTP code: $http_code Page title: $page_title Page extract:\n$page_extract" > $TEST_CONTEXT/curl_result From 5c42ae077490e072e8e706c4414d80b990df58c0 Mon Sep 17 00:00:00 2001 From: Kay0u Date: Wed, 13 Oct 2021 14:56:04 +0200 Subject: [PATCH 3/5] change LXC_NAME to WORKER_ID for logs and results --- lib/tests_coordination.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tests_coordination.sh b/lib/tests_coordination.sh index 9861f03..70d748c 100644 --- a/lib/tests_coordination.sh +++ b/lib/tests_coordination.sh @@ -4,7 +4,7 @@ source lib/lxc.sh source lib/tests.sh source lib/witness.sh -readonly complete_log="./Complete-${LXC_NAME}.log" +readonly complete_log="./Complete-${WORKER_ID}.log" # Purge some log files rm -f "$complete_log" && touch "$complete_log" @@ -295,7 +295,7 @@ run_all_tests() { # Print the final results of the tests log_title "Tests summary" - python3 lib/analyze_test_results.py $TEST_CONTEXT 2> ./results-${LXC_NAME}.json + python3 lib/analyze_test_results.py $TEST_CONTEXT 2> ./results-${WORKER_ID}.json [[ -e "$TEST_CONTEXT/summary.png" ]] && cp "$TEST_CONTEXT/summary.png" ./summary.png || rm -f summary.png # Restore the started time for the timer From 9f6cc8dceb4096040ec581e972c8db878c111286 Mon Sep 17 00:00:00 2001 From: Kay0u Date: Wed, 13 Oct 2021 14:56:26 +0200 Subject: [PATCH 4/5] run curl in lxc --- lib/tests.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/tests.sh b/lib/tests.sh index 6a457e7..7d126ad 100644 --- a/lib/tests.sh +++ b/lib/tests.sh @@ -187,16 +187,18 @@ _VALIDATE_THAT_APP_CAN_BE_ACCESSED () { log_debug "Running curl $check_domain$curl_check_path" # Call cURL to try to access to the URL of the app - curl --location --insecure --silent --show-error \ - --header "Host: $check_domain" \ + LXC_EXEC "curl --location --insecure --silent --show-error \ + --header 'Host: $check_domain' \ --resolve $DOMAIN:80:$LXC_IP \ --resolve $DOMAIN:443:$LXC_IP \ --resolve $SUBDOMAIN:80:$LXC_IP \ --resolve $SUBDOMAIN:443:$LXC_IP \ - --write-out "%{http_code};%{url_effective}\n" \ - --output "$curl_output" \ - $check_domain$curl_check_path \ + --write-out '%{http_code};%{url_effective}\n' \ + --output './curl_output' \ + $check_domain$curl_check_path" \ > "$TEST_CONTEXT/curl_print" + + LXC_EXEC "cat ./curl_output" > $curl_output # Analyze the result of curl command if [ $? -ne 0 ] From 03b82bf1c80d57b0696d0182231efe9931b5db3e Mon Sep 17 00:00:00 2001 From: Kay0u Date: Wed, 13 Oct 2021 16:51:03 +0200 Subject: [PATCH 5/5] displays the location to help debug if there is a problem when launching the container --- lib/lxc.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/lxc.sh b/lib/lxc.sh index f7b3049..03fcb97 100644 --- a/lib/lxc.sh +++ b/lib/lxc.sh @@ -25,7 +25,12 @@ LXC_CREATE () { else log_critical "Can't find base image $LXC_BASE, run ./package_check.sh --rebuild" fi - [[ "${PIPESTATUS[0]}" -eq 0 ]] || exit 1 + + pipestatus="${PIPESTATUS[0]}" + location=$(lxc list --format json | jq -e --arg LXC_NAME $LXC_NAME '.[] | select(.name==$LXC_NAME) | .location' | tr -d '"') + [[ "$location" != "none" ]] && log_info "... on $location" + + [[ "$pipestatus" -eq 0 ]] || exit 1 _LXC_START_AND_WAIT $LXC_NAME set_witness_files