Merge pull request #40 from YunoHost/testing

Testing
This commit is contained in:
Maniack Crudelis 2017-12-28 19:14:36 +01:00 committed by GitHub
commit 047fa1bddc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 295 additions and 133 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,8 +123,9 @@ 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 3 fois de suite, pour vérifier sa capacité à être multi-instance. Les 2e et 3e installations se font respectivement en ajoutant un suffixe et un préfixe au path. - `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/.
- `port_already_use`: Provoque une erreur sur le port en l'ouvrant avant le script d'install. - `port_already_use`: Provoque une erreur sur le port en l'ouvrant avant le script d'install.
Le test` port_already_use` peut éventuellement prendre en argument un numéro de port. Si celui-ci n'est pas dans le manifest. Le test` port_already_use` peut éventuellement prendre en argument un numéro de port. Si celui-ci n'est pas dans le manifest.
@ -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,8 +123,9 @@ 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 3 times to verify its ability to be multi-instance. The 2nd and 3rd respectively installs are adding a suffix then prefix path. - `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/.
- `port_already_use`: Causes an error on the port by opening before. - `port_already_use`: Causes an error on the port by opening before.
The `port_already_use` test may eventually take in argument the port number. The `port_already_use` test may eventually take in argument the port number.
@ -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

@ -254,6 +254,13 @@ EOF
# Give the execution right # Give the execution right
chmod +x "$script_dir/upgrade_script.sh" chmod +x "$script_dir/upgrade_script.sh"
# Temporary upgrade fix
# Check if lynx is already installed.
if [ ! -e "$(which lynx)" ]
then
sudo apt-get install -y lynx
fi
# Start the upgrade script by replacement of this process # Start the upgrade script by replacement of this process
exec "$script_dir/upgrade_script.sh" exec "$script_dir/upgrade_script.sh"
fi fi
@ -491,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"
@ -813,7 +817,7 @@ initialize_values() {
all_test=0 all_test=0
# Default path # Default path
test_path=/check test_path=/
} }
#================================================= #=================================================
@ -837,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
@ -1009,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)
@ -1021,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)
@ -1046,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
@ -1324,9 +1354,10 @@ if [ $type_exec_env -ge 1 ] && [ $send_mail -eq 1 ]
then then
# Add a 'from' header for the official CI only. # Add a 'from' header for the official CI only.
if [ $type_exec_env -eq 2 ]; then # Apparently, this trick is not needed anymore !?
from_yuno="-a \"From: yunohost@yunohost.org\"" # if [ $type_exec_env -eq 2 ]; then
fi # from_yuno="-a \"From: yunohost@yunohost.org\""
# fi
# Get the maintainer email from the manifest. If it doesn't found if the check_process # Get the maintainer email from the manifest. If it doesn't found if the check_process
if [ -z "$dest" ]; then if [ -z "$dest" ]; then

View file

