require 'test/unit' require 'rbvmomi' VIM = RbVmomi::VIM unless Object.const_defined? :VIM class DeserializationTest < Test::Unit::TestCase def setup @soap = VIM.new(:ns => 'urn:vim25', :rev => '4.0') end def check str, expected, type got = @soap.xml2obj Nokogiri(str).root, type assert_equal expected, got end def test_moref check <<-EOS, VIM.Folder(nil, 'ha-folder-root'), 'Folder' ha-folder-root EOS check <<-EOS, VIM.Datacenter(nil, 'ha-datacenter'), 'ManagedObjectReference' ha-datacenter EOS end def test_dataobject obj = VIM.DatastoreSummary( :capacity => 1000, :accessible => true, :datastore => VIM.Datastore(nil, "foo"), :freeSpace => 31, :multipleHostAccess => false, :name => "baz", :type => "VMFS", :url => "http://foo/", :dynamicProperty => [] ) check <<-EOS, obj, 'DatastoreSummary' 1000 1 foo 31 false baz VMFS http://foo/ EOS end def test_enum check <<-EOS, 'add', 'ConfigSpecOperation' add EOS end def test_array obj = VIM.ObjectContent( :obj => VIM.Folder(nil, 'ha-folder-root'), :dynamicProperty => [], :missingSet => [], :propSet => [ VIM.DynamicProperty( :name => 'childEntity', :val => [ VIM.Datacenter(nil, 'ha-datacenter') ] ) ] ) check <<-EOS, obj, 'ObjectContent' ha-folder-root childEntity ha-datacenter EOS end def test_array2 obj = VIM.DVPortStatus( :dynamicProperty => [], :linkUp => true, :blocked => false, :vlanIds => [ VIM::NumericRange(:dynamicProperty => [], :start => 5, :end => 7), VIM::NumericRange(:dynamicProperty => [], :start => 10, :end => 20), ], :vmDirectPathGen2InactiveReasonNetwork => [], :vmDirectPathGen2InactiveReasonOther => [] ) check <<-EOS, obj, 'DVPortStatus' 1 false 5 7 10 20 EOS end def test_empty_array obj = VIM.DVPortStatus( :dynamicProperty => [], :linkUp => true, :blocked => false, :vlanIds => [], :vmDirectPathGen2InactiveReasonNetwork => [], :vmDirectPathGen2InactiveReasonOther => [] ) check <<-EOS, obj, 'DVPortStatus' 1 false EOS end def test_fault obj = VIM.LocalizedMethodFault( :localizedMessage => "The attempted operation cannot be performed in the current state (Powered off).", :fault => VIM.InvalidPowerState( :requestedState => 'poweredOn', :existingState => 'poweredOff', :faultMessage => [] ) ) check <<-EOS, obj, "LocalizedMethodFault" poweredOn poweredOff The attempted operation cannot be performed in the current state (Powered off). EOS end def test_wait_for_updates obj = VIM.UpdateSet( :version => '7', :dynamicProperty => [], :filterSet => [ VIM.PropertyFilterUpdate( :dynamicProperty => [], :filter => VIM.PropertyFilter(nil, "session[528BA5EB-335B-4AF6-B49C-6160CF5E8D5B]71E3AC7E-7927-4D9E-8BC3-522769F22DAF"), :missingSet => [], :objectSet => [ VIM.ObjectUpdate( :dynamicProperty => [], :kind => 'enter', :obj => VIM.VirtualMachine(nil, 'vm-1106'), :missingSet => [], :changeSet => [ VIM.PropertyChange( :dynamicProperty => [], :name => 'runtime.powerState', :op => 'assign', :val => 'poweredOn' ) ] ) ] ) ] ) check <<-EOS, obj, "UpdateSet" 7 session[528BA5EB-335B-4AF6-B49C-6160CF5E8D5B]71E3AC7E-7927-4D9E-8BC3-522769F22DAF enter vm-1106 runtime.powerState assign poweredOn EOS end def test_binary obj = "\x00foo\x01bar\x02baz" check <<-EOS, obj, 'xsd:base64Binary' AGZvbwFiYXICYmF6 EOS end def test_hba obj = VIM::HostBlockHba( :dynamicProperty => [], :key => 'key-vim.host.BlockHba-vmhba0', :device => 'vmhba0', :bus => 0, :status => 'unknown', :model => 'Virtual Machine Chipset', :driver => 'ata_piix', :pci => '00:07.1') check <<-EOS, obj, "HostBlockHba" key-vim.host.BlockHba-vmhba0 vmhba0 0 unknown Virtual Machine Chipset ata_piix 00:07.1 EOS end =begin def test_runtime_state obj = VIM::VirtualMachineDeviceRuntimeInfoVirtualEthernetCardRuntimeState( :dynamicProperty => [], vmDirectPathGen2:Active => false, vmDirectPathGen2:InactiveReasonOther => ["vmNptIncompatibleHost"], vmDirectPathGen2:InactiveReasonVm => [] ) check <<-EOS, obj, 'VirtualMachineDeviceRuntimeInfoDeviceRuntimeState' false vmNptIncompatibleHost EOS end =end def test_runtime_info obj = VIM::VirtualMachineRuntimeInfo( :bootTime => Time.parse('2010-08-20 05:44:35 UTC'), :connectionState => "connected", :dynamicProperty => [], :faultToleranceState => "notConfigured", :host => VIM::HostSystem(nil, "host-32"), :maxCpuUsage => 5612, :maxMemoryUsage => 3072, :memoryOverhead => 128671744, :numMksConnections => 1, :powerState => "poweredOn", :recordReplayState => "inactive", :suspendInterval => 0, :toolsInstallerMounted => false, :device => [] ) check <<-EOS, obj, 'VirtualMachineRuntimeInfo' host-32 connected poweredOn notConfigured false 2010-08-20T05:44:35.0Z 0 128671744 5612 3072 1 inactive EOS end end