Fixes @_@

This commit is contained in:
Alexandre Aubin 2020-12-17 05:25:07 +01:00
parent 62132f7ed1
commit 446d7fc7c5
4 changed files with 25 additions and 33 deletions

View file

@ -47,11 +47,6 @@ clean_exit () {
# Remove temporary files # Remove temporary files
rm -rf "$TEST_CONTEXT" rm -rf "$TEST_CONTEXT"
# Remove the application which been tested
if [ -n "$package_path" ]; then
rm -rf "$package_path"
fi
# Remove the lock file # Remove the lock file
rm -f "$lock_file" rm -f "$lock_file"

View file

@ -25,11 +25,6 @@ readonly lock_file="./pcheck.lock"
# LXC helpers # LXC helpers
#================================================= #=================================================
RUN_INSIDE_LXC() {
sudo lxc exec $LXC_NAME -- "$@"
sudo lxc-attach -n -- "$@"
}
assert_we_are_the_setup_user() { assert_we_are_the_setup_user() {
[ -e "./.setup_user" ] || return [ -e "./.setup_user" ] || return
local setup_user=$(cat "./.setup_user") local setup_user=$(cat "./.setup_user")

View file

@ -1,21 +1,15 @@
# #!/bin/bash # #!/bin/bash
#=================================================
# Globals variables
#=================================================
# -q aims to disable the display of 'Debian GNU/Linux' each time a command is ran
arg_ssh="-tt -q"
#================================================= #=================================================
# RUNNING SNAPSHOT # RUNNING SNAPSHOT
#================================================= #=================================================
LXC_CREATE () { LXC_CREATE () {
lxc launch $LXC_NAME-base $LXC_NAME || exit 1 sudo lxc launch $LXC_NAME-base $LXC_NAME || exit 1
lxc config set "$LXC_NAME" security.nesting true sudo lxc config set "$LXC_NAME" security.nesting true
_LXC_START_AND_WAIT $LXC_NAME _LXC_START_AND_WAIT $LXC_NAME
CREATE_LXC_SNAPSHOT snap0 set_witness_files
sudo lxc snapshot $LXC_NAME snap0
} }
LXC_SNAPSHOT_EXISTS() { LXC_SNAPSHOT_EXISTS() {
@ -30,7 +24,7 @@ CREATE_LXC_SNAPSHOT () {
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
[ $snapname != "snap0" ] && check_witness_files >&2 check_witness_files >&2
# Remove swap files to avoid killing the CI with huge snapshots. # Remove swap files to avoid killing the CI with huge snapshots.
sudo lxc exec $LXC_NAME -- bash -c 'for swapfile in $(ls /swap_* 2>/dev/null); do swapoff $swapfile; done' sudo lxc exec $LXC_NAME -- bash -c 'for swapfile in $(ls /swap_* 2>/dev/null); do swapoff $swapfile; done'
@ -52,6 +46,7 @@ LOAD_LXC_SNAPSHOT () {
snapname=$1 snapname=$1
sudo lxc stop --timeout 15 $LXC_NAME 2>/dev/null sudo lxc stop --timeout 15 $LXC_NAME 2>/dev/null
sudo lxc restore $LXC_NAME $snapname sudo lxc restore $LXC_NAME $snapname
sudo lxc start $LXC_NAME
_LXC_START_AND_WAIT $LXC_NAME _LXC_START_AND_WAIT $LXC_NAME
} }
@ -67,10 +62,10 @@ LXC_START () {
# Copy the package into the container. # Copy the package into the container.
lxc exec $LXC_NAME -- rm -rf /app_folder lxc exec $LXC_NAME -- rm -rf /app_folder
lxc file push -r "$package_path" $LXC_NAME/app_folder lxc file push -p -r "$package_path" $LXC_NAME/app_folder --quiet
# 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.
lxc exec $LXC_NAME -- $cmd | tee -a "$complete_log" lxc exec $LXC_NAME --env PACKAGE_CHECK_EXEC=1 -t -- $cmd | 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]}
@ -117,7 +112,7 @@ _LXC_START_AND_WAIT() {
if [ "$j" == "10" ]; then if [ "$j" == "10" ]; then
log_error 'Failed to start the container' log_error 'Failed to start the container'
lxc info $1 lxc info --show-log $1
failstart=1 failstart=1
restart_container "$1" restart_container "$1"
@ -128,7 +123,7 @@ _LXC_START_AND_WAIT() {
# Wait for container to access the internet # Wait for container to access the internet
for j in $(seq 1 10); do for j in $(seq 1 10); do
if lxc exec "$1" -- /bin/bash -c "! which wget > /dev/null 2>&1 || wget -q --spider http://github.com"; then if lxc exec "$1" -- /bin/bash -c "! which wget > /dev/null 2>&1 || wget -q --spider http://debian.org"; then
break break
fi fi
@ -157,3 +152,10 @@ _LXC_START_AND_WAIT() {
LXC_IP=$(lxc exec $1 -- hostname -I | grep -E -o "\<[0-9.]{8,}\>") LXC_IP=$(lxc exec $1 -- hostname -I | grep -E -o "\<[0-9.]{8,}\>")
} }
RUN_INSIDE_LXC() {
sudo lxc exec $LXC_NAME -- $@
}

View file

@ -27,7 +27,7 @@ RUN_YUNOHOST_CMD() {
log_debug "Running yunohost $1" log_debug "Running yunohost $1"
# --output-as none is to disable the json-like output for some commands like backup create # --output-as none is to disable the json-like output for some commands like backup create
LXC_START "PACKAGE_CHECK_EXEC=1 yunohost --output-as none --debug $1" \ LXC_START "yunohost --output-as none --debug $1" \
| grep --line-buffered -v --extended-regexp '^[0-9]+\s+.{1,15}DEBUG' \ | grep --line-buffered -v --extended-regexp '^[0-9]+\s+.{1,15}DEBUG' \
| grep --line-buffered -v 'processing action' | grep --line-buffered -v 'processing action'
@ -454,7 +454,7 @@ TEST_BACKUP_RESTORE () {
# Remove the previous residual backups # Remove the previous residual backups
sudo rm -rf ./ynh_backups sudo rm -rf ./ynh_backups
sudo lxc exec $LXC_NAME -- rm -rf /home/yunohost.backup/archives RUN_INSIDE_LXC rm -rf /home/yunohost.backup/archives
# BACKUP # BACKUP
# Made a backup if the installation succeed # Made a backup if the installation succeed
@ -495,7 +495,7 @@ TEST_BACKUP_RESTORE () {
LOAD_LXC_SNAPSHOT snap0 LOAD_LXC_SNAPSHOT snap0
# Remove the previous residual backups # Remove the previous residual backups
lxc exec $LXC_NAME -- rm -f /rootfs/home/yunohost.backup/archives/* RUN_INSIDE_LXC rm -f /rootfs/home/yunohost.backup/archives/*
# Place the copy of the backup archive in the container. # Place the copy of the backup archive in the container.
sudo lxc file push -r ./ynh_backups $LXC_NAME/home/yunohost.backup/archives/ sudo lxc file push -r ./ynh_backups $LXC_NAME/home/yunohost.backup/archives/
@ -936,7 +936,7 @@ set_witness_files () {
create_witness_file () { create_witness_file () {
[ "$2" = "file" ] && local action="touch" || local action="mkdir -p" [ "$2" = "file" ] && local action="touch" || local action="mkdir -p"
sudo lxc exec $LXC_NAME -- $action $1 RUN_INSIDE_LXC $action $1
} }
# Nginx conf # Nginx conf
@ -968,7 +968,7 @@ set_witness_files () {
create_witness_file "/etc/systemd/system/witnessfile.service" file create_witness_file "/etc/systemd/system/witnessfile.service" file
# Database # Database
local mysqlpwd=$(lxc exec $LXC_NAME -- cat /etc/yunohost/mysql) local mysqlpwd=$(RUN_INSIDE_LXC cat /etc/yunohost/mysql)
RUN_INSIDE_LXC mysqladmin --user=root --password="$mysqlpwd" --wait status > /dev/null 2>&1 RUN_INSIDE_LXC mysqladmin --user=root --password="$mysqlpwd" --wait status > /dev/null 2>&1
RUN_INSIDE_LXC mysql --user=root --password="$mysqlpwd" --wait --execute="CREATE DATABASE witnessdb" > /dev/null 2>&1 RUN_INSIDE_LXC mysql --user=root --password="$mysqlpwd" --wait --execute="CREATE DATABASE witnessdb" > /dev/null 2>&1
} }
@ -977,7 +977,7 @@ check_witness_files () {
# Check all the witness files, to verify if them still here # Check all the witness files, to verify if them still here
check_file_exist () { check_file_exist () {
if sudo lxc exec $LXC_NAME -- test ! -e "{1}" if RUN_INSIDE_LXC test ! -e "$1"
then then
log_error "The file $1 is missing ! Something gone wrong !" log_error "The file $1 is missing ! Something gone wrong !"
SET_RESULT "failure" witness SET_RESULT "failure" witness
@ -1013,7 +1013,7 @@ check_witness_files () {
check_file_exist "/etc/systemd/system/witnessfile.service" check_file_exist "/etc/systemd/system/witnessfile.service"
# Database # Database
local mysqlpwd=$(lxc exec $LXC_NAME -- cat /etc/yunohost/mysql) local mysqlpwd=$(RUN_INSIDE_LXC cat /etc/yunohost/mysql)
if ! RUN_INSIDE_LXC mysqlshow --user=root --password="$mysqlpwd" witnessdb > /dev/null 2>&1 if ! RUN_INSIDE_LXC mysqlshow --user=root --password="$mysqlpwd" witnessdb > /dev/null 2>&1
then then
log_error "The database witnessdb is missing ! Something gone wrong !" log_error "The database witnessdb is missing ! Something gone wrong !"