[Libvirt-cim] [PATCH] [TEST] Fix CSI to call handle_sub, sub_ind, and poll_for_ind from ind module

Kaitlin Rupert kaitlin at linux.vnet.ibm.com
Sat Dec 12 01:15:51 UTC 2009


# HG changeset patch
# User Kaitlin Rupert <karupert at us.ibm.com>
# Date 1260576721 28800
# Node ID f6a811d7118444d411baa03847cb96d8cb483ab4
# Parent  bbb978cccd1bd3d08bbb9d5e5ff796771d0bfd77
[TEST] Fix CSI to call handle_sub, sub_ind, and poll_for_ind from ind module

No need to have duplicate code in this test case, as these functions
already exist in the indications.py module.

Signed-off-by: Kaitlin Rupert <karupert at us.ibm.com>

diff -r bbb978cccd1b -r f6a811d71184 suites/libvirt-cim/cimtest/ComputerSystemIndication/01_created_indication.py
--- a/suites/libvirt-cim/cimtest/ComputerSystemIndication/01_created_indication.py	Fri Nov 27 19:24:42 2009 -0200
+++ b/suites/libvirt-cim/cimtest/ComputerSystemIndication/01_created_indication.py	Fri Dec 11 16:12:01 2009 -0800
@@ -31,39 +31,12 @@
 from XenKvmLib.indication_tester import CIMIndicationSubscription
 from XenKvmLib.vxml import set_default
 from XenKvmLib.vxml import get_class
+from XenKvmLib.indications import sub_ind, handle_request, poll_for_ind
 
 SUPPORTED_TYPES = ['Xen', 'XenFV', 'KVM']
 
 test_dom = "domU"
 
-def sub_ind(ip, virt):
-    dict = set_default(ip)
-    ind_names = {"define" : 'ComputerSystemCreatedIndication', 
-                 "start" : 'ComputerSystemModifiedIndication',
-                 "destroy" : 'ComputerSystemDeletedIndication'
-                }
-
-    sub_list = {}
-    port = 5
-
-    for ind, iname in ind_names.iteritems():
-        ind_name = get_typed_class(virt, iname)
-
-        sub_name = "Test%s" % ind_name
-        port += 1
-
-        sub = CIMIndicationSubscription(sub_name, ind_name,
-                                        dict['default_ns'],
-                                        dict['default_print_ind'],
-                                        dict['default_sysname'],
-                                        port)
-        sub.subscribe(dict['default_url'], dict['default_auth'])
-        logger.info("Watching for %s", iname)
-        ind_names[ind] = ind_name
-        sub_list[ind] = sub
-
-    return sub_list, ind_names, dict
-
 def gen_ind(test_dom, ip, vtype, ind, cxml):
     if ind == "define":
         ret = cxml.cim_define(ip)
@@ -85,57 +58,6 @@
         
     return FAIL 
 
-def handle_request(sub, ind_name, dict, exp_ind_ct):
-    #sfcb delivers indications to all registrations, even if the indication
-    #isn't what the registration was subscribed to.  So, for modified and 
-    #deleted indications, we must loop through until the indication we are
-    #looking for is triggered.
-    for i in range(0, exp_ind_ct):
-        sub.server.handle_request() 
-        if len(sub.server.indications) < 1:
-            logger.error("No valid indications received")
-            return FAIL
-
-        if str(sub.server.indications[0]) == ind_name:
-                sub.unsubscribe(dict['default_auth'])
-                logger.info("Cancelling subscription for %s", ind_name)
-                return PASS
-        else:
-                sub.server.indications.remove(sub.server.indications[0])
-
-    logger.error("Did not recieve indication %s", ind_name)
-    return FAIL
-
-def poll_for_ind(pid, ind_name):
-    status = FAIL
-    for i in range(0, 20):
-        pw = waitpid(pid, WNOHANG)
-
-        # If pid exits, waitpid returns [pid, return_code] 
-        # If pid is still running, waitpid returns [0, 0]
-        # Only return a success if waitpid returns the expected pid
-        # and the return code is 0.
-        if pw[0] == pid and pw[1] == 0:
-            logger.info("Great, got %s indication successfuly", ind_name)
-            status = PASS
-            break
-        elif pw[1] == 0 and i < 19:
-            if i % 10 == 0:
-                logger.info("In child, waiting for %s indication", ind_name)
-            sleep(1)
-        else:
-            # Time is up and waitpid never returned the expected pid
-            if pw[0] != pid:
-                logger.error("Waited too long for %s indication", ind_name)
-                kill(pid, SIGKILL)
-            else:
-                logger.error("Received indication error: %d", pw[1])
-
-            status = FAIL
-            break
-
-    return status
-
 @do_main(SUPPORTED_TYPES)
 def main():
     options = main.options
@@ -143,20 +65,24 @@
     virt = options.virt
     status = FAIL
 
-    sub_list, ind_names, dict = sub_ind(ip, virt)
-
-    ind_list = ["define", "start", "destroy"]
+    ind_names = {"define" : 'ComputerSystemCreatedIndication', 
+                 "start" : 'ComputerSystemModifiedIndication',
+                 "destroy" : 'ComputerSystemDeletedIndication'
+                }
 
     cxml = get_class(virt)(test_dom)
 
-    for ind in ind_list:
+    sub_list, ind_names, dict = sub_ind(ip, virt, ind_names)
+    for ind in ind_names.keys():
+
         sub = sub_list[ind]
         ind_name = ind_names[ind]
 
         try:
             pid = fork()
             if pid == 0:
-                status = handle_request(sub, ind_name, dict, len(ind_list))
+                status = handle_request(sub, ind_name, dict, 
+                                        len(ind_names.keys()))
                 if status != PASS:
                     _exit(1)
 
@@ -180,6 +106,9 @@
             logger.error("Exception: %s", details)
             status = FAIL
 
+    #Give threads time to execute before unsubscribing
+    sleep(30)
+
     #Make sure all subscriptions are really unsubscribed
     for ind, sub in sub_list.iteritems():
         sub.unsubscribe(dict['default_auth'])




More information about the Libvirt-cim mailing list