[lxc-devel] [lxd/master] tests: Add extra cleanup code

stgraber on Github lxc-bot at linuxcontainers.org
Wed Apr 25 00:33:07 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 354 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180425/744cb9e5/attachment.bin>
-------------- next part --------------
From 98153a5da4b24b9a472c4590645abe8fb3bae856 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 24 Apr 2018 20:32:13 -0400
Subject: [PATCH] tests: Add extra cleanup code
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 test/includes/lxd.sh        |  6 ++++++
 test/suites/clustering.sh   | 23 +++++++++++++++++++++++
 test/suites/init_auto.sh    |  3 ++-
 test/suites/serverconfig.sh |  2 ++
 4 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/test/includes/lxd.sh b/test/includes/lxd.sh
index 58bfb9178..c8a442d36 100644
--- a/test/includes/lxd.sh
+++ b/test/includes/lxd.sh
@@ -128,6 +128,12 @@ kill_lxd() {
 
     daemon_dir=${1}
     LXD_DIR=${daemon_dir}
+
+    # Check if already killed
+    if [ ! -f "${daemon_dir}/lxd.pid" ]; then
+      return
+    fi
+
     daemon_pid=$(cat "${daemon_dir}/lxd.pid")
     check_leftovers="false"
     lxd_backend=$(storage_backend "$daemon_dir")
diff --git a/test/suites/clustering.sh b/test/suites/clustering.sh
index 964b53905..22fcfc0c6 100644
--- a/test/suites/clustering.sh
+++ b/test/suites/clustering.sh
@@ -161,6 +161,12 @@ test_clustering_membership() {
 
   teardown_clustering_netns
   teardown_clustering_bridge
+
+  kill_lxd "${LXD_ONE_DIR}"
+  kill_lxd "${LXD_TWO_DIR}"
+  kill_lxd "${LXD_THREE_DIR}"
+  kill_lxd "${LXD_FOUR_DIR}"
+  kill_lxd "${LXD_FIVE_DIR}"
 }
 
 test_clustering_containers() {
@@ -311,6 +317,10 @@ test_clustering_containers() {
 
   teardown_clustering_netns
   teardown_clustering_bridge
+
+  kill_lxd "${LXD_ONE_DIR}"
+  kill_lxd "${LXD_TWO_DIR}"
+  kill_lxd "${LXD_THREE_DIR}"
 }
 
 test_clustering_storage() {
@@ -532,6 +542,12 @@ test_clustering_storage() {
 
   teardown_clustering_netns
   teardown_clustering_bridge
+
+  kill_lxd "${LXD_ONE_DIR}"
+  kill_lxd "${LXD_TWO_DIR}"
+  if [ -n "${LXD_THREE_DIR:-}" ]; then
+    kill_lxd "${LXD_THREE_DIR}"
+  fi
 }
 
 test_clustering_network() {
@@ -598,6 +614,9 @@ test_clustering_network() {
 
   teardown_clustering_netns
   teardown_clustering_bridge
+
+  kill_lxd "${LXD_ONE_DIR}"
+  kill_lxd "${LXD_TWO_DIR}"
 }
 
 test_clustering_upgrade() {
@@ -686,4 +705,8 @@ test_clustering_upgrade() {
 
   teardown_clustering_netns
   teardown_clustering_bridge
+
+  kill_lxd "${LXD_ONE_DIR}"
+  kill_lxd "${LXD_TWO_DIR}"
+  kill_lxd "${LXD_THREE_DIR}"
 }
diff --git a/test/suites/init_auto.sh b/test/suites/init_auto.sh
index a0fe791c1..a8e0eab83 100644
--- a/test/suites/init_auto.sh
+++ b/test/suites/init_auto.sh
@@ -20,6 +20,7 @@ test_init_auto() {
 
     kill_lxd "${LXD_INIT_DIR}"
     sed -i "\\|^${loop_device_1}|d" "${TEST_DIR}/loops"
+    losetup -d "${loop_device_1}"
 
     # lxd init --auto --storage-backend zfs --storage-pool <name>/<non-existing-dataset>
     LXD_INIT_DIR=$(mktemp -d -p "${TEST_DIR}" XXX)
@@ -30,7 +31,6 @@ test_init_auto() {
     configure_loop_device loop_file_1 loop_device_1
     zpool create -m none -O compression=on "lxdtest-$(basename "${LXD_DIR}")-pool1-existing-pool" "${loop_device_1}"
     LXD_DIR=${LXD_INIT_DIR} lxd init --auto --storage-backend zfs --storage-pool "lxdtest-$(basename "${LXD_DIR}")-pool1-existing-pool/non-existing-dataset"
-
     kill_lxd "${LXD_INIT_DIR}"
 
     # lxd init --auto --storage-backend zfs --storage-pool <name>/<existing-dataset>
@@ -44,6 +44,7 @@ test_init_auto() {
     kill_lxd "${LXD_INIT_DIR}"
     zpool destroy "lxdtest-$(basename "${LXD_DIR}")-pool1-existing-pool"
     sed -i "\\|^${loop_device_1}|d" "${TEST_DIR}/loops"
+    losetup -d "${loop_device_1}"
 
     # lxd init --storage-backend zfs --storage-create-loop 1 --storage-pool <name> --auto
     LXD_INIT_DIR=$(mktemp -d -p "${TEST_DIR}" XXX)
diff --git a/test/suites/serverconfig.sh b/test/suites/serverconfig.sh
index f3db26f3b..36a035f72 100644
--- a/test/suites/serverconfig.sh
+++ b/test/suites/serverconfig.sh
@@ -23,4 +23,6 @@ test_server_config() {
   # macaroons are also enabled
   curl --unix-socket "$LXD_DIR/unix.socket" "lxd/1.0" | jq .metadata.auth_methods | grep macaroons
   lxc config unset core.macaroon.endpoint
+
+  kill_lxd "${LXD_SERVERCONFIG_DIR}"
 }


More information about the lxc-devel mailing list