Skip to content

Commit

Permalink
Merge pull request #18715 from lfu/src_vm_or_dest_host_1696889
Browse files Browse the repository at this point in the history
Add src_vm_or_dest_host_refresh_target.

(cherry picked from commit 8a87d0f)

https://bugzilla.redhat.com/show_bug.cgi?id=1712595
  • Loading branch information
Fryguy authored and simaishi committed May 22, 2019
1 parent 63c86d5 commit 5aab904
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/models/ems_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ def vm_refresh_target
end
alias_method :src_vm_refresh_target, :vm_refresh_target

def src_vm_or_dest_host_refresh_target
vm_or_template ? vm_refresh_target : dest_host_refresh_target
end

def host_refresh_target
(host && host.ext_management_system ? host : ems_refresh_target)
end
Expand Down
19 changes: 19 additions & 0 deletions spec/models/ems_event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -393,4 +393,23 @@
end
end
end

context 'refresh target' do
describe 'src_vm_or_dest_host_refresh_target' do
let(:ems) { FactoryBot.create(:ems_vmware) }
let(:vm) { FactoryBot.create(:vm_vmware, :ext_management_system => ems) }
let(:host1) { FactoryBot.create(:host, :ext_management_system => ems) }
let(:host2) { FactoryBot.create(:host, :ext_management_system => ems) }

it 'returns src_vm when it exists' do
event = FactoryBot.create(:ems_event, :vm_or_template => vm, :host => host1, :dest_host => host2)
expect(event.get_target("src_vm_or_dest_host_refresh_target")).to eq(vm)
end

it 'returns dest_host when src_vm does not exists' do
event = FactoryBot.create(:ems_event, :vm_or_template_id => 123, :host => host1, :dest_host => host2)
expect(event.get_target("src_vm_or_dest_host_refresh_target")).to eq(host2)
end
end
end
end

0 comments on commit 5aab904

Please sign in to comment.