
# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1217543970 25200 # Node ID a0f1042dd8dd0b685aa755e1cedbbd7cdd71bbfc # Parent 837943c970641071e55637386d9ac30df5d41e4b [TEST] Modify CSI test to support modified and deleted indications. This may fail on KVM with the following error message: "CIM_ERR_FAILED: Invalid state transition." Will follow up on this issue. Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r 837943c97064 -r a0f1042dd8dd suites/libvirt-cim/cimtest/ComputerSystemIndication/01_created_indication.py --- a/suites/libvirt-cim/cimtest/ComputerSystemIndication/01_created_indication.py Thu Jul 31 15:35:35 2008 -0700 +++ b/suites/libvirt-cim/cimtest/ComputerSystemIndication/01_created_indication.py Thu Jul 31 15:39:30 2008 -0700 @@ -24,91 +24,163 @@ import os import signal import time +from pywbem.cim_obj import CIMInstanceName from CimTest.Globals import logger from CimTest.Globals import do_main from CimTest.ReturnCodes import PASS, FAIL -from XenKvmLib.common_util import create_using_definesystem -from XenKvmLib.test_doms import undefine_test_domain +from XenKvmLib.common_util import create_using_definesystem, \ + call_request_state_change +from XenKvmLib.test_doms import destroy_and_undefine_domain from XenKvmLib.classes import get_typed_class from XenKvmLib.indication_tester import CIMIndicationSubscription from XenKvmLib.vxml import set_default +from XenKvmLib.vsms import get_vsms_class SUPPORTED_TYPES = ['Xen', 'XenFV', 'KVM'] test_dom = "domU" +REQ_STATE = 2 +TIME = "00000000000000.000000:000" + +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): + if ind == "define": + return create_using_definesystem(test_dom, ip, virt=vtype) + + elif ind == "start": + rc = call_request_state_change(test_dom, ip, REQ_STATE, TIME, vtype) + if rc != 0: + logger.error("Failed to start domain: %s" % test_dom) + return FAIL + return PASS + + elif ind == "destroy": + service = get_vsms_class(vtype)(ip) + try: + classname = get_typed_class(vtype, 'ComputerSystem') + cs_ref = CIMInstanceName(classname, keybindings = { + 'Name':test_dom, + 'CreationClassName':classname}) + service.DestroySystem(AffectedSystem=cs_ref) + except Exception, details: + logger.error('Unknow exception happened') + logger.error(details) + return FAIL + return PASS + + return FAIL + +def handle_request(sub, ind_name): + sub.server.handle_request() + if len(sub.server.indications) == 0: + logger.error("No valid indications received") + return FAIL + elif str(sub.server.indications[0]) != ind_name: + logger.error("Received indication %s instead of %s" % \ + (str(sub.server.indications[0])), ind_name) + return FAIL + + return PASS + +def poll_for_ind(pid): + for i in range(0, 20): + pw = os.waitpid(pid, os.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 indication successfuly") + status = PASS + break + elif pw[1] == 0 and i < 19: + if i % 10 == 0: + logger.info("In child process, waiting for indication") + time.sleep(1) + else: + # Time is up and waitpid never returned the expected pid + if pw[0] != pid: + logger.error("Waited too long for indication") + os.kill(pid, signal.SIGKILL) + else: + logger.error("Received indication error: %d" % pw[1]) + + status = FAIL + break + + return status @do_main(SUPPORTED_TYPES) def main(): options = main.options status = FAIL - dict = set_default(options.ip) - indication_name = get_typed_class(options.virt, - 'ComputerSystemCreatedIndication') - - sub = CIMIndicationSubscription(dict['default_name'], indication_name, - dict['default_ns'], - dict['default_print_ind'], - dict['default_sysname']) - sub.subscribe(dict['default_url'], dict['default_auth']) - logger.info("Watching for %s" % indication_name) - - try: - pid = os.fork() - if pid == 0: - sub.server.handle_request() - if len(sub.server.indications) == 0: - logger.error("No valid indications received") - os._exit(1) - elif str(sub.server.indications[0]) != indication_name: - logger.error("Received indication %s instead of %s" % \ - (indication_name, str(sub.server.indications[0]))) - os._exit(2) + sub_list, ind_names, dict = sub_ind(options.ip, options.virt) + + ind_list = ["define", "start", "destroy"] + + for ind in ind_list: + sub = sub_list[ind] + ind_name = ind_names[ind] + + try: + pid = os.fork() + if pid == 0: + status = handle_request(sub, ind_name) + if status != PASS: + os._exit(1) + + os._exit(0) else: - os._exit(0) - else: - status = create_using_definesystem(test_dom, options.ip, None, None, - options.virt) - if status != PASS: - sub.unsubscribe(dict['default_auth']) - logger.info("Cancelling subscription for %s" % indication_name) - os.kill(pid, signal.SIGKILL) - return status + try: + status = gen_ind(test_dom, options.ip, options.virt, ind) + if status != PASS: + os.kill(pid, signal.SIGKILL) + return FAIL - status = FAIL - for i in range(0,100): - pw = os.waitpid(pid, os.WNOHANG) + status = poll_for_ind(pid) + except Exception, details: + logger.error("Exception: %s" % details) + os.kill(pid, signal.SIGKILL) + return FAIL - # 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 indication successfuly") - status = PASS - break - elif pw[1] == 0 and i < 99: - if i % 10 == 0: - logger.info("In child process, waiting for indication") - time.sleep(1) - else: - status = FAIL - - # Time is up and waitpid never returned the expected pid - if pw[0] != pid: - logger.error("Waited too long for indication") - os.kill(pid, signal.SIGKILL) - else: - logger.error("Received indication error: %d" % pw[1]) - break + except Exception, details: + logger.error("Exception: %s" % details) + return FAIL - except Exception, details: - logger.error("Unknown exception happened") - logger.error(details) - - sub.unsubscribe(dict['default_auth']) - logger.info("Cancelling subscription for %s" % indication_name) - undefine_test_domain(test_dom, options.ip, options.virt) + for ind, sub in sub_list.iteritems(): + sub.unsubscribe(dict['default_auth']) + logger.info("Cancelling subscription for %s" % ind_names[ind]) + + destroy_and_undefine_domain(test_dom, options.ip, options.virt) return status