LXC_SNAPSHOT_EXISTS to ynh_lxc_snapshot_exists

This commit is contained in:
yalh76 2022-10-24 00:13:06 +02:00
parent 9f5cf5bdb6
commit efb7367e2e
3 changed files with 11 additions and 11 deletions

View file

@ -126,7 +126,7 @@ _LOAD_SNAPSHOT_OR_INSTALL_APP () {
local _install_type="$(path_to_install_type $check_path)" local _install_type="$(path_to_install_type $check_path)"
local snapname="snap_${_install_type}install" local snapname="snap_${_install_type}install"
if ! LXC_SNAPSHOT_EXISTS $snapname if ! ynh_lxc_snapshot_exists $snapname
then then
log_warning "Expected to find an existing snapshot $snapname but it doesn't exist yet .. will attempt to create it" log_warning "Expected to find an existing snapshot $snapname but it doesn't exist yet .. will attempt to create it"
LOAD_LXC_SNAPSHOT snap0 \ LOAD_LXC_SNAPSHOT snap0 \
@ -370,7 +370,7 @@ TEST_INSTALL () {
# Create the snapshot that'll be used by other tests later # Create the snapshot that'll be used by other tests later
[ "$install_type" != "private" ] \ [ "$install_type" != "private" ] \
&& ! LXC_SNAPSHOT_EXISTS $snapname \ && ! ynh_lxc_snapshot_exists $snapname \
&& log_debug "Create a snapshot after app install" \ && log_debug "Create a snapshot after app install" \
&& ynh_lxc_pc_snapshot_create $snapname && ynh_lxc_pc_snapshot_create $snapname

View file

@ -4,3 +4,11 @@
# LXD HELPERS # LXD HELPERS
#================================================= #=================================================
ynh_lxc_snapshot_exists () {
local snapname=$1
lxc list --format json \
| jq -e --arg LXC_NAME $LXC_NAME --arg snapname $snapname \
'.[] | select(.name==$LXC_NAME) | .snapshots[] | select(.name==$snapname)' \
>/dev/null
}

View file

@ -148,14 +148,6 @@ ynh_lxc_pc_create () {
lxc snapshot $LXC_NAME snap0 lxc snapshot $LXC_NAME snap0
} }
LXC_SNAPSHOT_EXISTS() {
local snapname=$1
lxc list --format json \
| jq -e --arg LXC_NAME $LXC_NAME --arg snapname $snapname \
'.[] | select(.name==$LXC_NAME) | .snapshots[] | select(.name==$snapname)' \
>/dev/null
}
ynh_lxc_pc_snapshot_create () { ynh_lxc_pc_snapshot_create () {
# Create a temporary snapshot # Create a temporary snapshot
@ -172,7 +164,7 @@ ynh_lxc_pc_snapshot_create () {
LXC_STOP $LXC_NAME LXC_STOP $LXC_NAME
# Check if the snapshot already exist # Check if the snapshot already exist
if ! LXC_SNAPSHOT_EXISTS "$snapname" if ! ynh_lxc_snapshot_exists "$snapname"
then then
log_info "(Creating snapshot $snapname ...)" log_info "(Creating snapshot $snapname ...)"
lxc snapshot $LXC_NAME $snapname lxc snapshot $LXC_NAME $snapname