# HG changeset patch
# User Kaitlin Rupert <karupert(a)us.ibm.com>
# Date 1214156795 25200
# Node ID 6cb3a4b4b0b21497dbfc812c49e555699d580d21
# Parent 59fce67164a22315bb712f692dfd93314c4f30e0
[TEST] Add generic poll function to poll for guest state.
Signed-off-by: Kaitlin Rupert <karupert(a)us.ibm.com>
diff -r 59fce67164a2 -r 6cb3a4b4b0b2 suites/libvirt-cim/lib/XenKvmLib/common_util.py
--- a/suites/libvirt-cim/lib/XenKvmLib/common_util.py Thu Jun 05 19:37:57 2008 -0700
+++ b/suites/libvirt-cim/lib/XenKvmLib/common_util.py Sun Jun 22 10:46:35 2008 -0700
@@ -23,6 +23,7 @@
import os
import pywbem
import random
+from time import sleep
from distutils.file_util import move_file
from XenKvmLib.test_xml import *
from XenKvmLib.test_doms import *
@@ -135,6 +136,33 @@
return 1
return 0
+
+def poll_for_state_change(server, virt, dom, exp_state):
+ timeout = 30
+ cs = computersystem.get_cs_class(virt)
+
+ try:
+ for i in range(1, (timeout + 1)):
+ sleep(1)
+ dom_cs = cs(server, name=dom)
+ if dom_cs is None:
+ logger.error("CS instance not returned for %s." % dom)
+ return FAIL
+
+ if dom_cs.EnabledState == exp_state:
+ break
+
+ except Exception, detail:
+ logger.error("Exception: %s" % detail)
+ return FAIL
+
+ if dom_cs.EnabledState != exp_state:
+ logger.error("EnabledState is %i instead of %i." %
(dom_cs.EnabledState,
+ exp_state))
+ logger.error("Try to increase the timeout and run the test again")
+ return FAIL
+
+ return PASS
def get_host_info(server, virt="Xen"):
status = PASS