From 0206677353ab413b85105f311990f7f8ac9cec1e Mon Sep 17 00:00:00 2001 From: yalh76 Date: Mon, 24 Oct 2022 00:56:44 +0200 Subject: [PATCH] Implement ynh_lxc_pc_snapshot_create --- lib/tests.sh | 4 ++-- lib/ynh_lxd_package_check | 27 +++++++++++++++++++-------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/lib/tests.sh b/lib/tests.sh index 204df29..6c9c0ca 100644 --- a/lib/tests.sh +++ b/lib/tests.sh @@ -132,7 +132,7 @@ _LOAD_SNAPSHOT_OR_INSTALL_APP () { ynh_lxc_snapshot_load snap0 \ && _PREINSTALL \ && _INSTALL_APP "path=$check_path" \ - && ynh_lxc_pc_snapshot_create $snapname + && ynh_lxc_pc_snapshot_create --name=LXC_NAME --snapname=$snapname else # Or uses an existing snapshot log_info "(Reusing existing snapshot $snapname)" \ @@ -372,7 +372,7 @@ TEST_INSTALL () { [ "$install_type" != "private" ] \ && ! ynh_lxc_snapshot_exists $snapname \ && log_debug "Create a snapshot after app install" \ - && ynh_lxc_pc_snapshot_create $snapname + && ynh_lxc_pc_snapshot_create --name=LXC_NAME --snapname=$snapname # Remove and reinstall the application _REMOVE_APP \ diff --git a/lib/ynh_lxd_package_check b/lib/ynh_lxd_package_check index 533bb7e..7bdd530 100644 --- a/lib/ynh_lxd_package_check +++ b/lib/ynh_lxd_package_check @@ -233,29 +233,40 @@ ynh_lxc_pc_create () { lxc snapshot $name snap0 } -ynh_lxc_pc_snapshot_create () { - # Create a temporary snapshot - - local snapname=$1 +# Create a snapshot of an LXC container +# +# usage: ynh_lxc_pc_snapshot_create --name=LXC_NAME --snapname= --name=name --snapname=snapname +# | arg: -n, --name= - name of the LXC +# | arg: -s, --snapname= - name of the snapshot +# +# Requires YunoHost version *.*.* or higher. +ynh_lxc_pc_snapshot_create --name=LXC_NAME --snapname= () { + # Declare an array to define the options of this helper. + local legacy_args=ns + local -A args_array=([n]=name= [s]=snapname=) + local name + local snapname + # Manage arguments with getopts + ynh_handle_getopts_args "$@" start_timer # Check all the witness files, to verify if them still here - ynh_lxc_pc_witness_files_check --name=$LXC_NAME >&2 + ynh_lxc_pc_witness_files_check --name=$name >&2 # Remove swap files to avoid killing the CI with huge snapshots. ynh_lxc_swapfiles_clean - ynh_lxc_stop $LXC_NAME + ynh_lxc_stop $name # Check if the snapshot already exist if ! ynh_lxc_snapshot_exists "$snapname" then log_info "(Creating snapshot $snapname ...)" - lxc snapshot $LXC_NAME $snapname + lxc snapshot $name $snapname fi - _ynh_lxc_start_and_wait $LXC_NAME + _ynh_lxc_start_and_wait $name stop_timer 1 }