<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=us-ascii" http-equiv="Content-Type">
</head>
<body alink="#ff6666" bgcolor="#ffffff" link="#000099" text="#000000"
 vlink="#990099">
<br>
<br>
<a class="moz-txt-link-abbreviated" href="mailto:yunguol@cn.ibm.com">yunguol@cn.ibm.com</a> wrote:
<blockquote
 cite="midbdb5911993d5e56c6398.1223272344@elm3b217.beaverton.ibm.com"
 type="cite">
  <pre wrap=""># HG changeset patch
# User Guolian Yun <a class="moz-txt-link-rfc2396E" href="mailto:yunguol@cn.ibm.com"><yunguol@cn.ibm.com></a>
# Date 1223272339 25200
# Node ID bdb5911993d5e56c6398a447b3e5eabc5d41f83d
# Parent  b710ecb26adf500caa6b801fdf10e4efbed3877e
[TEST] #4 Fix HostedService - 03_forward_errs.py to work with sblim base provider installed

Updates from 3 to 4:

1) Update the tc to verify the case when we pass Invalid CreationClassName
2) Verify the complete exception instead of just verifying part of it

Signed-off-by: Guolian Yun <a class="moz-txt-link-rfc2396E" href="mailto:yunguol@cn.ibm.com"><yunguol@cn.ibm.com></a>

diff -r b710ecb26adf -r bdb5911993d5 suites/libvirt-cim/cimtest/HostedService/03_forward_errs.py
--- a/suites/libvirt-cim/cimtest/HostedService/03_forward_errs.py       Fri Oct 03 06:34:29 2008 -0700
+++ b/suites/libvirt-cim/cimtest/HostedService/03_forward_errs.py       Sun Oct 05 22:52:19 2008 -0700
@@ -25,6 +25,7 @@ from pywbem.cim_obj import CIMInstanceNa
 from pywbem.cim_obj import CIMInstanceName
 from XenKvmLib import assoc
 from XenKvmLib import enumclass
+from XenKvmLib.common_util import get_host_info
 from XenKvmLib.classes import get_typed_class
 from CimTest.Globals import logger, CIM_ERROR_ENUMERATE, CIM_USER, \
                             CIM_PASS, CIM_NS
@@ -33,7 +34,8 @@ from CimTest.ReturnCodes import PASS, FA

 sup_types = ['Xen', 'XenFV', 'KVM', 'LXC']
 exp_rc = 6 #CIM_ERR_NOT_FOUND
-exp_desc = "No such instance"
+exp_desc = ["No such instance (Name)",
+            "No such instance (CreationClassName)"]

 @do_main(sup_types)
 def main():
@@ -41,37 +43,41 @@ def main():
     rc = -1
     status = FAIL
     keys = ['Name', 'CreationClassName']
-    try:
-        host_sys = enumclass.enumerate(options.ip, 'HostSystem', keys, options.virt)[0]
-    except Exception:
-        logger.error(CIM_ERROR_ENUMERATE % host_sys.name)
+    status, host_name, host_ccn = get_host_info(options.ip, options.virt)
+    if status != PASS:
+        logger.error("Error in calling get_host_info function")
         return FAIL
-
     
     conn = assoc.myWBEMConnection('<a class="moz-txt-link-freetext" href="http://%s">http://%s</a>' % options.ip,                                        
                                   (CIM_USER, CIM_PASS),
                                    CIM_NS)
-    instanceref = CIMInstanceName(get_typed_class(options.virt, "HostSystem"), 
-                                  keybindings = {"Wrong" : "wrong", "CreationClassName" : host_sys.CreationClassName})
-
+    hostsystem = get_typed_class(options.virt, "HostSystem")
+    instanceref = [CIMInstanceName(hostsystem, 
+                                  keybindings = {"Wrong" : "wrong", "CreationClassName" : host_ccn}),
+                   CIMInstanceName(hostsystem,
+                                  keybindings = {"Name" : host_name, "Wrong" : "wrong"})]
+                     
  </pre>
</blockquote>
The instanceref[0] will produce unexpected result as below and not the
required exception <br>
<br>
 DEBUG instanceref is <b>Xen_HostSystem</b>.CreationClassName="Linux_ComputerSystem",Wrong="wrong"<br>
 Unexpected rc code 6 and description CIM_ERR_NOT_FOUND: No such
instance (CreationClassName)<br>
<br>
<br>
Replace <b>CIMInstanceName(hostsystem</b>, of instanceref[0] with <b>CIMInstanceName(host_ccn,</b>
otherwise it the instanceref will give unexpected exception as above
when sblim-base-provider is installed.<br>
<blockquote
 cite="midbdb5911993d5e56c6398.1223272344@elm3b217.beaverton.ibm.com"
 type="cite">
  <pre wrap="">     names = []

-    try:
-        names = conn.AssociatorNames(instanceref, AssocClass = get_typed_class(options.virt, "HostedService"))
-        rc = 0
-    except pywbem.CIMError, (rc, desc):
-        if rc == exp_rc and desc.find(exp_desc) >= 0:
-            logger.info("Got excepted rc code and error string")
-            status = PASS
-        else:
-            logger.error("Unexpected rc code %s and description %s\n" %(rc, desc))
-    except Exception, details:
-        logger.error("Unknown exception happened")
-        logger.error(details)
+    hostedservice = get_typed_class(options.virt, "HostedService")
+    for i in range(0, len(instanceref)):
+        try:
+            names = conn.AssociatorNames(instanceref[i], AssocClass = hostedservice)
+            rc = 0
+        except pywbem.CIMError, (rc, desc):
+            if rc == exp_rc and desc.find(exp_desc[i]) >= 0:
+                logger.info("Got excepted rc code and error string")
+                status = PASS
+            else:
+                logger.error("Unexpected rc code %s and description %s\n" %(rc, desc))
+        except Exception, details:
+            logger.error("Unknown exception happened")
+            logger.error(details)

-    if rc == 0:
-        logger.error("HostedService associator should NOT return excepted result with a wrong key name and value of HostSystem input")
-        status = FAIL
+        if rc == 0:
+            logger.error("HostedService associator should NOT return excepted result\
+                         with a wrong key name and value of HostSystem input")
+            status = FAIL
  </pre>
</blockquote>
This does not exit the test case even when it fails. <br>
Return appropriate return value here directly, for sblim-base-provider
we need to return XFAIL.<br>
<blockquote
 cite="midbdb5911993d5e56c6398.1223272344@elm3b217.beaverton.ibm.com"
 type="cite">
  <pre wrap="">     
     return status        

  </pre>
</blockquote>
You can replace calling Associators() and verifications, with the
library function try_assoc() of common_util.py to verify the exceptions
for the associtations.<br>
<br>
This is not related to your changes, but can you change the following
log msg <br>
 logger.error("Unknown exception happened")<br>
to <br>
  logger.error("Unknown exception")
<blockquote
 cite="midbdb5911993d5e56c6398.1223272344@elm3b217.beaverton.ibm.com"
 type="cite">
  <pre wrap="">
_______________________________________________
Libvirt-cim mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Libvirt-cim@redhat.com">Libvirt-cim@redhat.com</a>
<a class="moz-txt-link-freetext" href="https://www.redhat.com/mailman/listinfo/libvirt-cim">https://www.redhat.com/mailman/listinfo/libvirt-cim</a>
  </pre>
</blockquote>
</body>
</html>