[Libvirt-cim] [PATCH] [TEST] #3 Adding new tc to verify KVMRedirectionSAP

Deepti B. Kalakeri deeptik at linux.vnet.ibm.com
Tue Jan 27 08:39:38 UTC 2009


# HG changeset patch
# User Deepti B. Kalakeri <deeptik at linux.vnet.ibm.com>
# Date 1233045430 28800
# Node ID 4ad705c27d10d7be718ee92a9d0bdfb60563a4b5
# Parent  a9dd0a50858aa1c382278393d863b213c8c5b565
[TEST] #3 Adding new tc to verify KVMRedirectionSAP.

Changes:
--------

>From Patch 2 to 3:
------------------
1) Changed the import stmt for randrange.
2) Changes to verify KVMRedirectionSAP for defined guest in case of LXC.
3) Included g.mof() in the RASD list returned by default_vssd_rasd_str().

Updates from patch 1 to 2:
--------------------------
Added GRASD support in the call to DefineSytem().
Modified vxml.py , vsms.py and const.py to support GRASD.

Tested with KVM/Xen/LXC on current sources and KVM with F9 rpm.
This tc will fail for Xen with current sources.

Signed-off-by: Deepti B. Kalakeri <deeptik at linux.vnet.ibm.com>

diff -r a9dd0a50858a -r 4ad705c27d10 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	Tue Jan 27 00:37:10 2009 -0800
@@ -0,0 +1,178 @@
+#!/usr/bin/python
+#
+# Copyright 2008 IBM Corp.
+#
+# Authors:
+#    Deepti B. Kalakeri <dkalaker at 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] = port used in the GRASD:-1
+#
+# When the defined domain is started:
+# KVMRedirectionSAP.Enabled = 6 and 
+# KVMRedirectionSAP.[ElementName, Name] = port used in the GRASD:0
+#
+#                                               Date : 15-01-2009
+#
+
+import sys
+from random import randrange
+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', 'LXC']
+libvirtcim_redSAP_changes = 716
+test_dom = 'test_kvmredsap_dom'
+
+def enum_redsap(server, virt, classname):
+    redsap_insts = { }
+    status = FAIL
+
+    try:
+        redsap_list = EnumInstances(server, classname)
+        for redsap in redsap_list:
+            if redsap.SystemName == 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
+
+ at 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)
+        lport = randrange(5900, 5999)
+        vsxml = virt_xml(test_dom, port_num=str(lport))
+
+        # Define the VS, and verify the KVMRedirectionSAP values.
+        ret = vsxml.cim_define(server)
+        if not ret:
+            raise Exception("Failed to define the dom: %s" % test_dom)
+
+        # val_list that will be used for comparing with enum of 
+        # KVMRedirectionSAP values
+        sccn = get_typed_class(virt, 'ComputerSystem')
+        val_list  = {
+                       'SystemCreationClassName' : sccn, 
+                       'SystemName'              : test_dom,
+                       'CreationClassName'       : classname,
+                       'KVMProtocol'             : KVMRedSAP_proto["vnc"],
+                       'EnabledState'            : CIM_SAP_INACTIVE_STATE 
+                    }
+        val_list['ElementName'] = val_list['Name'] = "%s:-1" % lport 
+
+        status, redsap_inst = enum_redsap(server, virt, classname)
+        if status != PASS:
+            raise Exception("Failed to get information on the defined dom:%s" \
+                             % test_dom)
+
+        status = verify_redsap_values(val_list, redsap_inst, classname)
+        if status != PASS:
+            raise Exception("Failed to verify information for the defined "\
+                            "dom:%s" % test_dom)
+
+        # For now verifying KVMRedirectoinSAP only for a defined LXC guest.
+        # Once complete Graphics support for LXC is in, we need to verify the
+        # KVMRedirectionSAP for a running guest.
+        if virt == 'LXC':
+            logger.error("DEBUG")
+            vsxml.undefine(server)
+            return status
+
+        # start the guest and verify the KVMRedirectionSAP values
+        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)
+
+        val_list['ElementName'] = val_list['Name'] = "%s:0" % lport
+        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 a9dd0a50858a -r 4ad705c27d10 suites/libvirt-cim/lib/XenKvmLib/const.py
--- a/suites/libvirt-cim/lib/XenKvmLib/const.py	Thu Jan 22 08:55:09 2009 -0800
+++ b/suites/libvirt-cim/lib/XenKvmLib/const.py	Tue Jan 27 00:37:10 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 a9dd0a50858a -r 4ad705c27d10 suites/libvirt-cim/lib/XenKvmLib/vsms.py
--- a/suites/libvirt-cim/lib/XenKvmLib/vsms.py	Thu Jan 22 08:55:09 2009 -0800
+++ b/suites/libvirt-cim/lib/XenKvmLib/vsms.py	Tue Jan 27 00:37:10 2009 -0800
@@ -33,6 +33,7 @@
 RASD_TYPE_NET_ETHER = 10
 RASD_TYPE_NET_OTHER = 11
 RASD_TYPE_DISK = 17
