# HG changeset patch
# User Veerendra C <vechandr@in.ibm.com>
# Date 1228287169 28800
# Node ID 2b2bb6f1b2a9e560322608d837244677a7a75c45
# Parent  70ecd9e8867cc277b31f4703e73b5dba7ad53128
Adding a testcase to test the invalid inputs to the KVMRedirectionSAP class
Also included the defintion of graphics for the class KVMXML under devices.

diff -r 70ecd9e8867c -r 2b2bb6f1b2a9 suites/libvirt-cim/cimtest/RedirectionService/03_RedirectionSAP_errs.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/suites/libvirt-cim/cimtest/RedirectionService/03_RedirectionSAP_errs.py	Tue Dec 02 22:52:49 2008 -0800
@@ -0,0 +1,147 @@
+#!/usr/bin/python
+####################################################################################
+# Copyright 2008 IBM Corp.
+#
+# Authors:
+#    Veerendra C <vechandr@in.ibm.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+####################################################################################
+# Example :
+# wbemcli gi 'http://root:passwd@localhost:5988/root/virt:KVM_KVMRedirectionSAP. \
+# CreationClassName="KVM_KVMRedirectionSAP",Name="1:1",SystemCreationClassName=  \
+# "KVM_ComputerSystem",SystemName="demo2"' -nl
+#
+# Test Case Info:
+# --------------
+# This testcase is used to verify if appropriate exceptions are
+# returned by KVMRedirectionSAP on giving invalid inputs.
+#
+
+import sys
+import pywbem
+from XenKvmLib import assoc
+from XenKvmLib.common_util import try_getinstance
+from XenKvmLib.classes import get_typed_class
+from XenKvmLib.vxml import get_class
+from XenKvmLib.test_doms import destroy_and_undefine_all
+from CimTest.ReturnCodes import PASS, FAIL, SKIP
+from CimTest.Globals import logger, CIM_USER, CIM_PASS, CIM_NS
+from XenKvmLib.const import do_main, get_provider_version
+
+SHAREMODE = 3
+REDIRECTION_SER_TYPE = 3
+CRS_MAX_SAP_REV = 724
+libvirtcim_hr_crs_changes = 688
+
+sup_types = ['KVM']
+
+expr_values = {
+    "invalid_ccname"         : {'rc'   : pywbem.CIM_ERR_NOT_FOUND,
+                                'desc' : "No such instance (CreationClassName)" },
+    "invalid_sccname"        : {'rc'   : pywbem.CIM_ERR_NOT_FOUND,
+                                'desc' : "No such instance (SystemCreationClassName)" },
+    "invalid_name"           : {'rc'   : pywbem.CIM_ERR_NOT_FOUND,
+                                'desc' : "No such instance (Name)" },
+    "invalid_nameport"       : {'rc'   : pywbem.CIM_ERR_FAILED,
+                                'desc' : " Unable to determine console port for guest" },
+    "invalid_sysname"        : {'rc'   : pywbem.CIM_ERR_NOT_FOUND,
+                                'desc' : "No such instance (SystemName)" },
+    "invalid_sysval"        : {'rc'   : pywbem.CIM_ERR_NOT_FOUND,
+                                'desc' : "No such instance" }
+              }
+
+test_dom = "demo1"
+test_vcpus = 1
+
+def try_invalid_gi(i, field1, field2):
+    j = 0
+    keys = {}
+    temp = name_val[i]
+    name_val[i] = field1
+    for j in range(len(name_val)/2):
+        k = j * 2
+        keys[name_val[k]] = name_val[k+1]
+
+    ret_value = try_getinstance(conn, classname, keys, field_name=field1,
+                                expr_values=expr_values[field2], bug_no="")
+    if ret_value != PASS:
+        logger.error(" -------------- FAILED %s ----------- : " % field1)
+    name_val[i] = temp
+    return ret_value
+
+@do_main(sup_types)
+def main():
+    options = main.options
+    virt = main.options.virt
+    server = main.options.ip
+
+   # This check is required for libivirt-cim providers which do not have
+   # CRS changes in it and the CRS provider is available with revision >= 688.
+    curr_cim_rev, changeset = get_provider_version(virt, server)
+    if curr_cim_rev  < libvirtcim_hr_crs_changes:
+        logger.info("ConsoleRedirectionService provider not supported, "
+                    "hence skipping the test ....")
+        return SKIP
+
+    name = "%s:%s" % ("1", "1")
+    status = PASS
+
+    # Getting the VS list and deleting the test_dom if it already exists.
+    destroy_and_undefine_all(options.ip)
+    vsxml = get_class(options.virt)(test_dom, vcpus=test_vcpus)
+    vsxml.define(options.ip)
+    ret = vsxml.start(options.ip)
+    if not ret:
+        logger.error("Failed to Create the dom: %s", test_dom)
+        return FAIL
+    global conn
+    conn = assoc.myWBEMConnection('http://%s' % options.ip, (CIM_USER, CIM_PASS), CIM_NS)
+
+    global name_val
+    global classname
+    classname = get_typed_class(options.virt, 'KVMRedirectionSAP')
+    name_val = [
+               'CreationClassName',       classname,
+               'SystemCreationClassName', get_typed_class(options.virt, 'ComputerSystem'),
+               'Name',                    name,
+               'SystemName',              test_dom,
+               ]
+
+    tc_scen = { 
+                'INVALID_cc_Keyname'            : 'invalid_ccname',
+                'INVALID_cc_Keyvalue'           : 'invalid_ccname',
+                'INVALID_scc_Keyname'           : 'invalid_sccname',
+                'INVALID_scc_Keyvalue'          : 'invalid_sccname',
+                'INVALID_yname_Keyname'         : 'invalid_name',
+                'INVALID_yname_port_Keyvalue'   : 'invalid_nameport',
+                'INVALID_zsysname_Keyname'      : 'invalid_sysname',
+                'INVALID_zsysname_Keyvalue'     : 'invalid_sysval',
+              }
+
+    i = 0
+    for field1, field2 in sorted(tc_scen.items()):
+        retval = try_invalid_gi(i, field1, field2)
+        if retval != PASS:
+            status = retval
+        i = i + 1
+
+    vsxml.destroy(options.ip)
+    vsxml.undefine(options.ip)
+    return status
+
+if __name__ == "__main__":
+    sys.exit(main())
+
diff -r 70ecd9e8867c -r 2b2bb6f1b2a9 suites/libvirt-cim/lib/XenKvmLib/vxml.py
--- a/suites/libvirt-cim/lib/XenKvmLib/vxml.py	Mon Dec 01 22:15:38 2008 -0800
+++ b/suites/libvirt-cim/lib/XenKvmLib/vxml.py	Tue Dec 02 22:52:49 2008 -0800
@@ -710,6 +710,8 @@
         devices = self.get_node('/domain/devices')
 
         self.add_sub_node(devices, 'emulator', emu)
+        self.add_sub_node(devices, 'graphics', type='vnc', port='5900',
+                          keymap='en-us')
         disk = self.add_sub_node(devices, 'disk', type='file', device='disk')
         self.add_sub_node(disk, 'source', file=disk_img)
         self.add_sub_node(disk, 'target', dev=disk_dev)
