[PATCH 0 of 2] [TEST] [RFC] Possible way of handling stale libvirt info

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1217542638 25200 # Node ID d0c5bdff331b674690f973a70d4ef00878e484f4 # Parent 365e478e317b6559dd8869051aeda8d54d358686 Add function to poll for a guest This function is a work around to deal with a stale data issue seen with libvirt on RHEL 5.x. Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r 365e478e317b -r d0c5bdff331b suites/libvirt-cim/lib/XenKvmLib/common_util.py --- a/suites/libvirt-cim/lib/XenKvmLib/common_util.py Thu Jul 31 15:19:33 2008 -0700 +++ b/suites/libvirt-cim/lib/XenKvmLib/common_util.py Thu Jul 31 15:17:18 2008 -0700 @@ -33,10 +33,12 @@ from pywbem.cim_obj import CIMInstanceName from XenKvmLib.devices import CIM_Instance from XenKvmLib.classes import get_typed_class -from CimTest.Globals import logger, log_param, CIM_ERROR_ENUMERATE +from CimTest.Globals import logger, log_param, CIM_ERROR_ENUMERATE, \ + CIM_ERROR_GETINSTANCE from CimTest.ReturnCodes import PASS, FAIL, XFAIL_RC -from VirtLib.live import diskpool_list, virsh_version, net_list +from VirtLib.live import diskpool_list, virsh_version, net_list, domain_list from XenKvmLib.vxml import PoolXML, NetXML +from XenKvmLib.enumclass import getInstance test_dpath = "foo" disk_file = '/etc/libvirt/diskpool.conf' @@ -57,7 +59,7 @@ return (1, cs) except Exception, detail: - logger.error(Globals.CIM_ERROR_GETINSTANCE, + logger.error(CIM_ERROR_GETINSTANCE, get_typed_class(virt, 'ComputerSystem')) logger.error("Exception: %s", detail) return (1, cs) @@ -397,3 +399,18 @@ return PASS +def check_virsh_poll(ip, virt, dom_name): + cs = None + + dom_list = domain_list(ip, virt) + if dom_name in dom_list: + timeout = 10 + + for i in range(0, timeout): + rc, cs = get_cs_instance(dom_name, ip, virt) + if rc == 0: + return cs + + sleep(1) + + return cs

