More refactoring, less black magic using global vars ...

This commit is contained in:
Alexandre Aubin 2020-12-11 06:02:32 +01:00
parent 9823ed5aaa
commit 2ef016b842
4 changed files with 356 additions and 776 deletions

View file

@ -32,8 +32,6 @@ Usage:
package_check.sh [OPTION]... PACKAGE_TO_CHECK package_check.sh [OPTION]... PACKAGE_TO_CHECK
-b, --branch=BRANCH -b, --branch=BRANCH
Specify a branch to check. 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 -i, --interactive
Wait for the user to continue before each remove. Wait for the user to continue before each remove.
-h, --help -h, --help
@ -92,7 +90,6 @@ do
arguments[$i]=${arguments[$i]//--branch=/} arguments[$i]=${arguments[$i]//--branch=/}
fi fi
# For each argument in the array, reduce to short argument for getopts # 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]//--interactive/-i}
arguments[$i]=${arguments[$i]//--help/-h} arguments[$i]=${arguments[$i]//--help/-h}
arguments[$i]=${arguments[$i]//--build-lxc/-l} arguments[$i]=${arguments[$i]//--build-lxc/-l}
@ -117,11 +114,6 @@ parse_arg () {
gitbranch="-b $OPTARG" gitbranch="-b $OPTARG"
shift_value=2 shift_value=2
;; ;;
f)
# --force-install-ok
force_install_ok=1
shift_value=1
;;
i) i)
# --interactive # --interactive
interactive=1 interactive=1
@ -209,7 +201,6 @@ fi
# Stop and restore the LXC container. In case of previous incomplete execution. # Stop and restore the LXC container. In case of previous incomplete execution.
LXC_STOP LXC_STOP
# Deactivate LXC network
LXC_TURNOFF LXC_TURNOFF
#================================================= #=================================================
@ -594,7 +585,15 @@ parse_check_process() {
# Extract the Options section # Extract the Options section
extract_check_process_section "^;;; Options" ";; " > $TEST_CONTEXT/check_process.options 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 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 # Parse each tests serie
while read <&3 tests_serie while read <&3 tests_serie
@ -612,14 +611,19 @@ parse_check_process() {
echo "$tests_serie" > $test_serie_dir/test_serie_name echo "$tests_serie" > $test_serie_dir/test_serie_name
extract_check_process_section "^$tests_serie" "^;;" > $test_serie_rawconf 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 "^; 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 "^; 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 "^; 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 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" # This is the test of commits to test upgrade from
cat $test_serie_dir/check_process.manifest_infos \ for LINE in $(grep "^upgrade=1" "$test_serie_dir/check_process.tests_infos")
| awk '{print $1}' | tr -d '"' | tr '\n' '&' > $test_serie_dir/install_args 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 () { is_test_enabled () {
# Find the line for the given check option # Find the line for the given check option
@ -715,12 +719,7 @@ run_all_tests() {
# Print the final results of the tests # Print the final results of the tests
COMPUTE_RESULTS_SUMMARY $test_serie_id COMPUTE_RESULTS_SUMMARY $test_serie_id
# Set snap0 as the current snapshot # FIXME FIXME FIXME gotta reset the snapshot
current_snapshot=snap0
# And clean temporary snapshots
unset root_snapshot
unset subpath_snapshot
done done
# Restore the started time for the timer # Restore the started time for the timer

View file

@ -6,7 +6,6 @@
# -q aims to disable the display of 'Debian GNU/Linux' each time a command is ran # -q aims to disable the display of 'Debian GNU/Linux' each time a command is ran
arg_ssh="-tt -q" arg_ssh="-tt -q"
current_snapshot=snap0
#================================================= #=================================================
# RUNNING SNAPSHOT # RUNNING SNAPSHOT
@ -15,8 +14,7 @@ current_snapshot=snap0
CREATE_LXC_SNAPSHOT () { CREATE_LXC_SNAPSHOT () {
# Create a temporary snapshot # Create a temporary snapshot
# snap1 for subpath or snap2 for root install local snapname=$1
snap_number=$1
start_timer start_timer
# Check all the witness files, to verify if them still here # Check all the witness files, to verify if them still here
@ -34,26 +32,23 @@ CREATE_LXC_SNAPSHOT () {
fi fi
# Check if the snapshot already exist # Check if the snapshot already exist
if [ ! -e "$LXC_SNAPSHOTS/snap$snap_number" ] if [ ! -e "$LXC_SNAPSHOTS/$snapname" ]
then 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. # Create the snapshot.
sudo lxc-snapshot --name $LXC_NAME >> "$complete_log" 2>&1 sudo lxc-snapshot --name $LXC_NAME >> "$complete_log" 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 snap_foo, it will be named snap1.
if [ "$snap_number" == "2" ] && [ ! -e "$LXC_SNAPSHOTS/snap2" ] if [ "$snapname" != "snap1" ] && [ ! -e "$LXC_SNAPSHOTS/$snapname" ]
then then
# Rename snap1 to snap2 # Rename snap1
sudo mv "$LXC_SNAPSHOTS/snap1" "$LXC_SNAPSHOTS/snap2" sudo mv "$LXC_SNAPSHOTS/snap1" "$LXC_SNAPSHOTS/$snapname"
fi fi
fi fi
# Update the snapshot with rsync to clone the current lxc state # 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" sudo rsync --acls --archive --delete --executability --itemize-changes --xattrs "$LXC_ROOTFS/" "$LXC_SNAPSHOTS/$snapname/rootfs/" > /dev/null 2>> "$complete_log"
# Set this snapshot as the current snapshot
current_snapshot=snap$snap_number
stop_timer 1 stop_timer 1
@ -64,19 +59,21 @@ CREATE_LXC_SNAPSHOT () {
LOAD_LXC_SNAPSHOT () { LOAD_LXC_SNAPSHOT () {
# Use a temporary snapshot, if it already exists # Use a temporary snapshot, if it already exists
# $1 = Name of the snapshot to use # $1 = Name of the snapshot to use
current_snapshot=$1 local snapshot=$1
log_debug "Restoring snapshot $snapshot"
start_timer start_timer
# Fix the missing hostname in the hosts file... # 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. # 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 stop_timer 1
# Fake the yunohost_result return code of the installation return $ret
yunohost_result=0
} }
#================================================= #=================================================
@ -91,10 +88,10 @@ LXC_INIT () {
sudo rm --force $LXC_ROOTFS/swap_* sudo rm --force $LXC_ROOTFS/swap_*
sudo swapoff $LXC_SNAPSHOTS/snap0/rootfs/swap_* 2>/dev/null sudo swapoff $LXC_SNAPSHOTS/snap0/rootfs/swap_* 2>/dev/null
sudo rm --force $LXC_SNAPSHOTS/snap0/rootfs/swap_* sudo rm --force $LXC_SNAPSHOTS/snap0/rootfs/swap_*
sudo swapoff $LXC_SNAPSHOTS/snap1/rootfs/swap_* 2>/dev/null sudo swapoff $LXC_SNAPSHOTS/snap_rootinstall/rootfs/swap_* 2>/dev/null
sudo rm --force $LXC_SNAPSHOTS/snap1/rootfs/swap_* sudo rm --force $LXC_SNAPSHOTS/snap_rooinstall/rootfs/swap_*
sudo swapoff $LXC_SNAPSHOTS/snap2/rootfs/swap_* 2>/dev/null sudo swapoff $LXC_SNAPSHOTS/snap_subdirintsall/rootfs/swap_* 2>/dev/null
sudo rm --force $LXC_SNAPSHOTS/snap2/rootfs/swap_* sudo rm --force $LXC_SNAPSHOTS/snap_subdirinstall/rootfs/swap_*
# Initialize LXC network # Initialize LXC network
@ -111,7 +108,7 @@ LXC_INIT () {
LXC_START () { LXC_START () {
# Start the lxc container and execute the given command in it # Start the lxc container and execute the given command in it
# $1 = Command to execute in the container local cmd=$1
start_timer start_timer
# Try to start the container 3 times. # Try to start the container 3 times.
@ -143,13 +140,11 @@ LXC_START () {
fi fi
sleep 1 sleep 1
done done
echo ""
if [ "$(uname -m)" == "aarch64" ] [ "$(uname -m)" == "aarch64" ] && sleep 30
then
sleep 30
fi
local failstart=0 local failstart=0
# Check if the container is running # Check if the container is running
if ! is_lxc_running; then if ! is_lxc_running; then
log_critical "The LXC container didn't start..." log_critical "The LXC container didn't start..."
@ -158,7 +153,7 @@ LXC_START () {
log_info "Rebooting the container..." log_info "Rebooting the container..."
fi fi
LXC_STOP 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 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 then
log_critical "The container failed to connect to internet..." log_critical "The container failed to connect to internet..."
@ -167,7 +162,7 @@ LXC_START () {
log_info "Rebooting the container..." log_info "Rebooting the container..."
fi fi
LXC_STOP 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 else
[ $avoid_witness -eq 0 ] && set_witness_files [ $avoid_witness -eq 0 ] && set_witness_files
@ -243,7 +238,7 @@ LXC_START () {
rsync -rq --delete "$package_path" "$LXC_NAME": >> "$complete_log" 2>&1 rsync -rq --delete "$package_path" "$LXC_NAME": >> "$complete_log" 2>&1
# Execute the command given in argument in the container and log its results. # 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 # Store the return code of the command
local returncode=${PIPESTATUS[0]} local returncode=${PIPESTATUS[0]}
@ -254,34 +249,20 @@ LXC_START () {
} }
LXC_STOP () { LXC_STOP () {
# Stop and restore the LXC container if is_lxc_running;
then
start_timer
# Stop the LXC container
if is_lxc_running; then
log_debug "Stop the LXC container" log_debug "Stop the LXC container"
sudo lxc-stop --name=$LXC_NAME | tee --append "$complete_log" 2>&1 sudo lxc-stop --name=$LXC_NAME | tee --append "$complete_log" 2>&1
fi fi
}
# Fix the missing hostname in the hosts file LOAD_LXC_SNAPSHOT () {
# If the hostname is missing in /etc/hosts inside the snapshot snapname=$1
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
# Restore the snapshot. LXC_STOP
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" log_debug "Restoring snapshot $snapname"
stop_timer 1 sudo rsync --acls --archive --delete --executability --itemize-changes --xattrs "$LXC_SNAPSHOTS/$snapname/rootfs/" "$LXC_ROOTFS/" > /dev/null 2>> "$complete_log"
} }
LXC_TURNOFF () { LXC_TURNOFF () {
@ -306,7 +287,4 @@ LXC_TURNOFF () {
then then
sudo ifdown --force $LXC_BRIDGE | tee --append "$complete_log" 2>&1 sudo ifdown --force $LXC_BRIDGE | tee --append "$complete_log" 2>&1
fi fi
# Set snap0 as the current snapshot
current_snapshot=snap0
} }

View file

@ -20,8 +20,8 @@ sudo rm -f /etc/network/interfaces.d/$LXC_BRIDGE
log_title "Suppression de la machine et de son snapshots" 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 snap0
sudo lxc-snapshot -n $LXC_NAME -d snap1 sudo lxc-snapshot -n $LXC_NAME -d snap_rootinstall
sudo lxc-snapshot -n $LXC_NAME -d snap2 sudo lxc-snapshot -n $LXC_NAME -d snap_subdirinstall
sudo rm -f /var/lib/lxcsnaps/$LXC_NAME/snap0.tar.gz sudo rm -f /var/lib/lxcsnaps/$LXC_NAME/snap0.tar.gz
sudo lxc-destroy -n $LXC_NAME -f sudo lxc-destroy -n $LXC_NAME -f

File diff suppressed because it is too large Load diff