os-cmpi-xen

changeset 141:be22f410b2a3

Basis for extrinsic tests using xm-test.

Signed-off-by: Luke Szymanski <Lukasz.Szymanski@unisys.com>
author Jim Fehlig <jfehlig@novell.com>
date Mon Aug 13 10:55:46 2007 -0600 (2007-08-13)
parents 93e1e1824ab0
children 57fe177533bc
files ChangeLog Makefile.am configure.ac test/README test/extrinsics_setup.py test/extrinsics_shutdown.py test/run-test.sh
line diff
     1.1 --- a/ChangeLog	Fri Aug 10 15:32:54 2007 -0600
     1.2 +++ b/ChangeLog	Mon Aug 13 10:55:46 2007 -0600
     1.3 @@ -1,3 +1,10 @@
     1.4 +-------------------------------------------------------------------
     1.5 +Mon Aug 13 10:51:25 MDT 2007 - jfehlig@novell.com
     1.6 +
     1.7 +         - Test suite integration with xm-test, which will provide
     1.8 +           a kernel/ramdisk for use by various automated tests.
     1.9 +           Provided by Luke Szymanski.
    1.10 +
    1.11  -------------------------------------------------------------------
    1.12  Fri Aug 10 15:30:22 MDT 2007 - jfehlig@novell.com
    1.13  
     2.1 --- a/Makefile.am	Fri Aug 10 15:32:54 2007 -0600
     2.2 +++ b/Makefile.am	Mon Aug 13 10:55:46 2007 -0600
     2.3 @@ -19,6 +19,7 @@
     2.4  # Contributors: Tokunbo Adeshiyan <tokunbo@us.ibm.com>
     2.5  #               Jim Fehlig <jfehlig@novell.com>
     2.6  #		Rajagopalan Subrahmanian <raj.subrahmanian@unisys.com>
     2.7 +#		Luke Szymanski <Lukasz.Szymanski@unisys.com>
     2.8  # Description:
     2.9  #    Automake input file for the CMPI Xen CIM provider.
    2.10  # =============================================================================
    2.11 @@ -269,6 +270,9 @@ postinstall:
    2.12  preuninstall:
    2.13  	sh provider-register.sh -d -t @CIMSERVER@ -r $(REGS) -m $(MOFS)
    2.14  
    2.15 +runtest:
    2.16 +	cd test && ./setup-test.sh && ./run-test.sh @XMTESTDIR@
    2.17 +
    2.18  # Add the schema files to the distribution file list
    2.19  pkgdata_DATA=$(MOFS) $(REGS)
    2.20  pkgdata_SCRIPTS=provider-register.sh
     3.1 --- a/configure.ac	Fri Aug 10 15:32:54 2007 -0600
     3.2 +++ b/configure.ac	Mon Aug 13 10:55:46 2007 -0600
     3.3 @@ -18,6 +18,7 @@
     3.4  # Author:       Dr. Gareth S. Bestor <bestor@us.ibm.com>
     3.5  # Contributors: Viktor Mihajlovski <mihajlov@de.ibm.com>
     3.6  #               Jim Fehlig <jfehlig@novell.com>
     3.7 +#		Luke Szymanski <Lukasz.Szymanski@unisys.com>
     3.8  # Summary:      Autoconf input file for CMPI Xen Provider
     3.9  # Description:
    3.10  #    This file is processed by autoconf to generate the configure script for
    3.11 @@ -165,6 +166,7 @@ CPPFLAGS="$CPPFLAGS -DSBLIM_DEBUG"
    3.12  AC_ARG_VAR([CIMSERVER],[the target CIM server (pegasus|sfcb|openwbem|sniacimom).])
    3.13  AC_ARG_VAR([PROVIDERDIR],[the directory where the CMPI providers will be installed.])
    3.14  AC_ARG_VAR([TESTSUITEDIR],[the directory where the SBLIM testsuite is installed.])
    3.15 +AC_ARG_VAR([XMTESTDIR],[the directory where xm-test is installed.])
    3.16  
    3.17  # Autogenerate the autoconf header file to store build settings
    3.18  AC_CONFIG_HEADER([config.h])
    3.19 @@ -217,6 +219,7 @@ echo ""
    3.20  echo "The following configuration options have been selected:"
    3.21  echo "   CIMSERVER: " $CIMSERVER
    3.22  echo "   PROVIDERDIR: " $PROVIDERDIR
    3.23 +echo "   XMTESTDIR: " $XMTESTDIR
    3.24  echo "   TESTSUITE_SUPPORT: " $TESTSUITE_SUPPORT
    3.25  if test x"$TESTSUITEDIR" != x; then
    3.26     echo "   TESTSUITEDIR: " $TESTSUITEDIR
     4.1 --- a/test/README	Fri Aug 10 15:32:54 2007 -0600
     4.2 +++ b/test/README	Mon Aug 13 10:55:46 2007 -0600
     4.3 @@ -19,6 +19,14 @@ associatorNames
     4.4  references
     4.5  referenceNames
     4.6  
     4.7 +The basis for extrinsic tests exists as well.  A VM is created based on the 
     4.8 +ramdisk and kernel provided by xm-test.  If xm-test has not been run, the
     4.9 +location is requested so that it can be created.  This process can take some
    4.10 +time, but a user may opt out and simply run the tests outlined in the paragraph 
    4.11 +above.  If a user chooses to go with the xm-test set up, the basis for exstrinsic
    4.12 +tests is in place.  At this point the VM is simply created, and destroyed with a 
    4.13 +state change in between, but more intricate tests will follow.
    4.14 +
    4.15  2.  CONFIGURING
    4.16  
    4.17  You must have sblim-wbemcli and sblim-testsuite working properly in order
    4.18 @@ -28,6 +36,9 @@ Location of installed sblim-testsuite ca
    4.19  environment variable.  If not specified, /usr/share/sblim-testsuite and
    4.20  /usr/local/share/sblim-testsuite will be tried.
    4.21  
    4.22 +Should you wish to run the extrinsic tests and have not run xm-test, 
    4.23 +run the configure script with XMTESTDIR=xm-test-location as an argument.
    4.24 +
    4.25  3.  BUILDING
    4.26  
    4.27  
    4.28 @@ -42,6 +53,6 @@ on provider type) and it will automatica
    4.29  
    4.30  5.  RUNNING
    4.31  
    4.32 -Run the run-test.sh script.  Instance provider test results are placed in
    4.33 -the file 'instance_provider_results'.  Association provider test results
    4.34 -are placed in 'association_provider_results'.
    4.35 +In the main directoy (one up from this one), type make runtest. Instance 
    4.36 +provider test results are placed in the file 'test/instance_provider_results'.
    4.37 +Association provider test results are placed in 'test/association_provider_results'.
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/test/extrinsics_setup.py	Mon Aug 13 10:55:46 2007 -0600
     5.3 @@ -0,0 +1,162 @@
     5.4 +#!/usr/bin/python
     5.5 +# Author: Jim Fehlig <jfehlig@novell.com>
     5.6 +# Contributors: Luke Szymanski <Lukasz.Szymanski@Unisys.com>
     5.7 +#
     5.8 +# Description: Set up VM and exercise the extrinsic provider methods
     5.9 +#
    5.10 +# Copyright (C) 2007 Novell Corporation
    5.11 +# Copyright (C) 2007 Unisys Corporation
    5.12 +#
    5.13 +# This library is free software; you can redistribute it and/or
    5.14 +# modify it under the terms of the GNU Lesser General Public
    5.15 +# License as published by the Free Software Foundation; either
    5.16 +# version 2.1 of the License, or (at your option) any later version.
    5.17 +#
    5.18 +# This library is distributed in the hope that it will be useful,
    5.19 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.20 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    5.21 +# Lesser General Public License for more details.
    5.22 +#
    5.23 +# You should have received a copy of the GNU Lesser General Public
    5.24 +# License along with this library; if not, write to the Free Software
    5.25 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    5.26 +#
    5.27 +
    5.28 +import sys
    5.29 +import pywbem
    5.30 +import time
    5.31 +import os
    5.32 +import string
    5.33 +
    5.34 +# Frequently used functions
    5.35 +def EnumerateCSInstnaces():
    5.36 +    print ' Enumerating instances of Xen_ComputerSystem:'
    5.37 +    inst_names = conn.EnumerateInstanceNames('Xen_ComputerSystem')
    5.38 +    for n in inst_names:
    5.39 +      inst = conn.GetInstance(n, LocalOnly=False)
    5.40 +      print '  Domain %s: EnabledState %s' % (inst['Name'],inst['EnabledState'])
    5.41 +
    5.42 +
    5.43 +# Set up ramdisk and kernel.
    5.44 +# See if /tmp/xm-test.conf exists.  If so, xm-test has already been run
    5.45 +# and therefore, there is no need to run make on the ramdisk; otherwise, run it	
    5.46 +if  (os.system ('ls /tmp/xm-test.conf 2> /dev/null 1> /dev/null') != 0):
    5.47 +    # Build ramdisk, use XMTESTDIR passed from run script
    5.48 +    print '...Building a RAMDISK...'
    5.49 +    xmtestdir = sys.argv[1]
    5.50 +    os.chdir(xmtestdir)
    5.51 +    os.system('./autogen')
    5.52 +    os.system('./configure')
    5.53 +    os.system('make -j `cat /proc/cpuinfo | grep processor | wc -l`')
    5.54 +    os.chdir('tests/create')
    5.55 +
    5.56 +    # Sanity check done by xm-test; also, this creates xm-test.conf		
    5.57 +    os.system('TEST_VERBOSE=1 make check TESTS=01_create_basic_pos.test')
    5.58 +    os.chdir('../..')
    5.59 +    time.sleep(5)
    5.60 +
    5.61 +print '...Setting up VM...'
    5.62 +# Extract info from xm-test.conf file
    5.63 +command = "grep ramdisk /tmp/xm-test.conf | sed 's/^.* = \"//' | sed s'/\"//' > temp"
    5.64 +os.system(command)
    5.65 +file = open("temp","r+")
    5.66 +ramdisk_location = file.read()
    5.67 +ramdisk_location = ramdisk_location.replace('\n','')
    5.68 +
    5.69 +command = "grep kernel /tmp/xm-test.conf | sed 's/^.* = \"//' | sed s'/\"$//' >> temp"
    5.70 +os.system(command)
    5.71 +kernel_location = file.read()
    5.72 +kernel_location = kernel_location.replace('\n','')
    5.73 +file.close()
    5.74 +os.unlink("temp")
    5.75 +
    5.76 +# Connect to cimom
    5.77 +user='root'
    5.78 +pw='password'
    5.79 +
    5.80 +conn = pywbem.WBEMConnection('http://localhost', (user,pw))
    5.81 +
    5.82 +# Get instance of Virtual System Management Service
    5.83 +print 'Looking for Virtual System Management Service...'
    5.84 +vsms = conn.EnumerateInstanceNames("Xen_VirtualSystemManagementService")
    5.85 +print 'Got Virtual System Management Service: %s' % str(vsms[0])
    5.86 +
    5.87 +# Create virtual system settings for new VM
    5.88 +vssd = pywbem.CIMInstance('Xen_ComputerSystemSettingData',
    5.89 +	 {'VirtualSystemIdentifier':'xen-cim-test-12345',
    5.90 +	 'VirtualSystemType':'xen-3.0-x86',
    5.91 +         'Kernel':kernel_location,
    5.92 +         'RAMDisk':'/boot/initrd-xen',
    5.93 +         'UUID':'20904d23-8a89-1d63-134c-d2606f2fcc47',
    5.94 +	 'KernelOptions':'Term=xterm',
    5.95 +         'OnPoweroff':pywbem.Uint16(0),
    5.96 +         'OnReboot':pywbem.Uint16(1),
    5.97 +         'OnCrash':pywbem.Uint16(2)})
    5.98 +
    5.99 +proc_rasd = pywbem.CIMInstance('Xen_ProcessorSettingData',
   5.100 +	{'ResourceType':pywbem.Uint16(3),
   5.101 +	 'VirtualQuantity':pywbem.Uint64(2),
   5.102 +	 'AllocationUnits':'Cores',
   5.103 +         'Weight':pywbem.Uint32(512),
   5.104 +         'Limit':pywbem.Uint64(100)})
   5.105 +
   5.106 +mem_rasd = pywbem.CIMInstance('Xen_MemorySettingData',
   5.107 +	{'ResourceType':pywbem.Uint16(4), 
   5.108 +	 'VirtualQuantity':pywbem.Uint64(256),
   5.109 +	 'AllocationUnits':'MegaBytes'})
   5.110 +
   5.111 +ramdisk_location = "file:" + ramdisk_location + ",xvda,w"
   5.112 +disk_rasd = pywbem.CIMInstance('Xen_DiskSettingData',
   5.113 +         {'ResourceType':pywbem.Uint16(19),
   5.114 +	 'DiskConfigInfo':ramdisk_location})
   5.115 +
   5.116 +nic_rasd = pywbem.CIMInstance('Xen_NetworkPortSettingData', 
   5.117 +	{'ResourceType':pywbem.Uint16(10), 
   5.118 +	 'NICConfigInfo':'mac=00:16:3e:39:7a:f7'})
   5.119 +
   5.120 +con_rasd = pywbem.CIMInstance('Xen_ConsoleSettingData', 
   5.121 +	{'ResourceType':pywbem.Uint16(24),
   5.122 +         'Protocol':pywbem.Uint16(1),
   5.123 +         'ConsoleConfigInfo':'vncunused=1'})
   5.124 +
   5.125 +rasds = [proc_rasd, mem_rasd, disk_rasd, nic_rasd, con_rasd]
   5.126 +
   5.127 +in_params = {'SystemSettings': vssd, 'ResourceSettings': rasds}
   5.128 +
   5.129 +
   5.130 +# Invoke DefineSystem on Virtual System Management Serive to define a new VM,
   5.131 +# providing the new VM settings and its resource settings.
   5.132 +new_vm = None
   5.133 +try:
   5.134 +    print 'Calling DefineSystem to create a new VM ...'
   5.135 +    (rval, out_params) = conn.InvokeMethod('DefineSystem', vsms[0], **in_params)
   5.136 +    print 'Return Value of DefineSystem: %s' % rval
   5.137 +    print 'Output = %s' % out_params
   5.138 +    new_vm = out_params['ResultingSystem']
   5.139 +
   5.140 +except pywbem.CIMError, arg:
   5.141 +    print 'Caught exception when calling InvokeMethod'
   5.142 +    if arg[0] != pywbem.CIM_ERR_NOT_SUPPORTED:
   5.143 +        print 'InvokeMethod(instancename): %s' % arg[1]
   5.144 +        sys.exit(1)
   5.145 +
   5.146 +# Get instances of Xen_ComputerSystem
   5.147 +EnumerateCSInstnaces()
   5.148 +
   5.149 +print 'Activating newly defined VM ...'
   5.150 +try:
   5.151 +    # state 2 = enabled(running)
   5.152 +    (rval, out_params) = conn.InvokeMethod('RequestStateChange', new_vm, RequestedState='2')
   5.153 +except Exception, e:
   5.154 +    sys.stderr.write('Exception caught in starting VM: %s\n' % e)
   5.155 +    sys.exit(1)
   5.156 +    if rval == 0:
   5.157 +        print 'Successfully activated new vm'
   5.158 +    else:
   5.159 +        sys.stderr.write('Unable to start VM, return code: %s\n' % rval)
   5.160 +        sys.exit(1)
   5.161 +
   5.162 +time.sleep(5)
   5.163 +
   5.164 +EnumerateCSInstnaces()
   5.165 +
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/test/extrinsics_shutdown.py	Mon Aug 13 10:55:46 2007 -0600
     6.3 @@ -0,0 +1,75 @@
     6.4 +#!/usr/bin/python
     6.5 +# Author: Jim Fehlig <jfehlig@novell.com>
     6.6 +# Contributors: Luke Szymanski <Lukasz.Szymanski@Unisys.com>
     6.7 +#
     6.8 +# Description: Shutdown vm used in extrinsic test
     6.9 +#
    6.10 +# Copyright (C) 2007 Novell Corporation
    6.11 +# Copyright (C) 2007 Unisys Corporation
    6.12 +#
    6.13 +# This library is free software; you can redistribute it and/or
    6.14 +# modify it under the terms of the GNU Lesser General Public
    6.15 +# License as published by the Free Software Foundation; either
    6.16 +# version 2.1 of the License, or (at your option) any later version.
    6.17 +#
    6.18 +# This library is distributed in the hope that it will be useful,
    6.19 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.20 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    6.21 +# Lesser General Public License for more details.
    6.22 +#
    6.23 +# You should have received a copy of the GNU Lesser General Public
    6.24 +# License along with this library; if not, write to the Free Software
    6.25 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    6.26 +#
    6.27 +
    6.28 +import sys
    6.29 +import pywbem
    6.30 +import time
    6.31 +import os
    6.32 +import string
    6.33 +
    6.34 +# Frequently used functions
    6.35 +def EnumerateCSInstnaces():
    6.36 +    print ' Enumerating instances of Xen_ComputerSystem:'
    6.37 +    inst_names = conn.EnumerateInstanceNames('Xen_ComputerSystem')
    6.38 +    for n in inst_names:
    6.39 +      inst = conn.GetInstance(n, LocalOnly=False)
    6.40 +      print '  Domain %s: EnabledState %s' % (inst['Name'],inst['EnabledState'])
    6.41 +      if inst['Name'] == 'xen-cim-test-12345':
    6.42 +	 new_vm = inst
    6.43 +
    6.44 +# Connect to cimom
    6.45 +user='root'
    6.46 +pw='password'
    6.47 +
    6.48 +conn = pywbem.WBEMConnection('http://localhost', (user,pw))
    6.49 +
    6.50 +# Find vm created by this test
    6.51 +inst_names = conn.EnumerateInstanceNames('Xen_ComputerSystem')
    6.52 +for n in inst_names:
    6.53 +   inst = conn.GetInstance(n, LocalOnly=False)
    6.54 +   if inst['Name'] == 'xen-cim-test-12345':
    6.55 +	 new_vm = n
    6.56 +
    6.57 +print 'Stopping newly defined VM ...'
    6.58 +try:
    6.59 +    # state 3 = destroy
    6.60 +    (rval, out_params) = conn.InvokeMethod('RequestStateChange', new_vm, RequestedState='3')
    6.61 +except Exception, e:
    6.62 +    sys.stderr.write('Exception caught in stopping VM: %s\n' % e)
    6.63 +    sys.exit(1)
    6.64 +    if rval == 0:
    6.65 +        print 'Successfully activated new vm'
    6.66 +    else:
    6.67 +        sys.stderr.write('Unable to start VM, return code: %s\n' % rval)
    6.68 +        sys.exit(1)
    6.69 +
    6.70 +time.sleep(5)
    6.71 +
    6.72 +EnumerateCSInstnaces()
    6.73 +
    6.74 +print 'Deleting VM ...'
    6.75 +os.system('xm delete xen-cim-test-12345')
    6.76 +
    6.77 +EnumerateCSInstnaces()
    6.78 +
     7.1 --- a/test/run-test.sh	Fri Aug 10 15:32:54 2007 -0600
     7.2 +++ b/test/run-test.sh	Mon Aug 13 10:55:46 2007 -0600
     7.3 @@ -1,8 +1,8 @@
     7.4  #! /bin/bash
     7.5  # Author: Luke Szymanski <Lukasz.Szymanski@Unisys.com>
     7.6  # Contributors:
     7.7 -# Description: Run sblim-test suite with Xen CIM providers
     7.8 -#
     7.9 +# Description: Run sblim-test suite with Xen CIM providers.
    7.10 +#	       Set up vm if possible.
    7.11  # Copyright (C) 2007 Unisys Corporation
    7.12  #
    7.13  # This library is free software; you can redistribute it and/or
    7.14 @@ -20,10 +20,41 @@
    7.15  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    7.16  #
    7.17  
    7.18 +INTRINSIC_ONLY=0
    7.19 +
    7.20 +# xm-test not run and XMTESTDIR variable not passed in
    7.21 +if test ! -e /tmp/xm-test.conf -a x"$1" == x; then
    7.22 +	echo ''
    7.23 +	echo 'This test uses the ramdisk from xm-test.'
    7.24 +	echo 'You have not run xm-test.'
    7.25 +	echo 'You have not specified the location for xm-test.'
    7.26 +	echo 'If you wish to specify it, go to the main directory'
    7.27 +	echo ' ./configure XMTESTDIR=location'
    7.28 +	echo ' make runtest'
    7.29 +	echo 'Creating the ramdisk may take around 20 minutes.'
    7.30 +	echo 'You can still run intrinsic tests without this setup.'
    7.31 +	echo 'Do you wish to start over and define XMTESTDIR?'
    7.32 +	read answer
    7.33 +	answer=`echo $answer | tr A-Z a-z`
    7.34 +	answer=`echo $answer | awk '{printf substr($0, 1, 1)}'`
    7.35 +	if [ $answer == y ]; then
    7.36 +		exit 1
    7.37 +	else
    7.38 +		INTRINSIC_ONLY=1		
    7.39 +	fi
    7.40 +fi
    7.41 +
    7.42 +# Set up extrinsics
    7.43 +echo '-----------------------------------------------------------'
    7.44 +if [ $INTRINSIC_ONLY -eq 0 ]; then
    7.45 +	python extrinsics_setup.py $1
    7.46 +fi
    7.47 +
    7.48  cp instance_provider_list sblim-test-suite/instance_provider_list
    7.49  CMPI_TEST_PATH=`pwd`
    7.50  cd sblim-test-suite
    7.51  
    7.52 +echo '-----------------------------------------------------------'
    7.53  echo 'Starting instance provider tests ...'
    7.54  
    7.55  cat instance_provider_list |   \
    7.56 @@ -50,3 +81,10 @@ done
    7.57  
    7.58  echo 'Done. Results are in file association_provider_results.'
    7.59  rm association_provider_list
    7.60 +
    7.61 +# Take down VM
    7.62 +echo '-----------------------------------------------------------'
    7.63 +cd $CMPI_TEST_PATH
    7.64 +if [ $INTRINSIC_ONLY -eq 0 ]; then
    7.65 +	python extrinsics_shutdown.py
    7.66 +fi