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_private=1
setup_public=1 setup_public=1
upgrade=1 upgrade=1
upgrade=1 from_commit=65c382d138596fcb32b4c97c39398815a1dcd4e8
backup_restore=1 backup_restore=1
multi_instance=1 multi_instance=1
incorrect_path=1 incorrect_path=1
@ -88,6 +89,10 @@ package_check/package_check.sh APP_ynh
;;; Options ;;; Options
Email= Email=
Notification=none 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 test`
Nom du scénario de test qui sera effectué. 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_private`: Installation en privé.
- `setup_public`: Installation en public. - `setup_public`: Installation en public.
- `upgrade`: Upgrade du package sur la même version. Test uniquement le script upgrade. - `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. - `backup_restore`: Backup et restauration.
- `multi_instance`: Installation de l'application 2 fois de suite, pour vérifier sa capacité à être multi-instance. - `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/. - `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é. - `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. - `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. 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. - `--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_private=1
setup_public=1 setup_public=1
upgrade=1 upgrade=1
upgrade=1 from_commit=65c382d138596fcb32b4c97c39398815a1dcd4e8
backup_restore=1 backup_restore=1
multi_instance=1 multi_instance=1
incorrect_path=1 incorrect_path=1
@ -88,6 +89,10 @@ package_check/package_check.sh APP_ynh
;;; Options ;;; Options
Email= Email=
Notification=none 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` ### `;; Test name`
Name of tests series that will be perform. 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_private`: Private installation.
- `setup_public`: Public installation. - `setup_public`: Public installation.
- `upgrade`: Upgrade package on same version. Only test the upgrade script. - `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. - `backup_restore`: Backup then restore.
- `multi_instance`: Installing the application 2 times to verify its ability to be multi-instance. - `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/. - `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. - `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. - `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. The `package_check.sh` script accept 6 arguments in addition of package to be checked.
- `--bash-mode`: The script will work without user intervention. - `--bash-mode`: The script will work without user intervention.

View file

@ -20,6 +20,7 @@
setup_private=1 setup_private=1
setup_public=1 setup_public=1
upgrade=1 upgrade=1
upgrade=1 from_commit=65c382d138596fcb32b4c97c39398815a1dcd4e8
backup_restore=1 backup_restore=1
multi_instance=1 multi_instance=1
incorrect_path=1 incorrect_path=1
@ -39,3 +40,7 @@
;;; Options ;;; Options
Email= Email=
Notification=none 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 clean_exit 1
fi fi
# Remove the .git directory.
rm -rf "$package_path/.git"
@ -844,7 +841,7 @@ then
# Search a string in the partial check_process # Search a string in the partial check_process
find_string () { 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 # 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)) test "$1" -eq 1 && all_test=$((all_test+1))
} }
# Get standard options
pkg_linter=$(read_check_option pkg_linter) pkg_linter=$(read_check_option pkg_linter)
count_test $pkg_linter count_test $pkg_linter
setup_sub_dir=$(read_check_option setup_sub_dir) setup_sub_dir=$(read_check_option setup_sub_dir)
@ -1028,8 +1026,6 @@ then
count_test $setup_private count_test $setup_private
setup_public=$(read_check_option setup_public) setup_public=$(read_check_option setup_public)
count_test $setup_public count_test $setup_public
upgrade=$(read_check_option upgrade)
count_test $upgrade
backup_restore=$(read_check_option backup_restore) backup_restore=$(read_check_option backup_restore)
count_test $backup_restore count_test $backup_restore
multi_instance=$(read_check_option multi_instance) multi_instance=$(read_check_option multi_instance)
@ -1053,6 +1049,33 @@ then
fi fi
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 # Launch all tests successively
TESTING_PROCESS TESTING_PROCESS
# Print the final results of the tests # Print the final results of the tests

View file

@ -533,7 +533,24 @@ CHECK_SETUP () {
CHECK_UPGRADE () { CHECK_UPGRADE () {
# Try the upgrade script # Try the upgrade script
unit_test_title "Upgrade..." # 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
# 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 if an install have previously work # Check if an install have previously work
local previous_install=$(is_install_failed) local previous_install=$(is_install_failed)
@ -558,14 +575,44 @@ CHECK_UPGRADE () {
# Install the application in a LXC container # Install the application in a LXC container
ECHO_FORMAT "\nPreliminary install...\n" "white" "bold" clog ECHO_FORMAT "\nPreliminary install...\n" "white" "bold" clog
if [ "$commit" == "current" ]
then
# If no commit is specified, use the current version.
STANDARD_SETUP_APP 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
# Check if the install had work # Check if the install had work
if [ $yunohost_result -ne 0 ] if [ $yunohost_result -ne 0 ]
then then
ECHO_FORMAT "\nInstallation failed...\n" "red" "bold" ECHO_FORMAT "\nInstallation failed...\n" "red" "bold"
else else
ECHO_FORMAT "\nUpgrade on the same version...\n" "white" "bold" clog ECHO_FORMAT "\nUpgrade...\n" "white" "bold" clog
# Upgrade the application in a LXC container # Upgrade the application in a LXC container
LXC_START "sudo yunohost --debug app upgrade $ynh_app_id -f \"$package_dir\"" LXC_START "sudo yunohost --debug app upgrade $ynh_app_id -f \"$package_dir\""
@ -593,13 +640,22 @@ CHECK_UPGRADE () {
# Check the result and print SUCCESS or FAIL # Check the result and print SUCCESS or FAIL
if check_test_result if check_test_result
then # Success 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 RESULT_check_upgrade=1 # Upgrade succeed
fi
else # Fail else # Fail
RESULT_check_upgrade=-1 # Upgrade failed RESULT_check_upgrade=-1 # Upgrade failed
fi fi
# Remove the application # Remove the application
REMOVE_APP 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 () { CHECK_PUBLIC_PRIVATE () {