[Libvirt-cim] [PATCH] [TEST]updating 01_enum.py, 02_rp_gi_errors.py to use of the lib fn conf_file(), cleanup_restore() and create_diskpool_file()

Deepti B. Kalakeri deeptik at linux.vnet.ibm.com
Wed Apr 23 14:24:29 UTC 2008


# HG changeset patch
# User Deepti B. Kalakeri <deeptik at linux.vnet.ibm.com>
# Date 1208960650 -19800
# Node ID 3bf33b37a58657888f404b87a1504b0453b7761c
# Parent  91d726c978e3fcc360774c34293a67166bc3b9e6
[TEST]updating 01_enum.py, 02_rp_gi_errors.py to use of the lib fn conf_file(), cleanup_restore() and create_diskpool_file()

Signed-off-by: Deepti B. Kalakeri <deeptik at linux.vnet.ibm.com>

diff -r 91d726c978e3 -r 3bf33b37a586 suites/libvirt-cim/cimtest/ResourcePool/01_enum.py
--- a/suites/libvirt-cim/cimtest/ResourcePool/01_enum.py	Wed Apr 23 19:52:12 2008 +0530
+++ b/suites/libvirt-cim/cimtest/ResourcePool/01_enum.py	Wed Apr 23 19:54:10 2008 +0530
@@ -36,63 +36,24 @@ from VirtLib.live import net_list
 from VirtLib.live import net_list
 from XenKvmLib.vsms import RASD_TYPE_PROC, RASD_TYPE_MEM, RASD_TYPE_NET_ETHER, \
 RASD_TYPE_DISK 
-
+from XenKvmLib.common_util import cleanup_restore, test_dpath, \
+create_diskpool_file
 
 sup_types = ['Xen', 'KVM']
 
-test_dpath = "foo"
-disk_file = '/tmp/diskpool.conf'
-back_disk_file = disk_file + "." + "resourcepool_enum"
 diskid = "%s/%s" % ("DiskPool", test_dpath)
 dp_cn = 'DiskPool'
 mp_cn = 'MemoryPool'
 pp_cn = 'ProcessorPool'
 np_cn = 'NetworkPool'
 
-def conf_file():
-    """
-       Creating diskpool.conf file.
-    """
-    status = PASS
-    try:
-        f = open(disk_file, 'w')
-        f.write('%s %s' % (test_dpath, '/'))
-        f.close()
-    except Exception,detail:
-        logger.error("Exception: %s", detail)
-        status = SKIP
-    if status != PASS:
-        logger.error("Creation of Disk Conf file Failed")
-    return status
-        
-
-def clean_up_restore():
-    """
-        Restoring back the original diskpool.conf 
-        file.
-    """
-    status = PASS
-    try:
-        if os.path.exists(back_disk_file):
-            os.remove(disk_file)
-            move_file(back_disk_file, disk_file)
-    except Exception, detail:
-        logger.error("Exception: %s", detail)
-        return SKIP
-    if status != PASS:
-        logger.error("Failed to Disk Conf file")
-    return status
-
 def init_list(server, virt):
-    status = PASS
-    os.system("rm -f %s" % back_disk_file )
-    if not (os.path.exists(disk_file)):
-        status = conf_file()
-    else:
-        move_file(disk_file, back_disk_file)
-        status = conf_file()
+    # Verify DiskPool on machine
+    status = create_diskpool_file()
     if status != PASS:
         return status, None
+
+   # Verify the Virtual network on machine
     vir_network = net_list(server, virt)
     if len(vir_network) > 0:
         test_network = vir_network[0]
@@ -105,6 +66,7 @@ def init_list(server, virt):
             logger.error("Failed to create the Virtual Network '%s'", \
                                                            test_network)
             return SKIP, None
+
     disk_instid = '%s/%s' % (dp_cn, test_dpath)
     net_instid = '%s/%s' % (np_cn, test_network)
     mem_instid = '%s/0' % mp_cn
@@ -144,7 +106,6 @@ def main():
 def main():
     ip = main.options.ip
     virt = main.options.virt
-
     status, pool_list = init_list(ip, virt)
     if status != PASS: 
         logger.error("Failed to initialise the list")
@@ -180,7 +141,7 @@ def main():
         return FAIL
     status = verify_fields(pool_list, netpool, get_typed_class(virt, np_cn))
     
-    status = clean_up_restore()
+    cleanup_restore()
     return status
 
 if __name__ == "__main__":
