# HG changeset patch # User root@1089 # Date 1187377166 14400 # Node ID e2be7710c98c7ece3e1b3da3be2ba844b0fec94c # Parent e87f0fc42edca736361bb6566d17d5b840c9c698 Add more functionality to extrinsic tests Signed-off-by: Luke Szymanski diff -r e87f0fc42edc -r e2be7710c98c test/README --- a/test/README Fri Aug 17 14:42:24 2007 -0400 +++ b/test/README Fri Aug 17 14:59:26 2007 -0400 @@ -23,9 +23,13 @@ ramdisk and kernel provided by xm-test. 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. +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 created, followed by some fuctional +tests, state change tests, and then a creation of another VM takes place. +At the end of the tests, everything is destroyed. + 2. CONFIGURING diff -r e87f0fc42edc -r e2be7710c98c test/extrinsics_setup.py --- a/test/extrinsics_setup.py Fri Aug 17 14:42:24 2007 -0400 +++ b/test/extrinsics_setup.py Fri Aug 17 14:59:26 2007 -0400 @@ -29,6 +29,8 @@ import string import string # Frequently used functions + +# Enumerate Computer System instances def EnumerateCSInstnaces(): print ' Enumerating instances of Xen_ComputerSystem:' inst_names = conn.EnumerateInstanceNames('Xen_ComputerSystem') @@ -36,6 +38,24 @@ def EnumerateCSInstnaces(): inst = conn.GetInstance(n, LocalOnly=False) print ' Domain %s: EnabledState %s' % (inst['Name'],inst['EnabledState']) +# Invoke RequestStateChange on vm +def ChangeState(state, VM_Inst): + try: + (rval, out_params) = conn.InvokeMethod('RequestStateChange', VM_Inst, RequestedState=str(state)) + + 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 + + time.sleep(5) + EnumerateCSInstnaces() + +# End of frequently used functions. # Set up ramdisk and kernel. # See if /tmp/xm-test.conf exists. If so, xm-test has already been run @@ -105,10 +125,10 @@ mem_rasd = pywbem.CIMInstance('Xen_Memor 'VirtualQuantity':pywbem.Uint64(256), 'AllocationUnits':'MegaBytes'}) -ramdisk_location = "file:" + ramdisk_location + ",xvda,w" +disk_file_location = "file:" + ramdisk_location + ",xvda,w" disk_rasd = pywbem.CIMInstance('Xen_DiskSettingData', {'ResourceType':pywbem.Uint16(19), - 'DiskConfigInfo':ramdisk_location}) + 'DiskConfigInfo':disk_file_location}) nic_rasd = pywbem.CIMInstance('Xen_NetworkPortSettingData', {'ResourceType':pywbem.Uint16(10), @@ -120,9 +140,7 @@ con_rasd = pywbem.CIMInstance('Xen_Conso '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. @@ -140,23 +158,206 @@ except pywbem.CIMError, arg: 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) - +print '--- Begin Sanity test ---' +print 'Activating newly defined VM ...(state=2)' +# state 2 = activate +ChangeState(2, new_vm) + +print 'Get instance of newly created VM' +new_vm_inst = conn.GetInstance(new_vm) + +print 'Enumerate Computer System instances' +conn.EnumerateInstances('Xen_ComputerSystem') + +print 'Get instance of newly created VM again' +new_vm_inst_2 = conn.GetInstance(new_vm) + +print 'See if it matches the original one' +if (new_vm_inst == new_vm_inst_2): + print 'Matches ...' +else: + print 'Does not match: EnumerateInstances has corrputed the new vm instance' + +print '--- End Sanity test ---' + +print '--- Begin Functional test ---' + +print 'Attempting to attach a network port' +nic_rasd_2 = pywbem.CIMInstance('Xen_NetworkPortSettingData', + {'ResourceType':pywbem.Uint16(10), + 'NICConfigInfo':'mac=00:16:3e:39:7a:f8'}) + +# Get computer system setting data of new vm. +inst_names = conn.EnumerateInstanceNames('Xen_ComputerSystemSettingData') +for n in inst_names: + inst = conn.GetInstance(n, LocalOnly=False) + if inst['ElementName'] == 'xen-cim-test-12345': + new_vm_sd = n + break + +in_params = {'AffectedConfiguration': new_vm_sd, 'ResourceSetting': nic_rasd_2} +# Invoke Add resrouce setting on vm +try: + (rval, out_params) = conn.InvokeMethod('AddResourceSetting', vsms[0], **in_params) + +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 + +# See if the network attach worked properly +count=0 +inst_names = conn.EnumerateInstanceNames('Xen_NetworkPortSettingData') +for n in inst_names: + inst = conn.GetInstance(n, LocalOnly=False) + if (inst['NICConfigInfo'] == 'mac=00:16:3e:39:7a:f7') or \ + (inst['NICConfigInfo'] == 'mac=00:16:3e:39:7a:f8'): + count+=1 + +if count != 2: + print 'Network Port attach not successful' +else: + print 'Netwrok Port attach successful' + +print 'Get instance of newly created VM again' +new_vm_inst_2 = conn.GetInstance(new_vm) + +print 'See if it matches the original one' +if (new_vm_inst == new_vm_inst_2): + print 'Matches ...' +else: + print 'Does not match: Attach network port has corrputed the new vm instance' + +print 'Attempting to attach a block device' + +disk_file_location_2 = "file:" + ramdisk_location + ",xvdb,w" +disk_rasd_2 = pywbem.CIMInstance('Xen_DiskSettingData', + {'ResourceType':pywbem.Uint16(19), + 'DiskConfigInfo':disk_file_location_2}) + +in_params = {'AffectedConfiguration': new_vm_sd, 'ResourceSetting': disk_rasd_2} + +# Invoke AddResrouceSetting on vm +try: + (rval, out_params) = conn.InvokeMethod('AddResourceSetting', vsms[0], **in_params) + +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 + +# See if the block attach worked properly +count=0 +inst_names = conn.EnumerateInstanceNames('Xen_DiskSettingData') +for n in inst_names: + inst = conn.GetInstance(n, LocalOnly=False) + if (inst['DiskConfigInfo'] == disk_file_location) or \ + (inst['DiskConfigInfo'] == disk_file_location_2): + count+=1 + +if count != 2: + print 'Block device attach not successful' +else: + print 'Block device attach successful' + +print 'Get instance of newly created VM again' +new_vm_inst_2 = conn.GetInstance(new_vm) + +print 'See if it matches the original one' +if (new_vm_inst == new_vm_inst_2): + print 'Matches ...' +else: + print 'Does not match: Attach network port has corrputed the new vm instance' + +print '--- End Functional test ---' + +print '--- Begin State Change test ---' +print 'Quiescing VM (state=9)...' +# state 9 = quiesce +ChangeState(9, new_vm) + +print 'Re-activating VM (state=2)...' +# state 2 = activate +ChangeState(2, new_vm) + +print 'Restarting VM (state=2)...' +# state 10 = restart/reboot. +ChangeState(10, new_vm) + +print 'Off-lining VM (state=6)...' +# state 6 = offline +ChangeState(6, new_vm) + +print 'Re-activating VM (state=2)...' +# state 2 = activate +ChangeState(2, new_vm) + +print '--- End State Change test ---' + +print '--- Create another VM ---' +vssd_2 = pywbem.CIMInstance('Xen_ComputerSystemSettingData', + {'VirtualSystemIdentifier':'xen-cim-test-67890', + 'VirtualSystemType':'xen-3.0-x86', + 'Kernel':kernel_location, + 'RAMDisk':'/boot/initrd-xen', + 'UUID':'20904d23-8a89-1d63-134c-d2606f2fcc48', + 'KernelOptions':'Term=xterm', + 'OnPoweroff':pywbem.Uint16(0), + 'OnReboot':pywbem.Uint16(1), + 'OnCrash':pywbem.Uint16(2)}) + +disk_file_location_2 = "file:" + ramdisk_location + ",xvdc,w" +disk_rasd_2 = pywbem.CIMInstance('Xen_DiskSettingData', + {'ResourceType':pywbem.Uint16(19), + 'DiskConfigInfo':disk_file_location_2}) + +nic_rasd_2 = pywbem.CIMInstance('Xen_NetworkPortSettingData', + {'ResourceType':pywbem.Uint16(10), + 'NICConfigInfo':'mac=00:16:3e:39:7a:fa'}) + +rasds_2 = [proc_rasd, mem_rasd, disk_rasd_2, nic_rasd_2, con_rasd] + +in_params_2 = {'SystemSettings': vssd_2, 'ResourceSettings': rasds_2} + +# Invoke DefineSystem on Virtual System Management Serive to define a new VM, +# providing the new VM settings and its resource settings. +new_vm_2 = None +try: + print 'Calling DefineSystem to create a new VM ...' + (rval, out_params) = conn.InvokeMethod('DefineSystem', vsms[0], **in_params_2) + print 'Return Value of DefineSystem: %s' % rval + print 'Output = %s' % out_params + new_vm_2 = 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 second VM ...(state=2)' +# state 2 = activate +ChangeState(2, new_vm_2) + +print '--- Done creating another VM ---' + diff -r e87f0fc42edc -r e2be7710c98c test/extrinsics_shutdown.py --- a/test/extrinsics_shutdown.py Fri Aug 17 14:42:24 2007 -0400 +++ b/test/extrinsics_shutdown.py Fri Aug 17 14:59:26 2007 -0400 @@ -29,14 +29,66 @@ import string import string # Frequently used functions + +# Enumerate Computer System instances 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 + +# Invoke RequestStateChange on vm +def ChangeState(state, VM_Inst): + try: + (rval, out_params) = conn.InvokeMethod('RequestStateChange', VM_Inst, RequestedState=str(state)) + + 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 + + time.sleep(5) + EnumerateCSInstnaces() + +# Destroy vm +def DestroyVM(VM_Inst): + vsms = conn.EnumerateInstanceNames("Xen_VirtualSystemManagementService") + in_params = {'AffectedSystem': new_vm} + + try: + # Destroy VM + (rval, out_params) = conn.InvokeMethod('DestroySystem', vsms[0], **in_params) + except Exception, e: + sys.stderr.write('Exception caught in stopping VM: %s\n' % e) + sys.exit(1) + if rval == 0: + print 'Successfully destroyed vm' + else: + sys.stderr.write('Unable to destroy VM, return code: %s\n' % rval) + sys.exit(1) + + time.sleep(5) + EnumerateCSInstnaces() + +# Find vm created by this test +def FindVM(VM_Name): + new_vm = None + inst_names = conn.EnumerateInstanceNames('Xen_ComputerSystem') + for n in inst_names: + inst = conn.GetInstance(n, LocalOnly=False) + if inst['Name'] == VM_Name: + return n + + if new_vm == None: + print 'Could not shut down VM named %s ' % VM_Name + sys.exit(1) + +# End of frequently used functions # Connect to cimom user='root' @@ -44,32 +96,21 @@ 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 +new_vm = None +new_vm = FindVM('xen-cim-test-12345') -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) +print 'Stopping VM ...(state=3)' +ChangeState(3, new_vm) -time.sleep(5) +print 'Destroying VM ...' +DestroyVM(new_vm) -EnumerateCSInstnaces() +# Find second vm created by this test +new_vm = FindVM('xen-cim-test-67890') -print 'Deleting VM ...' -os.system('xm delete xen-cim-test-12345') +print 'Stopping VM ...(state=3)' +ChangeState(3, new_vm) -EnumerateCSInstnaces() +print 'Destroying VM ...' +DestroyVM(new_vm)