Skip to content

Commit

Permalink
Fixes #6476 - oVirt VM association with multiple interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
treydock authored and Dominic Cleal committed Aug 15, 2014
1 parent a52580f commit 5743465
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/compute_resources/foreman/model/ovirt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def update_required?(old_attrs, new_attrs)
end

def associated_host(vm)
Host.authorized(:view_hosts, Host).where(:mac => vm.mac).first
Host.authorized(:view_hosts, Host).where(:mac => vm.interfaces.map { |i| i.mac }).first
end

def self.provider_friendly_name
Expand Down
12 changes: 12 additions & 0 deletions test/unit/compute_resources/ovirt_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'test_helper'

class OvirtTest < ActiveSupport::TestCase
test "#associated_host matches any NIC" do
host = FactoryGirl.create(:host, :mac => 'ca:d0:e6:32:16:97')
cr = FactoryGirl.build(:ovirt_cr)
iface1 = mock('iface1', :mac => '36:48:c5:c9:86:f2')
iface2 = mock('iface2', :mac => 'ca:d0:e6:32:16:97')
vm = mock('vm', :interfaces => [iface1, iface2])
assert_equal host, as_admin { cr.associated_host(vm) }
end
end

0 comments on commit 5743465

Please sign in to comment.