# HG changeset patch # User root@1089 # Date 1187376144 14400 # Node ID e87f0fc42edca736361bb6566d17d5b840c9c698 # Parent fc498265d2938d711a11ab6b2bd9d63bcc18062a Removed dos formatting from python scripts Signed-off-by: Luke Szymanski diff -r fc498265d293 -r e87f0fc42edc test/extrinsics_setup.py --- a/test/extrinsics_setup.py Thu Aug 16 17:49:08 2007 -0600 +++ b/test/extrinsics_setup.py Fri Aug 17 14:42:24 2007 -0400 @@ -1,162 +1,162 @@ -#!/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.unlink("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(256), - '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) - -# 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() - +#!/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.unlink("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(256), + '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) + +# 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 fc498265d293 -r e87f0fc42edc test/extrinsics_shutdown.py --- a/test/extrinsics_shutdown.py Thu Aug 16 17:49:08 2007 -0600 +++ b/test/extrinsics_shutdown.py Fri Aug 17 14:42:24 2007 -0400 @@ -1,75 +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() - +#!/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() +