Bug #22192

Fact import code does not work with VLAN primary NIC

Added by Lukas Zapletal 6 months ago. Updated 6 months ago.

Target version:-
Difficulty: Team Backlog:
Triaged: Fixed in Releases:
Bugzilla link: Found in Releases:
Pull request:


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"=>"", "netmask"=>"", "network"=>"", "link"=>"true"}
[app|D] Discovery fact parser detected primary interface: ["eth0.2", {"macaddress"=>"52:54:00:00:00:99", "mtu"=>1500, "ipaddress"=>"", "netmask"=>"", "network"=>"", "link"=>"true", "virtual"=>true, "attached_to"=>"eth0", "tag"=>"2"}]


#1 Updated by Marek Hulán 6 months 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?

#2 Updated by Lukas Zapletal 6 months 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 => '', :virtual => false, :attached_to => "eth0", :tag => "42"}
      parser = stub(:interfaces => hash, :ipmi_interface => {}, :suggested_primary_interface => hash.to_a.last)
      assert_equal 'eth0_42', host.primary_interface.identifier
      assert_equal '00:00:00:44:55:77', host.primary_interface.mac
      assert_equal '', host.primary_interface.ip

Also available in: Atom PDF