@ -78,13 +78,13 @@ create_temp_backup () {
# Check if the snapshot already exist # Check if the snapshot already exist
if [ ! -e "$snapshot_path/snap$snap_number" ] if [ ! -e "$snapshot_path/snap$snap_number" ]
then then
echo "snap$snap_number doesn't exist, its first creation can be take a little while." >&2 echo "snap$snap_number doesn't exist, its first creation can takes a little while." >&2
# Create the snapshot. # Create the snapshot.
sudo lxc-snapshot --name $lxc_name >> "$test_result" 2>&1 sudo lxc-snapshot --name $lxc_name >> "$test_result" 2>&1
# lxc always creates the first snapshot it can creates. # lxc always creates the first snapshot it can creates.
# So if snap1 doesn't exist and you try to create snap2, it will be named snap1. # So if snap1 doesn't exist and you try to create snap2, it will be named snap1.
if [ "$snap_number" == "2" ] && [ ! -e "$snapshot_path/snap1" ] if [ "$snap_number" == "2" ] && [ ! -e "$snapshot_path/snap2" ]
then then
# Rename snap1 to snap2 # Rename snap1 to snap2
sudo mv "$snapshot_path/snap1" "$snapshot_path/snap2" sudo mv "$snapshot_path/snap1" "$snapshot_path/snap2"

View file

@ -71,8 +71,8 @@ echo -e "\e[1m> Update et install lxc lxctl\e[0m" | tee "$LOG_BUILD_LXC"
sudo apt-get update >> "$LOG_BUILD_LXC" 2>&1 sudo apt-get update >> "$LOG_BUILD_LXC" 2>&1
sudo apt-get install -y lxc lxctl >> "$LOG_BUILD_LXC" 2>&1 sudo apt-get install -y lxc lxctl >> "$LOG_BUILD_LXC" 2>&1
echo -e "\e[1m> Install git curl\e[0m" | tee "$LOG_BUILD_LXC" echo -e "\e[1m> Install git, curl and lynx\e[0m" | tee "$LOG_BUILD_LXC"
sudo apt-get install -y git curl >> "$LOG_BUILD_LXC" 2>&1 sudo apt-get install -y git curl lynx >> "$LOG_BUILD_LXC" 2>&1
sudo mkdir -p /var/lib/lxcsnaps # Créer le dossier lxcsnaps, pour s'assurer que lxc utilisera ce dossier, même avec lxc 2. sudo mkdir -p /var/lib/lxcsnaps # Créer le dossier lxcsnaps, pour s'assurer que lxc utilisera ce dossier, même avec lxc 2.
@ -80,6 +80,8 @@ if sudo lxc-info -n $LXC_NAME > /dev/null 2>&1
then # Si le conteneur existe déjà then # Si le conteneur existe déjà
echo -e "\e[1m> Suppression du conteneur existant.\e[0m" | tee -a "$LOG_BUILD_LXC" echo -e "\e[1m> Suppression du conteneur existant.\e[0m" | tee -a "$LOG_BUILD_LXC"
sudo lxc-snapshot -n $LXC_NAME -d snap0 | tee -a "$LOG_BUILD_LXC" sudo lxc-snapshot -n $LXC_NAME -d snap0 | tee -a "$LOG_BUILD_LXC"
sudo lxc-snapshot -n $LXC_NAME -d snap1 | tee -a "$LOG_BUILD_LXC"
sudo lxc-snapshot -n $LXC_NAME -d snap2 | tee -a "$LOG_BUILD_LXC"
sudo rm -f /var/lib/lxcsnaps/$LXC_NAME/snap0.tar.gz | tee -a "$LOG_BUILD_LXC" sudo rm -f /var/lib/lxcsnaps/$LXC_NAME/snap0.tar.gz | tee -a "$LOG_BUILD_LXC"
sudo lxc-destroy -n $LXC_NAME -f | tee -a "$LOG_BUILD_LXC" sudo lxc-destroy -n $LXC_NAME -f | tee -a "$LOG_BUILD_LXC"
fi fi
@ -124,6 +126,9 @@ if [ $dnsforce -eq 1 ]; then # Force la réécriture du resolv.conf
echo "nameserver $dns" | sudo tee /var/lib/lxc/$LXC_NAME/rootfs/etc/resolv.conf echo "nameserver $dns" | sudo tee /var/lib/lxc/$LXC_NAME/rootfs/etc/resolv.conf
fi fi
# Fix an issue with apparmor when the container start.
echo -e "\n# Fix apparmor issues\nlxc.aa_profile = unconfined" | sudo tee -a /var/lib/lxc/$LXC_NAME/config >> "$LOG_BUILD_LXC" 2>&1
echo -e "\e[1m> Démarrage de la machine\e[0m" | tee -a "$LOG_BUILD_LXC" echo -e "\e[1m> Démarrage de la machine\e[0m" | tee -a "$LOG_BUILD_LXC"
sudo lxc-start -n $LXC_NAME -d --logfile "$script_dir/lxc_boot.log" >> "$LOG_BUILD_LXC" 2>&1 sudo lxc-start -n $LXC_NAME -d --logfile "$script_dir/lxc_boot.log" >> "$LOG_BUILD_LXC" 2>&1
sleep 3 sleep 3

View file

@ -54,7 +54,7 @@ SETUP_APP () {
fi fi
# Install the application in a LXC container # Install the application in a LXC container
LXC_START "sudo yunohost --debug app install \"$package_dir\" -a \"$manifest_args_mod\"" LXC_START "sudo PACKAGE_CHECK_EXEC=1 yunohost --debug app install \"$package_dir\" -a \"$manifest_args_mod\""
# yunohost_result gets the return code of the installation # yunohost_result gets the return code of the installation
yunohost_result=$? yunohost_result=$?
@ -117,7 +117,7 @@ REMOVE_APP () {
ECHO_FORMAT "\nDeleting...\n" "white" "bold" clog ECHO_FORMAT "\nDeleting...\n" "white" "bold" clog
# Remove the application from the LXC container # Remove the application from the LXC container
LXC_START "sudo yunohost --debug app remove \"$ynh_app_id\"" LXC_START "sudo PACKAGE_CHECK_EXEC=1 yunohost --debug app remove \"$ynh_app_id\""
# yunohost_remove gets the return code of the deletion # yunohost_remove gets the return code of the deletion
yunohost_remove=$? yunohost_remove=$?
@ -145,7 +145,7 @@ CHECK_URL () {
ECHO_FORMAT "\nTry to access by url...\n" "white" "bold" ECHO_FORMAT "\nTry to access by url...\n" "white" "bold"
# Force a skipped_uris if public mode is not set # Force a skipped_uris if public mode is not set
if [ -z "$public_arg" ] if [ "$install_type" != "private" ] && [ "$install_type" != "public" ] && [ -z "$public_arg" ]
then then
# Add a skipped_uris on / for the app # Add a skipped_uris on / for the app
LXC_START "sudo yunohost app setting \"$ynh_app_id\" skipped_uris -v \"/\"" LXC_START "sudo yunohost app setting \"$ynh_app_id\" skipped_uris -v \"/\""
@ -248,7 +248,7 @@ CHECK_URL () {
ECHO_FORMAT "Service temporarily unavailable\n" "lyellow" "bold" ECHO_FORMAT "Service temporarily unavailable\n" "lyellow" "bold"
# 3 successive error are allowed # 3 successive error are allowed
http503=$(( http503 + 1 )) http503=$(( http503 + 1 ))
if [ $http503 -eq 3 ]; then if [ $http503 -ge 3 ]; then
# Over 3, it's definitively an error # Over 3, it's definitively an error
curl_error=1 curl_error=1
else else
@ -288,11 +288,71 @@ CHECK_URL () {
ECHO_FORMAT "The connection attempt fall on nginx default page.\n" "white" "bold" clog ECHO_FORMAT "The connection attempt fall on nginx default page.\n" "white" "bold" clog
fi fi
# Print the first 20 lines of the body # Print the first 20 lines of the page
ECHO_FORMAT "Extract of the body:\n" "white" ECHO_FORMAT "Extract of the page:\n" "white"
echo -e "\e[37m" # Write in 'light grey' echo -en "\e[37m" # Write in 'light grey'
grep "<body" --after-context=20 "$script_dir/url_output" | sed 1d | tee --append "$test_result" lynx -dump -force_html "$script_dir/url_output" | head --lines 20 | tee --append "$test_result"
echo -e "\e[0m" echo -e "\e[0m"
# Get all the resources for the main page of the app.
local HTTP_return
local moved=0
local ignored=0
while read HTTP_return
do
# Ignore robots.txt and ynhpanel.js. They always redirect to the portal.
if echo "$HTTP_return" | grep --quiet "$check_domain/robots.txt\|$check_domain/ynhpanel.js"; then
ECHO_FORMAT "Ressource ignored:" "white"
ECHO_FORMAT " ${HTTP_return##*http*://}\n"
ignored=1
fi
# If it's the line with the resource to get
if echo "$HTTP_return" | grep --quiet "^--.*-- http"
then
# Get only the resource itself.
local resource=${HTTP_return##*http*://}
# Else, if would be the HTTP return code.
else
# If the return code is different than 200.
if ! echo "$HTTP_return" | grep --quiet "200 OK$"
then
# Skipped the check of ignored ressources.
if [ $ignored -eq 1 ]
then
ignored=0
continue
fi
# Isolate the http return code.
http_code="${HTTP_return##*awaiting response... }"
http_code="${http_code:0:3}"
# If the return code is 301 or 302, let's check the redirection.
if echo "$HTTP_return" | grep --quiet "30[12] Moved"
then
ECHO_FORMAT "Ressource moved:" "white"
ECHO_FORMAT " $resource\n"
moved=1
else
ECHO_FORMAT "Resource unreachable (Code $http_code)" "red" "bold"
ECHO_FORMAT " $resource\n"
# curl_error=1
moved=0
fi
else
if [ $moved -eq 1 ]
then
if echo "$resource" | grep --quiet "/yunohost/sso/"
then
ECHO_FORMAT "The previous resource is redirected to the YunoHost portal\n" "red"
# curl_error=1
fi
fi
moved=0
fi
fi
done <<< "$(cd "$package_path"; LC_ALL=C wget --adjust-extension --page-requisites --no-check-certificate $check_domain$curl_check_path 2>&1 | grep "^--.*-- http\|^HTTP request sent")"
echo ""
fi fi
fi fi
done done
@ -536,73 +596,129 @@ 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
# Check if an install have previously work do
local previous_install=$(is_install_failed) if [ "$commit" == "current" ]
# Abort if none install worked then
[ "$previous_install" = "1" ] && return unit_test_title "Upgrade from the same version..."
# 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
else 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 fi
# Check all the witness files, to verify if them still here # Check if an install have previously work
check_witness_files local previous_install=$(is_install_failed)
# Abort if none install worked
[ "$previous_install" = "1" ] && return
# Analyse the log to extract "warning" and "error" lines # Copy original arguments
LOG_EXTRACTOR local manifest_args_mod="$manifest_arguments"
# Try to access the app by its url # Replace manifest key for the test
CHECK_URL check_domain=$sub_domain
fi 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 # Install the application in a LXC container
if check_test_result ECHO_FORMAT "\nPreliminary install...\n" "white" "bold" clog
then # Success if [ "$commit" == "current" ]
RESULT_check_upgrade=1 # Upgrade succeed then
else # Fail # If no commit is specified, use the current version.
RESULT_check_upgrade=-1 # Upgrade failed STANDARD_SETUP_APP
fi 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 # Check if the install had work
REMOVE_APP 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 PACKAGE_CHECK_EXEC=1 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 () { CHECK_PUBLIC_PRIVATE () {
@ -735,48 +851,38 @@ CHECK_MULTI_INSTANCE () {
unit_test_title "Multi-instance installations..." unit_test_title "Multi-instance installations..."
# Check if the sub path install have previously work # Check if an install have previously work
if [ $RESULT_check_sub_dir -ne 1 ] && [ $force_install_ok -ne 1 ] local previous_install=$(is_install_failed)
then # Abort if none install worked
# If subdir installation doesn't worked and force_install_ok not setted, aborted this test. [ "$previous_install" = "1" ] && return
ECHO_FORMAT "Sub path install failed, impossible to perform this test...\n" "red" clog
return
fi
# Copy original arguments # Copy original arguments
local manifest_args_mod="$manifest_arguments" local manifest_args_mod="$manifest_arguments"
# Replace manifest key for the test # Replace manifest key for the test
check_domain=$sub_domain replace_manifest_key "path" "$test_path"
replace_manifest_key "domain" "$check_domain" check_path=$test_path
replace_manifest_key "user" "$test_user" replace_manifest_key "user" "$test_user"
replace_manifest_key "public" "$public_public_arg" replace_manifest_key "public" "$public_public_arg"
# Install 3 times the same app # Install 2 times the same app
local i=0 local i=0
for i in 1 2 3 for i in 1 2
do do
# First installation # First installation
if [ $i -eq 1 ] if [ $i -eq 1 ]
then then
local path_1=$test_path check_domain=$main_domain
ECHO_FORMAT "First installation: path=$path_1\n" clog ECHO_FORMAT "First installation: path=$check_domain$check_path\n" clog
check_path=$path_1
# Second installation # Second installation
elif [ $i -eq 2 ] elif [ $i -eq 2 ]
then then
local path_2="/2${test_path#/}" check_domain=$sub_domain
ECHO_FORMAT "Second installation: path=$path_2\n" clog ECHO_FORMAT "Second installation: path=$check_domain$check_path\n" clog
check_path=$path_2
# Third installation
else
local path_3="/3-${test_path#/}"
ECHO_FORMAT "Third installation: path=$path_3\n" clog
check_path=$path_3
fi fi
# Replace path manifest key for the test # Replace path and domain manifest keys for the test
replace_manifest_key "path" "$check_path" replace_manifest_key "domain" "$check_domain"
# Install the application in a LXC container # Install the application in a LXC container
SETUP_APP SETUP_APP
@ -786,36 +892,28 @@ CHECK_MULTI_INSTANCE () {
if [ $i -eq 1 ] if [ $i -eq 1 ]
then then
local multi_yunohost_result_1=$yunohost_result local multi_yunohost_result_1=$yunohost_result
local ynh_app_id_1=$ynh_app_id local ynh_app_id_1=$ynh_app_id
# Second installation # Second installation
elif [ $i -eq 2 ] elif [ $i -eq 2 ]
then then
local multi_yunohost_result_2=$yunohost_result local multi_yunohost_result_2=$yunohost_result
local ynh_app_id_2=$ynh_app_id local ynh_app_id_2=$ynh_app_id
# Third installation
else
local multi_yunohost_result_3=$yunohost_result
local ynh_app_id_3=$ynh_app_id
fi fi
done done
# Try to access to the 3 apps by theirs url # Try to access to the 2 apps by theirs url
for i in 1 2 3 for i in 1 2
do do
# First app # First app
if [ $i -eq 1 ] if [ $i -eq 1 ]
then then
check_path=$path_1 check_domain=$main_domain
ynh_app_id=$ynh_app_id_1 ynh_app_id=$ynh_app_id_1
# Second app # Second app
elif [ $i -eq 2 ] elif [ $i -eq 2 ]
then then
check_path=$path_2 check_domain=$sub_domain
ynh_app_id=$ynh_app_id_2 ynh_app_id=$ynh_app_id_2
# Third app
else
check_path=$path_3
ynh_app_id=$ynh_app_id_3
fi fi
# Try to access the app by its url # Try to access the app by its url
@ -833,16 +931,13 @@ CHECK_MULTI_INSTANCE () {
elif [ $i -eq 2 ] elif [ $i -eq 2 ]
then then
multi_yunohost_result_2=1 multi_yunohost_result_2=1
# Third app
else
multi_yunohost_result_3=1
fi fi
fi fi
done done
# Check the result and print SUCCESS or FAIL # Check the result and print SUCCESS or FAIL
# Succeed if first installation works, and either the second or the third works also # Succeed if the 2 installations work;
if [ $multi_yunohost_result_1 -eq 0 ] && ( [ $multi_yunohost_result_2 -eq 0 ] || [ $multi_yunohost_result_3 -eq 0 ] ) if [ $multi_yunohost_result_1 -eq 0 ] && [ $multi_yunohost_result_2 -eq 0 ]
then # Success then # Success
check_success check_success
RESULT_check_multi_instance=1 RESULT_check_multi_instance=1
@ -1026,7 +1121,7 @@ CHECK_BACKUP_RESTORE () {
ECHO_FORMAT "\nBackup of the application...\n" "white" "bold" clog ECHO_FORMAT "\nBackup of the application...\n" "white" "bold" clog
# Made a backup of the application # Made a backup of the application
LXC_START "sudo yunohost --debug backup create -n Backup_test --apps $ynh_app_id --system $backup_hooks" LXC_START "sudo PACKAGE_CHECK_EXEC=1 yunohost --debug backup create -n Backup_test --apps $ynh_app_id --system $backup_hooks"
# yunohost_result gets the return code of the backup # yunohost_result gets the return code of the backup
yunohost_result=$? yunohost_result=$?
@ -1093,7 +1188,7 @@ CHECK_BACKUP_RESTORE () {
fi fi
# Restore the application from the previous backup # Restore the application from the previous backup
LXC_START "sudo yunohost --debug backup restore Backup_test --force --apps $ynh_app_id" LXC_START "sudo PACKAGE_CHECK_EXEC=1 yunohost --debug backup restore Backup_test --force --apps $ynh_app_id"
# yunohost_result gets the return code of the restore # yunohost_result gets the return code of the restore
yunohost_result=$? yunohost_result=$?
@ -1231,7 +1326,7 @@ CHECK_CHANGE_URL () {
ECHO_FORMAT "Change the url from $sub_domain$check_path to $new_domain$new_path...\n" "white" "bold" clog ECHO_FORMAT "Change the url from $sub_domain$check_path to $new_domain$new_path...\n" "white" "bold" clog
# Change the url # Change the url
LXC_START "sudo yunohost --debug app change-url $ynh_app_id -d \"$new_domain\" -p \"$new_path\"" LXC_START "sudo PACKAGE_CHECK_EXEC=1 yunohost --debug app change-url $ynh_app_id -d \"$new_domain\" -p \"$new_path\""
# yunohost_result gets the return code of the change-url script # yunohost_result gets the return code of the change-url script
yunohost_result=$? yunohost_result=$?