Add new feature upgrade from commit

This commit is contained in:
Maniack Crudelis 2017-11-12 19:00:23 +01:00
parent dbb7e9f9e7
commit 0c841b6bbc
5 changed files with 176 additions and 66 deletions

View file

@ -69,6 +69,7 @@ package_check/package_check.sh APP_ynh
setup_private=1
setup_public=1
upgrade=1
upgrade=1 from_commit=65c382d138596fcb32b4c97c39398815a1dcd4e8
backup_restore=1
multi_instance=1
incorrect_path=1
@ -88,6 +89,10 @@ package_check/package_check.sh APP_ynh
;;; Options
Email=
Notification=none
;;; Upgrade options
; commit=65c382d138596fcb32b4c97c39398815a1dcd4e8
name=Name of this previous version
manifest_arg=domain=DOMAIN&path=PATH&admin=USER&password=pass&is_public=1&
```
### `;; Nom du test`
Nom du scénario de test qui sera effectué.
@ -118,6 +123,7 @@ Si un test est absent de la liste, il sera ignoré. Cela revient à le noter à
- `setup_private`: Installation en privé.
- `setup_public`: Installation en public.
- `upgrade`: Upgrade du package sur la même version. Test uniquement le script upgrade.
- `upgrade from_commit`: Upgrade du package à partir du commit spécifié vers la dernière version.
- `backup_restore`: Backup et restauration.
- `multi_instance`: Installation de l'application 2 fois de suite, pour vérifier sa capacité à être multi-instance.
- `incorrect_path`: Provoque une erreur avec un path malformé, path/.
@ -159,6 +165,13 @@ Ces options sont facultatives.
- `change` : Envoi un mail seulement si le niveau de l'application a changé.
- `all` : Envoi un mail pour chaque test de l'application, quel que ce soit le résultat.
### `;;; Upgrade options`
*Instruction optionnelle*
Pour chaque commit indiqué pour un upgrade, permet d'indiquer un nom pour cette version et les paramètres du manifest à utiliser lors de l'installation préliminaire.
En cas d'absence de nom, le commit sera utilisé.
De même en cas d'absence d'arguments pour le manifest, les arguments du check_process seront utilisés.
> 3 variables doivent être utilisées pour les arguments du manifest, DOMAIN, PATH et USER.
---
Le script `package_check.sh` accepte 6 arguments en plus du package à tester.
- `--bash-mode`: Rend le script autonome. Aucune intervention de l'utilisateur ne sera nécessaire.

View file

@ -69,6 +69,7 @@ package_check/package_check.sh APP_ynh
setup_private=1
setup_public=1
upgrade=1
upgrade=1 from_commit=65c382d138596fcb32b4c97c39398815a1dcd4e8
backup_restore=1
multi_instance=1
incorrect_path=1
@ -88,6 +89,10 @@ package_check/package_check.sh APP_ynh
;;; Options
Email=
Notification=none
;;; Upgrade options
; commit=65c382d138596fcb32b4c97c39398815a1dcd4e8
name=Name of this previous version
manifest_arg=domain=DOMAIN&path=PATH&admin=USER&password=pass&is_public=1&
```
### `;; Test name`
Name of tests series that will be perform.
@ -118,6 +123,7 @@ If a test is not in the list, it will be ignored. It's similar to marked at 0.
- `setup_private`: Private installation.
- `setup_public`: Public installation.
- `upgrade`: Upgrade package on same version. Only test the upgrade script.
- `upgrade from_commit`: Upgrade package from the specified commit to the latest version.
- `backup_restore`: Backup then restore.
- `multi_instance`: Installing the application 2 times to verify its ability to be multi-instance.
- `incorrect_path`: Causes an arror with a malformed path, path/.
@ -159,6 +165,13 @@ These options are facultative.
- `change` : Send an email if the level of this application has changed.
- `all` : Send an email for each test on this application, which ever the result.
### `;;; Upgrade options`
*Optionnal instruction*
For each specified commit for an upgrade, allow to give a name for this version and manifest parameters which will be used for the preliminary installation.
In case of lack of name, the commit will be used.
And so on in case of lack of manifest arguments, the default arguments of the check process will be used.
> 3 variables shall be used for the arguments of the manifest, DOMAIN, PATH et USER.
---
The `package_check.sh` script accept 6 arguments in addition of package to be checked.
- `--bash-mode`: The script will work without user intervention.

View file

