[PATCH] Clean up the temporary pools virt-install makes.

Chris Lumens clumens at redhat.com
Mon Jul 27 16:35:39 UTC 2015


For a directory path like /var/tmp/kstest-whatever/disks, virt-install is
making two storage pools:  kstest-whatever, and disks-XX.  It also doesn't
get rid of these pools after it shuts down, and you will eventually end up
with a giant pile of them clogging everything up.

So there are two fixes here to do the clean up:

(1) We know the name of the first pool associated with a single test.  It's
the temporary directory being created in /var/tmp.  So just use the virsh
commands to destroy that pool.

(2) We don't know (and can't figure out) the name of the disks-XX pool.
However, that one is only being created because of the subdirectory that disk
images are being stored in.  So instead store them in /var/tmp/kstest-whatever
and do not create the disks subdirectory any more.
---
 tests/kickstart_tests/basic-ostree.sh     | 4 ++--
 tests/kickstart_tests/btrfs-1.sh          | 2 +-
 tests/kickstart_tests/btrfs-2.sh          | 2 +-
 tests/kickstart_tests/driverdisk-disk.sh  | 6 +++---
 tests/kickstart_tests/encrypt-device.sh   | 2 +-
 tests/kickstart_tests/functions.sh        | 6 +++---
 tests/kickstart_tests/hostname.sh         | 2 +-
 tests/kickstart_tests/kstest-runner       | 6 ++++--
 tests/kickstart_tests/raid-1.sh           | 8 ++++----
 tests/kickstart_tests/run_one_ks.sh       | 9 ++-------
 tests/kickstart_tests/tmpfs-fixed_size.sh | 2 +-
 11 files changed, 23 insertions(+), 26 deletions(-)

