[PATCH] [TEST] Update 32_start_reboot.py to use cim_() functions

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1231194787 28800 # Node ID f317d11f46a29a8141563498076d716153dfc5f2 # Parent ae40dfa1b8f6e134d200233d2e5b3395855cafa2 [TEST] Update 32_start_reboot.py to use cim_() functions Also change cim_state_change() to support enable and requested state parameters. Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r ae40dfa1b8f6 -r f317d11f46a2 suites/libvirt-cim/cimtest/ComputerSystem/32_start_reboot.py --- a/suites/libvirt-cim/cimtest/ComputerSystem/32_start_reboot.py Mon Jan 05 14:08:38 2009 -0800 +++ b/suites/libvirt-cim/cimtest/ComputerSystem/32_start_reboot.py Mon Jan 05 14:33:07 2009 -0800 @@ -28,26 +28,13 @@ # The test is considered to be successful if RequestedState Property # has a value of 10 when the VS is moved from active to reboot state. # -# List of Valid state values (Refer to VSP spec doc Table 2 for more) -# --------------------------------- -# State | Values -# --------------------------------- -# Defined | 3 -# Active | 2 -# Rebooted | 10 -# # Date: 03-03-2008 import sys -from VirtLib import utils -from time import sleep from CimTest.Globals import logger from XenKvmLib.const import do_main from CimTest.ReturnCodes import PASS, FAIL, XFAIL_RC -from XenKvmLib.test_doms import destroy_and_undefine_domain -from XenKvmLib.common_util import create_using_definesystem, \ - call_request_state_change, \ - poll_for_state_change +from XenKvmLib.vxml import get_class sup_types = ['Xen', 'XenFV', 'KVM', 'LXC'] @@ -64,45 +51,35 @@ server = options.ip virt = options.virt - tc_scen = [('Start', [ACTIVE_STATE, ACTIVE_STATE]), \ - ('Reboot', [ACTIVE_STATE, REBOOT_STATE])] - + action_failed = False try: # define the vs - status = create_using_definesystem(default_dom, server, - virt=virt) + cxml = get_class(virt)(default_dom) + ret = cxml.cim_define(server) + if not ret: + raise Exception("Failed to define the guest: %s" % default_dom) + + status = cxml.cim_start(server) if status != PASS: - logger.error("Unable to define domain '%s' using DefineSystem()", - default_dom) - return status + action_failed = True + raise Exception("Unable start dom '%s'" % default_dom) - # start, then reboot - for action, state in tc_scen: - en_state = state[0] - rq_state = state[1] - status = call_request_state_change(default_dom, server, - rq_state, TIME, - virt=virt) - if status != PASS: - logger.error("Unable to '%s' dom '%s' using RequestedStateChange()", - action, default_dom) - status = XFAIL_RC(bug_libvirt) - break - - status, dom_cs = poll_for_state_change(server, virt, default_dom, en_state, - timeout=10) - - if status != PASS or dom_cs.RequestedState != rq_state: - status = FAIL - logger.error("Attributes for dom '%s' is not set as expected.", - default_dom) - break + status = cxml.cim_reboot(server) + if status != PASS: + action_failed = True + raise Exception("Unable reboot dom '%s'" % default_dom) except Exception, detail: logger.error("Exception: %s", detail) status = FAIL - destroy_and_undefine_domain(default_dom, server, virt) + cxml.cim_destroy(server) + cxml.undefine(server) + + if action_failed: + if virt == "KVM" or virt == "LXC": + return XFAIL_RC(bug_libvirt) + return status if __name__ == "__main__": diff -r ae40dfa1b8f6 -r f317d11f46a2 suites/libvirt-cim/lib/XenKvmLib/vxml.py --- a/suites/libvirt-cim/lib/XenKvmLib/vxml.py Mon Jan 05 14:08:38 2009 -0800 +++ b/suites/libvirt-cim/lib/XenKvmLib/vxml.py Mon Jan 05 14:33:07 2009 -0800 @@ -535,7 +535,7 @@ try: cs = GetInstance(server, cs_class, keys) - if cs.Name != self.domain_name: + if cs is None or cs.Name != self.domain_name: raise Exception("Wrong guest instance") if cs.EnabledState != en_state: @@ -553,7 +553,11 @@ return PASS - def cim_state_change(self, server, req_state, req_timeout, poll_time): + def cim_state_change(self, server, req_state, req_timeout, poll_time, + en_state=None): + if en_state is None: + en_state = req_state + cs = None cs_class = get_typed_class(self.virt, 'ComputerSystem') keys = { 'Name' : self.domain_name, 'CreationClassName' : cs_class } @@ -562,7 +566,7 @@ return status try: - req_state_change = pywbem.cim_types.Uint16(req_state) + req_state_change = pywbem.cim_types.Uint16(req_state) time_period = pywbem.cim_types.CIMDateTime(req_timeout) cs.RequestStateChange(RequestedState=req_state_change, TimeoutPeriod=time_period) @@ -574,7 +578,7 @@ return FAIL for i in range(1, (poll_time + 1)): - status = self.check_guest_state(server, req_state) + status = self.check_guest_state(server, en_state, req_state) if status == PASS: break @@ -606,7 +610,7 @@ def cim_reboot(self, server, req_time=const.TIME, poll_time=30): return self.cim_state_change(server, const.CIM_REBOOT, - req_time, poll_time) + req_time, poll_time, const.CIM_ENABLE) def cim_reset(self, server, req_time=const.TIME, poll_time=30): return self.cim_state_change(server, const.CIM_RESET,

