Zblerg^8578

This commit is contained in:
Alexandre Aubin 2020-12-17 04:11:36 +01:00
parent cf98294d14
commit 62132f7ed1
4 changed files with 260 additions and 255 deletions

View file

@ -11,7 +11,7 @@ complete_log="./Complete.log"
> "$complete_log" > "$complete_log"
> "./lxc_boot.log" > "./lxc_boot.log"
TEST_CONTEXT=$(mktemp -d) TEST_CONTEXT=$(mktemp -d /tmp/package_check.XXXXXX)
# Redirect fd 3 (=debug steam) to complete log # Redirect fd 3 (=debug steam) to complete log
exec 3>>$complete_log exec 3>>$complete_log
@ -165,7 +165,7 @@ echo "start:$(date +%s):$$" > "$lock_file"
assert_we_are_the_setup_user assert_we_are_the_setup_user
assert_we_are_connected_to_the_internets assert_we_are_connected_to_the_internets
self_upgrade #self_upgrade
fetch_or_upgrade_package_linter fetch_or_upgrade_package_linter
# Reset and create a fresh container to work with # Reset and create a fresh container to work with
@ -176,7 +176,7 @@ LXC_CREATE
# Pick up the package # Pick up the package
#================================================= #=================================================
function FETCH_PACKAGE_TO_TEST() { FETCH_PACKAGE_TO_TEST() {
local path_to_package_to_test="$1" local path_to_package_to_test="$1"
@ -226,7 +226,7 @@ function FETCH_PACKAGE_TO_TEST() {
} }
FETCH_PACKAGE_TO_TEST $path_to_package_to_test FETCH_PACKAGE_TO_TEST $path_to_package_to_test
readonly app_id="$(cat $package_path/manifest.json | jq .id | tr -d '"')" readonly app_id="$(cat $package_path/manifest.json | jq -r .id)"
#================================================= #=================================================
@ -235,223 +235,225 @@ readonly app_id="$(cat $package_path/manifest.json | jq .id | tr -d '"')"
COMPUTE_RESULTS_SUMMARY () { COMPUTE_RESULTS_SUMMARY () {
local test_serie_id=$1 return
source $TEST_CONTEXT/$test_serie_id/results #
# local test_serie_id=$1
# Print the test result # source $TEST_CONTEXT/$test_serie_id/results
print_result () { #
# # Print the test result
# Print the result of this test # print_result () {
# we use printf to force the length to 30 (filled with space) #
testname=$(printf %-30.30s "$1:") # # Print the result of this test
if [ $2 -eq 1 ] # # we use printf to force the length to 30 (filled with space)
then # testname=$(printf %-30.30s "$1:")
echo "$testname ${BOLD}${GREEN}SUCCESS${NORMAL}" # if [ $2 -eq 1 ]
elif [ $2 -eq -1 ] # then
then # echo "$testname ${BOLD}${GREEN}SUCCESS${NORMAL}"
echo "$testname ${BOLD}${RED}FAIL${NORMAL}" # elif [ $2 -eq -1 ]
else # then
echo "$testname Not evaluated." # echo "$testname ${BOLD}${RED}FAIL${NORMAL}"
fi # else
} # echo "$testname Not evaluated."
# fi
# Print the result for each test # }
echo -e "\n\n" #
print_result "Package linter" $RESULT_linter # # Print the result for each test
print_result "Install (root)" $RESULT_check_root # echo -e "\n\n"
print_result "Install (subpath)" $RESULT_check_subdir # print_result "Package linter" $RESULT_linter
print_result "Install (no url)" $RESULT_check_nourl # print_result "Install (root)" $RESULT_check_root
print_result "Install (private)" $RESULT_check_private # print_result "Install (subpath)" $RESULT_check_subdir
print_result "Install (multi-instance)" $RESULT_check_multi_instance # print_result "Install (no url)" $RESULT_check_nourl
print_result "Upgrade" $RESULT_check_upgrade # print_result "Install (private)" $RESULT_check_private
print_result "Backup" $RESULT_check_backup # print_result "Install (multi-instance)" $RESULT_check_multi_instance
print_result "Restore" $RESULT_check_restore # print_result "Upgrade" $RESULT_check_upgrade
print_result "Change URL" $RESULT_change_url # print_result "Backup" $RESULT_check_backup
print_result "Port already used" $RESULT_check_port # print_result "Restore" $RESULT_check_restore
print_result "Actions and config-panel" $RESULT_action_config_panel # print_result "Change URL" $RESULT_change_url
# print_result "Port already used" $RESULT_check_port
# Determine the level for this app # print_result "Actions and config-panel" $RESULT_action_config_panel
#
# Each level can has 5 different values # # Determine the level for this app
# 0 -> If this level can't be validated #
# 1 -> If this level is forced. Even if the tests fails # # Each level can has 5 different values
# 2 -> Indicates the tests had previously validated this level # # 0 -> If this level can't be validated
# auto -> This level has not a value yet. # # 1 -> If this level is forced. Even if the tests fails
# na -> This level will not be checked, but it'll be ignored in the final sum # # 2 -> Indicates the tests had previously validated this level
# # auto -> This level has not a value yet.
# Set default values for level, if they're empty. # # na -> This level will not be checked, but it'll be ignored in the final sum
test -n "${level[1]}" || level[1]=auto #
test -n "${level[2]}" || level[2]=auto # # Set default values for level, if they're empty.
test -n "${level[3]}" || level[3]=auto # test -n "${level[1]}" || level[1]=auto
test -n "${level[4]}" || level[4]=auto # test -n "${level[2]}" || level[2]=auto
test -n "${level[5]}" || level[5]=auto # test -n "${level[3]}" || level[3]=auto
test -n "${level[5]}" || level[5]=auto # test -n "${level[4]}" || level[4]=auto
test -n "${level[6]}" || level[6]=auto # test -n "${level[5]}" || level[5]=auto
test -n "${level[7]}" || level[7]=auto # test -n "${level[5]}" || level[5]=auto
test -n "${level[8]}" || level[8]=auto # test -n "${level[6]}" || level[6]=auto
test -n "${level[9]}" || level[9]=0 # test -n "${level[7]}" || level[7]=auto
test -n "${level[10]}" || level[10]=0 # test -n "${level[8]}" || level[8]=auto
# test -n "${level[9]}" || level[9]=0
pass_level_1() { # test -n "${level[10]}" || level[10]=0
# FIXME FIXME #FIXME #
return 0 # pass_level_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 # pass_level_2() {
[ $RESULT_check_subdir -ne -1 ] && \ # # -> The package can be install and remove in all tested configurations.
[ $RESULT_check_root -ne -1 ] && \ # # Validated if none install failed
[ $RESULT_check_private -ne -1 ] && \ # [ $RESULT_check_subdir -ne -1 ] && \
[ $RESULT_check_multi_instance -ne -1 ] # [ $RESULT_check_root -ne -1 ] && \
} # [ $RESULT_check_private -ne -1 ] && \
# [ $RESULT_check_multi_instance -ne -1 ]
pass_level_3() { # }
# -> The package can be upgraded from the same version. #
# Validated if the upgrade is ok. Or if the upgrade has been not tested but already validated before. # pass_level_3() {
[ $RESULT_check_upgrade -eq 1 ] || \ # # -> The package can be upgraded from the same version.
( [ $RESULT_check_upgrade -ne -1 ] && \ # # Validated if the upgrade is ok. Or if the upgrade has been not tested but already validated before.
[ "${level[3]}" == "2" ] ) # [ $RESULT_check_upgrade -eq 1 ] || \
} # ( [ $RESULT_check_upgrade -ne -1 ] && \
# [ "${level[3]}" == "2" ] )
pass_level_4() { # }
# -> The package can be backup and restore without error #
# Validated if backup and restore are ok. Or if backup and restore have been not tested but already validated before. # pass_level_4() {
( [ $RESULT_check_backup -eq 1 ] && \ # # -> The package can be backup and restore without error
[ $RESULT_check_restore -eq 1 ] ) || \ # # Validated if backup and restore are ok. Or if backup and restore have been not tested but already validated before.
( [ $RESULT_check_backup -ne -1 ] && \ # ( [ $RESULT_check_backup -eq 1 ] && \
[ $RESULT_check_restore -ne -1 ] && \ # [ $RESULT_check_restore -eq 1 ] ) || \
[ "${level[4]}" == "2" ] ) # ( [ $RESULT_check_backup -ne -1 ] && \
} # [ $RESULT_check_restore -ne -1 ] && \
# [ "${level[4]}" == "2" ] )
pass_level_5() { # }
# -> The package have no error with package linter #
# -> The package does not have any alias_traversal error # pass_level_5() {
# Validated if Linter is ok. Or if Linter has been not tested but already validated before. # # -> The package have no error with package linter
[ $RESULT_alias_traversal -ne 1 ] && \ # # -> The package does not have any alias_traversal error
([ $RESULT_linter -ge 1 ] || \ # # Validated if Linter is ok. Or if Linter has been not tested but already validated before.
( [ $RESULT_linter -eq 0 ] && \ # [ $RESULT_alias_traversal -ne 1 ] && \
[ "${level[5]}" == "2" ] ) ) # ([ $RESULT_linter -ge 1 ] || \
} # ( [ $RESULT_linter -eq 0 ] && \
# [ "${level[5]}" == "2" ] ) )
pass_level_6() { # }
# -> The package can be backup and restore without error #
# This is from the linter, tests if app is the Yunohost-apps organization # pass_level_6() {
[ $RESULT_linter_level_6 -eq 1 ] || \ # # -> The package can be backup and restore without error
([ $RESULT_linter_level_6 -eq 0 ] && \ # # This is from the linter, tests if app is the Yunohost-apps organization
[ "${level[6]}" == "2" ] ) # [ $RESULT_linter_level_6 -eq 1 ] || \
} # ([ $RESULT_linter_level_6 -eq 0 ] && \
# [ "${level[6]}" == "2" ] )
pass_level_7() { # }
# -> None errors in all tests performed #
# Validated if none errors is happened. # pass_level_7() {
[ $RESULT_check_subdir -ne -1 ] && \ # # -> None errors in all tests performed
[ $RESULT_check_upgrade -ne -1 ] && \ # # Validated if none errors is happened.
[ $RESULT_check_private -ne -1 ] && \ # [ $RESULT_check_subdir -ne -1 ] && \
[ $RESULT_check_multi_instance -ne -1 ] && \ # [ $RESULT_check_upgrade -ne -1 ] && \
[ $RESULT_check_port -ne -1 ] && \ # [ $RESULT_check_private -ne -1 ] && \
[ $RESULT_check_backup -ne -1 ] && \ # [ $RESULT_check_multi_instance -ne -1 ] && \
[ $RESULT_check_restore -ne -1 ] && \ # [ $RESULT_check_port -ne -1 ] && \
[ $RESULT_change_url -ne -1 ] && \ # [ $RESULT_check_backup -ne -1 ] && \
[ $RESULT_action_config_panel -ne -1 ] && \ # [ $RESULT_check_restore -ne -1 ] && \
([ $RESULT_linter_level_7 -ge 1 ] || # [ $RESULT_change_url -ne -1 ] && \
([ $RESULT_linter_level_7 -eq 0 ] && \ # [ $RESULT_action_config_panel -ne -1 ] && \
[ "${level[8]}" == "2" ] )) # ([ $RESULT_linter_level_7 -ge 1 ] ||
} # ([ $RESULT_linter_level_7 -eq 0 ] && \
# [ "${level[8]}" == "2" ] ))
pass_level_8() { # }
# This happens in the linter #
# When writing this, defined as app being maintained + long term quality (= # pass_level_8() {
# certain amount of time level 5+ in the last year) # # This happens in the linter
[ $RESULT_linter_level_8 -ge 1 ] || \ # # When writing this, defined as app being maintained + long term quality (=
([ $RESULT_linter_level_8 -eq 0 ] && \ # # certain amount of time level 5+ in the last year)
[ "${level[8]}" == "2" ] ) # [ $RESULT_linter_level_8 -ge 1 ] || \
} # ([ $RESULT_linter_level_8 -eq 0 ] && \
# [ "${level[8]}" == "2" ] )
pass_level_9() { # }
list_url="https://raw.githubusercontent.com/YunoHost/apps/master/apps.json" #
curl --silent $list_url | jq ".[\"$app_id\"].high_quality" | grep -q "true" # pass_level_9() {
} # list_url="https://raw.githubusercontent.com/YunoHost/apps/master/apps.json"
# curl --silent $list_url | jq ".[\"$app_id\"].high_quality" | grep -q "true"
# Check if the level can be changed # }
level_can_change () { #
# If the level is set at auto, it's waiting for a change # # Check if the level can be changed
# And if it's set at 2, its value can be modified by a new result # level_can_change () {
[ "${level[$1]}" == "auto" ] || [ "${level[$1]}" -eq 2 ] # # If the level is set at auto, it's waiting for a change
} # # And if it's set at 2, its value can be modified by a new result
# [ "${level[$1]}" == "auto" ] || [ "${level[$1]}" -eq 2 ]
if level_can_change 1; then pass_level_1 && level[1]=2 || level[1]=0; fi # }
if level_can_change 2; then pass_level_2 && level[2]=2 || level[2]=0; fi #
if level_can_change 3; then pass_level_3 && level[3]=2 || level[3]=0; fi # if level_can_change 1; then pass_level_1 && level[1]=2 || level[1]=0; fi
if level_can_change 4; then pass_level_4 && level[4]=2 || level[4]=0; fi # if level_can_change 2; then pass_level_2 && level[2]=2 || level[2]=0; fi
if level_can_change 5; then pass_level_5 && level[5]=2 || level[5]=0; fi # if level_can_change 3; then pass_level_3 && level[3]=2 || level[3]=0; fi
if level_can_change 6; then pass_level_6 && level[6]=2 || level[6]=0; fi # if level_can_change 4; then pass_level_4 && level[4]=2 || level[4]=0; fi
if level_can_change 7; then pass_level_7 && level[7]=2 || level[7]=0; fi # if level_can_change 5; then pass_level_5 && level[5]=2 || level[5]=0; fi
if level_can_change 8; then pass_level_8 && level[8]=2 || level[8]=0; fi # if level_can_change 6; then pass_level_6 && level[6]=2 || level[6]=0; fi
if level_can_change 9; then pass_level_9 && level[9]=2 || level[9]=0; fi # if level_can_change 7; then pass_level_7 && level[7]=2 || level[7]=0; fi
# if level_can_change 8; then pass_level_8 && level[8]=2 || level[8]=0; fi
# Level 10 has no definition yet # if level_can_change 9; then pass_level_9 && level[9]=2 || level[9]=0; fi
level[10]=0 #
# # Level 10 has no definition yet
# Initialize the global level # level[10]=0
global_level=0 #
# # Initialize the global level
# Calculate the final level # global_level=0
for i in `seq 1 10` #
do # # Calculate the final level
# for i in `seq 1 10`
# If there is a level still at 'auto', it's a mistake. # do
if [ "${level[i]}" == "auto" ] #
then # # If there is a level still at 'auto', it's a mistake.
# So this level will set at 0. # if [ "${level[i]}" == "auto" ]
level[i]=0 # then
# # So this level will set at 0.
# If the level is at 1 or 2. The global level will be set at this level # level[i]=0
elif [ "${level[i]}" -ge 1 ] #
then # # If the level is at 1 or 2. The global level will be set at this level
global_level=$i # elif [ "${level[i]}" -ge 1 ]
# then
# But, if the level is at 0, the loop stop here # global_level=$i
# Like that, the global level rise while none level have failed #
else # # But, if the level is at 0, the loop stop here
break # # Like that, the global level rise while none level have failed
fi # else
done # break
# fi
# If some witness files was missing, it's a big error ! So, the level fall immediately at 0. # done
if [ $RESULT_witness -eq 1 ] #
then # # If some witness files was missing, it's a big error ! So, the level fall immediately at 0.
log_error "Some witness files has been deleted during those tests ! It's a very bad thing !" # if [ $RESULT_witness -eq 1 ]
global_level=0 # then
fi # log_error "Some witness files has been deleted during those tests ! It's a very bad thing !"
# global_level=0
# If the package linter returned a critical error, the app is flagged as broken / level 0 # fi
if [ $RESULT_linter_broken -eq 1 ] #
then # # If the package linter returned a critical error, the app is flagged as broken / level 0
log_error "The package linter reported a critical failure ! App is considered broken !" # if [ $RESULT_linter_broken -eq 1 ]
global_level=0 # then
fi # log_error "The package linter reported a critical failure ! App is considered broken !"
# global_level=0
if [ $RESULT_alias_traversal -eq 1 ] # fi
then #
log_error "Issue alias_traversal was detected ! Please see here https://github.com/YunoHost/example_ynh/pull/45 to fix that." # if [ $RESULT_alias_traversal -eq 1 ]
fi # then
# log_error "Issue alias_traversal was detected ! Please see here https://github.com/YunoHost/example_ynh/pull/45 to fix that."
# Then, print the levels # fi
# Print the global level #
verbose_level=$(grep "^$global_level " "./levels.list" | cut -c4-) # # Then, print the levels
# # Print the global level
log_info "Level of this application: $global_level ($verbose_level)" # verbose_level=$(grep "^$global_level " "./levels.list" | cut -c4-)
#
# And print the value for each level # log_info "Level of this application: $global_level ($verbose_level)"
for i in `seq 1 10` #
do # # And print the value for each level
display="0" # for i in `seq 1 10`
if [ "${level[$i]}" -ge 1 ]; then # do
display="1" # display="0"
fi # if [ "${level[$i]}" -ge 1 ]; then
echo -e "\t Level $i: $display" # display="1"
done # fi
# echo -e "\t Level $i: $display"
# done
} }
#================================================= #=================================================
@ -560,14 +562,15 @@ parse_check_process() {
extra="$(jq -n --arg configpanel "$configpanel_infos" '{ $configpanel }')" extra="$(jq -n --arg configpanel "$configpanel_infos" '{ $configpanel }')"
fi fi
jq -n -f "$TEST_CONTEXT/tests/$test_id.json" \ jq -n \
--arg test_serie "$test_serie" \ --arg test_serie "$test_serie" \
--arg test_type "$test_type" \ --arg test_type "$test_type" \
--arg test_arg "$test_arg" \ --arg test_arg "$test_arg" \
--arg preinstall_template "$preinstall_template" \ --arg preinstall_template "$preinstall_template" \
--arg install_args "$_install_args" \ --arg install_args "$_install_args" \
--argjson "$extra" \ --argjson extra "$extra" \
'{ $test_serie, $test_type, $test_arg, $preinstall_template, $install_args, $extra }' '{ $test_serie, $test_type, $test_arg, $preinstall_template, $install_args, $extra }' \
> "$TEST_CONTEXT/tests/$test_id.json"
} }
# For not-the-main-test-serie, we only consider testing the install and # For not-the-main-test-serie, we only consider testing the install and
@ -603,7 +606,6 @@ parse_check_process() {
while IFS= read -r LINE; while IFS= read -r LINE;
do do
commit=$(echo $LINE | grep -o "from_commit=.*" | awk -F= '{print $2}') commit=$(echo $LINE | grep -o "from_commit=.*" | awk -F= '{print $2}')
[ -n "$commit" ] || commit="current"
add_test "TEST_UPGRADE" "$commit" add_test "TEST_UPGRADE" "$commit"
done done
@ -640,14 +642,15 @@ guess_test_configuration() {
test_id="$((test_id+1))" test_id="$((test_id+1))"
local extra="{}" local extra="{}"
jq -n -f "$TEST_CONTEXT/tests/$test_id.json" jq -n \
--arg test_serie "default" \ --arg test_serie "default" \
--arg test_type "$test_type" \ --arg test_type "$test_type" \
--arg test_arg "$test_arg" \ --arg test_arg "$test_arg" \
--arg preinstall_template "" \ --arg preinstall_template "" \
--arg install_args "$install_args" \ --arg install_args "$install_args" \
--argjson "$extra" \ --argjson extra "$extra" \
'{ $test_serie, $test_type, $test_arg, $preinstall_template, $install_args, $extra }' '{ $test_serie, $test_type, $test_arg, $preinstall_template, $install_args, $extra }' \
> "$TEST_CONTEXT/tests/$test_id.json"
} }
local install_args=$(python "./sub_scripts/manifest_parsing.py" "$package_path/manifest.json" | cut -d ':' -f1,2 | tr ':' '=' | tr '\n' '&') local install_args=$(python "./sub_scripts/manifest_parsing.py" "$package_path/manifest.json" | cut -d ':' -f1,2 | tr ':' '=' | tr '\n' '&')
@ -664,7 +667,7 @@ guess_test_configuration() {
add_test "TEST_MULTI_INSTANCE" add_test "TEST_MULTI_INSTANCE"
fi fi
add_test "TEST_BACKUP_RESTORE" add_test "TEST_BACKUP_RESTORE"
add_test "TEST_UPGRADE current" add_test "TEST_UPGRADE"
} }
#================================================= #=================================================
@ -697,6 +700,9 @@ run_all_tests() {
} }
mkdir -p $TEST_CONTEXT/tests
mkdir -p $TEST_CONTEXT/results
[ -e "$check_process" ] \ [ -e "$check_process" ] \
&& parse_check_process \ && parse_check_process \
|| guess_test_configuration || guess_test_configuration

