# HG changeset patch
# User Deepti B. Kalakeri <deeptik(a)linux.vnet.ibm.com>
# Date 1246972788 25200
# Node ID 9903b1d91bd966f453392ddbd0378feb50a4f771
# Parent 479f287a17fd08e4e22ac37459393f6f8327315a
[TEST] Modified the indication_tester.py to support MigrationIndications.
Modified indication_tester.py to include
- sub_ind() --> Subscribe for the indications to be watched.
- handle_request() --> Filters the required indications.
- poll_for_ind() --> Wait for the required indications to be triggered.
Tested with KVM and current sources on F10.
Signed-off-by: Deepti B. Kalakeri <deeptik(a)linux.vnet.ibm.com>
diff -r 479f287a17fd -r 9903b1d91bd9
suites/libvirt-cim/lib/XenKvmLib/indication_tester.py
--- a/suites/libvirt-cim/lib/XenKvmLib/indication_tester.py Tue Jun 30 06:53:22 2009
-0700
+++ b/suites/libvirt-cim/lib/XenKvmLib/indication_tester.py Tue Jul 07 06:19:48 2009
-0700
@@ -11,6 +11,13 @@
import httplib
import base64
from xml.dom.minidom import parse, parseString
+from os import kill, WNOHANG
+from signal import SIGKILL
+from CimTest.Globals import logger
+from XenKvmLib.vxml import set_default
+from XenKvmLib.classes import get_typed_class
+from CimTest.ReturnCodes import PASS, FAIL
+from os import waitpid, kill, fork, _exit, WNOHANG
def filter_xml(name, type, ns, sysname):
return """
@@ -381,6 +388,80 @@
print "CreateSubscription:\n%s\n" % subscript_str
print "DeleteSubscription:\n%s\n" % del_subscript_str
+def sub_ind(ip, virt, ind_names):
+ dict = set_default(ip)
+ 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 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, timeout=20):
+ status = FAIL
+ for i in range(0, timeout):
+ 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 successfully",
ind_name)
+ status = PASS
+ break
+ elif pw[1] == 0 and i < timeout:
+ 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
+
def main():
usage = "usage: %prog [options] provider\nex: %prog CIM_InstModification"
parser = OptionParser(usage)