Bug #22192
openFact import code does not work with VLAN primary NIC
Description
When importing a host with primary interface on VLAN, it doesn't get imported properly. Both interfaces are saved correctly, but primary_interface reference is wrong (to the non-VLAN interface eth0
instead of eth0_2
. This does not work regardless discovery installed or not (it provides its own detection mechanism).
[app|D] We have following interfaces 'eth0, eth0_2' based on facts [app|D] Interface eth0 facts: {"macaddress"=>"52:54:00:00:00:99", "mtu"=>1500, "link"=>"true"} [app|D] Interface eth0_2 facts: {"macaddress"=>"52:54:00:00:00:99", "mtu"=>1500, "ipaddress"=>"192.168.99.56", "netmask"=>"255.255.255.0", "network"=>"192.168.99.0", "link"=>"true"} [app|D] Discovery fact parser detected primary interface: ["eth0.2", {"macaddress"=>"52:54:00:00:00:99", "mtu"=>1500, "ipaddress"=>"192.168.99.56", "netmask"=>"255.255.255.0", "network"=>"192.168.99.0", "link"=>"true", "virtual"=>true, "attached_to"=>"eth0", "tag"=>"2"}]
Updated by Marek Hulán over 7 years ago
How could we tell which interface is primary? IIRC Foreman prefers physical interfaces over virtual. If you provision host from pure Foreman, you always choose which interface is primary explicit/
ly. The same issue is there though, when host is created based on facts import... perhaps in case of discovery. I thought discovery prefered interface specified in bootif. Would custom fact be a solution?
Updated by Lukas Zapletal over 7 years ago
Here is the test that is failing, put it into host_test.rb and see yourself. Will take a quick look tomorrow, but I have other priorities, so will leave it here as is:
test "#set_interfaces sets previously detected VLAN as primary interface " do host = FactoryBot.create(:host, :hostgroup => FactoryBot.create(:hostgroup), :mac => '00:00:00:11:22:33') hash = { :eth0 => {:macaddress => '00:00:00:44:55:66', :mtu => 1500, :link => true}, :eth0_42 => {:macaddress => '00:00:00:44:55:77', :ipaddress => '10.10.0.1', :virtual => false, :attached_to => "eth0", :tag => "42"} }.with_indifferent_access parser = stub(:interfaces => hash, :ipmi_interface => {}, :suggested_primary_interface => hash.to_a.last) host.set_interfaces(parser) assert_equal 'eth0_42', host.primary_interface.identifier assert_equal '00:00:00:44:55:77', host.primary_interface.mac assert_equal '10.10.0.1', host.primary_interface.ip end