@ -20,6 +20,7 @@
setup_private=1
setup_public=1
upgrade=1
upgrade=1 from_commit=65c382d138596fcb32b4c97c39398815a1dcd4e8
backup_restore=1
multi_instance=1
incorrect_path=1
@ -39,3 +40,7 @@
;;; Options
Email=
Notification=none
;;; Upgrade options
; commit=65c382d138596fcb32b4c97c39398815a1dcd4e8
name=Name of this previous version
manifest_arg=domain=DOMAIN&path=PATH&admin=USER&password=pass&is_public=1&

View file

@ -498,9 +498,6 @@ if [ ! -d "$package_path" ]; then
clean_exit 1
fi
# Remove the .git directory.
rm -rf "$package_path/.git"
@ -844,7 +841,7 @@ then
# Search a string in the partial check_process
find_string () {
echo $(grep "$1" "$partial_check_process")
echo $(grep -m1 "$1" "$partial_check_process")
}
# Extract a section found between $1 and $2 from the file $3
@ -1016,6 +1013,7 @@ then
test "$1" -eq 1 && all_test=$((all_test+1))
}
# Get standard options
pkg_linter=$(read_check_option pkg_linter)
count_test $pkg_linter
setup_sub_dir=$(read_check_option setup_sub_dir)
@ -1028,8 +1026,6 @@ then
count_test $setup_private
setup_public=$(read_check_option setup_public)
count_test $setup_public
upgrade=$(read_check_option upgrade)
count_test $upgrade
backup_restore=$(read_check_option backup_restore)
count_test $backup_restore
multi_instance=$(read_check_option multi_instance)
@ -1053,6 +1049,33 @@ then
fi
fi
# Clean the upgrade list
> "$script_dir/upgrade_list"
# Get multiples lines for upgrade option.
while $(grep --quiet "^upgrade=" "$partial_check_process")
do
# Get the value for the first upgrade test.
temp_upgrade=$(read_check_option upgrade)
count_test $temp_upgrade
# Set upgrade to 1, but never to 0.
if [ "$upgrade" != "1" ]; then
upgrade=$temp_upgrade
fi
# Get this line to find if there an option.
line=$(find_string "^upgrade=")
if echo "$line" | grep --quiet "from_commit="
then
# Add the commit to the upgrade list
line="${line##*from_commit=}"
echo "$line" >> "$script_dir/upgrade_list"
else
# Or simply 'current' for a standard upgrade.
echo "current" >> "$script_dir/upgrade_list"
fi
# Remove this line from the check_process
sed --in-place "\|${line}$|d" "$partial_check_process"
done
# Launch all tests successively
TESTING_PROCESS
# Print the final results of the tests

View file

