[Libvirt-cim] [PATCH 1/3] test: common_util, use number to check version

Wenchao Xia xiawenc at linux.vnet.ibm.com
Mon Apr 8 10:16:21 UTC 2013


From: root <root at RH64wenchao.(none)>

Signed-off-by: Wenchao Xia <xiawenc at linux.vnet.ibm.com>
---
 suites/libvirt-cim/lib/XenKvmLib/common_util.py |   28 ++++++++++++++++++++--
 1 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/suites/libvirt-cim/lib/XenKvmLib/common_util.py b/suites/libvirt-cim/lib/XenKvmLib/common_util.py
index 43e5e2c..3316c51 100644
--- a/suites/libvirt-cim/lib/XenKvmLib/common_util.py
+++ b/suites/libvirt-cim/lib/XenKvmLib/common_util.py
@@ -23,6 +23,7 @@
 import os
 import pywbem
 import random
+import string
 from time import sleep
 from tempfile import mkdtemp
 from commands import getstatusoutput
@@ -296,6 +297,17 @@ def conf_file():
         logger.error("Creation of Disk Conf file Failed")
     return status
 
+def get_version_number(version_str):
+    num = version_str.split(".")
+    l = len(num)
+    total = 0
+    multiple = 1
+    increase = 100
+    for i in range(0, l):
+        t = string.atoi(num[l - 1- i]) * multiple
+        total = total + t
+        multiple = multiple * increase
+    return total
 
 def cleanup_restore(server, virt):
     """
@@ -308,7 +320,11 @@ def cleanup_restore(server, virt):
     # libvirt_version >= 0.4.1
     # Hence Skipping the logic to delete the new conf file
     # and just returning PASS
-    if libvirt_version >= '0.4.1':
+    libvirt_version = virsh_version(server, virt)
+    libvirt_version_req = "0.4.1"
+    a = get_version_number(libvirt_version)
+    b = get_version_number(libvirt_version_req)
+    if a >= b:
         return status
     try:
         if os.path.exists(back_disk_file):
@@ -365,7 +381,10 @@ def create_diskpool(server, virt='KVM', dpool=default_pool_name,
 
 def create_diskpool_conf(server, virt, dpool=default_pool_name):
     libvirt_version = virsh_version(server, virt)
-    if libvirt_version >= '0.4.1':
+    libvirt_version_req = "0.4.1"
+    a = get_version_number(libvirt_version)
+    b = get_version_number(libvirt_version_req)
+    if a >= b:
         status, dpoolname = create_diskpool(server, virt, dpool)
         diskid = "%s/%s" % ("DiskPool", dpoolname)
     else:
@@ -376,7 +395,10 @@ def create_diskpool_conf(server, virt, dpool=default_pool_name):
 
 def destroy_diskpool(server, virt, dpool):
     libvirt_version = virsh_version(server, virt)
-    if libvirt_version >= '0.4.1':
+    libvirt_version_req = "0.4.1"
+    a = get_version_number(libvirt_version)
+    b = get_version_number(libvirt_version_req)
+    if a >= b:
         if dpool == None:
             logger.error("No disk pool specified")
             return FAIL
-- 
1.7.1





More information about the Libvirt-cim mailing list