Skip to content

Commit

Permalink
Merge pull request #764 from agrare/handle_missing_dvs
Browse files Browse the repository at this point in the history
Skip DV PortGroups with missing DV Switches

(cherry picked from commit 4f45103)
  • Loading branch information
Fryguy committed Dec 3, 2021
1 parent 0fd5cc8 commit 53dd634
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,19 @@ def parse_network(object, kind, props)
end
alias parse_opaque_network parse_network

def parse_distributed_virtual_portgroup(_object, kind, props)
def parse_distributed_virtual_portgroup(object, kind, props)
dvs = props.fetch_path(:config, :distributedVirtualSwitch)

# If the dvportgroup is deleted we don't want to pass kind="leave" to the
# switch parser because it will think the switch is being deleted
kind = "update" if kind == "leave"
parse_distributed_virtual_switch(dvs, kind, cache.find(dvs))

dvs_props = cache.find(dvs)
if dvs_props.nil?
_log.warn("#{object.class.wsdl_name}:#{object._ref} DVSwitch [#{dvs._ref}] not found in cache...Skipping")
else
parse_distributed_virtual_switch(dvs, kind, dvs_props)
end
end

def parse_portgroups_internal(object, props)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,11 @@
expect(new_dvpg.switch.uid_ems).to eq("dvs-8")
end

it "adding a new distributed virtual portgroup with an invalid DVS" do
expect { run_targeted_refresh(targeted_update_set([dvpg_create_invalid_object_update])) }
.not_to raise_error
end

it "deleting a distributed virtual portgroup" do
run_targeted_refresh(targeted_update_set([dvpg_delete_object_update]))

Expand Down Expand Up @@ -956,6 +961,23 @@ def dvpg_create_object_update
)
end

def dvpg_create_invalid_object_update
RbVmomi::VIM.ObjectUpdate(
:kind => "enter",
:obj => RbVmomi::VIM.DistributedVirtualPortgroup(vim, "dvportgroup-99"),
:changeSet => [
RbVmomi::VIM.PropertyChange(:name => "config.distributedVirtualSwitch", :op => "assign", :val => RbVmomi::VIM.VmwareDistributedVirtualSwitch(vim, "dvs-9999999")),
RbVmomi::VIM.PropertyChange(:name => "config.key", :op => "assign", :val => "dvportgroup-99"),
RbVmomi::VIM.PropertyChange(:name => "config.name", :op => "assign", :val => "New DVPG"),
RbVmomi::VIM.PropertyChange(:name => "host", :op => "assign", :val => []),
RbVmomi::VIM.PropertyChange(:name => "parent", :op => "assign", :val => RbVmomi::VIM.Folder(vim, "group-n6")),
RbVmomi::VIM.PropertyChange(:name => "name", :op => "assign", :val => "New DVPG"),
RbVmomi::VIM.PropertyChange(:name => "summary.name", :op => "assign", :val => "New DVPG"),
RbVmomi::VIM.PropertyChange(:name => "tag", :op => "assign", :val => [])
]
)
end

def dvpg_delete_object_update
RbVmomi::VIM.ObjectUpdate(
:kind => "leave",
Expand Down

0 comments on commit 53dd634

Please sign in to comment.