@ -533,73 +533,129 @@ CHECK_SETUP () {
CHECK_UPGRADE () {
# Try the upgrade script
unit_test_title "Upgrade..."
# Check if an install have previously work
local previous_install=$(is_install_failed)
# Abort if none install worked
[ "$previous_install" = "1" ] && return
# Copy original arguments
local manifest_args_mod="$manifest_arguments"
# Replace manifest key for the test
check_domain=$sub_domain
replace_manifest_key "domain" "$check_domain"
# Use a path according to previous succeeded installs
if [ "$previous_install" = "subdir" ]; then
local check_path=$test_path
elif [ "$previous_install" = "root" ]; then
local check_path=/
fi
replace_manifest_key "path" "$check_path"
replace_manifest_key "user" "$test_user"
replace_manifest_key "public" "$public_public_arg"
# Install the application in a LXC container
ECHO_FORMAT "\nPreliminary install...\n" "white" "bold" clog
STANDARD_SETUP_APP
# Check if the install had work
if [ $yunohost_result -ne 0 ]
then
ECHO_FORMAT "\nInstallation failed...\n" "red" "bold"
else
ECHO_FORMAT "\nUpgrade on the same version...\n" "white" "bold" clog
# Upgrade the application in a LXC container
LXC_START "sudo yunohost --debug app upgrade $ynh_app_id -f \"$package_dir\""
# yunohost_result gets the return code of the upgrade
yunohost_result=$?
# Print the result of the upgrade command
if [ $yunohost_result -eq 0 ]; then
ECHO_FORMAT "Upgrade successful. ($yunohost_result)\n" "white" clog
# Do an upgrade test for each commit in the upgrade list
while read <&4 commit
do
if [ "$commit" == "current" ]
then
unit_test_title "Upgrade from the same version..."
else
ECHO_FORMAT "Upgrade failed. ($yunohost_result)\n" "white" clog
# Get the specific section for this upgrade from the check_process
extract_section "^; commit=$commit" "^;" "$check_process"
# Get the name for this upgrade.
upgrade_name=$(grep "^name=" "$partial_check_process" | cut -d'=' -f2)
# Or use the commit if there's no name.
if [ -z "$upgrade_name" ]; then
unit_test_title "Upgrade from the commit $commit..."
else
unit_test_title "Upgrade from $upgrade_name..."
fi
fi
# Check all the witness files, to verify if them still here
check_witness_files
# Check if an install have previously work
local previous_install=$(is_install_failed)
# Abort if none install worked
[ "$previous_install" = "1" ] && return
# Analyse the log to extract "warning" and "error" lines
LOG_EXTRACTOR
# Copy original arguments
local manifest_args_mod="$manifest_arguments"
# Try to access the app by its url
CHECK_URL
fi
# Replace manifest key for the test
check_domain=$sub_domain
replace_manifest_key "domain" "$check_domain"
# Use a path according to previous succeeded installs
if [ "$previous_install" = "subdir" ]; then
local check_path=$test_path
elif [ "$previous_install" = "root" ]; then
local check_path=/
fi
replace_manifest_key "path" "$check_path"
replace_manifest_key "user" "$test_user"
replace_manifest_key "public" "$public_public_arg"
# Check the result and print SUCCESS or FAIL
if check_test_result
then # Success
RESULT_check_upgrade=1 # Upgrade succeed
else # Fail
RESULT_check_upgrade=-1 # Upgrade failed
fi
# Install the application in a LXC container
ECHO_FORMAT "\nPreliminary install...\n" "white" "bold" clog
if [ "$commit" == "current" ]
then
# If no commit is specified, use the current version.
STANDARD_SETUP_APP
else
# Otherwise, use a specific commit
# Backup the modified arguments
update_manifest_args="$manifest_args_mod"
# Get the arguments of the manifest for this upgrade.
manifest_args_mod=$(grep "^manifest_arg=" "$partial_check_process" | cut -d'=' -f2-)
if [ -z "$manifest_args_mod" ]; then
# If there's no specific arguments, use the previous one.
manifest_args_mod="$update_manifest_args"
else
# Otherwise, keep the new arguments, and replace the variables.
manifest_args_mod="${manifest_args_mod//DOMAIN/$check_domain}"
manifest_args_mod="${manifest_args_mod//PATH/$check_path}"
manifest_args_mod="${manifest_args_mod//USER/$test_user}"
fi
# Make a backup of the directory
sudo cp -a "$package_path" "${package_path}_back"
# Change to the specified commit
(cd "$package_path"; git checkout --force --quiet "$commit")
# Install the application
SETUP_APP
# Then replace the backup
sudo rm -r "$package_path"
sudo mv "${package_path}_back" "$package_path"
# And restore the arguments for the manifest
manifest_args_mod="$update_manifest_args"
fi
# Remove the application
REMOVE_APP
# Check if the install had work
if [ $yunohost_result -ne 0 ]
then
ECHO_FORMAT "\nInstallation failed...\n" "red" "bold"
else
ECHO_FORMAT "\nUpgrade...\n" "white" "bold" clog
# Upgrade the application in a LXC container
LXC_START "sudo yunohost --debug app upgrade $ynh_app_id -f \"$package_dir\""
# yunohost_result gets the return code of the upgrade
yunohost_result=$?
# Print the result of the upgrade command
if [ $yunohost_result -eq 0 ]; then
ECHO_FORMAT "Upgrade successful. ($yunohost_result)\n" "white" clog
else
ECHO_FORMAT "Upgrade failed. ($yunohost_result)\n" "white" clog
fi
# Check all the witness files, to verify if them still here
check_witness_files
# Analyse the log to extract "warning" and "error" lines
LOG_EXTRACTOR
# Try to access the app by its url
CHECK_URL
fi
# Check the result and print SUCCESS or FAIL
if check_test_result
then # Success
# The global success for an upgrade can't be a success if another upgrade failed
if [ $RESULT_check_upgrade -ne -1 ]; then
RESULT_check_upgrade=1 # Upgrade succeed
fi
else # Fail
RESULT_check_upgrade=-1 # Upgrade failed
fi
# Remove the application
REMOVE_APP
# Uses the default snapshot
current_snapshot=snap0
# Stop and restore the LXC container
LXC_STOP
done 4< "$script_dir/upgrade_list"
}
CHECK_PUBLIC_PRIVATE () {