From b134ed4f867f07c1dc90836e1a9c4299afbb3043 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Mon, 24 Oct 2022 00:17:19 +0200 Subject: [PATCH] LXC_RESET to ynh_lxc_reset --- lib/tests_coordination.sh | 2 +- lib/ynh_lxd | 17 +++++++++++++++++ lib/ynh_lxd_package_check | 17 ----------------- package_check.sh | 2 +- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/tests_coordination.sh b/lib/tests_coordination.sh index 07e1512..5706478 100644 --- a/lib/tests_coordination.sh +++ b/lib/tests_coordination.sh @@ -254,7 +254,7 @@ run_all_tests() { # Reset and create a fresh container to work with check_lxd_setup - LXC_RESET + ynh_lxc_reset ynh_lxc_pc_create # Be sure that the container is running ynh_lxc_pc_exec "true" diff --git a/lib/ynh_lxd b/lib/ynh_lxd index 7c8691e..a216345 100644 --- a/lib/ynh_lxd +++ b/lib/ynh_lxd @@ -39,3 +39,20 @@ ynh_lxc_snapshot_load () { _LXC_START_AND_WAIT $LXC_NAME } +ynh_lxc_reset () { + # If the container exists + if lxc info $LXC_NAME >/dev/null 2>/dev/null; then + # Remove swap files before deletting the continer + CLEAN_SWAPFILES + fi + + ynh_lxc_stop $LXC_NAME + + if lxc info $LXC_NAME >/dev/null 2>/dev/null; then + local current_storage=$(lxc list $LXC_NAME --format json --columns b | jq '.[].expanded_devices.root.pool') + swapoff "$(lxc storage get $current_storage source)/containers/$LXC_NAME/rootfs/swap" 2>/dev/null + fi + + lxc delete $LXC_NAME --force 2>/dev/null +} + diff --git a/lib/ynh_lxd_package_check b/lib/ynh_lxd_package_check index 10001dc..cbb5b35 100644 --- a/lib/ynh_lxd_package_check +++ b/lib/ynh_lxd_package_check @@ -175,23 +175,6 @@ ynh_lxc_pc_snapshot_create () { stop_timer 1 } -LXC_RESET () { - # If the container exists - if lxc info $LXC_NAME >/dev/null 2>/dev/null; then - # Remove swap files before deletting the continer - CLEAN_SWAPFILES - fi - - ynh_lxc_stop $LXC_NAME - - if lxc info $LXC_NAME >/dev/null 2>/dev/null; then - local current_storage=$(lxc list $LXC_NAME --format json --columns b | jq '.[].expanded_devices.root.pool') - swapoff "$(lxc storage get $current_storage source)/containers/$LXC_NAME/rootfs/swap" 2>/dev/null - fi - - lxc delete $LXC_NAME --force 2>/dev/null -} - _LXC_START_AND_WAIT() { diff --git a/package_check.sh b/package_check.sh index 27dc1c4..c98931f 100755 --- a/package_check.sh +++ b/package_check.sh @@ -124,7 +124,7 @@ parse_args function cleanup() { trap '' SIGINT # Disable ctrl+c in this function - LXC_RESET + ynh_lxc_reset [ -n "$TEST_CONTEXT" ] && rm -rf "$TEST_CONTEXT" [ -n "$lock_file" ] && rm -f "$lock_file"