diff --git a/tests/kickstart_tests/basic-ostree.sh b/tests/kickstart_tests/basic-ostree.sh
index 4329410..215d3e3 100755
--- a/tests/kickstart_tests/basic-ostree.sh
+++ b/tests/kickstart_tests/basic-ostree.sh
@@ -35,8 +35,8 @@ prepare() {
 
 validate() {
     disksdir=$1
-    qemuArgs=$(for d in ${disksdir}/*img; do echo -drive file=${d}; done)
-    virtCatArgs=$(for d in ${disksdir}/*img; do echo -a ${d}; done)
+    qemuArgs=$(for d in ${disksdir}/disk-*img; do echo -drive file=${d}; done)
+    virtCatArgs=$(for d in ${disksdir}/disk-*img; do echo -a ${d}; done)
 
     # Now attempt to boot the resulting VM and see if the install
     # actually worked.  The VM will shut itself down so there's no
diff --git a/tests/kickstart_tests/btrfs-1.sh b/tests/kickstart_tests/btrfs-1.sh
index 9b0c90a..16c00a8 100755
--- a/tests/kickstart_tests/btrfs-1.sh
+++ b/tests/kickstart_tests/btrfs-1.sh
@@ -21,7 +21,7 @@
 
 validate() {
     disksdir=$1
-    args=$(for d in ${disksdir}/*img; do echo -a ${d}; done)
+    args=$(for d in ${disksdir}/disk-*img; do echo -a ${d}; done)
 
     # There should be a /root/root/RESULT file with results in it.  Check
     # its contents and decide whether the test finally succeeded or
diff --git a/tests/kickstart_tests/btrfs-2.sh b/tests/kickstart_tests/btrfs-2.sh
index 9b0c90a..16c00a8 100755
--- a/tests/kickstart_tests/btrfs-2.sh
+++ b/tests/kickstart_tests/btrfs-2.sh
@@ -21,7 +21,7 @@
 
 validate() {
     disksdir=$1
-    args=$(for d in ${disksdir}/*img; do echo -a ${d}; done)
+    args=$(for d in ${disksdir}/disk-*img; do echo -a ${d}; done)
 
     # There should be a /root/root/RESULT file with results in it.  Check
     # its contents and decide whether the test finally succeeded or
diff --git a/tests/kickstart_tests/driverdisk-disk.sh b/tests/kickstart_tests/driverdisk-disk.sh
index c510742..862fdf1 100755
--- a/tests/kickstart_tests/driverdisk-disk.sh
+++ b/tests/kickstart_tests/driverdisk-disk.sh
@@ -18,10 +18,10 @@
 . ${KSTESTDIR}/functions.sh
 
 prepare_disks() {
-    local diskdir="$1/disks"
+    local diskdir="$1"
     # main disk
-    qemu-img create -q -f qcow2 ${diskdir}/a.img 10G
-    echo "${diskdir}/a.img"
+    qemu-img create -q -f qcow2 ${diskdir}/disk-a.img 10G
+    echo "${diskdir}/disk-a.img"
 
     # driverdisk image
     ${KSTESTDIR}/../lib/mkdud.py -k -b -L "TEST_DD" ${diskdir}/dd.iso >/dev/null
diff --git a/tests/kickstart_tests/encrypt-device.sh b/tests/kickstart_tests/encrypt-device.sh
index 918c0ca..a59197e 100755
--- a/tests/kickstart_tests/encrypt-device.sh
+++ b/tests/kickstart_tests/encrypt-device.sh
@@ -21,7 +21,7 @@
 
 validate() {
     disksdir=$1
-    args=$(for d in ${disksdir}/*img; do echo -a ${d}; done)
+    args=$(for d in ${disksdir}/disk-*img; do echo -a ${d}; done)
 
     # There should be a /home/RESULT (because / is encrypted) file with results
     # in it.  Check its contents and decide whether the test finally succeeded
diff --git a/tests/kickstart_tests/functions.sh b/tests/kickstart_tests/functions.sh
index 01c2f2b..04422db 100644
--- a/tests/kickstart_tests/functions.sh
+++ b/tests/kickstart_tests/functions.sh
@@ -32,13 +32,13 @@ prepare() {
 prepare_disks() {
     tmpdir=$1
 
-    qemu-img create -q -f qcow2 ${tmpdir}/disks/a.img 10G
-    echo ${tmpdir}/disks/a.img
+    qemu-img create -q -f qcow2 ${tmpdir}/disk-a.img 10G
+    echo ${tmpdir}/disk-a.img
 }
 
 validate() {
     disksdir=$1
-    args=$(for d in ${disksdir}/*img; do echo -a ${d}; done)
+    args=$(for d in ${disksdir}/disk-*img; do echo -a ${d}; done)
 
     # There should be a /root/RESULT file with results in it.  Check
     # its contents and decide whether the test finally succeeded or
diff --git a/tests/kickstart_tests/hostname.sh b/tests/kickstart_tests/hostname.sh
index 5aa73e5..050423c 100755
--- a/tests/kickstart_tests/hostname.sh
+++ b/tests/kickstart_tests/hostname.sh
@@ -21,7 +21,7 @@
 
 validate() {
     disksdir=$1
-    args=$(for d in ${disksdir}/*img; do echo -a ${d}; done)
+    args=$(for d in ${disksdir}/disk-*img; do echo -a ${d}; done)
 
     # There should be a /root/RESULT file with results in it.  Check
     # its contents and decide whether the test finally succeeded or
diff --git a/tests/kickstart_tests/kstest-runner b/tests/kickstart_tests/kstest-runner
index d6ff678..7b8d3ba 100755
--- a/tests/kickstart_tests/kstest-runner
+++ b/tests/kickstart_tests/kstest-runner
@@ -136,7 +136,7 @@ class VirtualInstall(object):
         else:
             log.info("Install finished. Or at least virt shut down.")
 
-    def destroy(self):
+    def destroy(self, poolName):
         """
         Make sure the virt has been shut down and destroyed
 
@@ -145,6 +145,8 @@ class VirtualInstall(object):
         log.info("Shutting down %s", self.virt_name)
         subprocess.call(["virsh", "destroy", self.virt_name])
         subprocess.call(["virsh", "undefine", self.virt_name])
+        subprocess.call(["virsh", "pool-destroy", poolName])
+        subprocess.call(["virsh", "pool-undefine", poolName])
 
 def virt_install(opts, install_log):
     """
@@ -173,7 +175,7 @@ def virt_install(opts, install_log):
                               virtio_host = log_monitor.host,
                               virtio_port = log_monitor.port)
 
-        virt.destroy()
+        virt.destroy(os.path.basename(opts.tmp))
         log_monitor.shutdown()
     except InstallError as e:
         log.error("VirtualInstall failed: %s", e)
diff --git a/tests/kickstart_tests/raid-1.sh b/tests/kickstart_tests/raid-1.sh
index 4ed81ed..fc7fc9b 100755
--- a/tests/kickstart_tests/raid-1.sh
+++ b/tests/kickstart_tests/raid-1.sh
@@ -22,14 +22,14 @@
 prepare_disks() {
     tmpdir=$1
 
-    qemu-img create -q -f qcow2 ${tmpdir}/disks/a.img 10G
-    qemu-img create -q -f qcow2 ${tmpdir}/disks/b.img 10G
-    echo ${tmpdir}/disks/a.img ${tmpdir}/disks/b.img
+    qemu-img create -q -f qcow2 ${tmpdir}/disk-a.img 10G
+    qemu-img create -q -f qcow2 ${tmpdir}/disk-b.img 10G
+    echo ${tmpdir}/disk-a.img ${tmpdir}/disk-b.img
 }
 
 validate() {
     disksdir=$1
-    args=$(for d in ${disksdir}/*img; do echo -a ${d}; done)
+    args=$(for d in ${disksdir}/disk-*img; do echo -a ${d}; done)
 
     # virt-cat doesn't setup /dev/md/* links so cross our fingers that
     # / always ends up on /dev/md126
diff --git a/tests/kickstart_tests/run_one_ks.sh b/tests/kickstart_tests/run_one_ks.sh
index b5234d9..cf48f4b 100755
--- a/tests/kickstart_tests/run_one_ks.sh
+++ b/tests/kickstart_tests/run_one_ks.sh
@@ -42,7 +42,7 @@ cleanup() {
     if [[ ${KEEPIT} == 2 ]]; then
         return
     elif [[ ${KEEPIT} == 1 ]]; then
-        rm -rf ${d}/disks ${d}/*ks
+        rm -f ${d}/disk-*.img ${d}/*ks
     elif [[ ${KEEPIT} == 0 ]]; then
         rm -rf ${d}
     fi
@@ -82,7 +82,6 @@ runone() {
         kargs="--kernel-args \"$kargs\""
     fi
 
-    mkdir -p ${tmpdir}/disks/
     disks=$(prepare_disks ${tmpdir})
     disk_args=$(for d in $disks; do echo --disk $d; done)
 
@@ -105,13 +104,9 @@ runone() {
             echo RESULT:${name}:FAILED:Test timed out.
             cleanup ${tmpdir}
             return 2
-        elif [[ ! -d ${tmpdir}/disks ]]; then
-            echo RESULT:${name}:FAILED:Disk images do not exist.
-            cleanup ${tmpdir}
-            return 1
         fi
 
-        result=$(validate ${tmpdir}/disks)
+        result=$(validate ${tmpdir})
         if [[ $? != 0 ]]; then
             echo RESULT:${name}:FAILED:"${result}"
             cleanup ${tmpdir}
diff --git a/tests/kickstart_tests/tmpfs-fixed_size.sh b/tests/kickstart_tests/tmpfs-fixed_size.sh
index 3c48321..d8ccfd2 100755
--- a/tests/kickstart_tests/tmpfs-fixed_size.sh
+++ b/tests/kickstart_tests/tmpfs-fixed_size.sh
@@ -21,7 +21,7 @@
 
 validate() {
     disksdir=$1
-    args=$(for d in ${disksdir}/*img; do echo -a ${d}; done)
+    args=$(for d in ${disksdir}/disk-*img; do echo -a ${d}; done)
 
     # There should be a /root/RESULT file with results in it.  Check
     # its contents and decide whether the test finally succeeded or
-- 
2.4.3



More information about the anaconda-patches mailing list