+1 from me =) libvirt-cim-bounces@redhat.com wrote on 2008-08-01 06:26:05:
# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1217542638 25200 # Node ID d0c5bdff331b674690f973a70d4ef00878e484f4 # Parent 365e478e317b6559dd8869051aeda8d54d358686 Add function to poll for a guest
This function is a work around to deal with a stale data issue seen with libvirt on RHEL 5.x.
Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com>
diff -r 365e478e317b -r d0c5bdff331b suites/libvirt- cim/lib/XenKvmLib/common_util.py --- a/suites/libvirt-cim/lib/XenKvmLib/common_util.py Thu Jul 31 15:19:33 2008 -0700 +++ b/suites/libvirt-cim/lib/XenKvmLib/common_util.py Thu Jul 31 15:17:18 2008 -0700 @@ -33,10 +33,12 @@ from pywbem.cim_obj import CIMInstanceName from XenKvmLib.devices import CIM_Instance from XenKvmLib.classes import get_typed_class -from CimTest.Globals import logger, log_param, CIM_ERROR_ENUMERATE +from CimTest.Globals import logger, log_param, CIM_ERROR_ENUMERATE, \ + CIM_ERROR_GETINSTANCE from CimTest.ReturnCodes import PASS, FAIL, XFAIL_RC -from VirtLib.live import diskpool_list, virsh_version, net_list +from VirtLib.live import diskpool_list, virsh_version, net_list, domain_list from XenKvmLib.vxml import PoolXML, NetXML +from XenKvmLib.enumclass import getInstance
test_dpath = "foo" disk_file = '/etc/libvirt/diskpool.conf' @@ -57,7 +59,7 @@ return (1, cs)
except Exception, detail: - logger.error(Globals.CIM_ERROR_GETINSTANCE, + logger.error(CIM_ERROR_GETINSTANCE, get_typed_class(virt, 'ComputerSystem')) logger.error("Exception: %s", detail) return (1, cs) @@ -397,3 +399,18 @@
return PASS
+def check_virsh_poll(ip, virt, dom_name): + cs = None + + dom_list = domain_list(ip, virt) + if dom_name in dom_list: + timeout = 10 + + for i in range(0, timeout): + rc, cs = get_cs_instance(dom_name, ip, virt) + if rc == 0: + return cs + + sleep(1) + + return cs
_______________________________________________ Libvirt-cim mailing list Libvirt-cim@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-cim

KR> +def check_virsh_poll(ip, virt, dom_name): KR> + cs = None KR> + KR> + dom_list = domain_list(ip, virt) KR> + if dom_name in dom_list: KR> + timeout = 10 KR> + KR> + for i in range(0, timeout): KR> + rc, cs = get_cs_instance(dom_name, ip, virt) KR> + if rc == 0: KR> + return cs KR> + KR> + sleep(1) KR> + KR> + return cs How many iterations does this normally have to go through to get fresh data? I suppose it's a reasonable band-aid for now. -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms@us.ibm.com

Dan Smith wrote:
KR> +def check_virsh_poll(ip, virt, dom_name): KR> + cs = None KR> + KR> + dom_list = domain_list(ip, virt) KR> + if dom_name in dom_list: KR> + timeout = 10 KR> + KR> + for i in range(0, timeout): KR> + rc, cs = get_cs_instance(dom_name, ip, virt) KR> + if rc == 0: KR> + return cs KR> + KR> + sleep(1) KR> + KR> + return cs
How many iterations does this normally have to go through to get fresh data?
6 - 7 iterations - seems pretty consistent in my testing.
I suppose it's a reasonable band-aid for now.
In the future, most of these tests will use the provider to create the guest (not virsh), so I think this problem will go away on its own in time. Although, we'll want to have some tests that use virsh, just to make sure the providers handle guests created outside of the providers. So we'll need this (or something like this) in those cases. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

KR> 6 - 7 iterations - seems pretty consistent in my testing. Okay. KR> In the future, most of these tests will use the provider to create the KR> guest (not virsh), so I think this problem will go away on its own in KR> time. Indeed. As long as that's the plan, I think doing this for those tests that need to check this behavior is fine. What's up with the name though? The function has 'virsh' in the name, but it's querying the providers, right? -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms@us.ibm.com

Dan Smith wrote:
KR> 6 - 7 iterations - seems pretty consistent in my testing.
Okay.
KR> In the future, most of these tests will use the provider to create the KR> guest (not virsh), so I think this problem will go away on its own in KR> time.
Indeed. As long as that's the plan, I think doing this for those tests that need to check this behavior is fine.
What's up with the name though? The function has 'virsh' in the name, but it's querying the providers, right?
It's checking both virsh and the providers. The hack here is that virsh doesn't hit the caching issue. So if virsh lists the guest, then we poll until the providers see it. If virsh doesn't see the guest, then the guest wasn't created. So we don't waste time polling for a guest that doesn't exist. Even still, the name is pretty poor. I'll think something else up and resend. =) -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

KR> It's checking both virsh and the providers. The hack here is that KR> virsh doesn't hit the caching issue. So if virsh lists the guest, KR> then we poll until the providers see it. Oh, okay, I see it now. I had lost sight of what the other patch did. KR> Even still, the name is pretty poor. I'll think something else up and KR> resend. =) Well, I wonder if the other function needs a more clear name, since it's what actually polls both. That might make this function name make more sense. -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms@us.ibm.com

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1217542648 25200 # Node ID b53b5a20e8f561366ff90f2156ad6d26d90b5d1b # Parent d0c5bdff331b674690f973a70d4ef00878e484f4 Update ElementConforms 02 to use check_virsh_poll() work around. Also clean this test case some. Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r d0c5bdff331b -r b53b5a20e8f5 suites/libvirt-cim/cimtest/ElementConforms/02_reverse.py --- a/suites/libvirt-cim/cimtest/ElementConforms/02_reverse.py Thu Jul 31 15:17:18 2008 -0700 +++ b/suites/libvirt-cim/cimtest/ElementConforms/02_reverse.py Thu Jul 31 15:17:28 2008 -0700 @@ -52,6 +52,7 @@ from XenKvmLib.vxml import XenXML, KVMXML, get_class from XenKvmLib.classes import get_typed_class from CimTest.ReturnCodes import PASS, FAIL +from XenKvmLib.common_util import check_virsh_poll, get_cs_instance sup_types = ['Xen', 'XenFV', 'KVM', 'LXC'] @@ -96,51 +97,41 @@ inst_list = [] + rc, cs = get_cs_instance(test_dom, options.ip, options.virt) + if rc != 0: + sys = check_virsh_poll(options.ip, options.virt, test_dom) + if sys is None: + logger.error("Instance for %s not created" % test_dom) + return FAIL + + inst_list.append(sys) + try: - cs_list = computersystem.enumerate(options.ip, options.virt) - # The len should be atleast two, as the CS returns info - # one regarding VS and the other one for Domain-0. - if len(cs_list) < 1: - logger.error("ERROR: Wrong number of instances returned") - return status - for item in cs_list: - if item.Name == test_dom: - inst_list.append(item) - break - - if len(inst_list) != 1: - logger.error("ERROR: Instance for %s not created" % test_dom) - return status - #Getting the hostname, to verify with the value returned by the assoc. host_sys = hostsystem.enumerate(options.ip, options.virt) if len(host_sys) < 1: logger.error("ERROR: Enumerate returned 0 host instances") - return status - elif host_sys[0].Name == "": - logger.error("ERROR: HostName seems to be empty") - return status - else: - # Instance of the HostSystem - inst_list.append(host_sys[0]) - except Exception , detail: - logger.error("Exception: %s" % detail) - return status + return FAIL + + inst_list.append(host_sys[0]) + + except Exception, details: + logger.error("Exception: %s" % details) + return FAIL prev_namespace = Globals.CIM_NS Globals.CIM_NS = 'root/interop' try: key_list = ["InstanceID"] - proflist = enumclass.enumerate(options.ip, \ - "RegisteredProfile", \ + proflist = enumclass.enumerate(options.ip, + "RegisteredProfile", key_list, options.virt) - except Exception, detail: - logger.error(CIM_ERROR_ENUMERATE, \ - 'RegisteredProfile') - logger.error("Exception: %s", detail) + except Exception, details: + logger.error(CIM_ERROR_ENUMERATE, 'RegisteredProfile') + logger.error("Exception: %s", details) return status Globals.CIM_NS = prev_namespace @@ -160,11 +151,12 @@ Name=name) if len(profs) != 1: logger.error("ElementConformsToProfile assoc failed") - return status + return FAIL status = verify_profile(profs[0], exp_list[cn]) if status != PASS: logger.error("Verification of profile instance failed") + return FAIL except Exception, detail: logger.error(CIM_ERROR_ASSOCIATORS, 'RegisteredProfile')

libvirt-cim-bounces@redhat.com wrote on 2008-08-01 06:26:06:
# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1217542648 25200 # Node ID b53b5a20e8f561366ff90f2156ad6d26d90b5d1b # Parent d0c5bdff331b674690f973a70d4ef00878e484f4 Update ElementConforms 02 to use check_virsh_poll() work around.
Also clean this test case some.
Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com>
diff -r d0c5bdff331b -r b53b5a20e8f5 suites/libvirt- cim/cimtest/ElementConforms/02_reverse.py --- a/suites/libvirt-cim/cimtest/ElementConforms/02_reverse.py Thu Jul 31 15:17:18 2008 -0700 +++ b/suites/libvirt-cim/cimtest/ElementConforms/02_reverse.py Thu Jul 31 15:17:28 2008 -0700 @@ -52,6 +52,7 @@ from XenKvmLib.vxml import XenXML, KVMXML, get_class from XenKvmLib.classes import get_typed_class from CimTest.ReturnCodes import PASS, FAIL +from XenKvmLib.common_util import check_virsh_poll, get_cs_instance
sup_types = ['Xen', 'XenFV', 'KVM', 'LXC']
@@ -96,51 +97,41 @@
inst_list = []
+ rc, cs = get_cs_instance(test_dom, options.ip, options.virt) + if rc != 0: + sys = check_virsh_poll(options.ip, options.virt, test_dom) + if sys is None: + logger.error("Instance for %s not created" % test_dom) + return FAIL + + inst_list.append(sys) + try: - cs_list = computersystem.enumerate(options.ip, options.virt) - # The len should be atleast two, as the CS returns info - # one regarding VS and the other one for Domain-0. - if len(cs_list) < 1: - logger.error("ERROR: Wrong number of instances returned") - return status - for item in cs_list: - if item.Name == test_dom: - inst_list.append(item) - break - - if len(inst_list) != 1: - logger.error("ERROR: Instance for %s not created" % test_dom) - return status - #Getting the hostname, to verify with the value returned bythe assoc. host_sys = hostsystem.enumerate(options.ip, options.virt)
if len(host_sys) < 1: logger.error("ERROR: Enumerate returned 0 host instances") - return status - elif host_sys[0].Name == "": - logger.error("ERROR: HostName seems to be empty") - return status - else: - # Instance of the HostSystem - inst_list.append(host_sys[0]) - except Exception , detail: - logger.error("Exception: %s" % detail) - return status + return FAIL + + inst_list.append(host_sys[0]) + + except Exception, details: + logger.error("Exception: %s" % details) + return FAIL
prev_namespace = Globals.CIM_NS Globals.CIM_NS = 'root/interop'
try: key_list = ["InstanceID"] - proflist = enumclass.enumerate(options.ip, \ - "RegisteredProfile", \ + proflist = enumclass.enumerate(options.ip, + "RegisteredProfile", key_list, options.virt) - except Exception, detail: - logger.error(CIM_ERROR_ENUMERATE, \ - 'RegisteredProfile') - logger.error("Exception: %s", detail) + except Exception, details: + logger.error(CIM_ERROR_ENUMERATE, 'RegisteredProfile')
It's better to log details. logger.error(CIM_ERROR_ENUMERATE, \ get_typed_class(options.virt, 'RegisteredProfile'))
+ logger.error("Exception: %s", details) return status
Globals.CIM_NS = prev_namespace @@ -160,11 +151,12 @@ Name=name) if len(profs) != 1: logger.error("ElementConformsToProfile assoc failed") - return status + return FAIL
status = verify_profile(profs[0], exp_list[cn]) if status != PASS: logger.error("Verification of profile instance failed") + return FAIL
except Exception, detail: logger.error(CIM_ERROR_ASSOCIATORS, 'RegisteredProfile')
_______________________________________________ Libvirt-cim mailing list Libvirt-cim@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-cim
participants (3)
-
Dan Smith
-
Guo Lian Yun
-
Kaitlin Rupert