From a4c0a3fcc4c4222ccf880a942a131684827a76a6 Mon Sep 17 00:00:00 2001 From: Kay0u Date: Thu, 24 Dec 2020 18:39:32 +0100 Subject: [PATCH 1/3] backup/restore for both root and subdir --- lib/tests.sh | 130 +++++++++++++++++++++----------------- lib/tests_coordination.sh | 18 ++++-- 2 files changed, 82 insertions(+), 66 deletions(-) diff --git a/lib/tests.sh b/lib/tests.sh index d9c8583..0f2d4e1 100644 --- a/lib/tests.sh +++ b/lib/tests.sh @@ -452,74 +452,86 @@ TEST_BACKUP_RESTORE () { # Check if an install have previously work at_least_one_install_succeeded || return 1 - local check_path="$(default_install_path)" + local check_paths=() - # Install the application in a LXC container - _LOAD_SNAPSHOT_OR_INSTALL_APP "$check_path" - - local ret=$? + if this_is_a_web_app; then + there_is_a_root_install_test && check_paths+=("$(root_path)") + there_is_a_subdir_install_test && check_paths+=("$(subdir_path)") + else + check_paths+=("") + fi local main_result=0 - # Remove the previous residual backups - RUN_INSIDE_LXC rm -rf /home/yunohost.backup/archives - - # BACKUP - # Made a backup if the installation succeed - if [ $ret -ne 0 ] - then - log_error "Installation failed..." - else - log_small_title "Backup of the application..." - - # Made a backup of the application - _RUN_YUNOHOST_CMD "backup create -n Backup_test --apps $app_id" - ret=$? - fi - - [ $ret -eq 0 ] || main_result=1 - - # Grab the backup archive into the LXC container, and keep a copy - lxc file pull -r $LXC_NAME/home/yunohost.backup/archives $TEST_CONTEXT/ynh_backups - - # RESTORE - # Try the restore process in 2 times, first after removing the app, second after a restore of the container. - local j=0 - for j in 0 1 + for check_path in "${check_paths[@]}" do - # First, simply remove the application - if [ $j -eq 0 ] - then - # Remove the application - _REMOVE_APP - - log_small_title "Restore after removing the application..." - - # Second, restore the whole container to remove completely the application - elif [ $j -eq 1 ] - then - - LOAD_LXC_SNAPSHOT snap0 - - # Remove the previous residual backups - RUN_INSIDE_LXC rm -rf /home/yunohost.backup/archives - - # 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..." - fi - - # Restore the application from the previous backup - _RUN_YUNOHOST_CMD "backup restore Backup_test --force --apps $app_id" \ - && _VALIDATE_THAT_APP_CAN_BE_ACCESSED "$SUBDOMAIN" "$check_path" + # Install the application in a LXC container + _LOAD_SNAPSHOT_OR_INSTALL_APP "$check_path" local ret=$? + + # Remove the previous residual backups + RUN_INSIDE_LXC rm -rf /home/yunohost.backup/archives + + # BACKUP + # Made a backup if the installation succeed + if [ $ret -ne 0 ] + then + log_error "Installation failed..." + main_result=1 + continue + else + log_small_title "Backup of the application..." + + # Made a backup of the application + _RUN_YUNOHOST_CMD "backup create -n Backup_test --apps $app_id" + ret=$? + fi + [ $ret -eq 0 ] || main_result=1 - break_before_continue + # Grab the backup archive into the LXC container, and keep a copy + lxc file pull -r $LXC_NAME/home/yunohost.backup/archives $TEST_CONTEXT/ynh_backups + + # RESTORE + # Try the restore process in 2 times, first after removing the app, second after a restore of the container. + local j=0 + for j in 0 1 + do + # First, simply remove the application + if [ $j -eq 0 ] + then + # Remove the application + _REMOVE_APP + + log_small_title "Restore after removing the application..." + + # Second, restore the whole container to remove completely the application + elif [ $j -eq 1 ] + then + + LOAD_LXC_SNAPSHOT snap0 + + # Remove the previous residual backups + RUN_INSIDE_LXC rm -rf /home/yunohost.backup/archives + + # 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..." + fi + + # Restore the application from the previous backup + _RUN_YUNOHOST_CMD "backup restore Backup_test --force --apps $app_id" \ + && _VALIDATE_THAT_APP_CAN_BE_ACCESSED "$SUBDOMAIN" "$check_path" + + ret=$? + [ $ret -eq 0 ] || main_result=1 + + break_before_continue + done done return $main_result diff --git a/lib/tests_coordination.sh b/lib/tests_coordination.sh index 8e330b0..d6b646f 100644 --- a/lib/tests_coordination.sh +++ b/lib/tests_coordination.sh @@ -403,15 +403,19 @@ this_is_a_web_app () { return $(there_is_a_root_install_test) || $(there_is_a_subdir_install_test) } +root_path () { + echo "/" +} + +subdir_path () { + echo "/path" +} + default_install_path() { # All webapps should be installable at the root or in a subpath of a domain - if there_is_a_root_install_test; then - echo "/" - elif there_is_a_subdir_install_test; then - echo "/path" - else - echo "" - fi + there_is_a_root_install_test && { root_path; return; } + there_is_a_subdir_install_test && { subdir_path; return; } + echo "" } path_to_install_type() { From 9279a913aa91108c93d86da328246745672a7251 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Fri, 25 Dec 2020 14:34:19 +0100 Subject: [PATCH 2/3] Update lib/tests.sh Co-authored-by: Kayou --- lib/tests.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/tests.sh b/lib/tests.sh index 0f2d4e1..4db3612 100644 --- a/lib/tests.sh +++ b/lib/tests.sh @@ -488,7 +488,7 @@ TEST_BACKUP_RESTORE () { ret=$? fi - [ $ret -eq 0 ] || main_result=1 + [ $ret -eq 0 ] || { main_result=1; break_before_continue; continue; } # Grab the backup archive into the LXC container, and keep a copy lxc file pull -r $LXC_NAME/home/yunohost.backup/archives $TEST_CONTEXT/ynh_backups @@ -903,4 +903,3 @@ ACTIONS_CONFIG_PANEL () { return $main_result } - From 0f5e1187e30fe441d75e7e0fed62099b687fbb5e Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Fri, 25 Dec 2020 14:34:30 +0100 Subject: [PATCH 3/3] Update lib/tests.sh Co-authored-by: Kayou --- lib/tests.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/tests.sh b/lib/tests.sh index 4db3612..1a913bb 100644 --- a/lib/tests.sh +++ b/lib/tests.sh @@ -479,6 +479,7 @@ TEST_BACKUP_RESTORE () { then log_error "Installation failed..." main_result=1 + break_before_continue continue else log_small_title "Backup of the application..."