+RASD_TYPE_GRAPHICS = 24
 
 VSSD_RECOVERY_NONE     = 2
 VSSD_RECOVERY_RESTART  = 3
@@ -232,6 +233,36 @@
 def get_masd_class(virt):
     pass
 
+
+class CIM_GraphicsResourceAllocationSettingData(CIMClassMOF):
+    def __init__(self, name, res_sub_type="vnc", ip="127.0.0.1", 
+                 lport='-1', keymap="en-us"):
+        self.InstanceID = '%s/graphics' %name
+        self.ResourceType = RASD_TYPE_GRAPHICS
+
+        if res_sub_type != None: 
+            self.ResourceSubType = res_sub_type
+
+        if ip != None and lport != None:
+           self.Address = '%s:%s' % (ip, lport)
+
+        if keymap != None:
+           self.KeyMap = keymap
+  
+
+class Xen_GraphicsResourceAllocationSettingData(CIM_GraphicsResourceAllocationSettingData):
+    pass
+
+class KVM_GraphicsResourceAllocationSettingData(CIM_GraphicsResourceAllocationSettingData):
+    pass
+
+class LXC_GraphicsResourceAllocationSettingData(CIM_GraphicsResourceAllocationSettingData):
+    pass
+
+ at eval_cls('GraphicsResourceAllocationSettingData')
+def get_gasd_class(virt):
+    pass
+
 def default_vssd_rasd_str(dom_name='test_domain', 
                           disk_dev='xvda',
                           disk_source=const.Xen_disk_path,
@@ -272,9 +303,12 @@
                    mallocunits=malloc_units,
                    name=dom_name)
 
+    class_gasd = get_gasd_class(virt)
+    g = class_gasd(name=dom_name)
+
     # LXC only takes disk and memory device for now.
     if virt == 'LXC':
-        return vssd, [d.mof(), m.mof()]
+        return vssd, [d.mof(), m.mof(), g.mof()]
     
     class_nasd = get_nasd_class(virt)
     if net_mac != const.Xen_default_mac:
@@ -293,5 +327,5 @@
     p = class_pasd(vcpu=proc_vcpu,
                    name=dom_name)
 
-    return vssd, [d.mof(), n.mof(), p.mof(), m.mof()]
+    return vssd, [d.mof(), n.mof(), p.mof(), m.mof(), g.mof()]
 
diff -r a9dd0a50858a -r 4ad705c27d10 suites/libvirt-cim/lib/XenKvmLib/vxml.py
--- a/suites/libvirt-cim/lib/XenKvmLib/vxml.py	Thu Jan 22 08:55:09 2009 -0800
+++ b/suites/libvirt-cim/lib/XenKvmLib/vxml.py	Tue Jan 27 00:37:10 2009 -0800
@@ -413,7 +413,6 @@
                 '/domain/devices/interface/source/@network')
         return networkStr
 
- 
     def dumpxml(self, ip):
         cmd = 'virsh -c %s dumpxml %s' % (self.vuri, self.dname)
         s, o = utils.run_remote(ip, cmd)
@@ -467,7 +466,8 @@
 class VirtCIM:
     def __init__(self, virt, dom_name, disk_dev, disk_source,
                  net_type, net_name, net_mac, vcpus, mem,
-                 mem_allocunits, emu_type):
+                 mem_allocunits, emu_type, grstype, ip,
+                 port_num, kmap):
         self.virt = virt
         self.domain_name = dom_name
         self.err_rc = None
@@ -488,7 +488,9 @@
         self.masd = vsms.get_masd_class(virt)(megabytes=mem, 
                                               mallocunits=mem_allocunits,
                                               name=dom_name)
-
+        self.gasd = vsms.get_gasd_class(virt)(name=dom_name, 
+                                              res_sub_type=grstype, ip=ip,
+                                              lport=port_num, keymap=kmap)
 
     def cim_define(self, ip, ref_conf=None):
         service = vsms.get_vsms_class(self.virt)(ip)