Kaitlin Rupert wrote:
# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1231194787 28800 # Node ID f317d11f46a29a8141563498076d716153dfc5f2 # Parent ae40dfa1b8f6e134d200233d2e5b3395855cafa2 [TEST] Update 32_start_reboot.py to use cim_() functions
Also change cim_state_change() to support enable and requested state parameters.
Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com>
diff -r ae40dfa1b8f6 -r f317d11f46a2 suites/libvirt-cim/cimtest/ComputerSystem/32_start_reboot.py --- a/suites/libvirt-cim/cimtest/ComputerSystem/32_start_reboot.py Mon Jan 05 14:08:38 2009 -0800 +++ b/suites/libvirt-cim/cimtest/ComputerSystem/32_start_reboot.py Mon Jan 05 14:33:07 2009 -0800 @@ -28,26 +28,13 @@ # The test is considered to be successful if RequestedState Property # has a value of 10 when the VS is moved from active to reboot state. # -# List of Valid state values (Refer to VSP spec doc Table 2 for more) -# --------------------------------- -# State | Values -# --------------------------------- -# Defined | 3 -# Active | 2 -# Rebooted | 10 -# # Date: 03-03-2008
import sys -from VirtLib import utils -from time import sleep from CimTest.Globals import logger from XenKvmLib.const import do_main from CimTest.ReturnCodes import PASS, FAIL, XFAIL_RC -from XenKvmLib.test_doms import destroy_and_undefine_domain -from XenKvmLib.common_util import create_using_definesystem, \ - call_request_state_change, \ - poll_for_state_change +from XenKvmLib.vxml import get_class
sup_types = ['Xen', 'XenFV', 'KVM', 'LXC']
The following can be removed from the test case since they are not used in the updated test case. ACTIVE_STATE = 2 REBOOT_STATE = 10 TIME = "00000000000000.000000:000"
@@ -64,45 +51,35 @@ server = options.ip virt = options.virt
- tc_scen = [('Start', [ACTIVE_STATE, ACTIVE_STATE]), \ - ('Reboot', [ACTIVE_STATE, REBOOT_STATE])] - + action_failed = False try: # define the vs - status = create_using_definesystem(default_dom, server, - virt=virt) + cxml = get_class(virt)(default_dom) + ret = cxml.cim_define(server) + if not ret: + raise Exception("Failed to define the guest: %s" % default_dom) + + status = cxml.cim_start(server) if status != PASS: - logger.error("Unable to define domain '%s' using DefineSystem()", - default_dom) - return status + action_failed = True
If we set action_failed here we return XFAIL even for start operation which is not valid. Since cim_start() is supported and should not XFAIL. No need to set action_failed here.
+ raise Exception("Unable start dom '%s'" % default_dom)
- # start, then reboot - for action, state in tc_scen: - en_state = state[0] - rq_state = state[1] - status = call_request_state_change(default_dom, server, - rq_state, TIME, - virt=virt) - if status != PASS: - logger.error("Unable to '%s' dom '%s' using RequestedStateChange()", - action, default_dom) - status = XFAIL_RC(bug_libvirt) - break - - status, dom_cs = poll_for_state_change(server, virt, default_dom, en_state, - timeout=10) - - if status != PASS or dom_cs.RequestedState != rq_state: - status = FAIL - logger.error("Attributes for dom '%s' is not set as expected.", - default_dom) - break + status = cxml.cim_reboot(server) + if status != PASS: + action_failed = True + raise Exception("Unable reboot dom '%s'" % default_dom)
except Exception, detail: logger.error("Exception: %s", detail) status = FAIL
- destroy_and_undefine_domain(default_dom, server, virt) + cxml.cim_destroy(server) + cxml.undefine(server) + + if action_failed: + if virt == "KVM" or virt == "LXC": + return XFAIL_RC(bug_libvirt) + return status
if __name__ == "__main__": diff -r ae40dfa1b8f6 -r f317d11f46a2 suites/libvirt-cim/lib/XenKvmLib/vxml.py --- a/suites/libvirt-cim/lib/XenKvmLib/vxml.py Mon Jan 05 14:08:38 2009 -0800 +++ b/suites/libvirt-cim/lib/XenKvmLib/vxml.py Mon Jan 05 14:33:07 2009 -0800 @@ -535,7 +535,7 @@
try: cs = GetInstance(server, cs_class, keys) - if cs.Name != self.domain_name: + if cs is None or cs.Name != self.domain_name: raise Exception("Wrong guest instance")
if cs.EnabledState != en_state: @@ -553,7 +553,11 @@
return PASS
- def cim_state_change(self, server, req_state, req_timeout, poll_time): + def cim_state_change(self, server, req_state, req_timeout, poll_time, + en_state=None): + if en_state is None: + en_state = req_state + cs = None cs_class = get_typed_class(self.virt, 'ComputerSystem') keys = { 'Name' : self.domain_name, 'CreationClassName' : cs_class } @@ -562,7 +566,7 @@ return status
try: - req_state_change = pywbem.cim_types.Uint16(req_state) + req_state_change = pywbem.cim_types.Uint16(req_state) time_period = pywbem.cim_types.CIMDateTime(req_timeout) cs.RequestStateChange(RequestedState=req_state_change, TimeoutPeriod=time_period) @@ -574,7 +578,7 @@ return FAIL
for i in range(1, (poll_time + 1)): - status = self.check_guest_state(server, req_state) + status = self.check_guest_state(server, en_state, req_state) if status == PASS: break
@@ -606,7 +610,7 @@
def cim_reboot(self, server, req_time=const.TIME, poll_time=30): return self.cim_state_change(server, const.CIM_REBOOT, - req_time, poll_time) + req_time, poll_time, const.CIM_ENABLE)
The test case gives a false positive. The following are the log messages which means the tc is suppose to fail. Tue, 06 Jan 2009 01:10:14:TEST LOG:INFO - ====32_start_reboot.py Log==== Tue, 06 Jan 2009 01:10:17:TEST LOG:ERROR - Unable to check guest state Tue, 06 Jan 2009 01:10:17:TEST LOG:ERROR - Exception: Wrong guest instance Tue, 06 Jan 2009 01:10:18:TEST LOG:ERROR - Unable to check guest state Tue, 06 Jan 2009 01:10:18:TEST LOG:ERROR - Exception: EnabledState is 9, expected 2. But, the test case gives a PASS message on the console.
def cim_reset(self, server, req_time=const.TIME, poll_time=30): return self.cim_state_change(server, const.CIM_RESET,
_______________________________________________ Libvirt-cim mailing list Libvirt-cim@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-cim

@@ -606,7 +610,7 @@ def cim_reboot(self, server, req_time=const.TIME, poll_time=30): return self.cim_state_change(server, const.CIM_REBOOT, - req_time, poll_time) + req_time, poll_time, const.CIM_ENABLE) The test case gives a false positive. The following are the log messages which means the tc is suppose to fail.
Tue, 06 Jan 2009 01:10:14:TEST LOG:INFO - ====32_start_reboot.py Log==== Tue, 06 Jan 2009 01:10:17:TEST LOG:ERROR - Unable to check guest state Tue, 06 Jan 2009 01:10:17:TEST LOG:ERROR - Exception: Wrong guest instance Tue, 06 Jan 2009 01:10:18:TEST LOG:ERROR - Unable to check guest state Tue, 06 Jan 2009 01:10:18:TEST LOG:ERROR - Exception: EnabledState is 9, expected 2.
But, the test case gives a PASS message on the console.
When you reboot a guest, the will be paused briefly before being restarted. When cim_state_change(), it calls check_guest_state() in a loop to verify the guest reaches the appropriate state. check_guest_state() prints an error message if the state is not in the expected state. I could change these from error messages to info messages. But check_guest_state() would still need to return an error in this case (even though the test doesn't report an error because the guest really is rebooted in this case). -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

Kaitlin Rupert wrote:
@@ -606,7 +610,7 @@ def cim_reboot(self, server, req_time=const.TIME, poll_time=30): return self.cim_state_change(server, const.CIM_REBOOT, - req_time, poll_time) + req_time, poll_time, const.CIM_ENABLE) The test case gives a false positive. The following are the log messages which means the tc is suppose to fail.
Tue, 06 Jan 2009 01:10:14:TEST LOG:INFO - ====32_start_reboot.py Log==== Tue, 06 Jan 2009 01:10:17:TEST LOG:ERROR - Unable to check guest state Tue, 06 Jan 2009 01:10:17:TEST LOG:ERROR - Exception: Wrong guest instance Tue, 06 Jan 2009 01:10:18:TEST LOG:ERROR - Unable to check guest state Tue, 06 Jan 2009 01:10:18:TEST LOG:ERROR - Exception: EnabledState is 9, expected 2.
But, the test case gives a PASS message on the console.
When you reboot a guest, the will be paused briefly before being restarted. When cim_state_change(), it calls check_guest_state() in a loop to verify the guest reaches the appropriate state.
check_guest_state() prints an error message if the state is not in the expected state.
I could change these from error messages to info messages. But check_guest_state() would still need to return an error in this case (even though the test doesn't report an error because the guest really is rebooted in this case). I get your point here, but still it left me confused as to why I am getting the Error Messages. It would be good to change the Error messages to Info messages whenever appropriate. We can use the timeout period to decide whether it is time to print an error message in case the guest info is not found or the states are not yet properly. Any thoughts ??
Thanks and Regards, Deepti.

I get your point here, but still it left me confused as to why I am getting the Error Messages. It would be good to change the Error messages to Info messages whenever appropriate. We can use the timeout period to decide whether it is time to print an error message in case the guest info is not found or the states are not yet properly. Any thoughts ??
Using the timeout won't work because it is check_guest_state() that is printing the error messages, not cim_state_change(). I'm going to submit a patch that changes the log message from error to info. The test case should be responsible for printing its own error message in the case of a failure, so changing this to info messages shouldn't be too problematic. The only problem it causes is that when you run with -debug, the info messages won't print to the terminal, so you'll have to check the individual log to see why the test failed. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

Kaitlin Rupert wrote:
I get your point here, but still it left me confused as to why I am getting the Error Messages. It would be good to change the Error messages to Info messages whenever appropriate. We can use the timeout period to decide whether it is time to print an error message in case the guest info is not found or the states are not yet properly. Any thoughts ??
Using the timeout won't work because it is check_guest_state() that is printing the error messages, not cim_state_change(). I'm going to submit a patch that changes the log message from error to info.
What I was thinking is to supply the timeout param and maintain a static like variable( that is present in C) and use this static like variable to compare in check_guest_state(). We can achieve the static behaviour in python by declaring a global variable in the check_guest_state() function. But, I think using globals is highly discouraged ?
The test case should be responsible for printing its own error message in the case of a failure, so changing this to info messages shouldn't be too problematic.
The only problem it causes is that when you run with -debug, the info messages won't print to the terminal, so you'll have to check the individual log to see why the test failed. I think it is better to leave this as it is for now. Since someone might forget to ON the --debug option to see the log messages. Any thoughts ??
-- Thanks and Regards, Deepti B. Kalakeri IBM Linux Technology Center deeptik@linux.vnet.ibm.com

What I was thinking is to supply the timeout param and maintain a static like variable( that is present in C) and use this static like variable to compare in check_guest_state(). We can achieve the static behaviour in python by declaring a global variable in the check_guest_state() function. But, I think using globals is highly discouraged ?
Yes, I think it is best to avoid global variables. It makes the code execution more confusing, and they are generally considered less safe.
The test case should be responsible for printing its own error message in the case of a failure, so changing this to info messages shouldn't be too problematic.
The only problem it causes is that when you run with -debug, the info messages won't print to the terminal, so you'll have to check the individual log to see why the test failed. I think it is better to leave this as it is for now. Since someone might forget to ON the --debug option to see the log messages.
Using the debug option doesn't print info messages to the console. Error messages are printed, info messages are not. I'll continue to do some more brainstorming on this issue. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com
participants (2)
-
Deepti B Kalakeri
-
Kaitlin Rupert