diff --git a/lib/tests.sh b/lib/tests.sh index ee56fc8..90ce154 100644 --- a/lib/tests.sh +++ b/lib/tests.sh @@ -126,7 +126,7 @@ _LOAD_SNAPSHOT_OR_INSTALL_APP () { local _install_type="$(path_to_install_type $check_path)" local snapname="snap_${_install_type}install" - if ! LXC_SNAPSHOT_EXISTS $snapname + if ! ynh_lxc_snapshot_exists $snapname then log_warning "Expected to find an existing snapshot $snapname but it doesn't exist yet .. will attempt to create it" LOAD_LXC_SNAPSHOT snap0 \ @@ -370,7 +370,7 @@ TEST_INSTALL () { # Create the snapshot that'll be used by other tests later [ "$install_type" != "private" ] \ - && ! LXC_SNAPSHOT_EXISTS $snapname \ + && ! ynh_lxc_snapshot_exists $snapname \ && log_debug "Create a snapshot after app install" \ && ynh_lxc_pc_snapshot_create $snapname diff --git a/lib/ynh_lxd b/lib/ynh_lxd index 6f59efb..ddd52bc 100644 --- a/lib/ynh_lxd +++ b/lib/ynh_lxd @@ -4,3 +4,11 @@ # 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 +} + diff --git a/lib/ynh_lxd_package_check b/lib/ynh_lxd_package_check index fda68bd..27241cc 100644 --- a/lib/ynh_lxd_package_check +++ b/lib/ynh_lxd_package_check @@ -148,14 +148,6 @@ ynh_lxc_pc_create () { 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 () { # Create a temporary snapshot @@ -172,7 +164,7 @@ ynh_lxc_pc_snapshot_create () { LXC_STOP $LXC_NAME # Check if the snapshot already exist - if ! LXC_SNAPSHOT_EXISTS "$snapname" + if ! ynh_lxc_snapshot_exists "$snapname" then log_info "(Creating snapshot $snapname ...)" lxc snapshot $LXC_NAME $snapname