Project

General

Profile

« Previous | Next » 

Revision a0f78f20

Added by Marek Hulán almost 9 years ago

Fixes #10607 - match bonds based on identifier only

(cherry picked from commit 7be20b248502eb8682008e1c6b03fef71da4f73d)

View differences:

app/models/host/base.rb
end
parser.interfaces.each do |name, attributes|
begin
macaddress = Net::Validations.normalize_mac(attributes[:macaddress])
rescue ArgumentError
logger.debug "invalid mac during parsing: #{attributes[:macaddress]}"
end
base = self.interfaces.where(:mac => macaddress)
if attributes[:virtual]
# for virtual devices we don't check only mac address since it's not unique,
# if we want to update the device it must have same identifier
base = base.virtual.where(:identifier => name)
else
base = base.physical
end
iface = base.first || interface_class(name).new(:managed => false)
iface = get_interface_scope(name, attributes).first || interface_class(name).new(:managed => false)
# create or update existing interface
set_interface(attributes, name, iface)
end
......
self.primary_interface.provision = true if self.provision_interface.nil?
end
def get_interface_scope(name, attributes, base = self.interfaces)
case interface_class(name).to_s
# we search bonds based on identifiers, e.g. ubuntu sets random MAC after each reboot se we can't
# rely on mac
when 'Nic::Bond'
base.virtual.where(:identifier => name)
# for other interfaces we distinguish between virtual and physical interfaces
# for virtual devices we don't check only mac address since it's not unique,
# if we want to update the device it must have same identifier
else
begin
macaddress = Net::Validations.normalize_mac(attributes[:macaddress])
rescue ArgumentError
logger.debug "invalid mac during parsing: #{attributes[:macaddress]}"
end
base = base.where(:mac => macaddress)
if attributes[:virtual]
base.virtual.where(:identifier => name)
else
base.physical
end
end
end
def set_interface(attributes, name, iface)
attributes = attributes.clone
iface.mac = attributes.delete(:macaddress)
test/unit/host_test.rb
assert_equal 'eth1', virtual.attached_to
end
test "#set_interfaces matches bonds based on identifier and even updates its mac" do
# interface with empty identifier was renamed to eth5 (same MAC)
host = FactoryGirl.create(:host, :hostgroup => FactoryGirl.create(:hostgroup), :mac => '00:00:00:11:22:33')
hash = { :bond0 => {:macaddress => 'aa:bb:cc:44:55:66', :ipaddress => '10.10.0.3', :virtual => true},
:eth5 => {:macaddress => '00:00:00:11:22:33', :ipaddress => '10.10.0.1', :virtual => false, :identifier => 'eth5'},
}.with_indifferent_access
parser = stub(:interfaces => hash, :ipmi_interface => {}, :suggested_primary_interface => hash.to_a.first)
bond0 = FactoryGirl.create(:nic_bond, :host => host, :mac => '00:00:00:44:55:66', :ip => '10.10.0.2', :identifier => 'bond0')
host.set_interfaces(parser)
host.interfaces.reload
assert_equal 1, host.interfaces.bonds.size
bond0.reload
assert_equal 'aa:bb:cc:44:55:66', bond0.mac
assert_equal '10.10.0.3', bond0.ip
end
test "#set_interfaces updates associated virtuals identifier on identifier change mutualy exclusively" do
# eth4 was renamed to eth5 and eth5 renamed to eth4
host = FactoryGirl.create(:host, :hostgroup => FactoryGirl.create(:hostgroup))

Also available in: Unified diff