View file

@ -15,7 +15,7 @@ SUBDOMAIN="sub.$DOMAIN"
# User de test # User de test
TEST_USER="package_checker" TEST_USER="package_checker"
LXC_NAME="ynh-appci" LXC_NAME="ynh-appci-$DEFAULT_DIST"
[[ -e "./config" ]] && source "./config" [[ -e "./config" ]] && source "./config"

View file

@ -19,7 +19,7 @@ LXC_CREATE () {
} }
LXC_SNAPSHOT_EXISTS() { LXC_SNAPSHOT_EXISTS() {
lxc info $LXC_NAME | grep -A10 Snapshots | tail -n -1 | awk '{print $1}' | greq -q -w "$1" lxc info $LXC_NAME 2>/dev/null | grep -A10 Snapshots | tail -n -1 | awk '{print $1}' | grep -q -w "$1"
} }
CREATE_LXC_SNAPSHOT () { CREATE_LXC_SNAPSHOT () {
@ -33,17 +33,16 @@ CREATE_LXC_SNAPSHOT () {
[ $snapname != "snap0" ] && check_witness_files >&2 [ $snapname != "snap0" ] && check_witness_files >&2
# Remove swap files to avoid killing the CI with huge snapshots. # Remove swap files to avoid killing the CI with huge snapshots.
sudo lxc exec $LXC_NAME -- bash -c 'for swapfile in $(ls /swap_*); do swapoff $swapfile; done' sudo lxc exec $LXC_NAME -- bash -c 'for swapfile in $(ls /swap_* 2>/dev/null); do swapoff $swapfile; done'
sudo lxc exec $LXC_NAME -- bash -c 'for swapfile in $(ls /swap_*); do rm -f $swapfile; done' sudo lxc exec $LXC_NAME -- bash -c 'for swapfile in $(ls /swap_* 2>/dev/null); do rm -f $swapfile; done'
# Stop the container, before its snapshot
sudo lxc stop --timeout 15 $LXC_NAME 2>/dev/null sudo lxc stop --timeout 15 $LXC_NAME 2>/dev/null
# Check if the snapshot already exist # Check if the snapshot already exist
if ! LXC_SNAPSHOT_EXISTS "$snapname" if ! LXC_SNAPSHOT_EXISTS "$snapname"
then then
log_debug "$snapname doesn't exist, its first creation can takes a little while." >&2 log_debug "$snapname doesn't exist, its first creation can takes a little while." >&2
sudo lxc snapshot $LXC_NAME $snapname --stateful sudo lxc snapshot $LXC_NAME $snapname
fi fi
stop_timer 1 stop_timer 1
@ -52,7 +51,7 @@ CREATE_LXC_SNAPSHOT () {
LOAD_LXC_SNAPSHOT () { LOAD_LXC_SNAPSHOT () {
snapname=$1 snapname=$1
sudo lxc stop --timeout 15 $LXC_NAME 2>/dev/null sudo lxc stop --timeout 15 $LXC_NAME 2>/dev/null
sudo lxc restore $LXC_NAME $snapname --stateful sudo lxc restore $LXC_NAME $snapname
_LXC_START_AND_WAIT $LXC_NAME _LXC_START_AND_WAIT $LXC_NAME
} }
@ -62,7 +61,6 @@ LXC_START () {
# Start the lxc container and execute the given command in it # Start the lxc container and execute the given command in it
local cmd=$1 local cmd=$1
sudo lxc start $LXC_NAME
_LXC_START_AND_WAIT $LXC_NAME _LXC_START_AND_WAIT $LXC_NAME
start_timer start_timer
@ -90,7 +88,7 @@ LXC_STOP () {
LXC_RESET () { LXC_RESET () {
sudo lxc stop --timeout 15 $LXC_NAME 2>/dev/null sudo lxc stop --timeout 15 $LXC_NAME 2>/dev/null
sudo lxc delete $LXC_NAME sudo lxc delete $LXC_NAME 2>/dev/null
} }
@ -98,8 +96,8 @@ _LXC_START_AND_WAIT() {
restart_container() restart_container()
{ {
lxc stop "$1" sudo lxc stop "$1"
lxc start "$1" sudo lxc start "$1"
} }
# Try to start the container 3 times. # Try to start the container 3 times.
@ -118,7 +116,8 @@ _LXC_START_AND_WAIT() {
fi fi
if [ "$j" == "10" ]; then if [ "$j" == "10" ]; then
error 'Failed to start the container' log_error 'Failed to start the container'
lxc info $1
failstart=1 failstart=1
restart_container "$1" restart_container "$1"
@ -134,7 +133,7 @@ _LXC_START_AND_WAIT() {
fi fi
if [ "$j" == "10" ]; then if [ "$j" == "10" ]; then
error 'Failed to access the internet' log_error 'Failed to access the internet'
failstart=1 failstart=1
restart_container "$1" restart_container "$1"

View file

@ -58,8 +58,8 @@ default_install_path() {
#================================================= #=================================================
INSTALL_APP () { INSTALL_APP () {
local install_args="$(jq '.install_args' $current_test_infos)" local install_args="$(jq -r '.install_args' $current_test_infos)"
local preinstall_template="$(jq '.preinstall_template' $current_test_infos)" local preinstall_template="$(jq -r '.preinstall_template' $current_test_infos)"
# We have default values for domain, user and is_public, but these # We have default values for domain, user and is_public, but these
# may still be overwritten by the args ($@) # may still be overwritten by the args ($@)
@ -319,7 +319,7 @@ TEST_INSTALL () {
# Create the snapshot that'll be used by other tests later # Create the snapshot that'll be used by other tests later
[ "$install_type" != "private" ] \ [ "$install_type" != "private" ] \
&& ! LXC_SNAPSHOT_EXISTS $snapname && ! LXC_SNAPSHOT_EXISTS $snapname \
&& log_debug "Create a snapshot after app install" \ && log_debug "Create a snapshot after app install" \
&& CREATE_LXC_SNAPSHOT $snapname && CREATE_LXC_SNAPSHOT $snapname
@ -340,7 +340,7 @@ TEST_UPGRADE () {
then then
start_test "Upgrade from the same version" start_test "Upgrade from the same version"
else else
upgrade_name="$(jq '.extra.upgrade_name' $current_test_infos)" upgrade_name="$(jq -r '.extra.upgrade_name' $current_test_infos)"
[ -n "$upgrade_name" ] || upgrade_name="commit $commit" [ -n "$upgrade_name" ] || upgrade_name="commit $commit"
start_test "Upgrade from $upgrade_name" start_test "Upgrade from $upgrade_name"
fi fi
@ -1054,13 +1054,13 @@ TEST_LAUNCHER () {
# And keep this value separately # And keep this value separately
local global_start_timer=$starttime local global_start_timer=$starttime
current_test_id=$(basename $test | cut -d. -f1) current_test_id=$(basename $testfile | cut -d. -f1)
current_test_infos="$TEST_CONTEXT/tests/$current_test_id.json" current_test_infos="$TEST_CONTEXT/tests/$current_test_id.json"
current_test_results="$TEST_CONTEXT/results/$current_test_id.json" current_test_results="$TEST_CONTEXT/results/$current_test_id.json"
echo "{}" > $current_test_results echo "{}" > $current_test_results
local test_type=$(jq '.test_type' $testfile) local test_type=$(jq -r '.test_type' $testfile)
local test_arg=$(jq '.test_arg' $testfile) local test_arg=$(jq -r '.test_arg' $testfile)
# Execute the test # Execute the test
$test_type $test_arg $test_type $test_arg
@ -1084,7 +1084,7 @@ TEST_LAUNCHER () {
SET_RESULT() { SET_RESULT() {
local result=$1 local result=$1
local name=$2 local name=$2
[ $result -eq "success" ] && log_report_test_success || log_report_test_failed [ "$result" == "success" ] && log_report_test_success || log_report_test_failed
local current_results="$(cat $current_test_results)" local current_results="$(cat $current_test_results)"
echo "$current_results" | jq --arg result $result ".$name=\$result" > $current_test_results echo "$current_results" | jq --arg result $result ".$name=\$result" > $current_test_results
} }
@ -1094,8 +1094,8 @@ at_least_one_install_succeeded () {
for TEST in $(ls $TEST_CONTEXT/tests/*.json) for TEST in $(ls $TEST_CONTEXT/tests/*.json)
do do
local test_id=$(basename $TEST | cut -d. -f1) local test_id=$(basename $TEST | cut -d. -f1)
jq -e '. | select(.test_type == "TEST_INSTALL")' $TEST \ jq -e '. | select(.test_type == "TEST_INSTALL")' $TEST >/dev/null \
&& jq -e '. | select(.main_result == "success")' $TEST_CONTEXT/results/$test_id.json \ && jq -e '. | select(.main_result == "success")' $TEST_CONTEXT/results/$test_id.json >/dev/null \
&& return 0 && return 0
done done