diff -r 91d726c978e3 -r 3bf33b37a586 suites/libvirt-cim/cimtest/ResourcePool/02_rp_gi_errors.py
--- a/suites/libvirt-cim/cimtest/ResourcePool/02_rp_gi_errors.py	Wed Apr 23 19:52:12 2008 +0530
+++ b/suites/libvirt-cim/cimtest/ResourcePool/02_rp_gi_errors.py	Wed Apr 23 19:54:10 2008 +0530
@@ -37,6 +37,8 @@ from CimTest.ReturnCodes import PASS, SK
 from CimTest.ReturnCodes import PASS, SKIP
 from CimTest.Globals import logger, CIM_USER, CIM_PASS, CIM_NS
 from CimTest.Globals import do_main
+from XenKvmLib.common_util import cleanup_restore, test_dpath, \
+create_diskpool_file
 
 sup_types = ['Xen', 'KVM']
 
@@ -47,39 +49,7 @@ expr_values = {
                                'desc' : 'No such instance (Invalid_Keyvalue)'}
         }
 
-test_dpath = "foo"
-disk_file = '/tmp/diskpool.conf'
-back_disk_file = disk_file + "." + "02_rp_gi_errors"
-
-def conf_file():
-    """
-       Creating diskpool.conf file.
-    """
-    try:
-        f = open(disk_file, 'w')
-        f.write('%s %s' % (test_dpath, '/'))
-        f.close()
-    except Exception,detail:
-        logger.error("Exception: %s", detail)
-        status = SKIP
-        sys.exit(status)
-
-def clean_up_restore():
-    """
-        Restoring back the original diskpool.conf
-        file.
-    """
-    try:
-        if os.path.exists(back_disk_file):
-            os.remove(disk_file)
-            move_file(back_disk_file, disk_file)
-    except Exception, detail:
-        logger.error("Exception: %s", detail)
-        status = SKIP
-        sys.exit(status)
-
-
-def err_invalid_instid_keyname(classname, instid):
+def err_invalid_instid_keyname(conn, classname, instid):
     # Input:
     # ------
     # wbemcli gi '<scheme>://[user:pwd@]<host>:<port>/<namespace:<ClassName>.
@@ -97,7 +67,7 @@ def err_invalid_instid_keyname(classname
                            bug_no="")
 
 
-def err_invalid_instid_keyvalue(classname):
+def err_invalid_instid_keyvalue(conn, classname):
     # Input:
     # ------
     # wbemcli gi '<scheme>://[user:pwd@]<host>:<port>/<namespace:<ClassName>.
@@ -119,21 +89,15 @@ def main():
 def main():
     ip = main.options.ip
     virt = main.options.virt
-    status = PASS
+    conn = assoc.myWBEMConnection('http://%s' % ip, (CIM_USER, CIM_PASS),
+                                                                  CIM_NS)
 
-    global conn
-    conn = assoc.myWBEMConnection('http://%s' % ip, (CIM_USER, CIM_PASS),
-                                  CIM_NS)
+    # Verify DiskPool on machine
+    status = create_diskpool_file()
+    if status != PASS:
+        return status
 
-
-    # Taking care of already existing diskconf file
-    # Creating diskpool.conf if it does not exist
-    # Otherwise backing up the prev file and create new one.
-    os.system("rm -f %s" % back_disk_file )
-    if (os.path.exists(disk_file)):
-        move_file(disk_file, back_disk_file)
-    conf_file()
-
+    # Verify the Virtual Network on the machine.
     vir_network = net_list(ip, virt)
     if len(vir_network) > 0:
         test_network = vir_network[0]
@@ -144,8 +108,8 @@ def main():
         ret = netxml.create_vnet()
         if not ret:
             logger.error("Failed to create the Virtual Network '%s'",
-                         test_network)
-            clean_up_restore()
+                                                        test_network)
+            cleanup_restore()
             return SKIP
     netid = "%s/%s" % ("NetworkPool", test_network)
 
@@ -157,18 +121,20 @@ def main():
             }
 
     for cn, instid in cn_instid_list.items():
-        ret_value = err_invalid_instid_keyname(cn, instid)
+        ret_value = err_invalid_instid_keyname(conn, cn, instid)
         if ret_value != PASS:
             logger.error("------ FAILED: Invalid InstanceID Key Name.------")
-            status = ret_value
+            cleanup_restore()
+            return  ret_value
 
-        ret_value = err_invalid_instid_keyvalue(cn)
+        ret_value = err_invalid_instid_keyvalue(conn, cn)
         if ret_value != PASS:
             logger.error("------ FAILED: Invalid InstanceID Key Value.------")
-            status = ret_value
+            cleanup_restore()
+            return ret_value
 
-    clean_up_restore()
-    return status
+    cleanup_restore()
+    return PASS
 
 if __name__ == "__main__":
     sys.exit(main())




More information about the Libvirt-cim mailing list