Skip to content

Commit

Permalink
Fix array access with moref as array key
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Apr 3, 2018
1 parent 67060ee commit b3049f0
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,14 @@ def get_array_entry(array, key)
return nil, nil unless array.kind_of?(Array)

array.each_index do |n|
h = array[n]
case h
when RbVmomi::BasicTypes::DataObject
return array, n if h.respond_to?("key") && h.key.to_s == key
array_entry = array[n]

entry_key = array_entry.respond_to?("key") ? array_entry.key : array_entry
case entry_key
when RbVmomi::BasicTypes::ManagedObject
return array, n if h._ref == key
return array, n if entry_key._ref == key
else
return array, n if entry_key.to_s == key
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,56 @@
device_keys = props[:config][:hardware][:device].map(&:key)
expect(device_keys).not_to include(2000)
end

it "assigns to array with a ref as an array key" do
datastore = RbVmomi::VIM.Datastore(nil, "datastore-1")
datastore_host = [
RbVmomi::VIM.DatastoreHostMount(
:key => RbVmomi::VIM.HostSystem(nil, "host-815"),
:mountInfo => RbVmomi::VIM.HostMountInfo(
:path => "/vmfs/volumes/b4db3893-29a32816",
:accessMode => "readWrite",
:mounted => true,
:accessible => true
)
),
RbVmomi::VIM.DatastoreHostMount(
:key => RbVmomi::VIM.HostSystem(nil, "host-244"),
:mountInfo => RbVmomi::VIM.HostMountInfo(
:path => "/vmfs/volumes/b4db3893-29a32816",
:accessMode => "readWrite",
:mounted => true,
:accessible => true
)
),
]

initial_change_set = [
RbVmomi::VIM.PropertyChange(:dynamicProperty => [], :name => "host", :op => "assign", :val => datastore_host),
]

cache.insert(datastore, initial_change_set)

update_change_set = [
RbVmomi::VIM::PropertyChange(
:dynamicProperty => [],
:name => "host[\"host-244\"].mountInfo",
:op => "assign",
:val => RbVmomi::VIM::HostMountInfo(
:dynamicProperty => [],
:path => "/vmfs/volumes/b4db3893-29a32816",
:accessMode => "readWrite",
:mounted => false,
:accessible => false
)
)
]

props = cache.update(datastore, update_change_set)

host_mount = props[:host].detect { |h| h.key._ref == "host-244" }
expect(host_mount.mountInfo.props).to include(:mounted => false, :accessible => false)
end
end
end
end

0 comments on commit b3049f0

Please sign in to comment.