diff --git a/package_check.sh b/package_check.sh
index 0f5cef2..e163b1e 100755
--- a/package_check.sh
+++ b/package_check.sh
@@ -32,8 +32,6 @@ Usage:
package_check.sh [OPTION]... PACKAGE_TO_CHECK
-b, --branch=BRANCH
Specify a branch to check.
- -f, --force-install-ok
- Force remaining tests even if installation tests failed or were not selected for execution.
-i, --interactive
Wait for the user to continue before each remove.
-h, --help
@@ -92,7 +90,6 @@ do
arguments[$i]=${arguments[$i]//--branch=/}
fi
# For each argument in the array, reduce to short argument for getopts
- arguments[$i]=${arguments[$i]//--force-install-ok/-f}
arguments[$i]=${arguments[$i]//--interactive/-i}
arguments[$i]=${arguments[$i]//--help/-h}
arguments[$i]=${arguments[$i]//--build-lxc/-l}
@@ -117,11 +114,6 @@ parse_arg () {
gitbranch="-b $OPTARG"
shift_value=2
;;
- f)
- # --force-install-ok
- force_install_ok=1
- shift_value=1
- ;;
i)
# --interactive
interactive=1
@@ -209,7 +201,6 @@ fi
# Stop and restore the LXC container. In case of previous incomplete execution.
LXC_STOP
-# Deactivate LXC network
LXC_TURNOFF
#=================================================
@@ -594,7 +585,15 @@ parse_check_process() {
# Extract the Options section
extract_check_process_section "^;;; Options" ";; " > $TEST_CONTEXT/check_process.options
+
+ # Extract the Upgrade infos
extract_check_process_section "^;;; Upgrade options" ";; " > $TEST_CONTEXT/check_process.upgrade_options
+ mkdir -p $TEST_CONTEXT/upgrades.d
+ for commit in $(cat $TEST_CONTEXT/check_process.upgrade_options | grep "^; commit=.*" | awk -F= '{print $2}')
+ do
+ cat $TEST_CONTEXT/check_process.upgrade_options | sed -n -e "/^;; $commit/,/^;;/ p" | grep -v "^;;" > $TEST_CONTEXT/upgrades
+ done
+ rm $TEST_CONTEXT/check_process.upgrade_options
# Parse each tests serie
while read <&3 tests_serie
@@ -612,14 +611,19 @@ parse_check_process() {
echo "$tests_serie" > $test_serie_dir/test_serie_name
extract_check_process_section "^$tests_serie" "^;;" > $test_serie_rawconf
extract_check_process_section "^; pre-install" "^; " $test_serie_rawconf > $test_serie_dir/preinstall.sh.template
- extract_check_process_section "^; Manifest" "^; " $test_serie_rawconf > $test_serie_dir/check_process.manifest_infos
+ # This is the arg list to be later fed to "yunohost app install"
+ extract_check_process_section "^; Manifest" "^; " $test_serie_rawconf | awk '{print $1}' | tr -d '"' | tr '\n' '&' > $test_serie_dir/install_args
extract_check_process_section "^; Actions" "^; " $test_serie_rawconf > $test_serie_dir/check_process.actions_infos
extract_check_process_section "^; Config_panel" "^; " $test_serie_rawconf > $test_serie_dir/check_process.configpanel_infos
extract_check_process_section "^; Checks" "^; " $test_serie_rawconf > $test_serie_dir/check_process.tests_infos
- # This is the arg list to be later fed to "yunohost app install"
- cat $test_serie_dir/check_process.manifest_infos \
- | awk '{print $1}' | tr -d '"' | tr '\n' '&' > $test_serie_dir/install_args
+ # This is the test of commits to test upgrade from
+ for LINE in $(grep "^upgrade=1" "$test_serie_dir/check_process.tests_infos")
+ do
+ commit=$(echo $LINE | grep -o "from_commit=.*" | awk -F= '{print $2}')
+ [ -n "$commit" ] || commit="current"
+ echo $commit >> $test_serie_dir/upgrades_to_test
+ done
is_test_enabled () {
# Find the line for the given check option
@@ -715,12 +719,7 @@ run_all_tests() {
# Print the final results of the tests
COMPUTE_RESULTS_SUMMARY $test_serie_id
- # Set snap0 as the current snapshot
- current_snapshot=snap0
- # And clean temporary snapshots
- unset root_snapshot
- unset subpath_snapshot
-
+ # FIXME FIXME FIXME gotta reset the snapshot
done
# Restore the started time for the timer
diff --git a/sub_scripts/launcher.sh b/sub_scripts/launcher.sh
index c6d508f..dcd9263 100755
--- a/sub_scripts/launcher.sh
+++ b/sub_scripts/launcher.sh
@@ -6,7 +6,6 @@
# -q aims to disable the display of 'Debian GNU/Linux' each time a command is ran
arg_ssh="-tt -q"
-current_snapshot=snap0
#=================================================
# RUNNING SNAPSHOT
@@ -15,8 +14,7 @@ current_snapshot=snap0
CREATE_LXC_SNAPSHOT () {
# Create a temporary snapshot
- # snap1 for subpath or snap2 for root install
- snap_number=$1
+ local snapname=$1
start_timer
# Check all the witness files, to verify if them still here
@@ -34,26 +32,23 @@ CREATE_LXC_SNAPSHOT () {
fi
# Check if the snapshot already exist
- if [ ! -e "$LXC_SNAPSHOTS/snap$snap_number" ]
+ if [ ! -e "$LXC_SNAPSHOTS/$snapname" ]
then
- log_debug "snap$snap_number doesn't exist, its first creation can takes a little while." >&2
+ log_debug "$snapname doesn't exist, its first creation can takes a little while." >&2
# Create the snapshot.
sudo lxc-snapshot --name $LXC_NAME >> "$complete_log" 2>&1
# 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.
- if [ "$snap_number" == "2" ] && [ ! -e "$LXC_SNAPSHOTS/snap2" ]
+ # So if snap1 doesn't exist and you try to create snap_foo, it will be named snap1.
+ if [ "$snapname" != "snap1" ] && [ ! -e "$LXC_SNAPSHOTS/$snapname" ]
then
- # Rename snap1 to snap2
- sudo mv "$LXC_SNAPSHOTS/snap1" "$LXC_SNAPSHOTS/snap2"
+ # Rename snap1
+ sudo mv "$LXC_SNAPSHOTS/snap1" "$LXC_SNAPSHOTS/$snapname"
fi
fi
# Update the snapshot with rsync to clone the current lxc state
- sudo rsync --acls --archive --delete --executability --itemize-changes --xattrs "$LXC_ROOTFS/" "$LXC_SNAPSHOTS/snap$snap_number/rootfs/" > /dev/null 2>> "$complete_log"
-
- # Set this snapshot as the current snapshot
- current_snapshot=snap$snap_number
+ sudo rsync --acls --archive --delete --executability --itemize-changes --xattrs "$LXC_ROOTFS/" "$LXC_SNAPSHOTS/$snapname/rootfs/" > /dev/null 2>> "$complete_log"
stop_timer 1
@@ -64,19 +59,21 @@ CREATE_LXC_SNAPSHOT () {
LOAD_LXC_SNAPSHOT () {
# Use a temporary snapshot, if it already exists
# $1 = Name of the snapshot to use
- current_snapshot=$1
+ local snapshot=$1
+
+ log_debug "Restoring snapshot $snapshot"
start_timer
# Fix the missing hostname in the hosts file...
- echo "127.0.0.1 $LXC_NAME" | sudo tee --append "$LXC_SNAPSHOTS/$current_snapshot/rootfs/etc/hosts" > /dev/null
+ echo "127.0.0.1 $LXC_NAME" | sudo tee --append "$LXC_SNAPSHOTS/$snapshot/rootfs/etc/hosts" > /dev/null
# Restore this snapshot.
- sudo rsync --acls --archive --delete --executability --itemize-changes --xattrs "$LXC_SNAPSHOTS/$current_snapshot/rootfs/" "$LXC_ROOTFS/" > /dev/null 2>> "$complete_log"
+ sudo rsync --acls --archive --delete --executability --itemize-changes --xattrs "$LXC_SNAPSHOTS/$snapshot/rootfs/" "$LXC_ROOTFS/" > /dev/null 2>> "$complete_log"
+ local ret=$?
stop_timer 1
- # Fake the yunohost_result return code of the installation
- yunohost_result=0
+ return $ret
}
#=================================================
@@ -91,10 +88,10 @@ LXC_INIT () {
sudo rm --force $LXC_ROOTFS/swap_*
sudo swapoff $LXC_SNAPSHOTS/snap0/rootfs/swap_* 2>/dev/null
sudo rm --force $LXC_SNAPSHOTS/snap0/rootfs/swap_*
- sudo swapoff $LXC_SNAPSHOTS/snap1/rootfs/swap_* 2>/dev/null
- sudo rm --force $LXC_SNAPSHOTS/snap1/rootfs/swap_*
- sudo swapoff $LXC_SNAPSHOTS/snap2/rootfs/swap_* 2>/dev/null
- sudo rm --force $LXC_SNAPSHOTS/snap2/rootfs/swap_*
+ sudo swapoff $LXC_SNAPSHOTS/snap_rootinstall/rootfs/swap_* 2>/dev/null
+ sudo rm --force $LXC_SNAPSHOTS/snap_rooinstall/rootfs/swap_*
+ sudo swapoff $LXC_SNAPSHOTS/snap_subdirintsall/rootfs/swap_* 2>/dev/null
+ sudo rm --force $LXC_SNAPSHOTS/snap_subdirinstall/rootfs/swap_*
# Initialize LXC network
@@ -111,7 +108,7 @@ LXC_INIT () {
LXC_START () {
# Start the lxc container and execute the given command in it
- # $1 = Command to execute in the container
+ local cmd=$1
start_timer
# Try to start the container 3 times.
@@ -143,13 +140,11 @@ LXC_START () {
fi
sleep 1
done
- echo ""
- if [ "$(uname -m)" == "aarch64" ]
- then
- sleep 30
- fi
+
+ [ "$(uname -m)" == "aarch64" ] && sleep 30
local failstart=0
+
# Check if the container is running
if ! is_lxc_running; then
log_critical "The LXC container didn't start..."
@@ -158,7 +153,7 @@ LXC_START () {
log_info "Rebooting the container..."
fi
LXC_STOP
- # Try to ping security.debian.org to check the connectivity from the container
+ # Try to ping security.debian.org to check the connectivity from the container
elif ! ssh $arg_ssh -o ConnectTimeout=60 $LXC_NAME "sudo ping -q -c 2 security.debian.org > /dev/null 2>&1; exit \$?" >> "$complete_log" 2>&1
then
log_critical "The container failed to connect to internet..."
@@ -167,7 +162,7 @@ LXC_START () {
log_info "Rebooting the container..."
fi
LXC_STOP
- # Create files to check if the remove script does not remove them accidentally
+ # Create files to check if the remove script does not remove them accidentally
else
[ $avoid_witness -eq 0 ] && set_witness_files
@@ -243,7 +238,7 @@ LXC_START () {
rsync -rq --delete "$package_path" "$LXC_NAME": >> "$complete_log" 2>&1
# Execute the command given in argument in the container and log its results.
- ssh $arg_ssh $LXC_NAME "$1; exit $?" | tee -a "$complete_log"
+ ssh $arg_ssh $LXC_NAME "$cmd; exit $?" | tee -a "$complete_log"
# Store the return code of the command
local returncode=${PIPESTATUS[0]}
@@ -254,34 +249,20 @@ LXC_START () {
}
LXC_STOP () {
- # Stop and restore the LXC container
-
- start_timer
- # Stop the LXC container
- if is_lxc_running; then
+ if is_lxc_running;
+ then
log_debug "Stop the LXC container"
sudo lxc-stop --name=$LXC_NAME | tee --append "$complete_log" 2>&1
fi
+}
- # Fix the missing hostname in the hosts file
- # If the hostname is missing in /etc/hosts inside the snapshot
- if ! sudo grep --quiet "$LXC_NAME" "$LXC_SNAPSHOTS/$current_snapshot/rootfs/etc/hosts"
- then
- # If the hostname was replaced by name of the snapshot, fix it
- if sudo grep --quiet "$current_snapshot" "$LXC_SNAPSHOTS/$current_snapshot/rootfs/etc/hosts"
- then
- # Replace snapX by the real hostname
- sudo sed --in-place "s/$current_snapshot/$LXC_NAME/" "$LXC_SNAPSHOTS/$current_snapshot/rootfs/etc/hosts"
- else
- # Otherwise, simply add the hostname
- echo "127.0.0.1 $LXC_NAME" | sudo tee --append "$LXC_SNAPSHOTS/$current_snapshot/rootfs/etc/hosts" > /dev/null
- fi
- fi
+LOAD_LXC_SNAPSHOT () {
+ snapname=$1
- # Restore the snapshot.
- log_debug "Restore the previous snapshot."
- sudo rsync --acls --archive --delete --executability --itemize-changes --xattrs "$LXC_SNAPSHOTS/$current_snapshot/rootfs/" "$LXC_ROOTFS/" > /dev/null 2>> "$complete_log"
- stop_timer 1
+ LXC_STOP
+
+ log_debug "Restoring snapshot $snapname"
+ sudo rsync --acls --archive --delete --executability --itemize-changes --xattrs "$LXC_SNAPSHOTS/$snapname/rootfs/" "$LXC_ROOTFS/" > /dev/null 2>> "$complete_log"
}
LXC_TURNOFF () {
@@ -306,7 +287,4 @@ LXC_TURNOFF () {
then
sudo ifdown --force $LXC_BRIDGE | tee --append "$complete_log" 2>&1
fi
-
- # Set snap0 as the current snapshot
- current_snapshot=snap0
}
diff --git a/sub_scripts/lxc_remove.sh b/sub_scripts/lxc_remove.sh
index 3db0703..98d1fac 100755
--- a/sub_scripts/lxc_remove.sh
+++ b/sub_scripts/lxc_remove.sh
@@ -20,8 +20,8 @@ sudo rm -f /etc/network/interfaces.d/$LXC_BRIDGE
log_title "Suppression de la machine et de son snapshots"
sudo lxc-snapshot -n $LXC_NAME -d snap0
-sudo lxc-snapshot -n $LXC_NAME -d snap1
-sudo lxc-snapshot -n $LXC_NAME -d snap2
+sudo lxc-snapshot -n $LXC_NAME -d snap_rootinstall
+sudo lxc-snapshot -n $LXC_NAME -d snap_subdirinstall
sudo rm -f /var/lib/lxcsnaps/$LXC_NAME/snap0.tar.gz
sudo lxc-destroy -n $LXC_NAME -f
diff --git a/sub_scripts/testing_process.sh b/sub_scripts/testing_process.sh
index 4d85897..7e6fd14 100755
--- a/sub_scripts/testing_process.sh
+++ b/sub_scripts/testing_process.sh
@@ -27,21 +27,24 @@ start_test () {
RUN_YUNOHOST_CMD() {
+ log_debug "Running yunohost $1"
+
# --output-as none is to disable the json-like output for some commands like backup create
LXC_START "sudo PACKAGE_CHECK_EXEC=1 yunohost --output-as none --debug $1" \
| grep --line-buffered -v --extended-regexp '^[0-9]+\s+.{1,15}DEBUG' \
| grep --line-buffered -v 'processing action'
returncode=${PIPESTATUS[0]}
- check_witness_files
- return $returncode
+ check_witness_files && return $returncode || return 2
}
SET_RESULT() {
+ [ $2 -eq 1 ] && log_report_test_success || log_report_test_failed
sed --in-place "s/RESULT_$1=.*$/RESULT_$1=$2/g" $test_serie_dir/results
}
SET_RESULT_IF_NONE_YET() {
+ [ $2 -eq 1 ] && log_report_test_success || log_report_test_failed
if [ $(GET_RESULT $1) -eq 0 ]
then
sed --in-place "s/RESULT_$1=.*$/RESULT_$1=$2/g" $test_serie_dir/results
@@ -59,16 +62,16 @@ GET_RESULT() {
INSTALL_APP () {
local install_args="$(cat "$test_serie_dir/install_args")"
- for arg_override in "$@"
+
+ # We have default values for domain, user and is_public, but these
+ # may still be overwritten by the args ($@)
+ for arg_override in "domain=$SUBDOMAIN" "user=$TEST_USER" "is_public=1" "$@"
do
key="$(echo $arg_override | cut -d '=' -f 1)"
value="$(echo $arg_override | cut -d '=' -f 2-)"
install_args=$(echo $install_args | sed "s@$key=[^&]*\&@$key=$value\&@")
done
- # Uses the default snapshot
- current_snapshot=snap0
-
# Exec the pre-install instruction, if there one
preinstall_script_template="$test_serie_dir/preinstall.sh.template"
if [ -n "$(cat $preinstall_script_template)" ]
@@ -94,49 +97,27 @@ INSTALL_APP () {
# Install the application in a LXC container
RUN_YUNOHOST_CMD "app install --force ./app_folder/ -a '$install_args'"
- # yunohost_result gets the return code of the installation
- yunohost_result=$?
-
- # Print the result of the install command
- if [ $yunohost_result -eq 0 ]; then
- log_debug "Installation successful."
- else
- log_error "Installation failed. ($yunohost_result)"
- fi
-
- return $yunohost_result
+ local ret=$?
+ [ $ret -eq 0 ] && log_debug "Installation successful." || log_error "Installation failed."
+ return $ret
}
LOAD_SNAPSHOT_OR_INSTALL_APP () {
- # Try to find an existing snapshot for this install, or make an install
- # If it's a root install
- if [ "$check_path" = "/" ]
- then
- install_type="root"
- snapshot=$root_snapshot
- snapshot_id=2
- else
- install_type="subpath"
- snapshot=$subpath_snapshot
- snapshot_id=1
- fi
+ local check_path="$1"
+ local _install_type=$([ "$check_path" = "/" ] && echo "root" || echo "subdir")
+ local snapname="snap_${_install_type}install"
- # Create a snapshot if needed
- if [ -z "$snapshot" ]
+ if [ ! -e "$LXC_SNAPSHOTS/$snapname" ]
then
- # Create a snapshot for this installation, to be able to reuse it instead of a new installation.
- # But only if this installation has worked fine
- if INSTALL_APP
- then
- log_debug "Creating a snapshot for $install_type installation."
- CREATE_LXC_SNAPSHOT $snapshot_id
- root_snapshot=snap$snapshot_id
- fi
+ LOAD_LXC_SNAPSHOT snap0 \
+ && INSTALL_APP "path=$check_path" \
+ && log_debug "Creating a snapshot for $_install_type installation." \
+ && CREATE_LXC_SNAPSHOT $snapname
else
# Or uses an existing snapshot
- log_debug "Reusing an existing snapshot for $install_type installation."
- LOAD_LXC_SNAPSHOT $snapshot
+ log_debug "Reusing an existing snapshot for $_install_type installation." \
+ && LOAD_LXC_SNAPSHOT $snapname
fi
}
@@ -150,17 +131,9 @@ REMOVE_APP () {
# Remove the application from the LXC container
RUN_YUNOHOST_CMD "app remove $app_id"
- # yunohost_remove gets the return code of the deletion
- local yunohost_remove=$?
-
- # Print the result of the remove command
- if [ "$yunohost_remove" -eq 0 ]; then
- log_debug "Remove successful."
- else
- log_error "Remove failed. ($yunohost_remove)"
- fi
-
- return $yunohost_remove
+ local ret=$?
+ [ "$ret" -eq 0 ] && log_debug "Remove successful." || log_error "Remove failed."
+ return $ret
}
#=================================================
@@ -169,171 +142,131 @@ REMOVE_APP () {
VALIDATE_THAT_APP_CAN_BE_ACCESSED () {
- local app_id_to_check=${1:-$app_id}
+ local check_domain=$1
+ local check_path=$2
+ local expected_to_be=${3} # Can be empty, public or private, later used to check if it's okay to end up on the portal
+ local app_id_to_check=${4:-$app_id}
+
+ local curl_error=0
+ local fell_on_sso_portal=0
+ local curl_output=$test_serie_dir/curl_output
# Not checking this if this ain't relevant for the current test / app
- if [ $enable_validate_that_app_can_be_accessed == "true" ]
- then
- curl_error=0
- yuno_portal=0
- return
- fi
+ [ $enable_validate_that_app_can_be_accessed == "true" ] || return 0
log_small_title "Validating that the app can (or cannot) be accessed with its url..."
# Force a skipped_uris if public mode is not set
- if [ "$install_type" != "private" ] && [ "$install_type" != "public" ]
+ if [ -z "$expected_to_be" ]
then
- log_warning "Forcing public access using a skipped_uris setting"
+ log_debug "Forcing public access using a skipped_uris setting"
# Add a skipped_uris on / for the app
RUN_YUNOHOST_CMD "app setting $app_id_to_check skipped_uris -v \"/\""
# Regen the config of sso
RUN_YUNOHOST_CMD "app ssowatconf"
+ expected_to_be="public"
fi
- # curl_error indicate the result of curl test
- curl_error=0
- # 503 Service Unavailable can would have some time to work.
- local http503=0
- # yuno_portal equal 1 if the test fall on the portal
- yuno_portal=0
-
# Try to access to the url in 2 times, with a final / and without
- i=1;
- while [ $i -ne 3 ]
+ for i in $(seq 1 2)
do
+ curl_check_path="${check_path:0:${#check_path}-1}"
- # First time, try without final /
- if [ $i -eq 1 ]
- then
- # If the last character is /
- if [ "${check_path: -1}" = "/" ]
- then
- # Remove it
- local curl_check_path="${check_path:0:${#check_path}-1}"
- else
- curl_check_path=$check_path
- fi
-
- # The next loop will try the second test
- i=2
- elif [ $i -eq 2 ]
- then
- # Second time, try with the final /
-
- # If the last character isn't /
- if [ "${check_path: -1}" != "/" ]
- then
- # Add it
- curl_check_path="$check_path/"
- else
- curl_check_path=$check_path
- fi
-
- # The next loop will break the while loop
- i=3
- fi
+ # First time we'll try without the trailing slash,
+ # Second time *with* the trailing slash
+ [ $i -eq 1 ] || curl_check_path="$check_path/"
# Remove the previous curl output
- rm -f "./url_output"
+ rm -f "$curl_output"
- # Call curl to try to access to the url of the app
- curl --location --insecure --silent --show-error \
- --header "Host: $check_domain" \
- --resolve $check_domain:443:$LXC_NETWORK.2 \
- --write-out "%{http_code};%{url_effective}\n" \
- --output "./url_output" \
- $check_domain$curl_check_path \
- > "./curl_print"
+ local http_code="noneyet"
- # Analyze the result of curl command
- if [ $? -ne 0 ]
- then
- log_error "Connection error..."
- curl_error=1
- fi
+ local retry=0
+ function should_retry() {
+ [ "${http_code}" = "noneyet" ] || [ "${http_code}" = "502" ] || [ "${http_code}" = "503" ] || [ "${http_code}" = "504" ]
+ }
- # Print informations about the connection
- local http_code=$(cat "./curl_print" | cut -d ';' -f1)
- test_url_details="
- Test url: $check_domain$curl_check_path
- Real url: $(cat "./curl_print" | cut --delimiter=';' --fields=2)
- HTTP code: $http_code"
- log_debug "$test_url_details"
+ while [ $retry -lt 3 ] && should_retry;
+ do
+ sleep 1
- # Analyze the http code
- if [ "${http_code:0:1}" = "0" ] || [ "${http_code:0:1}" = "4" ] || [ "${http_code:0:1}" = "5" ] || [ "${http_code:0:1}" = "6" ]
+ log_debug "Running curl $check_domain$curl_check_path"
+
+ # Call curl to try to access to the url of the app
+ curl --location --insecure --silent --show-error \
+ --header "Host: $check_domain" \
+ --resolve $check_domain:80:$LXC_NETWORK.2 \
+ --resolve $check_domain:443:$LXC_NETWORK.2 \
+ --write-out "%{http_code};%{url_effective}\n" \
+ --output "$curl_output" \
+ $check_domain$curl_check_path \
+ > "./curl_print"
+
+ # Analyze the result of curl command
+ if [ $? -ne 0 ]
+ then
+ log_error "Connection error..."
+ curl_error=1
+ fi
+
+ http_code=$(cat "./curl_print" | cut -d ';' -f1)
+
+ log_debug "HTTP code: $http_code"
+
+ retry=$((retry+1))
+ done
+
+ # Analyze the http code (we're looking for 0xx 4xx 5xx 6xx codes)
+ if [ -n "$http_code" ] && echo "0 4 5 6" | grep -q "${http_code:0:1}"
then
# If the http code is a 0xx 4xx or 5xx, it's an error code.
curl_error=1
# 401 is "Unauthorized", so is a answer of the server. So, it works!
- test "${http_code}" = "401" && curl_error=0
+ [ "${http_code}" == "401" ] && curl_error=0
- # 503 is Service Unavailable, it's a temporary error.
- if [ "${http_code}" = "503" ]
- then
- curl_error=0
- log_warning "Service temporarily unavailable"
- # 3 successive error are allowed
- http503=$(( http503 + 1 ))
- if [ $http503 -ge 3 ]; then
- # Over 3, it's definitively an error
- curl_error=1
- else
- # Below 3 times, retry.
- # Decrease the value of 'i' to retry the same test
- i=$(( i - 1 ))
- # Wait 1 second to let's some time to the 503 error
- sleep 1
- # And retry immediately
- continue
- fi
- fi
-
- if [ $curl_error -eq 1 ]; then
- log_error "The HTTP code shows an error."
- fi
+ [ $curl_error -eq 1 ] && log_error "The HTTP code shows an error."
fi
# Analyze the output of curl
- if [ -e "./url_output" ]
+ if [ -e "$curl_output" ]
then
# Print the title of the page
- local page_title=$(grep "
" "./url_output" | cut --delimiter='>' --fields=2 | cut --delimiter='<' --fields=1)
- log_debug "Title of the page: $page_title"
+ local page_title=$(grep "" "$curl_output" | cut --delimiter='>' --fields=2 | cut --delimiter='<' --fields=1)
+ local page_extract=$(lynx -dump -force_html "$curl_output" | head --lines 20 | tee -a "$complete_log")
# Check if the page title is neither the YunoHost portail or default nginx page
if [ "$page_title" = "YunoHost Portal" ]
then
log_debug "The connection attempt fall on the YunoHost portal."
- yuno_portal=1
- else
- yuno_portal=0
- if [ "$page_title" = "Welcome to nginx on Debian!" ]
- then
- # Falling on nginx default page is an error.
- curl_error=1
- log_error "The connection attempt fall on nginx default page."
- fi
-
- # Print the first 20 lines of the page
- log_debug "Extract of the page:"
- page_extract=$(lynx -dump -force_html "./url_output" | head --lines 20 | tee -a "$complete_log")
-
+ fell_on_sso_portal=1
+ # Falling on nginx default page is an error.
+ elif [ "$page_title" = "Welcome to nginx on Debian!" ]
+ then
+ log_error "The connection attempt fall on nginx default page."
+ curl_error=1
fi
fi
+
+ log_debug "Test url: $check_domain$curl_check_path"
+ log_debug "Real url: $(cat "./curl_print" | cut --delimiter=';' --fields=2)"
+ log_debug "HTTP code: $http_code"
+ log_debug "$test_url_details"
+ log_debug "Page title: $page_title"
+ log_debug "Page extract: $page_extract"
+
+ if [[ $curl_error -ne 0 ]]
+ then
+ log_warning "Test url: $check_domain$curl_check_path"
+ log_warning "Real url: $(cat "./curl_print" | cut --delimiter=';' --fields=2)"
+ log_warning "HTTP code: $http_code"
+ log_warning "$test_url_details"
+ log_warning "Page title: $page_title"
+ log_warning "Page extract: $page_extract"
+ fi
done
- if [[ $curl_error -ne 0 ]]
- then
- log_warning "$test_url_details"
- log_warning "Page title: $page_title"
- log_warning "Page extract: $page_extract"
- fi
-
# Detect the issue alias_traversal, https://github.com/yandex/gixy/blob/master/docs/en/plugins/aliastraversal.md
-
# Create a file to get for alias_traversal
echo "
alias_traversal test
@@ -345,65 +278,26 @@ VALIDATE_THAT_APP_CAN_BE_ACCESSED () {
| grep "title" | grep --quiet "alias_traversal test" \
&& log_error "Issue alias_traversal detected ! Please see here https://github.com/YunoHost/example_ynh/pull/45 to fix that." \
&& SET_RESULT alias_traversal 1
+
+ [ "$curl_error" -eq 0 ] || return 1
+ [ "$expected_to_be" == "public" ] && [ $fell_on_sso_portal -eq 0 ] || return 2
+ [ "$expected_to_be" == "private" ] && [ $fell_on_sso_portal -eq 1 ] || return 2
+ return 0
}
#=================================================
# Generic functions for unit tests
#=================================================
-check_test_result () {
-
- # Check the result and print SUCCESS or FAIL
-
- if [ $yunohost_result -eq 0 ] && [ $curl_error -eq 0 ] && [ $yuno_portal -eq 0 ]
- then
- log_report_test_success
- return 0
- else
- log_report_test_failed
- return 1
- fi
-}
validate_that_at_least_one_install_succeeded () {
- # Check if an install have previously work
- # If the test for install in sub dir isn't desactivated
- sub_dir_install=0
- if [ $setup_sub_dir -ne 0 ]
- then
- # If a test succeed or if force_install_ok is set
- # Or if $setup_sub_dir isn't set in the check_process
- if [ $(GET_RESULT check_sub_dir) -eq 1 ] || [ $force_install_ok -eq 1 ] || [ $setup_sub_dir -eq -1 ]
- then
- # Validate installation in sub dir.
- sub_dir_install=1
- fi
- else
- sub_dir_install=0
- fi
-
- # If the test for install on root isn't desactivated
-
- root_install=0
- if [ $setup_root -ne 0 ] || [ $setup_nourl -eq 1 ]
- then
- # If a test succeed or if force_install_ok is set
- # Or if $setup_root isn't set in the check_process
- if [ $(GET_RESULT check_root) -eq 1 ] || [ $force_install_ok -eq 1 ] || [ $setup_root -eq -1 ]
- then
- # Validate installation on root.
- root_install=1
- fi
- else
- root_install=0
- fi
-
- if [ $sub_dir_install -eq 0 ] && [ $root_install -eq 0 ]
+ if [ $(GET_RESULT check_sub_dir) -eq 0 ] && [ $(GET_RESULT check_root) -eq 0 ]
then
log_error "All installs failed, therefore this test cannot be performed..."
return 1
fi
+
}
#=================================================
@@ -415,71 +309,46 @@ TEST_INSTALL () {
# $1 = install type
local install_type=$1
- if [ "$install_type" = "subdir" ]; then
- start_test "Installation in a sub path"
- elif [ "$install_type" = "root" ]; then
- start_test "Installation on the root"
- else
- start_test "Installation without url access"
- fi
+ [ "$install_type" = "subdir" ] && { start_test "Installation in a sub path"; local check_path=/path; }
+ [ "$install_type" = "root" ] && { start_test "Installation on the root"; local check_path=/; }
+ [ "$install_type" = "no_url" ] && { start_test "Installation without url access"; local check_path=""; }
- # Replace manifest key for the test
- check_domain=$SUBDOMAIN
- if [ "$install_type" = "subdir" ]; then
- local check_path=$test_path
- elif [ "$install_type" = "root" ]; then
- local check_path=/
- fi
+ LOAD_LXC_SNAPSHOT snap0
# Install the application in a LXC container
- INSTALL_APP "domain=$check_domain" "path=$check_path" "user=$TEST_USER" "is_public=1"
-
- # Try to access the app by its url
- VALIDATE_THAT_APP_CAN_BE_ACCESSED
+ INSTALL_APP "path=$check_path" \
+ && VALIDATE_THAT_APP_CAN_BE_ACCESSED $SUBDOMAIN $check_path
# Check the result and print SUCCESS or FAIL
- if check_test_result
- then # Success
- SET_RESULT global_setup 1 # Installation succeed
- local check_result_setup=1 # Installation succeed
- else # Fail
- # The global success for a installation can't be failed if another installation succeed
- SET_RESULT_IF_NONE_YET global_setup -1
- local check_result_setup=-1 # Installation failed
- fi
+ if [ $? -eq 0 ]
+ then
+ SET_RESULT global_setup 1
+ local check_result_setup=1
- # Create a snapshot for this installation, to be able to reuse it instead of a new installation.
- # But only if this installation has worked fine
- if [ $check_result_setup -eq 1 ]; then
- if [ "$check_path" = "/" ]
- then
- # Check if a snapshot already exist for a root install
- if [ -z "$root_snapshot" ]
- then
- log_debug "Create a snapshot for root installation."
- CREATE_LXC_SNAPSHOT 2
- root_snapshot=snap2
- fi
- else
- # Check if a snapshot already exist for a subpath (or no_url) install
- if [ -z "$subpath_snapshot" ]
- then
- # Then create a snapshot
- log_debug "Create a snapshot for sub path installation."
- CREATE_LXC_SNAPSHOT 1
- subpath_snapshot=snap1
- fi
- fi
+ if [ "$install_type" = "root" ]
+ then
+ [ -e "$LXC_SNAPSHOTS/snap_rootinstall" ] \
+ && log_debug "Create a snapshot for root installation." \
+ && CREATE_LXC_SNAPSHOT snap_rootinstall
+ else
+ # Check if a snapshot already exist for a subpath (or no_url) install
+ [ ! -e "$LXC_SNAPSHOTS/snap_subdirinstall" ] \
+ && log_debug "Create a snapshot for sub path installation." \
+ && CREATE_LXC_SNAPSHOT snap_subdirinstall
+ fi
+ else
+ SET_RESULT_IF_NONE_YET global_setup -1
+ local check_result_setup=-1
fi
# Remove the application
- if REMOVE_APP
+ REMOVE_APP
+
+ if [ $? -eq 0 ]
then
- log_report_test_success
local check_result_remove=1
SET_RESULT global_remove 1
else
- log_report_test_failed
# The global success for a deletion can't be failed if another remove succeed
SET_RESULT_IF_NONE_YET global_remove -1
local check_result_remove=-1
@@ -491,18 +360,11 @@ TEST_INSTALL () {
then
log_small_title "Reinstall the application after a removing."
- INSTALL_APP "domain=$check_domain" "path=$check_path" "user=$TEST_USER" "is_public=1"
-
- # Try to access the app by its url
- VALIDATE_THAT_APP_CAN_BE_ACCESSED
+ INSTALL_APP "path=$check_path" \
+ && VALIDATE_THAT_APP_CAN_BE_ACCESSED $SUBDOMAIN $check_path
# Check the result and print SUCCESS or FAIL
- if check_test_result
- then # Success
- local check_result_setup=1 # Installation succeed
- else # Fail
- local check_result_setup=-1 # Installation failed
- fi
+ [ $? -eq 0 ] && local check_result_setup=1 || local check_result_setup=-1
fi
# Fill the correct variable depend on the type of test
@@ -519,68 +381,49 @@ TEST_INSTALL () {
}
TEST_UPGRADE () {
- # Try the upgrade script
- commits=""
- for LINE in $(grep "^upgrade=1" "$test_serie_dir/check_process.tests_infos")
- do
- commit=$(echo $LINE | grep -o "from_commit=.*" | awk -F= '{print $2}')
- [ -n "$commit"] || commits+="current " || commits+="$commit "
- done
+ [ $(GET_RESULT check_sub_dir) -eq 1 ] && local check_path=/path || local check_path=/
# Do an upgrade test for each commit in the upgrade list
- for commit in $commits
+ for commit in $(cat $test_serie_dir/upgrades_to_test)
do
if [ "$commit" == "current" ]
then
start_test "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=" "$check_process_section" | cut -d'=' -f2)
- # Or use the commit if there's no name.
- if [ -z "$upgrade_name" ]; then
- start_test "Upgrade from the commit $commit"
- else
- start_test "Upgrade from $upgrade_name"
- fi
+ specific_upgrade_args="$(grep "^manifest_arg=" "$test_serie_dir/upgrades/$commit" | cut -d'=' -f2-)"
+ upgrade_name=$(grep "^name=" "$test_serie_dir/upgrades/$commit" | cut -d'=' -f2)
+
+ [ -n "$upgrade_name" ] || upgrade_name="commit $commit"
+ start_test "Upgrade from $upgrade_name"
fi
- # Check if an install have previously work
- # Abort if none install worked
- validate_that_at_least_one_install_succeeded || return
-
- # Replace manifest key for the test
- check_domain=$SUBDOMAIN
- # Use a path according to previous succeeded installs
- if [ $sub_dir_install -eq 1 ]; then
- local check_path=$test_path
- else
- local check_path=/
- fi
+ validate_that_at_least_one_install_succeeded || return
# Install the application in a LXC container
log_small_title "Preliminary install..."
if [ "$commit" == "current" ]
then
# If no commit is specified, use the current version.
- LOAD_SNAPSHOT_OR_INSTALL_APP "domain=$check_domain" "path=$check_path" "user=$TEST_USER" "is_public=1"
+ LOAD_SNAPSHOT_OR_INSTALL_APP "$check_path"
+ local ret=$?
else
# Get the arguments of the manifest for this upgrade.
- specific_upgrade_args="$(grep "^manifest_arg=" "$check_process_section" | cut -d'=' -f2-)"
if [ -n "$specific_upgrade_args" ]; then
cp "$test_serie_dir/install_args" "$test_serie_dir/install_args.bkp"
- echo $specific_upgrade_args > "$test_serie_dir/install_args"
+ echo "$specific_upgrade_args" > "$test_serie_dir/install_args"
fi
# Make a backup of the directory
# and Change to the specified commit
sudo cp -a "$package_path" "${package_path}_back"
(cd "$package_path"; git checkout --force --quiet "$commit")
-
+
+ LOAD_LXC_SNAPSHOT snap0
+
# Install the application
- INSTALL_APP "domain=$check_domain" "path=$check_path" "user=$TEST_USER"
+ INSTALL_APP "path=$check_path"
+ local ret=$?
if [ -n "$specific_upgrade_args" ]; then
mv "$test_serie_dir/install_args.bkp" "$test_serie_dir/install_args"
@@ -592,46 +435,23 @@ TEST_UPGRADE () {
fi
# Check if the install had work
- if [ $yunohost_result -ne 0 ]
- then
- log_error "Installation failed..."
- log_error "Upgrade test ignored..."
+ [ $ret -eq 0 ] || { log_error "Initial install failed... upgrade test ignore"; LXC_STOP; continue; }
+
+ log_small_title "Upgrade..."
+
+ # Upgrade the application in a LXC container
+ RUN_YUNOHOST_CMD "app upgrade $app_id -f ./app_folder/" \
+ && VALIDATE_THAT_APP_CAN_BE_ACCESSED $SUBDOMAIN $check_path
+
+ if [ $? -eq 0 ]
+ then
+ SET_RESULT_IF_NONE_YET check_upgrade 1
else
- log_small_title "Upgrade..."
-
- # Upgrade the application in a LXC container
- RUN_YUNOHOST_CMD "app upgrade $app_id -f '$package_path'"
-
- # yunohost_result gets the return code of the upgrade
- yunohost_result=$?
-
- # Print the result of the upgrade command
- if [ $yunohost_result -eq 0 ]; then
- log_debug "Upgrade successful."
- else
- log_error "Upgrade failed. ($yunohost_result)"
- fi
-
- # Try to access the app by its url
- VALIDATE_THAT_APP_CAN_BE_ACCESSED
-
- # 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
- SET_RESULT_IF_NONE_YET check_upgrade 1
- else # Fail
- SET_RESULT check_upgrade -1
- fi
-
- # Remove the application
- REMOVE_APP
+ SET_RESULT check_upgrade -1
fi
- # Uses the default snapshot
- current_snapshot=snap0
- # Stop and restore the LXC container
- LXC_STOP >> $complete_log
+ # Remove the application
+ REMOVE_APP
done
}
@@ -640,28 +460,20 @@ TEST_PUBLIC_PRIVATE () {
# $1 = install type
local install_type=$1
- if [ "$install_type" = "private" ]; then
- start_test "Installation in private mode"
- else [ "$install_type" = "public" ]
- start_test "Installation in public mode"
- fi
+ [ "$install_type" = "private" ] && start_test "Installation in private mode"
+ [ "$install_type" = "public" ] && start_test "Installation in public mode"
-
- # Check if an install have previously work
validate_that_at_least_one_install_succeeded || return
- # Replace manifest key for the test
- check_domain=$SUBDOMAIN
# Set public or private according to type of test requested
if [ "$install_type" = "private" ]; then
local is_public="0"
+ local test_name_for_result="check_private"
elif [ "$install_type" = "public" ]; then
local is_public="1"
+ local test_name_for_result="check_private"
fi
- # Initialize the value
- local check_result_public_private=0
-
# Try in 2 times, first in root and second in sub path.
local i=0
for i in 0 1
@@ -670,79 +482,46 @@ TEST_PUBLIC_PRIVATE () {
if [ $i -eq 0 ]
then
# Check if root installation worked
- if [ $root_install -eq 1 ]
- then
- # Replace manifest key for path
- local check_path=/
- else
- # Jump to the second path if this check cannot be do
- log_warning "Root install failed, therefore this test cannot be performed..."
- continue
- fi
+ [ $(GET_RESULT check_root) -eq 1 ] || { log_warning "Root install failed, therefore this test cannot be performed..."; continue; }
- # Second, try with a sub path install
+ local check_path=/
+
+ # Second, try with a sub path install
elif [ $i -eq 1 ]
then
# Check if sub path installation worked, or if force_install_ok is setted.
- if [ $sub_dir_install -eq 1 ]
- then
- # Replace manifest key for path
- local check_path=$test_path
- else
- # Jump to the second path if this check cannot be do
- log_warning "Sub path install failed, therefore this test cannot be performed..."
- return
- fi
+ [ $(GET_RESULT check_sub_dir) -eq 1 ] || { log_warning "Sub path install failed, therefore this test cannot be performed..."; continue; }
+
+ local check_path=/path
fi
+ LOAD_LXC_SNAPSHOT snap0
+
# Install the application in a LXC container
- INSTALL_APP "domain=$check_domain" "user=$TEST_USER" "is_public=$is_public" "path=$check_path"
+ INSTALL_APP "is_public=$is_public" "path=$check_path" \
+ && VALIDATE_THAT_APP_CAN_BE_ACCESSED $SUBDOMAIN $check_path "$install_type"
- # Try to access the app by its url
- VALIDATE_THAT_APP_CAN_BE_ACCESSED
+ local ret=$?
- # Change the result according to the results of the curl test
- if [ "$install_type" = "private" ]
+ # Result code = 2 means that we were expecting the app to be public but it's private or viceversa
+ if [ $ret -eq 2 ]
then
- # In private mode, if curl doesn't fell on the ynh portal, it's a fail.
- if [ $yuno_portal -eq 0 ]; then
- log_error "App is not private: it should redirect to the Yunohost portal, but is publicly accessible instead"
- yunohost_result=1
- fi
- elif [ "$install_type" = "public" ]
- then
- # In public mode, if curl fell on the ynh portal, it's a fail.
- if [ $yuno_portal -eq 1 ]; then
- log_error "App page is not public: it should be publicly accessible, but redirects to the Yunohost portal instead"
- yunohost_result=1
- fi
- fi
+ yunohost_result=1
+ [ "$install_type" = "private" ] && log_error "App is not private: it should redirect to the Yunohost portal, but is publicly accessible instead"
+ [ "$install_type" = "public" ] && log_error "App page is not public: it should be publicly accessible, but redirects to the Yunohost portal instead"
+ fi
# Check the result and print SUCCESS or FAIL
- if [ $yunohost_result -eq 0 ] && [ $curl_error -eq 0 ]
+ if [ $ret -eq 0 ]
then
- log_report_test_success
- # The global success for public/private mode can't be a success if another installation failed
- if [ $check_result_public_private -ne -1 ]; then
- check_result_public_private=1 # Installation succeed
- fi
+ SET_RESULT_IF_NONE_YET $test_name_for_result 1
else
- log_report_test_failed
- check_result_public_private=-1 # Installation failed
- fi
-
- # Fill the correct variable depend on the type of test
- if [ "$install_type" = "private" ]
- then
- SET_RESULT check_private $check_result_public_private
- else # public
- SET_RESULT check_public $check_result_public_private
+ SET_RESULT $test_name_for_result -1
fi
break_before_continue
- # Stop and restore the LXC container
- LXC_STOP >> $complete_log
+ LXC_STOP
done
}
@@ -754,81 +533,25 @@ TEST_MULTI_INSTANCE () {
# Check if an install have previously work
validate_that_at_least_one_install_succeeded || return
- # Replace manifest key for the test
- if [ $sub_dir_install -eq 1 ]; then
- local check_path=$test_path
- else
- local check_path=/
- fi
+ [ $(GET_RESULT check_sub_dir) -eq 1 ] && local check_path=/path || local check_path=/
- # Install 2 times the same app
- local i=0
- for i in 1 2
- do
- if [ $i -eq 1 ]
- then
- check_domain=$DOMAIN
- log_small_title "First installation: path=$check_domain$check_path"
- # Second installation
- elif [ $i -eq 2 ]
- then
- check_domain=$SUBDOMAIN
- log_small_title "Second installation: path=$check_domain$check_path"
- fi
+ local multi_yunohost_result_1=0
+ local multi_yunohost_result_2=0
- # Install the application in a LXC container
- INSTALL_APP "domain=$check_domain" "path=$check_path" "user=$TEST_USER" "is_public=1"
- # Store the result in the correct variable
- # First installation
- if [ $i -eq 1 ]
- then
- local multi_yunohost_result_1=$yunohost_result
- # Second installation
- elif [ $i -eq 2 ]
- then
- local multi_yunohost_result_2=$yunohost_result
- fi
- done
+ LOAD_LXC_SNAPSHOT snap0
- # Try to access to the 2 apps by theirs url
- for i in 1 2
- do
- # First app
- if [ $i -eq 1 ]
- then
- check_domain=$DOMAIN
- # Second app
- elif [ $i -eq 2 ]
- then
- check_domain=$SUBDOMAIN
- VALIDATE_THAT_APP_CAN_BE_ACCESSED ${app_id}__2
- fi
+ log_small_title "First installation: path=$DOMAIN$check_path" \
+ && INSTALL_APP "domain=$DOMAIN" "path=$check_path" \
+ && log_small_title "Second installation: path=$SUBDOMAIN$check_path" \
+ && INSTALL_APP "path=$check_path" \
+ && VALIDATE_THAT_APP_CAN_BE_ACCESSED $DOMAIN $check_path \
+ && VALIDATE_THAT_APP_CAN_BE_ACCESSED $SUBDOMAIN $check_path "" ${app_id}__2 \
- # Check the result of curl test
- if [ $curl_error -ne 0 ] || [ $yuno_portal -ne 0 ]
- then
- # The test failed if curl fell on ynh portal or had an error.
- # First app
- if [ $i -eq 1 ]
- then
- multi_yunohost_result_1=1
- # Second app
- elif [ $i -eq 2 ]
- then
- multi_yunohost_result_2=1
- fi
- fi
- done
-
- # Check the result and print SUCCESS or FAIL
- # Succeed if the 2 installations work;
- if [ $multi_yunohost_result_1 -eq 0 ] && [ $multi_yunohost_result_2 -eq 0 ]
- then # Success
- log_report_test_success
+ if [ $? -eq 0 ]
+ then
SET_RESULT check_multi_instance 1
- else # Fail
- log_report_test_failed
+ else
SET_RESULT check_multi_instance -1
fi
@@ -839,21 +562,12 @@ TEST_PORT_ALREADY_USED () {
# Try to install with specific complications
# $1 = install type
- local install_type=$1
start_test "Port already used"
# Check if an install have previously work
validate_that_at_least_one_install_succeeded || return
- # Replace manifest key for the test
- check_domain=$SUBDOMAIN
- # Replace path manifest key for the test
# Use a path according to previous succeeded installs
- if [ $sub_dir_install -eq 1 ]; then
- local check_path=$test_path
- else
- local check_path=/
- fi
if grep -q -m1 "port_already_use=1" "$test_serie_dir/check_process.tests_infos"
then
@@ -862,6 +576,8 @@ TEST_PORT_ALREADY_USED () {
local check_port=6660
fi
+ LOAD_LXC_SNAPSHOT snap0
+
# Build a service with netcat for use this port before the app.
echo -e "[Service]\nExecStart=/bin/netcat -l -k -p $check_port\n
[Install]\nWantedBy=multi-user.target" | \
@@ -871,22 +587,13 @@ TEST_PORT_ALREADY_USED () {
# Then start this service to block this port.
LXC_START "sudo systemctl enable netcat & sudo systemctl start netcat"
+ [ $(GET_RESULT check_sub_dir) -eq 1 ] && local check_path=/path || local check_path=/
+
# Install the application in a LXC container
- INSTALL_APP "domain=$check_domain" "user=$TEST_USER" "is_public=1" "path=$check_path" "port=$check_port"
+ INSTALL_APP "path=$check_path" "port=$check_port" \
+ && VALIDATE_THAT_APP_CAN_BE_ACCESSED $SUBDOMAIN $check_path
- # Try to access the app by its url
- VALIDATE_THAT_APP_CAN_BE_ACCESSED
-
- # Check the result and print SUCCESS or FAIL
- if check_test_result
- then # Success
- local check_result_setup=1
- else # Fail
- local check_result_setup=-1
- fi
-
- # Fill the correct variable depend on the type of test
- SET_RESULT check_port $check_result_setup
+ [ $? -eq 0 ] && SET_RESULT check_port 1 || SET_RESULT check_port -1
break_before_continue
}
@@ -899,9 +606,6 @@ TEST_BACKUP_RESTORE () {
# Check if an install have previously work
validate_that_at_least_one_install_succeeded || return
- # Replace manifest key for the test
- check_domain=$SUBDOMAIN
-
# Try in 2 times, first in root and second in sub path.
local i=0
for i in 0 1
@@ -910,73 +614,61 @@ TEST_BACKUP_RESTORE () {
if [ $i -eq 0 ]
then
# Check if root installation worked, or if force_install_ok is setted.
- if [ $root_install -eq 1 ]
+ if [ $(GET_RESULT check_root) -eq 0 ]
then
- # Replace manifest key for path
- local check_path=/
- log_small_title "Preliminary installation on the root..."
- else
- # Jump to the second path if this check cannot be do
log_warning "Root install failed, therefore this test cannot be performed..."
continue
fi
- # Second, try with a sub path install
+ local check_path=/
+ log_small_title "Preliminary installation on the root..."
+
+ # Second, try with a sub path install
elif [ $i -eq 1 ]
then
# Check if sub path installation worked, or if force_install_ok is setted.
- if [ $sub_dir_install -eq 1 ]
+ if [ $(GET_RESULT check_sub_dir) -eq 1 ]
then
- # Replace manifest key for path
- local check_path=$test_path
- log_small_title "Preliminary installation in a sub path..." "white" "bold" clog
- else
- # Jump to the second path if this check cannot be do
log_warning "Sub path install failed, therefore this test cannot be performed..."
- return
+ continue
fi
+ local check_path=/path
+ log_small_title "Preliminary installation in a sub path..." "white" "bold" clog
fi
# Install the application in a LXC container
- LOAD_SNAPSHOT_OR_INSTALL_APP "domain=$check_domain" "user=$TEST_USER" "is_public=1" "path=$check_path"
+ LOAD_SNAPSHOT_OR_INSTALL_APP "$check_path"
+
+ local ret=$?
# Remove the previous residual backups
sudo rm -rf $LXC_ROOTFS/home/yunohost.backup/archives
- sudo rm -rf $LXC_SNAPSHOTS/$current_snapshot/rootfs/home/yunohost.backup/archives
# BACKUP
# Made a backup if the installation succeed
- if [ $yunohost_result -ne 0 ]
+ if [ $ret -ne 0 ]
then
log_error "Installation failed..."
else
log_small_title "Backup of the application..."
- # A complete list of backup hooks is available at /usr/share/yunohost/hooks/backup/
- backup_hooks="conf_ssowat data_home conf_ynh_firewall conf_cron"
-
# Made a backup of the application
- RUN_YUNOHOST_CMD "backup create -n Backup_test --apps $app_id --system $backup_hooks"
+ RUN_YUNOHOST_CMD "backup create -n Backup_test --apps $app_id"
- # yunohost_result gets the return code of the backup
- yunohost_result=$?
+ ret=$?
- # Print the result of the backup command
- if [ $yunohost_result -eq 0 ]; then
+ if [ $ret -eq 0 ]; then
log_debug "Backup successful"
else
- log_error "Backup failed. ($yunohost_result)"
+ log_error "Backup failed."
fi
fi
# Check the result and print SUCCESS or FAIL
- if [ $yunohost_result -eq 0 ]
- then # Success
- log_report_test_success
- # The global success for a backup can't be a success if another backup failed
+ if [ $ret -eq 0 ]
+ then
SET_RESULT_IF_NONE_YET check_backup 1
else
- log_report_test_failed
SET_RESULT check_backup -1
fi
@@ -999,50 +691,38 @@ TEST_BACKUP_RESTORE () {
# Second, restore the whole container to remove completely the application
elif [ $j -eq 1 ]
then
- # Uses the default snapshot
- current_snapshot=snap0
# Remove the previous residual backups
- sudo rm -rf $LXC_SNAPSHOTS/$current_snapshot/rootfs/home/yunohost.backup/archives
+ sudo rm -rf $LXC_SNAPSHOTS/snap0/rootfs/home/yunohost.backup/archives
# Place the copy of the backup archive in the container.
- sudo mv -f ./archives $LXC_SNAPSHOTS/$current_snapshot/rootfs/home/yunohost.backup/
+ sudo mv -f ./archives $LXC_SNAPSHOTS/snap0/rootfs/home/yunohost.backup/
- # Stop and restore the LXC container
- LXC_STOP >> $complete_log
+ LXC_STOP
+ LOAD_LXC_SNAPSHOT snap0
log_small_title "Restore on a clean YunoHost system..."
fi
# Restore the application from the previous backup
- RUN_YUNOHOST_CMD "backup restore Backup_test --force --apps $app_id"
+ RUN_YUNOHOST_CMD "backup restore Backup_test --force --apps $app_id" \
+ && VALIDATE_THAT_APP_CAN_BE_ACCESSED $SUBDOMAIN $check_path
- # yunohost_result gets the return code of the restore
- yunohost_result=$?
+ local ret=$?
# Print the result of the backup command
- if [ $yunohost_result -eq 0 ]; then
+ if [ $ret -eq 0 ]; then
log_debug "Restore successful."
- else
- log_error "Restore failed. ($yunohost_result)"
- fi
-
- # Try to access the app by its url
- VALIDATE_THAT_APP_CAN_BE_ACCESSED
-
- # Check the result and print SUCCESS or FAIL
- if check_test_result
- then
- # The global success for a restore can't be a success if another restore failed
SET_RESULT_IF_NONE_YET check_restore 1
else
+ log_error "Restore failed."
SET_RESULT check_restore -1
fi
break_before_continue
# Stop and restore the LXC container
- LXC_STOP >> $complete_log
+ LXC_STOP
done
done
}
@@ -1055,132 +735,82 @@ TEST_CHANGE_URL () {
# Check if an install have previously work
validate_that_at_least_one_install_succeeded || return
- # Replace manifest key for the test
- check_domain=$SUBDOMAIN
# Try in 6 times !
# Without modify the domain, root to path, path to path and path to root.
# And then, same with a domain change
local i=0
for i in `seq 1 7`
do
+ # Same domain, root to path
if [ $i -eq 1 ]; then
- # Same domain, root to path
check_path=/
- local new_path=$test_path
+ local new_path=/path
local new_domain=$SUBDOMAIN
+
+ # Same domain, path to path
elif [ $i -eq 2 ]; then
- # Same domain, path to path
- check_path=$test_path
- local new_path=${test_path}_2
+ check_path=/path
+ local new_path=/path_2
local new_domain=$SUBDOMAIN
+
+ # Same domain, path to root
elif [ $i -eq 3 ]; then
- # Same domain, path to root
- check_path=$test_path
+ check_path=/path
local new_path=/
local new_domain=$SUBDOMAIN
+ # Other domain, root to path
elif [ $i -eq 4 ]; then
- # Other domain, root to path
check_path=/
- local new_path=$test_path
+ local new_path=/path
local new_domain=$DOMAIN
+
+ # Other domain, path to path
elif [ $i -eq 5 ]; then
- # Other domain, path to path
- check_path=$test_path
- local new_path=${test_path}_2
+ check_path=/path
+ local new_path=/path_2
local new_domain=$DOMAIN
+
+ # Other domain, path to root
elif [ $i -eq 6 ]; then
- # Other domain, path to root
- check_path=$test_path
+ check_path=/path
local new_path=/
local new_domain=$DOMAIN
+
+ # Other domain, root to root
elif [ $i -eq 7 ]; then
- # Other domain, root to root
check_path=/
local new_path=/
local new_domain=$DOMAIN
fi
- # Ignore the test if it tries to move to the same address
- if [ "$check_path" == "$new_path" ] && [ "$new_domain" == "$SUBDOMAIN" ]; then
- continue
- fi
+ # Validate that install worked in the corresponding configuration previously
- # Check if root or subpath installation worked, or if force_install_ok is setted.
- # Try with a sub path install
- if [ "$check_path" = "/" ]
- then
- if [ $root_install -eq 0 ]
- then
- # Skip this test
- log_warning "Root install failed, therefore this test cannot be performed..."
- continue
- elif [ "$new_path" != "/" ] && [ $sub_dir_install -eq 0 ]
- then
- # Skip this test
- log_warning "Sub path install failed, therefore this test cannot be performed..."
- continue
- fi
- # And with a sub path install
- else
- if [ $sub_dir_install -eq 0 ]
- then
- # Skip this test
- log_warning "Sub path install failed, therefore this test cannot be performed..."
- continue
- elif [ "$new_path" = "/" ] && [ $root_install -eq 0 ]
- then
- # Skip this test
- log_warning "Root install failed, therefore this test cannot be performed..."
- continue
- fi
- fi
+ # If any of the begin/end path is /, we need to have root install working
+ ( [ "$check_path" != "/" ] && [ "$new_path" != "/" ] ) || [ $(GET_RESULT check_root) -eq 1 ] \
+ || { log_warning "Root install failed, therefore this test cannot be performed..."; continue; }
+
+ # If any of the being/end path is not /, we need to have sub_dir install working
+ ( [ "$new_path" == "/" ] && [ "$new_path" == "/" ] ) || [ $(GET_RESULT check_sub_dir) -eq 1 ] \
+ || { log_warning "Subpath install failed, therefore this test cannot be performed..."; continue; }
# Install the application in a LXC container
- log_small_title "Preliminary install..."
- LOAD_SNAPSHOT_OR_INSTALL_APP "domain=$check_domain" "user=$TEST_USER" "is_public=1" "path=$check_path"
+ log_small_title "Preliminary install..." \
+ && LOAD_SNAPSHOT_OR_INSTALL_APP "$check_path" \
+ && log_small_title "Change the url from $SUBDOMAIN$check_path to $new_domain$new_path..." \
+ && RUN_YUNOHOST_CMD "app change-url $app_id -d '$new_domain' -p '$new_path'" \
+ && VALIDATE_THAT_APP_CAN_BE_ACCESSED $new_domain $new_path
- # Check if the install had work
- if [ $yunohost_result -ne 0 ]
+ if [ $ret -eq 0 ]
then
- log_error "Installation failed..."
- else
- log_small_title "Change the url from $SUBDOMAIN$check_path to $new_domain$new_path..."
-
- # Change the url
- RUN_YUNOHOST_CMD "app change-url $app_id -d '$new_domain' -p '$new_path'"
-
- # yunohost_result gets the return code of the change-url script
- yunohost_result=$?
-
- # Print the result of the change_url command
- if [ $yunohost_result -eq 0 ]; then
- log_debug "Change_url script successful"
- else
- log_error "Change_url script failed. ($yunohost_result)"
- fi
-
- # Try to access the app by its url
- check_path=$new_path
- check_domain=$new_domain
- VALIDATE_THAT_APP_CAN_BE_ACCESSED
- fi
-
- # Check the result and print SUCCESS or FAIL
- if check_test_result
- then # Success
- # The global success for a change_url can't be a success if another change_url failed
SET_RESULT_IF_NONE_YET change_url 1
- else # Fail
- SET_RESULT change_url -1 # Change_url failed
+ else
+ SET_RESULT change_url -1
fi
break_before_continue
- # Uses the default snapshot
- current_snapshot=snap0
- # Stop and restore the LXC container
- LXC_STOP >> $complete_log
+ LXC_STOP
done
}
@@ -1250,39 +880,21 @@ ACTIONS_CONFIG_PANEL () {
# Check if an install have previously work
validate_that_at_least_one_install_succeeded || return
- # Replace manifest key for the test
- check_domain=$SUBDOMAIN
# Use a path according to previous succeeded installs
- if [ $sub_dir_install -eq 1 ]; then
- local check_path=$test_path
- else
- local check_path=/
- fi
+ [ $(GET_RESULT check_sub_dir) -eq 1 ] && local check_path=/path || local check_path=/
# Install the application in a LXC container
log_small_title "Preliminary install..."
- LOAD_SNAPSHOT_OR_INSTALL_APP "domain=$check_domain" "user=$TEST_USER" "is_public=1" "path=$check_path"
+ LOAD_SNAPSHOT_OR_INSTALL_APP "$check_path"
validate_action_config_panel()
{
- # yunohost_result gets the return code of the command
- yunohost_result=$?
-
local message="$1"
# Print the result of the command
- if [ $yunohost_result -eq 0 ]; then
- log_debug "$message succeed."
- else
- log_error "$message failed. ($yunohost_result)"
- fi
-
- # Check the result and print SUCCESS or FAIL
- if check_test_result
- then # Success
- # The global success for a actions can't be a success if another iteration failed
+ if [ $ret -eq 0 ]; then
SET_RESULT_IF_NONE_YET action_config_panel 1 # Actions succeed
- else # Fail
+ else
SET_RESULT action_config_panel -1 # Actions failed
fi
@@ -1290,11 +902,12 @@ ACTIONS_CONFIG_PANEL () {
}
# List first, then execute
+ local ret=0
local i=0
for i in `seq 1 2`
do
# Do a test if the installation succeed
- if [ $yunohost_result -ne 0 ]
+ if [ $ret -ne 0 ]
then
log_error "The previous test has failed..."
continue
@@ -1308,6 +921,7 @@ ACTIONS_CONFIG_PANEL () {
# List the actions
RUN_YUNOHOST_CMD "app action list $app_id"
+ local ret=$?
validate_action_config_panel "yunohost app action list"
elif [ "$test_type" == "config_panel" ]
@@ -1316,6 +930,8 @@ ACTIONS_CONFIG_PANEL () {
# Show the config-panel
RUN_YUNOHOST_CMD "app config show-panel $app_id"
+ local ret=$?
+
validate_action_config_panel "yunohost app config show-panel"
fi
elif [ $i -eq 2 ]
@@ -1480,10 +1096,12 @@ ACTIONS_CONFIG_PANEL () {
then
# Aply a configuration
RUN_YUNOHOST_CMD "app config apply $app_id $action_config_action $action_config_argument_built"
+ ret=$?
elif [ "$test_type" == "actions" ]
then
# Execute an action
RUN_YUNOHOST_CMD "app action run $app_id $action_config_action $action_config_argument_built"
+ ret=$?
fi
validate_action_config_panel "yunohost action $action_config_action"
done
@@ -1491,10 +1109,7 @@ ACTIONS_CONFIG_PANEL () {
fi
done
- # Uses the default snapshot
- current_snapshot=snap0
- # Stop and restore the LXC container
- LXC_STOP >> $complete_log
+ LXC_STOP
}
PACKAGE_LINTER () {
@@ -1658,10 +1273,8 @@ check_witness_files () {
log_error "The database witnessdb is missing ! Something gone wrong !"
SET_RESULT witness 1
fi
- if [ $(GET_RESULT witness) -eq 1 ]
- then
- yunohost_result=1
- fi
+
+ [ $(GET_RESULT witness) -eq 1 ] && return 1 || return 0
}
RUN_TEST_SERIE() {
@@ -1669,10 +1282,6 @@ RUN_TEST_SERIE() {
test_serie_dir=$1
curl_error=0
- yuno_portal=0
-
- _path_arg=$(grep -m1 "(PATH)" $test_serie_dir/check_process.manifest_infos | grep -o "\S+=\S+" | awk -F= '{print $2}' | tr -d '"')
- [ -n "$_path_arg" ] && test_path="$_path_arg" || test_path="/"
log_title "Tests serie: $(cat $test_serie_dir/test_serie_name)"
@@ -1739,9 +1348,6 @@ TEST_LAUNCHER () {
# $1 = Name of the function to execute
# $2 = Argument for the function
- # Intialize values
- yunohost_result=-1
-
# Start the timer for this test
start_timer
# And keep this value separately
@@ -1750,11 +1356,8 @@ TEST_LAUNCHER () {
# Execute the test
$1 $2
- # Uses the default snapshot
- current_snapshot=snap0
-
# Stop and restore the LXC container
- LXC_STOP >> $complete_log
+ LXC_STOP
# Restore the started time for the timer
starttime=$global_start_timer