# HG changeset patch
# User Deepti B. Kalakeri <deeptik(a)linux.vnet.ibm.com>
# Date 1232018404 28800
# Node ID cc74023eeaf78970482e0a7a0c4c37a7ff997530
# Parent 43bf01b82ce9f627af1b5db55922b0584cd0e3b4
[TEST] Adding new tc to verify KVMRedirectionSAP.
Tested with KVM/Xen on current sources and KVM with F9 rpm.
Signed-off-by: Deepti B. Kalakeri <deeptik(a)linux.vnet.ibm.com>
diff -r 43bf01b82ce9 -r cc74023eeaf7
suites/libvirt-cim/cimtest/KVMRedirectionSAP/01_enum_KVMredSAP.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/suites/libvirt-cim/cimtest/KVMRedirectionSAP/01_enum_KVMredSAP.py Thu Jan 15
03:20:04 2009 -0800
@@ -0,0 +1,166 @@
+#!/usr/bin/python
+#
+# Copyright 2008 IBM Corp.
+#
+# Authors:
+# Deepti B. Kalakeri <dkalaker(a)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
+#
+# This test case is used to verify the KVMRedirectionSAP properties in detail.
+# This test case verifies the following:
+#
+# When the domain is defined:
+# KVMRedirectionSAP.Enabled = 3 and
+# KVMRedirectionSAP.[ElementName, Name] = -1:-1
+#
+# When the defined domain is started:
+# KVMRedirectionSAP.Enabled = 6 and
+# KVMRedirectionSAP.[ElementName, Name] = port used in the xml:0
+#
+# Date : 15-01-2009
+#
+
+import sys
+from XenKvmLib.vxml import get_class
+from XenKvmLib.classes import get_typed_class
+from XenKvmLib.const import do_main, get_provider_version
+from XenKvmLib.enumclass import EnumInstances
+from CimTest.Globals import logger, CIM_ERROR_ENUMERATE
+from CimTest.ReturnCodes import PASS, FAIL, SKIP
+from XenKvmLib.const import KVMRedSAP_proto, CIM_SAP_AVAILABLE_STATE, \
+ CIM_SAP_INACTIVE_STATE
+
+sup_types = ['Xen', 'KVM']
+libvirtcim_redSAP_changes = 716
+test_dom = 'test_redsap_dom'
+
+def enum_redsap(server, virt, classname):
+ redsap_insts = { }
+ status = FAIL
+
+ try:
+ redsap_list = EnumInstances(server, classname)
+ for redsap in redsap_list:
+ guest = redsap.SystemName
+ if guest == test_dom:
+ if redsap.Classname not in redsap_insts.keys():
+ redsap_insts[redsap.Classname] = redsap
+ status = PASS
+ else:
+ raise Exception("Got more than one record for: %s" \
+ % test_dom)
+ except Exception, details:
+ logger.error(CIM_ERROR_ENUMERATE, classname)
+ logger.error("Exception details: %s", details)
+ return status, redsap_insts
+
+
+def verify_redsap_values(val_list, redsap_inst, classname):
+ try:
+ for key in val_list.keys():
+ redsap = redsap_inst[classname]
+ ret_val = eval('redsap.' + key)
+ if ret_val != val_list[key]:
+ raise Exception("'%s' Value Mismatch, Expected %s, Got
%s" \
+ % (key, val_list[key], ret_val))
+ except Exception, details:
+ logger.error("Exception details: %s", details)
+ return FAIL
+
+ return PASS
+
+@do_main(sup_types)
+def main():
+ virt = main.options.virt
+ server = main.options.ip
+
+ cname = 'KVMRedirectionSAP'
+ classname = get_typed_class(virt, cname)
+
+ # This check is required for libivirt-cim providers which do not have
+ # REDSAP changes in it and the REDSAP provider is available with
+ # revision >= 716.
+ curr_cim_rev, changeset = get_provider_version(virt, server)
+ if curr_cim_rev < libvirtcim_redSAP_changes:
+ logger.info("'%s' provider not supported, hence skipping the tc
....",
+ classname)
+ return SKIP
+
+ vsxml = None
+ action_start = False
+
+ try:
+ virt_xml = get_class(virt)
+ vsxml = virt_xml(test_dom)
+ ret = vsxml.cim_define(server)
+ if not ret:
+ raise Exception("Failed to define the dom: %s" % test_dom)
+
+ status, redsap_inst = enum_redsap(server, virt, classname)
+ if status != PASS:
+ raise Exception("Failed to get information on the defined dom:%s"
\
+ % test_dom)
+
+ # val_list that will be used for comparing with enum of
+ # KVMRedirectionSAP values
+ sccn = get_typed_class(virt, 'ComputerSystem')
+ g_type = vsxml.xml_get_graphics_type()
+ val_list = {
+ 'SystemCreationClassName' : sccn,
+ 'SystemName' : test_dom,
+ 'CreationClassName' : classname,
+ 'KVMProtocol' : KVMRedSAP_proto[g_type],
+ 'EnabledState' : CIM_SAP_INACTIVE_STATE
+ }
+ val_list['ElementName'] = val_list['Name'] = "%s:%s" %
('-1', '-1')
+
+ status = verify_redsap_values(val_list, redsap_inst, classname)
+ if status != PASS:
+ raise Exception("Failed to verify information on the defined "\
+ "dom:%s" % test_dom)
+
+ status = vsxml.cim_start(server)
+ if not ret:
+ raise Exception("Failed to start the dom: %s" % test_dom)
+
+ status, redsap_inst = enum_redsap(server, virt, classname)
+ if status != PASS:
+ action_start = True
+ raise Exception("Failed to get information for running dom:%s" \
+ % test_dom)
+
+ lport = vsxml.xml_get_graphics_port()
+ val_list['ElementName'] = val_list['Name'] = "%s:%s" %
(lport, '0')
+ val_list['EnabledState'] = CIM_SAP_AVAILABLE_STATE
+
+ status = verify_redsap_values(val_list, redsap_inst, classname)
+ if status != PASS:
+ action_start = True
+ raise Exception("Failed to verify information for running dom:%s"
\
+ % test_dom)
+
+ except Exception, detail:
+ logger.error("Exception: %s", detail)
+ status = FAIL
+
+ if action_start == True:
+ vsxml.cim_destroy(server)
+
+ vsxml.undefine(server)
+ return status
+
+if __name__ == "__main__":
+ sys.exit(main())
diff -r 43bf01b82ce9 -r cc74023eeaf7 suites/libvirt-cim/lib/XenKvmLib/const.py
--- a/suites/libvirt-cim/lib/XenKvmLib/const.py Mon Jan 12 08:22:47 2009 -0800
+++ b/suites/libvirt-cim/lib/XenKvmLib/const.py Thu Jan 15 03:20:04 2009 -0800
@@ -46,6 +46,15 @@
# Default TimeoutPeriod param for CS.RequestedStateChange()
TIME = "00000000000000.000000:000"
+
+#KVMRedirectionSAP protocol values
+KVMRedSAP_proto = { 'raw' : 2, 'rdp' : 3, 'vnc' : 4 }
+
+# CIM values for KVMRedirectionSAP.EnabledState
+CIM_SAP_ACTIVE_STATE = 2
+CIM_SAP_INACTIVE_STATE = 3
+CIM_SAP_AVAILABLE_STATE = 6
+
# vxml.NetXML
default_bridge_name = 'testbridge'
diff -r 43bf01b82ce9 -r cc74023eeaf7 suites/libvirt-cim/lib/XenKvmLib/vxml.py
--- a/suites/libvirt-cim/lib/XenKvmLib/vxml.py Mon Jan 12 08:22:47 2009 -0800
+++ b/suites/libvirt-cim/lib/XenKvmLib/vxml.py Thu Jan 15 03:20:04 2009 -0800
@@ -413,6 +413,15 @@
'/domain/devices/interface/source/@network')
return networkStr
+ def xml_get_graphics_type(self):
+ graphicstypeStr = self.get_value_xpath(
+ '/domain/devices/graphics/@type')
+ return graphicstypeStr
+
+ def xml_get_graphics_port(self):
+ graphicsportStr = self.get_value_xpath(
+ '/domain/devices/graphics/@port')
+ return graphicsportStr
def dumpxml(self, ip):
cmd = 'virsh -c %s dumpxml %s' % (self.vuri, self.dname)