Skip to content

Commit

Permalink
Use vm_ems_ref to reconnect events
Browse files Browse the repository at this point in the history
Events delivered early in a VM's lifecycle often do not contain the
vmPathName yet and therefore cannot be connected to VMs which are saved
after the events are processed.  It is much more reliable to use the
VM's ems_ref since that is available in all tasks and events except the
initial CreateVM_Task/CloneVM_Task (since the target VM hasn't been
created yet it isn't possible to link these to a VM anyway).

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1428797
  • Loading branch information
agrare committed Mar 13, 2018
1 parent 4d5a753 commit 1cfd5eb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 8 additions & 1 deletion app/models/ems_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,13 @@ def manager_refresh_targets

private

def self.event_allowed_ems_ref_keys
%w(vm_ems_ref dest_vm_ems_ref)
end
private_class_method :event_allowed_ems_ref_keys

def self.create_event(event)
event.delete_if { |k,| k.to_s.ends_with?("_ems_ref") }
event.delete_if { |k,| k.to_s.ends_with?("_ems_ref") && !event_allowed_ems_ref_keys.include?(k.to_s) }

new_event = EmsEvent.create(event) unless EmsEvent.exists?(
:event_type => event[:event_type],
Expand Down Expand Up @@ -270,6 +275,7 @@ def self.create_completed_event(event, orig_task = nil)
:host_id => source_event.host_id,
:vm_name => source_event.vm_name,
:vm_location => source_event.vm_location,
:vm_ems_ref => source_event.vm_ems_ref,
:vm_or_template_id => source_event.vm_or_template_id
}
new_event[:username] = event.username unless event.username.blank?
Expand All @@ -284,6 +290,7 @@ def self.create_completed_event(event, orig_task = nil)
:dest_host_id => dest_event.host_id,
:dest_vm_name => dest_event.send("#{dest_key}vm_name"),
:dest_vm_location => dest_event.send("#{dest_key}vm_location"),
:dest_vm_ems_ref => dest_event.send("#{dest_key}vm_ems_ref"),
:dest_vm_or_template_id => dest_event.send("#{dest_key}vm_or_template_id")
)
end
Expand Down
6 changes: 3 additions & 3 deletions app/models/vm_or_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -823,19 +823,19 @@ def ems_host_list
end

def reconnect_events
events = EmsEvent.where("(vm_location = ? AND vm_or_template_id IS NULL) OR (dest_vm_location = ? AND dest_vm_or_template_id IS NULL)", path, path)
events = EmsEvent.where("ems_id = ? AND ((vm_ems_ref = ? AND vm_or_template_id IS NULL) OR (dest_vm_ems_ref = ? AND dest_vm_or_template_id IS NULL))", ext_management_system.id, ems_ref, ems_ref)
events.each do |e|
do_save = false

src_vm = e.src_vm_or_template
if src_vm.nil? && e.vm_location == path
if src_vm.nil? && e.vm_ems_ref == ems_ref
src_vm = self
e.vm_or_template_id = src_vm.id
do_save = true
end

dest_vm = e.dest_vm_or_template
if dest_vm.nil? && e.dest_vm_location == path
if dest_vm.nil? && e.dest_vm_ems_ref == ems_ref
dest_vm = self
e.dest_vm_or_template_id = dest_vm.id
do_save = true
Expand Down

0 comments on commit 1cfd5eb

Please sign in to comment.