# HG changeset patch # User root@1089 # Date 1192570166 14400 # Node ID 9cb4389e68f501fa54435f31eee490b9ac4ce7e7 # Parent e2be7710c98c7ece3e1b3da3be2ba844b0fec94c Upgrade of extrinsic tests. Signed-off-by: Luke Szymanski diff -r e2be7710c98c -r 9cb4389e68f5 test/extrinsics_setup.py --- a/test/extrinsics_setup.py Fri Aug 17 14:59:26 2007 -0400 +++ b/test/extrinsics_setup.py Tue Oct 16 17:29:26 2007 -0400 @@ -30,15 +30,10 @@ 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']) - -# Invoke RequestStateChange on vm +### +# Extrinsic functions +### + def ChangeState(state, VM_Inst): try: (rval, out_params) = conn.InvokeMethod('RequestStateChange', VM_Inst, RequestedState=str(state)) @@ -53,8 +48,204 @@ def ChangeState(state, VM_Inst): pass time.sleep(5) - EnumerateCSInstnaces() - + +def DefineVM(vsms, **in_params): + # 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: + (rval, out_params) = conn.InvokeMethod('DefineSystem', vsms[0], **in_params) + new_vm = out_params['ResultingSystem'] + return new_vm + + 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 + +def AddResourceSetting(vsms, vm_sd, rasd_test): + in_params = {'AffectedConfiguration': vm_sd, 'ResourceSetting': rasd_test} + + # 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 + +def DestroyVM(vsms, VM_Inst): + in_params = {'AffectedSystem': VM_Inst} + + 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) + +### +# Helper 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']) + +def GetSettingData(VM_Name): + # 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'] == VM_Name: + return n + else: + print 'Cannot find setting data of VM %s' % VM_Name + +def VerifyStateChange(state, VM_Name): + inst_names = conn.EnumerateInstanceNames('Xen_ComputerSystem') + + match=0 + for n in inst_names: + inst = conn.GetInstance(n, LocalOnly=False) + if (inst['Name'] == VM_Name) and (inst['EnabledState'] == state): + match=1 + print 'Test passed' + break + + if match==0: + print 'Test failed: requested state transition did not take place' + sys.exit(1) + +# 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 find VM named %s ' % VM_Name + +### +# Negative test functions +### + +# Define System for negative tests +def NegTestDefineVM(vsms, in_params, expected_error): + exception=0 + try: + (rval, out_params) = conn.InvokeMethod('DefineSystem', vsms[0], **in_params) + + except pywbem.CIMError, arg: + exception=1 + if arg[0] != pywbem.CIM_ERR_NOT_SUPPORTED: + if arg[1].rfind(expected_error) >= 0: + print 'Test passed' + else: + print 'Test failed, Unexpected return code: %s' % arg[1] + sys.exit(1) + + except ValueError, e: + pass + + if exception == 0: + print 'Test failed: there should have been an exception raised' + sys.exit(1) + +# AddResourceSetting for negative tests +def NegTestAddResourceSetting(vm_sd, rasd, expected_error): + in_params = {'AffectedConfiguration': vm_sd, 'ResourceSetting': rasd} + + exception=0 + # Invoke AddResrouceSetting on vm + try: + (rval, out_params) = conn.InvokeMethod('AddResourceSetting', vsms[0], **in_params) + + except pywbem.CIMError, arg: + exception=1 + if arg[0] != pywbem.CIM_ERR_NOT_SUPPORTED: + if arg[1].rfind(expected_error) >= 0: + print 'Test passed' + else: + print 'Test failed: Unexpected return code: %s' % arg[1] + sys.exit(1) + + except ValueError, e: + pass + + if exception == 0: + print 'Test failed: there should have been an exception raised' + sys.exit(1) + +def NegTestRequestStateChange(state, VM_Inst, expected_error): + + exception=0 + try: + (rval, out_params) = conn.InvokeMethod('RequestStateChange', VM_Inst, RequestedState=str(state)) + + except pywbem.CIMError, arg: + exception=1 + if arg[0] != pywbem.CIM_ERR_NOT_SUPPORTED: + if arg[1].rfind(expected_error) >= 0: + print 'Test passed' + else: + print 'Test failed, Unexpected return code: %s' % arg[1] + sys.exit(1) + + except ValueError, e: + pass + + if exception == 0: + print 'Test failed: there should have been an exception raised' + sys.exit(1) + +# Negative testing Destroy vm +def NegTestDestroyVM(vsms, VM_Inst, expected_error): + in_params = {'AffectedSystem': VM_Inst} + exception=0 + + try: + # Destroy VM + (rval, out_params) = conn.InvokeMethod('DestroySystem', vsms[0], **in_params) + + except pywbem.CIMError, arg: + exception=1 + if arg[0] != pywbem.CIM_ERR_NOT_SUPPORTED: + if arg[1].rfind(expected_error) >= 0: + print 'Test passed' + else: + print 'Test failed: Unexpected return code: %s' % arg[1] + + except ValueError, e: + pass + + if exception == 0: + print 'Test failed: there should have been an exception raised' + sys.exit(1) + # End of frequently used functions. # Set up ramdisk and kernel. @@ -75,7 +266,7 @@ if (os.system ('ls /tmp/xm-test.conf 2> os.chdir('../..') time.sleep(5) -print '...Setting up VM...' +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) @@ -99,7 +290,7 @@ conn = pywbem.WBEMConnection('http://loc # 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]) +print 'Got it' # Create virtual system settings for new VM vssd = pywbem.CIMInstance('Xen_ComputerSystemSettingData', @@ -125,7 +316,8 @@ mem_rasd = pywbem.CIMInstance('Xen_Memor 'VirtualQuantity':pywbem.Uint64(256), 'AllocationUnits':'MegaBytes'}) -disk_file_location = "file:" + ramdisk_location + ",xvda,w" +#disk_file_location = "file:" + ramdisk_location + ",xvda,w" +disk_file_location = "file:" + ramdisk_location + ",xvda,r" disk_rasd = pywbem.CIMInstance('Xen_DiskSettingData', {'ResourceType':pywbem.Uint16(19), 'DiskConfigInfo':disk_file_location}) @@ -142,51 +334,41 @@ rasds = [proc_rasd, mem_rasd, disk_rasd, 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 '--- Begin Sanity test ---' -print 'Activating newly defined VM ...(state=2)' +print 'Defining new VM' +new_vm = DefineVM(vsms, **in_params) + +print 'Activating newly defined VM' # state 2 = activate ChangeState(2, new_vm) -print 'Get instance of newly created VM' +# Get instance of newly created VM new_vm_inst = conn.GetInstance(new_vm) -print 'Enumerate Computer System instances' +# Enumerate Computer System instances conn.EnumerateInstances('Xen_ComputerSystem') -print 'Get instance of newly created VM again' +# 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 ...' + print 'Test passed' else: - print 'Does not match: EnumerateInstances has corrputed the new vm instance' - + print 'Test failed: EnumerateInstances has corrupted instance data' + sys.exit(1) + +# state 3 = stop +ChangeState(3, new_vm) +DestroyVM(vsms, new_vm) print '--- End Sanity test ---' -print '--- Begin Functional test ---' +############################## + +print '--- Begin Network Attach tests ---' +new_vm = DefineVM(vsms, **in_params) +ChangeState(2, new_vm) print 'Attempting to attach a network port' nic_rasd_2 = pywbem.CIMInstance('Xen_NetworkPortSettingData', @@ -194,26 +376,8 @@ nic_rasd_2 = pywbem.CIMInstance('Xen_Net '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 +new_vm_sd = GetSettingData('xen-cim-test-12345') +AddResourceSetting(vsms, new_vm_sd, nic_rasd_2) # See if the network attach worked properly count=0 @@ -225,40 +389,73 @@ for n in inst_names: count+=1 if count != 2: - print 'Network Port attach not successful' + print 'Test failed: Network Port attach not successful' + sys.exit(1) + +# Get instance of newly created VM again +new_vm_inst_2 = conn.GetInstance(new_vm) + +# See if it matches original +if (new_vm_inst == new_vm_inst_2): + print 'Test passed' 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 'Test failed: EnumerateInstances has corrupted instance data' + sys.exit(1) + +# state 3 = stop +ChangeState(3, new_vm) +DestroyVM(vsms, new_vm) + +############################## + +print 'Attempting negative tests for network port attach' + +new_vm = DefineVM(vsms, **in_params) +ChangeState(2, new_vm) +new_vm_sd = GetSettingData('xen-cim-test-12345') + +print 'Attempting blank rasd' +nic_rasd_blank = '' +expected_error = 'Cannot parse ResourceSettingData' +NegTestAddResourceSetting(new_vm_sd, nic_rasd_blank, expected_error) + +ChangeState(3, new_vm) +DestroyVM(vsms, new_vm) + +############################## + +print 'Attempting bad VM settings data, where vmsd=asdf' + +new_vm = DefineVM(vsms, **in_params) +ChangeState(2, new_vm) + +nic_rasd_2 = pywbem.CIMInstance('Xen_NetworkPortSettingData', + {'ResourceType':pywbem.Uint16(10), + 'NICConfigInfo':'mac=00:16:3e:39:7a:f8'}) +new_vm_bad = 'asdf' +expected_error = 'class name not found in instance name: asdf' +NegTestAddResourceSetting(new_vm_bad, nic_rasd_2, expected_error) + +ChangeState(3, new_vm) +DestroyVM(vsms, new_vm) + +print '--- End Network Attach tests ---' + +############################## + +print '--- Begin Block Attach tests ---' print 'Attempting to attach a block device' + +new_vm = DefineVM(vsms, **in_params) +ChangeState(2, new_vm) 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 +new_vm_sd = GetSettingData('xen-cim-test-12345') + +AddResourceSetting(vsms, new_vm_sd, disk_rasd_2) # See if the block attach worked properly count=0 @@ -270,45 +467,319 @@ for n in inst_names: count+=1 if count != 2: - print 'Block device attach not successful' + print 'Test failed: Block device attach not successful' + sys.exit(1) + +# Get instance of newly created VM again +new_vm_inst_2 = conn.GetInstance(new_vm) + +# See if it matches the original one +if (new_vm_inst == new_vm_inst_2): + print 'Test passed' 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)...' + print 'Test failed: EnumerateInstances has corrupted instance data' + sys.exit(1) + +ChangeState(3, new_vm) +DestroyVM(vsms, new_vm) + +############################## + +print 'Attempting negative tests for block device attach' + +print 'Attempting block device attach with blank rasd' +new_vm = DefineVM(vsms, **in_params) +ChangeState(2, new_vm) +new_vm_sd = GetSettingData('xen-cim-test-12345') + +disk_rasd_blank ='' +expected_error ='Cannot parse ResourceSettingData' +NegTestAddResourceSetting(new_vm_sd, disk_rasd_blank, expected_error) + +ChangeState(3, new_vm) +DestroyVM(vsms, new_vm) + +############################## + +print 'Attempting bad VM settings data, where vmsd=asdf' +new_vm = DefineVM(vsms, **in_params) +ChangeState(2, new_vm) + +disk_rasd_2 = pywbem.CIMInstance('Xen_DiskSettingData', + {'ResourceType':pywbem.Uint16(19), + 'DiskConfigInfo':disk_file_location_2}) +new_vm_bad = 'asdf' +expected_error = 'class name not found in instance name: asdf' +NegTestAddResourceSetting(new_vm_bad, disk_rasd_2, expected_error) + +ChangeState(3, new_vm) +DestroyVM(vsms, new_vm) + +############################## + +print 'Attempting rasd with known bad disk location' +new_vm = DefineVM(vsms, **in_params) +ChangeState(2, new_vm) +new_vm_sd = GetSettingData('xen-cim-test-12345') + +disk_rasd_bad=pywbem.CIMInstance('Xen_DiskSettingData', + {'ResourceType':pywbem.Uint16(19), + 'DiskConfigInfo':'asdf1234'}) +expected_error = 'Invalid disk setting data' +NegTestAddResourceSetting(new_vm_sd, disk_rasd_bad, expected_error) + +ChangeState(3, new_vm) +DestroyVM(vsms, new_vm) + +############################## + +print '--- End Block Attach tests ---' + +print '--- Begin State Change tests ---' +print 'Quiescing VM (state=9)' +new_vm = DefineVM(vsms, **in_params) +ChangeState(2, new_vm) + # 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)...' +VerifyStateChange(9, 'xen-cim-test-12345') + +ChangeState(3, new_vm) +DestroyVM(vsms, new_vm) + +############################## + +print 'Restarting VM (final state=2)' +new_vm = DefineVM(vsms, **in_params) +ChangeState(2, new_vm) + # state 10 = restart/reboot. ChangeState(10, new_vm) - -print 'Off-lining VM (state=6)...' +# 2 is the final state +VerifyStateChange(2, 'xen-cim-test-12345') + +ChangeState(3, new_vm) +DestroyVM(vsms, new_vm) + +############################## + +print 'Off-lining VM (state=6)' +new_vm = DefineVM(vsms, **in_params) +ChangeState(2, new_vm) + # state 6 = offline ChangeState(6, new_vm) - -print 'Re-activating VM (state=2)...' +VerifyStateChange(6, 'xen-cim-test-12345') + +# restart so it can be destroyed +ChangeState(2, new_vm) + +ChangeState(3, new_vm) +DestroyVM(vsms, new_vm) + +############################## + +print 'Attempting negative State Change tests' +print 'Attempting an invalid state (45)' +new_vm = DefineVM(vsms, **in_params) +ChangeState(2, new_vm) + +state=45 +expected_error = 'Invalid state requested' +NegTestRequestStateChange(state, new_vm, expected_error) + +ChangeState(3, new_vm) +DestroyVM(vsms, new_vm) + +############################## + +print 'Attempting a state change with blank VM' + +blank_vm='' +state=2 +exception=0 +expected_error = '/root/cimv2:' +NegTestRequestStateChange(state, blank_vm, expected_error) + +############################## + +print 'Attempting a state change with bogus VM' +bad_vm = 'xen-cim-test-a5a5a' +state=2 +expected_error = '/root/cimv2:xen-cim-test-a5a5a' +NegTestRequestStateChange(state, bad_vm, expected_error) + +############################## + +print 'Attempting to activate an already active domain' +new_vm = DefineVM(vsms, **in_params) +ChangeState(2, new_vm) + # state 2 = activate -ChangeState(2, new_vm) +state=2 +expected_error = 'Invalid state transition - VirtualSystem already active' +NegTestRequestStateChange(state, new_vm, expected_error) + +ChangeState(3, new_vm) +DestroyVM(vsms, new_vm) + +############################## + +print 'Attempting to disable an already disabled domain' +new_vm = DefineVM(vsms, **in_params) +ChangeState(2, new_vm) + +ChangeState(3, new_vm) +# state 3 = stop +state=3 +expected_error = 'Invalide state transition - VirtualSystem already disabled' +NegTestRequestStateChange(state, new_vm, expected_error) + +DestroyVM(vsms, new_vm) print '--- End State Change test ---' -print '--- Create another VM ---' +############################## + +print '--- Destroy VM tests ---' +print 'Attempting to destroy Dom 0' +bad_vm = FindVM('Domain-0') +expected_error = 'Failed to shutdown VirtualSystem' +NegTestDestroyVM(vsms, bad_vm, expected_error) + +############################## + +print 'Attempting to destroy bogus vm=xen-cim-test-abcde' +bad_vm = 'xen-cim-test-abcde' +expected_error = 'class name not found in instance name: xen-cim-test-abcde' +NegTestDestroyVM(vsms, bad_vm, expected_error) + +print '--- End of Destroy VM tests ---' + +############################## + +print '--- Create VM tests ---' + +print 'Attempting negative VM creation tests' +print 'Attempting creation with blank disk rasd' +disk_rasd_blank='' +rasds = [proc_rasd, mem_rasd, disk_rasd_blank, nic_rasd, con_rasd] +in_params = {'SystemSettings': vssd, 'ResourceSettings': rasds} +expected_error = 'Unable to parse resource setting data parameter' +NegTestDefineVM(vsms, in_params, expected_error) + +############################## + +print 'Attempting creation with known bad disk location' +disk_rasd_bad = pywbem.CIMInstance('Xen_DiskSettingData', + {'ResourceType':pywbem.Uint16(19), + 'DiskConfigInfo':'asdf1234'}) +rasds = [proc_rasd, mem_rasd, disk_rasd_bad, nic_rasd, con_rasd] +in_params = {'SystemSettings': vssd, 'ResourceSettings': rasds} +expected_error = 'Invalid disk setting data' +NegTestDefineVM(vsms, in_params, expected_error) + +############################## + +print 'Attempting creation with memory=0' +mem_rasd_bad = pywbem.CIMInstance('Xen_MemorySettingData', + {'ResourceType':pywbem.Uint16(4), + 'VirtualQuantity':pywbem.Uint64(0), + 'AllocationUnits':'MegaBytes'}) +rasds = [proc_rasd, mem_rasd_bad, disk_rasd, nic_rasd, con_rasd] +in_params = {'SystemSettings': vssd, 'ResourceSettings': rasds} +expected_error = 'INTERNAL_ERRORInvalid Configuration: memory_dynamic_max must be greater than zero' +NegTestDefineVM(vsms, in_params, expected_error) + +############################## + +print 'Attempting VM creation with memory=4MB' +mem_rasd_bad = pywbem.CIMInstance('Xen_MemorySettingData', + {'ResourceType':pywbem.Uint16(4), + 'VirtualQuantity':pywbem.Uint64(4), + 'AllocationUnits':'MegaBytes'}) + +rasds = [proc_rasd, mem_rasd_bad, disk_rasd, nic_rasd, con_rasd] +in_params = {'SystemSettings': vssd, 'ResourceSettings': rasds} + +new_vm = DefineVM(vsms, **in_params) +state=2 +expected_error = 'xc_dom_boot_domU_map: failed to mmap domU pages' + +NegTestRequestStateChange(state, new_vm, expected_error) + +DestroyVM(vsms, new_vm) +# This is really odd: +# Without the xm list statement, the next create tests fail with an internal error +# Also, enumerate instance will claim vm exists, xm test shows otherwise. +os.system('xm list > /dev/null') + +############################## + +print 'Attempting creation with blank virtual system settings data' +vssd_bad = '' +rasds = [proc_rasd, mem_rasd, disk_rasd, nic_rasd, con_rasd] +in_params = {'SystemSettings': vssd_bad, 'ResourceSettings': rasds} +expected_error = 'Cannot parse VirtualSystemSettingData' +NegTestDefineVM(vsms, in_params, expected_error) + +############################## + +print 'Attempting creation with no input parameters' +rasds_2 = [proc_rasd, mem_rasd, disk_rasd, nic_rasd, con_rasd] +in_params_blank = {} +expected_error = 'Cannot get method input argument' +NegTestDefineVM(vsms, in_params_blank, expected_error) + +############################## + +print 'Attempting creation with already used name' +rasds = [proc_rasd, mem_rasd, disk_rasd, nic_rasd, con_rasd] +in_params = {'SystemSettings': vssd, 'ResourceSettings': rasds} + +new_vm = DefineVM(vsms, **in_params) +ChangeState(2, new_vm) + +expected_error='is already connected' +new_vm_bad = NegTestDefineVM(vsms, in_params, expected_error) +ChangeState(3, new_vm) + +DestroyVM(vsms, new_vm) + +############################## + +# Running this, with a sys.exit afterwards, crashed CIMOM when doing shutdown script +# owcimomd: Xen_VirtualSystemManagementService.c:1033: InvokeMethod: Assertion `vms->size == 1' failed. +# Have not been able to reproduce it. + +print 'Attempting creation with no kernel' +kernel_location_blank = '' +vssd_bad = pywbem.CIMInstance('Xen_ComputerSystemSettingData', + {'VirtualSystemIdentifier':'xen-cim-test-67890', + 'VirtualSystemType':'xen-3.0-x86', + 'Kernel':kernel_location_blank, + '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)}) + +rasds = [proc_rasd, mem_rasd, disk_rasd, nic_rasd, con_rasd] +in_params = {'SystemSettings': vssd_bad, 'ResourceSettings': rasds} +expected_error = 'Invalid disk setting data' + +new_vm = DefineVM(vsms, **in_params) + +state=2 +expected_error = 'INTERNAL_ERRORBoot loader didn' +NegTestRequestStateChange(state, new_vm, expected_error) + +DestroyVM(vsms, new_vm) +os.system('xm list > /dev/null') + +############################## + vssd_2 = pywbem.CIMInstance('Xen_ComputerSystemSettingData', {'VirtualSystemIdentifier':'xen-cim-test-67890', 'VirtualSystemType':'xen-3.0-x86', @@ -329,35 +800,49 @@ nic_rasd_2 = pywbem.CIMInstance('Xen_Net {'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] - +proc_rasd_2 = proc_rasd +mem_rasd_2 = mem_rasd +con_rasd_2 = con_rasd + +rasds_2 = [proc_rasd_2, mem_rasd_2, disk_rasd_2, nic_rasd_2, con_rasd_2] in_params_2 = {'SystemSettings': vssd_2, 'ResourceSettings': rasds_2} -# Invoke DefineSystem on Virtual System Management Serive to define a new VM, +############################## + +# Invoke DefineSystem on Virtual System Management Service 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 + +# Start up original VM +rasds = [proc_rasd, mem_rasd, disk_rasd, nic_rasd, con_rasd] +in_params = {'SystemSettings': vssd, 'ResourceSettings': rasds} + +new_vm = DefineVM(vsms, **in_params) +ChangeState(2, new_vm) + +# Start second VM +print 'Attempting creation of second VM' + +rasds_2 = [proc_rasd_2, mem_rasd_2, disk_rasd_2, nic_rasd_2, con_rasd_2] +in_params_2 = {'SystemSettings': vssd_2, 'ResourceSettings': rasds_2} + +new_vm_2 = DefineVM(vsms, **in_params_2) ChangeState(2, new_vm_2) - -print '--- Done creating another VM ---' - +print 'Test passed' +print '--- Done VM creation tests ---' + +############################## + +#3# +""" +# CIMOM returns: +# CMPIProviderIFC found method provider Xen_VirtualSystemManagementService +# RequestHandlerIFCXML::doProcess caught Exception:OW_COWIntrusiveReference.cpp: +# 62 NULLCOWIntrusiveReferenceException: NULL COWReference dereferenced + +print 'Attempting negative tests for destroying VM' +print 'Attempting to destroy blank vm' +bad_vm = '' +# vsms = conn.EnumerateInstanceNames("Xen_VirtualSystemManagementService") +expected_error='' +NegTestDestroyVM(vsms, bad_vm, expected_error) +""" diff -r e2be7710c98c -r 9cb4389e68f5 test/extrinsics_shutdown.py --- a/test/extrinsics_shutdown.py Fri Aug 17 14:59:26 2007 -0400 +++ b/test/extrinsics_shutdown.py Tue Oct 16 17:29:26 2007 -0400 @@ -30,13 +30,10 @@ 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']) +### +# Extrinsic functions +### + # Invoke RequestStateChange on vm def ChangeState(state, VM_Inst): @@ -53,12 +50,10 @@ def ChangeState(state, VM_Inst): pass time.sleep(5) - EnumerateCSInstnaces() # Destroy vm -def DestroyVM(VM_Inst): - vsms = conn.EnumerateInstanceNames("Xen_VirtualSystemManagementService") - in_params = {'AffectedSystem': new_vm} +def DestroyVM(vsms, VM_Inst): + in_params = {'AffectedSystem': VM_Inst} try: # Destroy VM @@ -73,7 +68,18 @@ def DestroyVM(VM_Inst): sys.exit(1) time.sleep(5) - EnumerateCSInstnaces() + +### +# Helper 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']) # Find vm created by this test def FindVM(VM_Name): @@ -87,7 +93,8 @@ def FindVM(VM_Name): 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 @@ -95,22 +102,23 @@ pw='password' pw='password' conn = pywbem.WBEMConnection('http://localhost', (user,pw)) - +vsms = conn.EnumerateInstanceNames("Xen_VirtualSystemManagementService") + new_vm = None new_vm = FindVM('xen-cim-test-12345') -print 'Stopping VM ...(state=3)' +print 'Stopping VM xen-cim-test-12345 (state=3)' ChangeState(3, new_vm) -print 'Destroying VM ...' -DestroyVM(new_vm) +print 'Destroying VM' +DestroyVM(vsms, new_vm) # Find second vm created by this test new_vm = FindVM('xen-cim-test-67890') -print 'Stopping VM ...(state=3)' +print 'Stopping VM xen-cim-test-67890 (state=3)' ChangeState(3, new_vm) -print 'Destroying VM ...' -DestroyVM(new_vm) +print 'Destroying VM' +DestroyVM(vsms, new_vm)