This commit is contained in:
Jean-Baptiste 2018-04-07 12:28:51 +00:00 committed by GitHub
commit a0631742b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 96 additions and 2 deletions

View file

@ -777,6 +777,16 @@ start_timer
# And keep this value separately
complete_start_timer=$starttime
#=================================================
# Set the network followup for all tests
#=================================================
# Start the network usage followup
start_network_usage
# And keep these values separately
complete_start_rx_usage=$start_rx_usage
complete_start_tx_usage=$start_tx_usage
#=================================================
# Initialize tests
#=================================================
@ -1212,6 +1222,16 @@ starttime=$complete_start_timer
# End the timer for the test
stop_timer 3
#=================================================
# Ending the network usage followup
#=================================================
# Restore the orgin values
start_rx_usage=$complete_start_rx_usage
start_tx_usage=$complete_start_tx_usage
# End the followup
stop_network_usage 3
#=================================================
# Notification grade
#=================================================

View file

@ -10,6 +10,48 @@ arg_ssh="-tt"
snapshot_path="/var/lib/lxcsnaps/$lxc_name"
current_snapshot=snap0
#=================================================
# Network usage
#=================================================
start_network_usage () {
start_rx_usage=0
start_tx_usage=0
# package_check initialization
if [ -e "/sys/class/net/${lxc_bridge}/statistics/rx_bytes" ]
then
start_rx_usage=$(cat "/sys/class/net/${lxc_bridge}/statistics/rx_bytes")
start_tx_usage=$(cat "/sys/class/net/${lxc_bridge}/statistics/tx_bytes")
fi
}
stop_network_usage () {
local stop_rx_usage=0
local stop_tx_usage=0
if [ -e "/sys/class/net/${lxc_bridge}/statistics/rx_bytes" ]
then
local stop_rx_usage=$(cat "/sys/class/net/${lxc_bridge}/statistics/rx_bytes")
local stop_tx_usage=$(cat "/sys/class/net/${lxc_bridge}/statistics/tx_bytes")
fi
local rx_usage=$(numfmt --to=iec-i --suffix=B --padding=7 $(($stop_rx_usage-$start_rx_usage)))
local tx_usage=$(numfmt --to=iec-i --suffix=B --padding=7 $(($stop_tx_usage-$start_tx_usage)))
local rx_tx_usage=$(numfmt --to=iec-i --suffix=B --padding=7 $(($stop_rx_usage+$stop_tx_usage-$start_rx_usage-$start_tx_usage)))
if [ $1 -eq 2 ]; then
ECHO_FORMAT "Nextwork usage for this test: " "blue"
elif [ $1 -eq 3 ]; then
ECHO_FORMAT "Global network usage for all tests: " "blue"
else
ECHO_FORMAT "Network usage: " "blue"
fi
ECHO_FORMAT "${rx_tx_usage} (rx: ${rx_usage}, tx: ${tx_usage}).\n" "blue"
}
#=================================================
# TIMER
#=================================================
@ -69,6 +111,8 @@ create_temp_backup () {
snap_number=$1
start_timer
start_network_usage
# Check all the witness files, to verify if them still here
check_witness_files >&2
@ -98,6 +142,7 @@ create_temp_backup () {
current_snapshot=snap$snap_number
stop_timer 1 >&2
stop_network_usage 1 >&2
# Restart the container, after the snapshot
LXC_START "true" >&2
@ -109,6 +154,7 @@ use_temp_snapshot () {
current_snapshot=$1
start_timer
start_network_usage
# Fix the missing hostname in the hosts file...
echo "127.0.0.1 $lxc_name" | sudo tee --append "$snapshot_path/$current_snapshot/rootfs/etc/hosts" > /dev/null
@ -116,6 +162,7 @@ use_temp_snapshot () {
sudo rsync --acls --archive --delete --executability --itemize-changes --xattrs "$snapshot_path/$current_snapshot/rootfs/" "/var/lib/lxc/$lxc_name/rootfs/" > /dev/null 2>> "$test_result"
stop_timer 1
stop_network_usage 1
# Retrieve the app id in the log. To manage the app after
ynh_app_id=$(sudo tac "$yunohost_log" | grep --only-matching --max-count=1 "YNH_APP_INSTANCE_NAME=[^ ]*" | cut --delimiter='=' --fields=2)
@ -142,6 +189,8 @@ LXC_INIT () {
sudo iptables --append FORWARD --in-interface $lxc_bridge --out-interface $main_iface --jump ACCEPT | tee --append "$test_result" 2>&1
sudo iptables --append FORWARD --in-interface $main_iface --out-interface $lxc_bridge --jump ACCEPT | tee --append "$test_result" 2>&1
sudo iptables --table nat --append POSTROUTING --source $ip_range.0/24 --jump MASQUERADE | tee --append "$test_result" 2>&1
}
LXC_START () {
@ -149,6 +198,7 @@ LXC_START () {
# $1 = Command to execute in the container
start_timer
start_network_usage
# Try to start the container 3 times.
local max_try=3
local i=0
@ -212,6 +262,7 @@ LXC_START () {
ECHO_FORMAT "Boot log:\n" clog
cat "$script_dir/lxc_boot.log" | tee --append "$test_result"
stop_timer 1
stop_network_usage 1
return 1
fi
done
@ -231,6 +282,7 @@ LXC_START () {
sudo cat "/var/lib/lxc/$lxc_name/rootfs/home/pchecker/temp_yunohost-cli.log" >> "$temp_log"
stop_timer 1
stop_network_usage 1
# Return the exit code of the ssh command
return $returncode
}
@ -239,6 +291,7 @@ LXC_STOP () {
# Stop and restore the LXC container
start_timer
start_network_usage
# Stop the LXC container
if is_lxc_running; then
echo "Stop the LXC container" | tee --append "$test_result"
@ -264,6 +317,7 @@ LXC_STOP () {
echo "Restore the previous snapshot." | tee --append "$test_result"
sudo rsync --acls --archive --delete --executability --itemize-changes --xattrs "$snapshot_path/$current_snapshot/rootfs/" "/var/lib/lxc/$lxc_name/rootfs/" > /dev/null 2>> "$test_result"
stop_timer 1
stop_network_usage 1
}
LXC_TURNOFF () {

View file

@ -593,6 +593,9 @@ CHECK_SETUP () {
RESULT_check_root=$check_result_setup
RESULT_check_remove_root=$check_result_remove
fi
# Make a break if auto_remove is set
break_before_continue
}
CHECK_UPGRADE () {
@ -862,8 +865,13 @@ CHECK_MULTI_INSTANCE () {
local manifest_args_mod="$manifest_arguments"
# Replace manifest key for the test
replace_manifest_key "path" "$test_path"
check_path=$test_path
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"
@ -1410,6 +1418,12 @@ TEST_LAUNCHER () {
# And keep this value separately
local global_start_timer=$starttime
# Start the network usage followup
start_network_usage
# And keep these values separately
local complete_start_rx_usage=$start_rx_usage
local complete_start_tx_usage=$start_tx_usage
# Execute the test
$1 $2
@ -1424,6 +1438,12 @@ TEST_LAUNCHER () {
# End the timer for the test
stop_timer 2
# Restore the orgin values
start_rx_usage=$complete_start_rx_usage
start_tx_usage=$complete_start_tx_usage
# End the followup
stop_network_usage 2
# Update the lock file with the date of the last finished test.
echo "$1 $2:$(date +%s)" > "$lock_file"
}