@@ -506,6 +508,8 @@
                 pass
             else:
                 res_settings.append(str(self.nasd))
+        if self.gasd is not None:
+            res_settings.append(str(self.gasd))
 
         if ref_conf is None:
              ref_conf = ' '
@@ -657,6 +661,8 @@
                 self.dasd = rasd
             elif cn.find("NetResourceAllocationSettingData") >= 0:
                 self.nasd = rasd
+            elif cn.find("GraphicsResourceAllocationSettingData") >= 0:
+                self.gasd = rasd
 
     def verify_error_msg(self, exp_rc, exp_desc):
         try:
@@ -688,7 +694,8 @@
                        disk=const.Xen_default_disk_dev, 
                        ntype=const.default_net_type,
                        net_name=const.default_network_name,
-                       emu_type=None): 
+                       emu_type=None, grstype="vnc", address="127.0.0.1",
+                       port_num='-1', keymap="en-us"): 
         if not (os.path.exists(const.Xen_kernel_path) \
                 and os.path.exists(const.Xen_init_path)):
             logger.error('ERROR: Either the kernel image '
@@ -700,7 +707,7 @@
 
         VirtCIM.__init__(self, 'Xen', test_dom, disk, disk_file_path, 
                          ntype, net_name, mac, vcpus, mem, mem_allocunits, 
-                         emu_type)
+                         emu_type, grstype, address, port_num, keymap)
 
     def _os(self, os_kernel, os_initrd):
         os = self.get_node('/domain/os')
@@ -750,14 +757,16 @@
                        disk=const.KVM_default_disk_dev, 
                        ntype=const.default_net_type,
                        net_name=const.default_network_name,
-                       emu_type=None):
+                       emu_type=None, grstype="vnc", address="127.0.0.1",
+                       port_num='-1', keymap="en-us"):
         if not os.path.exists(disk_file_path):
             logger.error('Error: Disk image does not exist')
             sys.exit(1)
         VirtXML.__init__(self, 'kvm', test_dom, set_uuid(), mem, vcpus)
         VirtCIM.__init__(self, 'KVM', test_dom, disk, disk_file_path,
                          ntype, net_name, mac, vcpus, mem, 
-                         mem_allocunits, emu_type)
+                         mem_allocunits, emu_type, grstype, address, 
+                         port_num, keymap)
         self._os()
         self._devices(const.KVM_default_emulator, ntype,
                       disk_file_path, disk, mac, net_name)
@@ -802,14 +811,15 @@
                        disk=const.XenFV_default_disk_dev, 
                        ntype=const.default_net_type,
                        net_name=const.default_network_name,
-                       emu_type=None):
+                       emu_type=None, grstype="vnc", 
+                       address="127.0.0.1", port_num='-1', keymap="en-us"):
         if not os.path.exists(disk_file_path):
             logger.error('Error: Disk image does not exist')
             sys.exit(1)
         VirtXML.__init__(self, 'xenfv', test_dom, set_uuid(), mem, vcpus)
         VirtCIM.__init__(self, 'XenFV', test_dom, disk, disk_file_path,
                          ntype, net_name, mac, vcpus, mem, mem_allocunits, 
-                         emu_type)
+                         emu_type, grstype, address, port_num, keymap)
         self._features()
         self._os(const.XenFV_default_loader)
         self._devices(const.XenFV_default_emulator,
@@ -856,11 +866,13 @@
                        mac=const.LXC_default_mac,
                        ntype=const.default_net_type,
                        net_name=const.default_network_name,
-                       tty=const.LXC_default_tty):
+                       tty=const.LXC_default_tty, grstype="vnc",
+                       address="127.0.0.1", port_num='-1', keymap="en-us"):
         VirtXML.__init__(self, 'lxc', test_dom, set_uuid(), mem, vcpus)
         VirtCIM.__init__(self, 'LXC', test_dom, const.LXC_default_mp,
                          const.LXC_default_source, ntype, net_name, mac, vcpus,
-                         mem, const.default_mallocunits, None)
+                         mem, const.default_mallocunits, None, grstype, 
+                         address, port_num, keymap)
         self._os(const.LXC_init_path)
         self._devices(mac, ntype, net_name, const.LXC_default_tty)
         self.create_lxc_file(CIM_IP, const.LXC_init_path)




More information about the Libvirt-cim mailing list