diff --git a/lib/tests.sh b/lib/tests.sh index 267bd4f..08a166e 100644 --- a/lib/tests.sh +++ b/lib/tests.sh @@ -32,10 +32,10 @@ _PREINSTALL () { local preinstall_script="$TEST_CONTEXT/preinstall.sh" echo "$preinstall_template" > "$preinstall_script" # Hydrate the template with variables - sed -i "s/\$USER/$TEST_USER/" "$preinstall_script" - sed -i "s/\$DOMAIN/$DOMAIN/" "$preinstall_script" - sed -i "s/\$SUBDOMAIN/$SUBDOMAIN/" "$preinstall_script" - sed -i "s/\$PASSWORD/$YUNO_PWD/" "$preinstall_script" + sed -i "s/\$USER/$TEST_USER/g" "$preinstall_script" + sed -i "s/\$DOMAIN/$DOMAIN/g" "$preinstall_script" + sed -i "s/\$SUBDOMAIN/$SUBDOMAIN/g" "$preinstall_script" + sed -i "s/\$PASSWORD/$YUNO_PWD/g" "$preinstall_script" # Copy the pre-install script into the container. lxc file push "$preinstall_script" "$LXC_NAME/preinstall.sh" # Then execute the script to execute the pre-install commands. @@ -43,6 +43,31 @@ _PREINSTALL () { fi } +_PREUPGRADE () { + local preupgrade_template="$(jq -r '.preupgrade_template' $current_test_infos)" + local commit=${1:-HEAD} + + # Exec the pre-upgrade instruction, if there one + if [ -n "$preupgrade_template" ] + then + log_small_title "Running pre-upgrade steps" + # Copy all the instructions into a script + local preupgrade_script="$TEST_CONTEXT/preupgrade.sh" + echo "$preupgrade_template" >> "$preupgrade_script" + # Hydrate the template with variables + sed -i "s/\$USER/$TEST_USER/g" "$preupgrade_script" + sed -i "s/\$DOMAIN/$DOMAIN/g" "$preupgrade_script" + sed -i "s/\$SUBDOMAIN/$SUBDOMAIN/g" "$preupgrade_script" + sed -i "s/\$PASSWORD/$YUNO_PWD/g" "$preupgrade_script" + sed -i "s/\$FROM_COMMIT/$commit/g" "$preupgrade_script" + # Copy the pre-upgrade script into the container. + lxc file push "$preupgrade_script" "$LXC_NAME/preupgrade.sh" + # Then execute the script to execute the pre-upgrade commands. + LXC_EXEC "bash /preupgrade.sh" + return $? + fi +} + _INSTALL_APP () { local install_args="$(jq -r '.install_args' $current_test_infos)" @@ -433,6 +458,10 @@ TEST_UPGRADE () { log_small_title "Upgrade..." + _PREUPGRADE "${commit}" + ret=$? + [ $ret -eq 0 ] || { log_error "Pre-upgrade instruction failed"; return 1; } + # Upgrade the application in a LXC container _RUN_YUNOHOST_CMD "app upgrade $app_id --file /app_folder --force" \ && _VALIDATE_THAT_APP_CAN_BE_ACCESSED "$SUBDOMAIN" "$check_path" "upgrade" @@ -516,7 +545,7 @@ TEST_BACKUP_RESTORE () { _RUN_YUNOHOST_CMD "backup create -n Backup_test --apps $app_id" ret=$? fi - + [ $ret -eq 0 ] || { main_result=1; break_before_continue; continue; } # Grab the backup archive into the LXC container, and keep a copy @@ -546,7 +575,7 @@ TEST_BACKUP_RESTORE () { # Place the copy of the backup archive in the container. lxc file push -r $TEST_CONTEXT/ynh_backups/archives $LXC_NAME/home/yunohost.backup/ - + _PREINSTALL log_small_title "Restore on a fresh YunoHost system..." @@ -609,7 +638,7 @@ TEST_CHANGE_URL () { elif [ $i -eq 4 ]; then local new_path=/path local new_domain=$DOMAIN - + # Other domain, same path elif [ $i -eq 5 ]; then local new_path=/path diff --git a/lib/tests_coordination.sh b/lib/tests_coordination.sh index 9a0a806..26bfae5 100644 --- a/lib/tests_coordination.sh +++ b/lib/tests_coordination.sh @@ -80,6 +80,7 @@ parse_check_process() { # during tests local install_args=$( extract_check_process_section "^; Manifest" "^; " $test_serie_rawconf | sed 's/\s*(.*)$//g' | tr -d '"' | tr '\n' '&') local preinstall_template=$(extract_check_process_section "^; pre-install" "^; " $test_serie_rawconf) + local preupgrade_template=$(extract_check_process_section "^; pre-upgrade" "^; " $test_serie_rawconf) local action_infos=$( extract_check_process_section "^; Actions" "^; " $test_serie_rawconf) local configpanel_infos=$( extract_check_process_section "^; Config_panel" "^; " $test_serie_rawconf) @@ -130,9 +131,10 @@ parse_check_process() { --arg test_type "$test_type" \ --arg test_arg "$test_arg" \ --arg preinstall_template "$preinstall_template" \ + --arg preupgrade_template "$preupgrade_template" \ --arg install_args "${_install_args//\"}" \ --argjson extra "$extra" \ - '{ $test_serie, $test_type, $test_arg, $preinstall_template, $install_args, $extra }' \ + '{ $test_serie, $test_type, $test_arg, $preinstall_template, $preupgrade_template, $install_args, $extra }' \ > "$TEST_CONTEXT/tests/$test_id.json" }