From aac6226d4feab10e676e4a201e33f6997eb6ac12 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sat, 12 Dec 2020 01:38:05 +0100 Subject: [PATCH] Moar fiksize --- package_check.sh | 46 +++++++++++++++------------------- sub_scripts/launcher.sh | 6 +++-- sub_scripts/lxc_build.sh | 4 +-- sub_scripts/lxc_remove.sh | 2 +- sub_scripts/testing_process.sh | 28 +++++++++++---------- 5 files changed, 42 insertions(+), 44 deletions(-) diff --git a/package_check.sh b/package_check.sh index f82ef63..fb7cdad 100755 --- a/package_check.sh +++ b/package_check.sh @@ -290,7 +290,7 @@ COMPUTE_RESULTS_SUMMARY () { echo -e "\n\n" print_result "Package linter" $RESULT_linter print_result "Install (root)" $RESULT_check_root - print_result "Install (subpath)" $RESULT_check_sub_dir + print_result "Install (subpath)" $RESULT_check_subdir print_result "Install (no url)" $RESULT_check_nourl print_result "Install (private mode)" $RESULT_check_private print_result "Install (public mode)" $RESULT_check_public @@ -325,14 +325,14 @@ COMPUTE_RESULTS_SUMMARY () { test -n "${level[10]}" || level[10]=0 pass_level_1() { - # -> The package can be install and remove. - [ $RESULT_global_setup -eq 1 ] && \ + # FIXME FIXME #FIXME + return 0 } pass_level_2() { # -> The package can be install and remove in all tested configurations. # Validated if none install failed - [ $RESULT_check_sub_dir -ne -1 ] && \ + [ $RESULT_check_subdir -ne -1 ] && \ [ $RESULT_check_root -ne -1 ] && \ [ $RESULT_check_private -ne -1 ] && \ [ $RESULT_check_public -ne -1 ] && \ @@ -378,11 +378,7 @@ COMPUTE_RESULTS_SUMMARY () { pass_level_7() { # -> None errors in all tests performed # Validated if none errors is happened. - [ $RESULT_global_setup -ne -1 ] && \ - [ $RESULT_global_remove -ne -1 ] && \ - [ $RESULT_check_sub_dir -ne -1 ] && \ - [ $RESULT_check_remove_sub_dir -ne -1 ] && \ - [ $RESULT_check_remove_root -ne -1 ] && \ + [ $RESULT_check_subdir -ne -1 ] && \ [ $RESULT_check_upgrade -ne -1 ] && \ [ $RESULT_check_private -ne -1 ] && \ [ $RESULT_check_public -ne -1 ] && \ @@ -508,7 +504,7 @@ RESULT_linter_level_6=0 RESULT_linter_level_7=0 RESULT_linter_level_8=0 RESULT_linter_broken=0 -RESULT_check_sub_dir=0 +RESULT_check_subdir=0 RESULT_check_root=0 RESULT_check_nourl=0 RESULT_check_upgrade=0 @@ -572,10 +568,11 @@ parse_check_process() { # Extract the Upgrade infos extract_check_process_section "^;;; Upgrade options" ";; " > $TEST_CONTEXT/check_process.upgrade_options - mkdir -p $TEST_CONTEXT/upgrades.d + mkdir -p $TEST_CONTEXT/upgrades + local commit for commit in $(cat $TEST_CONTEXT/check_process.upgrade_options | grep "^; commit=.*" | awk -F= '{print $2}') do - cat $TEST_CONTEXT/check_process.upgrade_options | sed -n -e "/^;; $commit/,/^;;/ p" | grep -v "^;;" > $TEST_CONTEXT/upgrades + cat $TEST_CONTEXT/check_process.upgrade_options | sed -n -e "/^;; $commit/,/^;;/ p" | grep -v "^;;" > $TEST_CONTEXT/upgrades/$commit done rm $TEST_CONTEXT/check_process.upgrade_options @@ -608,19 +605,11 @@ parse_check_process() { # Find the line for the given check option local value=$(grep -m1 -o "^$1=." "$test_serie_dir/check_process.tests_infos" | awk -F= '{print $2}') # And return this value - if [ "${value:0:1}" = "1" ] - then - echo 1 - elif [ "${value:0:1}" = "0" ] - then - echo 0 - else - echo -1 - fi + [ "${value:0:1}" = "1" ] } is_test_enabled pkg_linter && echo "PACKAGE_LINTER" >> $test_serie_dir/tests_to_perform - is_test_enabled setup_sub_dir && echo "TEST_INSTALL subdir " >> $test_serie_dir/tests_to_perform + is_test_enabled setup_sub_dir && echo "TEST_INSTALL subdir" >> $test_serie_dir/tests_to_perform is_test_enabled setup_root && echo "TEST_INSTALL root" >> $test_serie_dir/tests_to_perform is_test_enabled setup_nourl && echo "TEST_INSTALL nourl" >> $test_serie_dir/tests_to_perform is_test_enabled setup_private && echo "TEST_PUBLIC_PRIVATE private" >> $test_serie_dir/tests_to_perform @@ -629,13 +618,13 @@ parse_check_process() { is_test_enabled backup_restore && echo "TEST_BACKUP_RESTORE" >> $test_serie_dir/tests_to_perform # Upgrades - - for LINE in $(grep "^upgrade=1" "$test_serie_dir/check_process.tests_infos") + grep "^upgrade=1" "$test_serie_dir/check_process.tests_infos" | + while IFS= read -r LINE; do commit=$(echo $LINE | grep -o "from_commit=.*" | awk -F= '{print $2}') [ -n "$commit" ] || commit="current" echo "TEST_UPGRADE $commit" >> $test_serie_dir/tests_to_perform - done + done # "Advanced" features @@ -654,8 +643,11 @@ parse_check_process() { is_test_enabled port_already_use && echo "TEST_PORT_ALREADY_USED $check_port" >> $test_serie_dir/tests_to_perform + cat $test_serie_dir/tests_to_perform + done 3<<< "$(grep "^;; " "$check_process")" + return 0 } guess_test_configuration() { @@ -665,9 +657,11 @@ guess_test_configuration() { local test_serie_id=$(tr -dc A-Za-z0-9 $test_serie_dir/test_serie_name test_series+="$test_serie_id " diff --git a/sub_scripts/launcher.sh b/sub_scripts/launcher.sh index 15840c6..8e22f78 100755 --- a/sub_scripts/launcher.sh +++ b/sub_scripts/launcher.sh @@ -109,7 +109,7 @@ LXC_INIT () { LXC_PURGE_SNAPSHOTS() { LXC_STOP - for SNAP in $(sudo ls $LXC_SNAPSHOTS/snap_*install) + for SNAP in $(sudo ls $LXC_SNAPSHOTS/snap_*install 2>/dev/null) do sudo lxc-snapshot -n $LXC_NAME -d $(basename $SNAP) done @@ -247,11 +247,13 @@ LXC_START () { rsync -rq --delete "$package_path" "$LXC_NAME": >> "$complete_log" 2>&1 # Execute the command given in argument in the container and log its results. - ssh $arg_ssh $LXC_NAME "$cmd; exit $?" | tee -a "$complete_log" + ssh $arg_ssh $LXC_NAME "$cmd" | tee -a "$complete_log" # Store the return code of the command local returncode=${PIPESTATUS[0]} + log_debug "Return code: $return_code" + stop_timer 1 # Return the exit code of the ssh command return $returncode diff --git a/sub_scripts/lxc_build.sh b/sub_scripts/lxc_build.sh index 5463220..150932c 100755 --- a/sub_scripts/lxc_build.sh +++ b/sub_scripts/lxc_build.sh @@ -20,7 +20,7 @@ LXC_BUILD() touch "$lock_file" echo $(whoami) > "./.setup_user" - log_title "Installing dependencies..." + log_title "Installing host dependencies..." DEPENDENCIES="lxc lxctl git curl lynx jq python3-pip debootstrap rsync bridge-utils" sudo apt-get update @@ -128,7 +128,7 @@ EOF fi done - log_title "Update et install aptitude sudo git" + log_title "Installing container dependencies" RUN_INSIDE_LXC apt-get update RUN_INSIDE_LXC apt-get install -y sudo git ssh openssh-server diff --git a/sub_scripts/lxc_remove.sh b/sub_scripts/lxc_remove.sh index aef4ef2..f29f703 100755 --- a/sub_scripts/lxc_remove.sh +++ b/sub_scripts/lxc_remove.sh @@ -28,7 +28,7 @@ sudo rm -f /etc/network/interfaces.d/$LXC_BRIDGE log_title "Suppression de la machine et de son snapshots" sudo lxc-snapshot -n $LXC_NAME -d snap0 -for SNAP in $(sudo ls $LXC_SNAPSHOTS/snap_*install) +for SNAP in $(sudo ls $LXC_SNAPSHOTS/snap_*install 2>/dev/null) do sudo lxc-snapshot -n $LXC_NAME -d $(basename $SNAP) done diff --git a/sub_scripts/testing_process.sh b/sub_scripts/testing_process.sh index ba47718..949b2ee 100755 --- a/sub_scripts/testing_process.sh +++ b/sub_scripts/testing_process.sh @@ -17,7 +17,7 @@ break_before_continue () { start_test () { - total_number_of_test=$(grep -c "=1$" $test_serie_dir/tests_to_perform) + total_number_of_test=$(cat $test_serie_dir/tests_to_perform | wc -l) log_title "$1 [Test $current_test_number/$total_number_of_test]" @@ -57,7 +57,7 @@ GET_RESULT() { at_least_one_install_succeeded () { - [ "$(GET_RESULT check_sub_dir)" -eq 1 ] \ + [ "$(GET_RESULT check_subdir)" -eq 1 ] \ || [ "$(GET_RESULT check_root)" -eq 1 ] \ || [ "$(GET_RESULT check_nourl)" -eq 1 ] \ || { log_error "All installs failed, therefore the following tests cannot be performed..."; @@ -67,12 +67,12 @@ at_least_one_install_succeeded () { this_is_a_web_app () { # Usually the fact that we test "nourl" # installs should be a good indicator for this - grep "TEST_INSTALL nourl" $test_serie_dir/tests_to_perform && return 1 + grep -q "TEST_INSTALL nourl" $test_serie_dir/tests_to_perform && return 1 } default_install_path() { - this_is_a_web_app && echo "" - || [ "$(GET_RESULT check_sub_dir)" -eq 1 ] && echo "/path " + this_is_a_web_app && echo "" \ + || [ "$(GET_RESULT check_subdir)" -eq 1 ] && echo "/path " \ || echo "/" } @@ -86,7 +86,7 @@ INSTALL_APP () { # We have default values for domain, user and is_public, but these # may still be overwritten by the args ($@) - for arg_override in "domain=$SUBDOMAIN" "user=$TEST_USER" "is_public=1" "$@" + for arg_override in "domain=$SUBDOMAIN" "admin=$TEST_USER" "user=$TEST_USER" "is_public=1" "$@" do key="$(echo $arg_override | cut -d '=' -f 1)" value="$(echo $arg_override | cut -d '=' -f 2-)" @@ -95,7 +95,7 @@ INSTALL_APP () { # Exec the pre-install instruction, if there one preinstall_script_template="$test_serie_dir/preinstall.sh.template" - if [ -n "$(cat $preinstall_script_template)" ] + if [ -e "$preinstall_script_template" ] && [ -n "$(cat $preinstall_script_template)" ] then log_small_title "Pre installation request" # Start the lxc container @@ -346,8 +346,8 @@ TEST_INSTALL () { # Remove and reinstall the application [ $install -eq 0 ] \ - && log_small_title "Remove and reinstall the application after a removal." \ && REMOVE_APP \ + && log_small_title "Reinstalling after removal." \ && INSTALL_APP "path=$check_path" \ && VALIDATE_THAT_APP_CAN_BE_ACCESSED $SUBDOMAIN $check_path @@ -362,6 +362,8 @@ TEST_INSTALL () { TEST_UPGRADE () { + local commit=$1 + if [ "$commit" == "current" ] then start_test "Upgrade from the same version" @@ -464,7 +466,7 @@ TEST_PUBLIC_PRIVATE () { elif [ $i -eq 1 ] then # Check if sub path installation worked, or if force_install_ok is setted. - [ $(GET_RESULT check_sub_dir) -eq 1 ] || { log_warning "Sub path install failed, therefore this test cannot be performed..."; continue; } + [ $(GET_RESULT check_subdir) -eq 1 ] || { log_warning "Sub path install failed, therefore this test cannot be performed..."; continue; } local check_path=/path fi @@ -723,7 +725,7 @@ TEST_CHANGE_URL () { || { log_warning "Root install failed, therefore this test cannot be performed..."; continue; } # If any of the being/end path is not /, we need to have sub_dir install working - ( [ "$new_path" == "/" ] && [ "$new_path" == "/" ] ) || [ $(GET_RESULT check_sub_dir) -eq 1 ] \ + ( [ "$new_path" == "/" ] && [ "$new_path" == "/" ] ) || [ $(GET_RESULT check_subdir) -eq 1 ] \ || { log_warning "Subpath install failed, therefore this test cannot be performed..."; continue; } # Install the application in a LXC container @@ -1227,13 +1229,13 @@ RUN_TEST_SERIE() { # Init the value for the current test current_test_number=1 - # The list of test contains for example "TEST_UPGRADE some_commit_id" - for test in $test_serie_dir/tests_to_perform + # The list of test contains for example "TEST_UPGRADE some_commit_id + readarray -t tests < $test_serie_dir/tests_to_perform + for test in "${tests[@]}"; do TEST_LAUNCHER $test done - } TEST_LAUNCHER () {