[Kimchi-devel] [PATCH] [Kimchi 2/8] Always use /var/tmp to store test files

Lucio Correia posted 8 patches 7 years, 3 months ago
[Kimchi-devel] [PATCH] [Kimchi 2/8] Always use /var/tmp to store test files
Posted by Lucio Correia 7 years, 3 months ago
Signed-off-by: Lucio Correia <luciojhc@linux.vnet.ibm.com>
---
 tests/test_model.py | 29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/tests/test_model.py b/tests/test_model.py
index 95c9e08..e1b957c 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -31,6 +31,7 @@ import platform
 import pwd
 import re
 import shutil
+import tempfile
 import time
 import unittest
 
@@ -65,8 +66,12 @@ invalid_repository_urls = ['www.fedora.org',       # missing protocol
                            'http://www.fedora',    # invalid domain name
                            'file:///home/foobar']  # invalid path
 
-TMP_DIR = '/var/lib/kimchi/tests/'
+BASE_DIR = tempfile.mkdtemp(dir='/var/tmp')
+DEFAULT_DIR = os.path.join(BASE_DIR, 'libvirt/images')
+ISO_DIR = os.path.join(BASE_DIR, 'kimchi/isos')
+TMP_DIR = os.path.join(BASE_DIR, 'kimchi/tests')
 UBUNTU_ISO = TMP_DIR + 'ubuntu14.04.iso'
+
 NON_NUMA_XML = """
 <domain type='kvm'>
   <name>non-numa-kimchi-test</name>
@@ -83,8 +88,10 @@ NON_NUMA_XML = """
 
 
 def setUpModule():
-    if not os.path.exists(TMP_DIR):
-        os.makedirs(TMP_DIR)
+    print __file__, "creating pools at", BASE_DIR
+    os.makedirs(DEFAULT_DIR)
+    os.makedirs(ISO_DIR)
+    os.makedirs(TMP_DIR)
 
     iso_gen.construct_fake_iso(UBUNTU_ISO, True, '14.04', 'ubuntu')
 
@@ -98,7 +105,21 @@ def setUpModule():
 
 
 def tearDownModule():
-    shutil.rmtree(TMP_DIR)
+    # Model will create default and ISO storagepools at /var/tmp: delete them.
+    conn = libvirt.open('qemu:///session')
+
+    pool = conn.storagePoolLookupByName('default')
+    pool and pool.isActive() and pool.destroy()
+    pool and pool.undefine()
+
+    pool = conn.storagePoolLookupByName('ISO')
+    pool and pool.isActive() and pool.destroy()
+    pool and pool.undefine()
+
+    conn.close()
+
+    # delete temporary directory contents
+    shutil.rmtree(BASE_DIR)
 
 
 def get_remote_iso_path():
-- 
2.7.4

_______________________________________________
Kimchi-devel mailing list
Kimchi-devel@ovirt.org
http://lists.ovirt.org/mailman/listinfo/kimchi-devel