# HG changeset patch # User root@1089 # Date 1186428502 14400 # Node ID df5e06d76f910db95d4495cb2c1ed3a9949c33c1 # Parent 3ccb96bfe2066d9c8d7f30bca3b4ce70c1194d23 Basis for extrinsic tests using xm-test Signed-off-by: Luke Szymanski diff -r 3ccb96bfe206 -r df5e06d76f91 Makefile.am --- a/Makefile.am Thu Aug 02 17:54:59 2007 -0600 +++ b/Makefile.am Mon Aug 06 15:28:22 2007 -0400 @@ -19,6 +19,7 @@ # Contributors: Tokunbo Adeshiyan # Jim Fehlig # Rajagopalan Subrahmanian +# Luke Szymanski # Description: # Automake input file for the CMPI Xen CIM provider. # ============================================================================= @@ -269,6 +270,9 @@ preuninstall: preuninstall: sh provider-register.sh -d -t @CIMSERVER@ -r $(REGS) -m $(MOFS) +runtest: + cd test && ./setup-test.sh && ./run-test.sh @XMTESTDIR@ + # Add the schema files to the distribution file list pkgdata_DATA=$(MOFS) $(REGS) pkgdata_SCRIPTS=provider-register.sh diff -r 3ccb96bfe206 -r df5e06d76f91 configure.ac --- a/configure.ac Thu Aug 02 17:54:59 2007 -0600 +++ b/configure.ac Mon Aug 06 15:28:22 2007 -0400 @@ -18,6 +18,7 @@ # Author: Dr. Gareth S. Bestor # Contributors: Viktor Mihajlovski # Jim Fehlig +# Luke Szymanski # Summary: Autoconf input file for CMPI Xen Provider # Description: # This file is processed by autoconf to generate the configure script for @@ -165,6 +166,7 @@ AC_ARG_VAR([CIMSERVER],[the target CIM s AC_ARG_VAR([CIMSERVER],[the target CIM server (pegasus|sfcb|openwbem|sniacimom).]) AC_ARG_VAR([PROVIDERDIR],[the directory where the CMPI providers will be installed.]) AC_ARG_VAR([TESTSUITEDIR],[the directory where the SBLIM testsuite is installed.]) +AC_ARG_VAR([XMTESTDIR],[the directory where xm-test is installed.]) # Autogenerate the autoconf header file to store build settings AC_CONFIG_HEADER([config.h]) @@ -217,6 +219,7 @@ echo "The following configuration option echo "The following configuration options have been selected:" echo " CIMSERVER: " $CIMSERVER echo " PROVIDERDIR: " $PROVIDERDIR +echo " XMTESTDIR: " $XMTESTDIR echo " TESTSUITE_SUPPORT: " $TESTSUITE_SUPPORT if test x"$TESTSUITEDIR" != x; then echo " TESTSUITEDIR: " $TESTSUITEDIR diff -r 3ccb96bfe206 -r df5e06d76f91 test/README --- a/test/README Thu Aug 02 17:54:59 2007 -0600 +++ b/test/README Mon Aug 06 15:28:22 2007 -0400 @@ -19,6 +19,14 @@ references references referenceNames +The basis for extrinsic tests exists as well. A VM is created based on the +ramdisk and kernel provided by xm-test. If xm-test has not been run, the +location is requested so that it can be created. This process can take some +time, but a user may opt out and simply run the tests outlined in the paragraph +above. If a user chooses to go with the xm-test set up, the basis for exstrinsic +tests is in place. At this point the VM is simply created, and destroyed with a +state change in between, but more intricate tests will follow. + 2. CONFIGURING You must have sblim-wbemcli and sblim-testsuite working properly in order @@ -27,6 +35,9 @@ Location of installed sblim-testsuite ca Location of installed sblim-testsuite can be specified using TESTSUITEDIR environment variable. If not specified, /usr/share/sblim-testsuite and /usr/local/share/sblim-testsuite will be tried. + +Should you wish to run the extrinsic tests and have not run xm-test, +run the configure script with XMTESTDIR=xm-test-location as an argument. 3. BUILDING @@ -42,6 +53,6 @@ on provider type) and it will automatica 5. RUNNING -Run the run-test.sh script. Instance provider test results are placed in -the file 'instance_provider_results'. Association provider test results -are placed in 'association_provider_results'. +In the main directoy (one up from this one), type make runtest. Instance +provider test results are placed in the file 'test/instance_provider_results'. +Association provider test results are placed in 'test/association_provider_results'. diff -r 3ccb96bfe206 -r df5e06d76f91 test/extrinsics_setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/extrinsics_setup.py Mon Aug 06 15:28:22 2007 -0400 @@ -0,0 +1,165 @@ +#!/usr/bin/python +# Author: Jim Fehlig +# Contributors: Luke Szymanski +# +# Description: Set up VM and exercise the extrinsic provider methods +# +# Copyright (C) 2007 Novell Corporation +# Copyright (C) 2007 Unisys Corporation +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser 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 +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# + +import sys +import pywbem +import time +import os +import string + +# Frequently used functions +def EnumerateCSInstnaces(): + print ' Enumerating instances of Xen_ComputerSystem:' + inst_names = conn.EnumerateInstanceNames('Xen_ComputerSystem') + for n in inst_names: + inst = conn.GetInstance(n, LocalOnly=False) + print ' Domain %s: EnabledState %s' % (inst['Name'],inst['EnabledState']) + + +# Set up ramdisk and kernel. +# See if /tmp/xm-test.conf exists. If so, xm-test has already been run +# and therefore, there is no need to run make on the ramdisk; otherwise, run it +if (os.system ('ls /tmp/xm-test.conf 2> /dev/null 1> /dev/null') != 0): + # Build ramdisk, use XMTESTDIR passed from run script + print '...Building a RAMDISK...' + xmtestdir = sys.argv[1] + os.chdir(xmtestdir) + os.system('./autogen') + os.system('./configure') + os.system('make -j `cat /proc/cpuinfo | grep processor | wc -l`') + os.chdir('tests/create') + + # Sanity check done by xm-test; also, this creates xm-test.conf + os.system('TEST_VERBOSE=1 make check TESTS=01_create_basic_pos.test') + os.chdir('../..') + time.sleep(5) + +print '...Setting up VM...' +# Extract info from xm-test.conf file +command = "grep ramdisk /tmp/xm-test.conf | sed 's/^.* = \"//' | sed s'/\"//' > temp" +os.system(command) +file = open("temp","r+") +ramdisk_location = file.read() +ramdisk_location = ramdisk_location.replace('\n','') + +command = "grep kernel /tmp/xm-test.conf | sed 's/^.* = \"//' | sed s'/\"$//' >> temp" +os.system(command) +kernel_location = file.read() +kernel_location = kernel_location.replace('\n','') +file.close() +os.system('rm temp') + +# Connect to cimom +user='root' +pw='password' + +conn = pywbem.WBEMConnection('http://localhost', (user,pw)) + +# Get instance of Virtual System Management Service +print 'Looking for Virtual System Management Service...' +vsms = conn.EnumerateInstanceNames("Xen_VirtualSystemManagementService") +print 'Got Virtual System Management Service: %s' % str(vsms[0]) + +# Create virtual system settings for new VM +vssd = pywbem.CIMInstance('Xen_ComputerSystemSettingData', + {'VirtualSystemIdentifier':'xen-cim-test-12345', + 'VirtualSystemType':'xen-3.0-x86', + 'Kernel':kernel_location, + 'RAMDisk':'/boot/initrd-xen', + 'UUID':'20904d23-8a89-1d63-134c-d2606f2fcc47', + 'KernelOptions':'Term=xterm', + 'OnPoweroff':pywbem.Uint16(0), + 'OnReboot':pywbem.Uint16(1), + 'OnCrash':pywbem.Uint16(2)}) + +proc_rasd = pywbem.CIMInstance('Xen_ProcessorSettingData', + {'ResourceType':pywbem.Uint16(3), + 'VirtualQuantity':pywbem.Uint64(2), + 'AllocationUnits':'Cores', + 'Weight':pywbem.Uint32(512), + 'Limit':pywbem.Uint64(100)}) + +mem_rasd = pywbem.CIMInstance('Xen_MemorySettingData', + {'ResourceType':pywbem.Uint16(4), + 'VirtualQuantity':pywbem.Uint64(512), + 'AllocationUnits':'MegaBytes'}) + +ramdisk_location = "file:" + ramdisk_location + ",xvda,w" +disk_rasd = pywbem.CIMInstance('Xen_DiskSettingData', + {'ResourceType':pywbem.Uint16(19), + 'DiskConfigInfo':ramdisk_location}) + +nic_rasd = pywbem.CIMInstance('Xen_NetworkPortSettingData', + {'ResourceType':pywbem.Uint16(10), + 'NICConfigInfo':'mac=00:16:3e:39:7a:f7'}) + +con_rasd = pywbem.CIMInstance('Xen_ConsoleSettingData', + {'ResourceType':pywbem.Uint16(24), + 'Protocol':pywbem.Uint16(1), + 'ConsoleConfigInfo':'vncunused=1'}) + +rasds = [proc_rasd, mem_rasd, disk_rasd, nic_rasd, con_rasd] + +in_params = {'SystemSettings': vssd, 'ResourceSettings': rasds} + + +# Invoke DefineSystem on Virtual System Management Serive to define a new VM, +# providing the new VM settings and its resource settings. +new_vm = None +try: + print 'Calling DefineSystem to create a new VM ...' + (rval, out_params) = conn.InvokeMethod('DefineSystem', vsms[0], **in_params) + print 'Return Value of DefineSystem: %s' % rval + print 'Output = %s' % out_params + new_vm = out_params['ResultingSystem'] + +except pywbem.CIMError, arg: + print 'Caught exception when calling InvokeMethod' + if arg[0] != pywbem.CIM_ERR_NOT_SUPPORTED: + print 'InvokeMethod(instancename): %s' % arg[1] + sys.exit(1) + +except ValueError, e: + pass + +# Get instances of Xen_ComputerSystem +EnumerateCSInstnaces() + +print 'Activating newly defined VM ...' +try: + # state 2 = enabled(running) + (rval, out_params) = conn.InvokeMethod('RequestStateChange', new_vm, RequestedState='2') +except Exception, e: + sys.stderr.write('Exception caught in starting VM: %s\n' % e) + sys.exit(1) + if rval == 0: + print 'Successfully activated new vm' + else: + sys.stderr.write('Unable to start VM, return code: %s\n' % rval) + sys.exit(1) + +time.sleep(5) + +EnumerateCSInstnaces() + diff -r 3ccb96bfe206 -r df5e06d76f91 test/extrinsics_shutdown.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/extrinsics_shutdown.py Mon Aug 06 15:28:22 2007 -0400 @@ -0,0 +1,75 @@ +#!/usr/bin/python +# Author: Jim Fehlig +# Contributors: Luke Szymanski +# +# Description: Shutdown vm used in extrinsic test +# +# Copyright (C) 2007 Novell Corporation +# Copyright (C) 2007 Unisys Corporation +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser 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 +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# + +import sys +import pywbem +import time +import os +import string + +# Frequently used functions +def EnumerateCSInstnaces(): + print ' Enumerating instances of Xen_ComputerSystem:' + inst_names = conn.EnumerateInstanceNames('Xen_ComputerSystem') + for n in inst_names: + inst = conn.GetInstance(n, LocalOnly=False) + print ' Domain %s: EnabledState %s' % (inst['Name'],inst['EnabledState']) + if inst['Name'] == 'xen-cim-test-12345': + new_vm = inst + +# Connect to cimom +user='root' +pw='password' + +conn = pywbem.WBEMConnection('http://localhost', (user,pw)) + +# Find vm created by this test +inst_names = conn.EnumerateInstanceNames('Xen_ComputerSystem') +for n in inst_names: + inst = conn.GetInstance(n, LocalOnly=False) + if inst['Name'] == 'xen-cim-test-12345': + new_vm = n + +print 'Stopping newly defined VM ...' +try: + # state 3 = destroy + (rval, out_params) = conn.InvokeMethod('RequestStateChange', new_vm, RequestedState='3') +except Exception, e: + sys.stderr.write('Exception caught in stopping VM: %s\n' % e) + sys.exit(1) + if rval == 0: + print 'Successfully activated new vm' + else: + sys.stderr.write('Unable to start VM, return code: %s\n' % rval) + sys.exit(1) + +time.sleep(5) + +EnumerateCSInstnaces() + +print 'Deleting VM ...' +os.system('xm delete xen-cim-test-12345') + +EnumerateCSInstnaces() + diff -r 3ccb96bfe206 -r df5e06d76f91 test/run-test.sh --- a/test/run-test.sh Thu Aug 02 17:54:59 2007 -0600 +++ b/test/run-test.sh Mon Aug 06 15:28:22 2007 -0400 @@ -1,8 +1,8 @@ #! /bin/bash # Author: Luke Szymanski # Contributors: -# Description: Run sblim-test suite with Xen CIM providers -# +# Description: Run sblim-test suite with Xen CIM providers. +# Set up vm if possible. # Copyright (C) 2007 Unisys Corporation # # This library is free software; you can redistribute it and/or @@ -20,10 +20,41 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # +INTRINSIC_ONLY=0 + +# xm-test not run and XMTESTDIR variable not passed in +if test ! -e /tmp/xm-test.conf -a x"$1" == x; then + echo '' + echo 'This test uses the ramdisk from xm-test.' + echo 'You have not run xm-test.' + echo 'You have not specified the location for xm-test.' + echo 'If you wish to specify it, go to the main directory' + echo ' ./configure XMTESTDIR=location' + echo ' make runtest' + echo 'Creating the ramdisk may take around 20 minutes.' + echo 'You can still run intrinsic tests without this setup.' + echo 'Do you wish to start over and define XMTESTDIR?' + read answer + answer=`echo $answer | tr A-Z a-z` + answer=`echo $answer | awk '{printf substr($0, 1, 1)}'` + if [ $answer == y ]; then + exit 1 + else + INTRINSIC_ONLY=1 + fi +fi + +# Set up extrinsics +echo '-----------------------------------------------------------' +if [ $INTRINSIC_ONLY -eq 0 ]; then + python extrinsics_setup.py $1 +fi + cp instance_provider_list sblim-test-suite/instance_provider_list CMPI_TEST_PATH=`pwd` cd sblim-test-suite +echo '-----------------------------------------------------------' echo 'Starting instance provider tests ...' cat instance_provider_list | \ @@ -50,3 +81,10 @@ done echo 'Done. Results are in file association_provider_results.' rm association_provider_list + +# Take down VM +echo '-----------------------------------------------------------' +cd $CMPI_TEST_PATH +if [ $INTRINSIC_ONLY -eq 0 ]; then + python extrinsics_shutdown.py +fi