Jira (FACT-2497) Facts are resolved multiple times

0 views
Skip to first unread message

Romain Tartière

unread,
Mar 25, 2020, 4:07:04 PM3/25/20
to puppe...@googlegroups.com
Romain Tartière created an issue
 
Facter / Bug FACT-2497
Facts are resolved multiple times
Issue Type: Bug Bug
Affects Versions: FACT 4.0.13
Assignee: Unassigned
Created: 2020/03/25 1:06 PM
Priority: Normal Normal
Reporter: Romain Tartière

Puppet Version: N/A — 6.14.0
Puppet Server Version: N/A — 6.9.2
OS Name/Version: FreeBSD

While adding support of FreeBSD to facter-ng, we discovered that the fact resolution was not behaving as expected. Inspecting the resolved facts after this line:

https://github.com/puppetlabs/facter-ng/blob/6323e3b6ef72271aa8176ad9662d649dc5442a53/lib/framework/core/fact/internal/internal_fact_manager.rb#L40

shows that a single fact (os.release) was resolved with by the Solaris and the Bsd providers, and they have been resolved multiple times (at the time of writting, the bsd provider is not part of facter yet):

puts resolved_facts.select { |r| r.name == 'os.release' }.map(&:value)

{{

{"full"=>nil, "major"=>nil, "minor"=>nil} {"full"=>"12.1-RELEASE-p3", "major"=>"12", "minor"=>"1", "branch"=>"RELEASE-p3", "patchlevel"=>"3"}{"full"=>nil, "major"=>nil, "minor"=>nil} {"full"=>"12.1-RELEASE-p3", "major"=>"12", "minor"=>"1", "branch"=>"RELEASE-p3", "patchlevel"=>"3"} {"full"=>nil, "major"=>nil, "minor"=>nil}{"full"=>"12.1-RELEASE-p3", "major"=>"12", "minor"=>"1", "branch"=>"RELEASE-p3", "patchlevel"=>"3"} {"full"=>nil, "major"=>nil, "minor"=>nil} {"full"=>"12.1-RELEASE-p3", "major"=>"12", "minor"=>"1", "branch"=>"RELEASE-p3", "patchlevel"=>"3"}{"full"=>nil, "major"=>nil, "minor"=>nil} {"full"=>"12.1-RELEASE-p3", "major"=>"12", "minor"=>"1", "branch"=>"RELEASE-p3", "patchlevel"=>"3"} {"full"=>nil, "major"=>nil, "minor"=>nil}{"full"=>"12.1-RELEASE-p3", "major"=>"12", "minor"=>"1", "branch"=>"RELEASE-p3", "patchlevel"=>"3"}

}}

Desired Behavior:

The fact should be resolved only once and only with the appropriate provider.

Actual Behavior:

Facts are resolved by multiple providers multiple times.

Current WIP FreeBSD provider for os.release :

{{# frozen_string_literal: true

module Facts
module Bsd
module Os
class Release
FACT_NAME = 'os.release'
ALIASES = %w[operatingsystemmajrelease operatingsystemrelease].freeze

def call_the_resolver
puts "#

{Thread.current}

FREE"
/(?<full_value>(?<major_value>\d+)\.(?<minor_value>\d+)-(?<branch_value>CURRENT|STABLE|RELEASE(-p(?<patchlevel_value>\d+))?))/ =~ `/bin/freebsd-version`

[Facter::ResolvedFact.new(FACT_NAME, full: full_value, major: major_value, minor: minor_value, branch: branch_value, patchlevel: patchlevel_value),
Facter::ResolvedFact.new(ALIASES.first, major_value, :legacy),
Facter::ResolvedFact.new(ALIASES.last, full_value, :legacy)]
end
end
end
end
end
}}

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v8.5.2#805002-sha1:a66f935)
Atlassian logo

Romain Tartière

unread,
Mar 25, 2020, 4:11:04 PM3/25/20
to puppe...@googlegroups.com
Romain Tartière updated an issue
Change By: Romain Tartière
*Puppet Version:* N/A — 6.14.0
*Puppet Server Version:* N/A — 6.9.2
*OS Name/Version:* FreeBSD


While adding support of FreeBSD to facter-ng, we discovered that the fact resolution was not behaving as expected. Inspecting the resolved facts after this line:

[ https://github.com/puppetlabs/facter-ng/blob/6323e3b6ef72271aa8176ad9662d649dc5442a53/lib/framework/core/fact/internal/internal_fact_manager.rb#L40 ]

shows that a single fact (os.release) was resolved with by the Solaris and the Bsd providers, and they have been resolved multiple times (at the time of writting, the bsd provider is not part of facter yet):

{{puts resolved_facts.select \{ |r| r.name == 'os.release'
\ }.map(&:value)}}

{{


{"full"=>nil, "major"=>nil, "minor"=>nil}
\ {"full"=>"12.1-RELEASE-p3", "major"=>"12", "minor"=>"1", "branch"=>"RELEASE-p3", "patchlevel"=>"3"}
{"full"=>nil, "major"=>nil, "minor"=>nil}
\ {"full"=>"12.1-RELEASE-p3", "major"=>"12", "minor"=>"1", "branch"=>"RELEASE-p3", "patchlevel"=>"3"}
\ {"full"=>nil, "major"=>nil, "minor"=>nil}
{"full"=>"12.1-RELEASE-p3", "major"=>"12", "minor"=>"1", "branch"=>"RELEASE-p3", "patchlevel"=>"3"}
\ {"full"=>nil, "major"=>nil, "minor"=>nil}
\ {"full"=>"12.1-RELEASE-p3", "major"=>"12", "minor"=>"1", "branch"=>"RELEASE-p3", "patchlevel"=>"3"}
{"full"=>nil, "major"=>nil, "minor"=>nil}
\ {"full"=>"12.1-RELEASE-p3", "major"=>"12", "minor"=>"1", "branch"=>"RELEASE-p3", "patchlevel"=>"3"}
\ {"full"=>nil, "major"=>nil, "minor"=>nil}
{"full"=>"12.1-RELEASE-p3", "major"=>"12", "minor"=>"1", "branch"=>"RELEASE-p3", "patchlevel"=>"3"}

}}

*Desired Behavior:*


The fact should be resolved only once and only with the appropriate provider.

*Actual Behavior:*


Facts are resolved by multiple providers multiple times.

Current WIP FreeBSD provider for os.release :

{{# frozen_string_literal: true

module Facts
  module Bsd
    module Os
      class Release
        FACT_NAME = 'os.release'
        ALIASES = %w[operatingsystemmajrelease operatingsystemrelease].freeze

        def call_the_resolver
          puts "#{Thread.current} FREE"
          /(?<full_value>(?<major_value>\d+)\.(?<minor_value>\d+)-(?<branch_value>CURRENT|STABLE|RELEASE(-p(?<patchlevel_value>\d+))?))/ =~ `/bin/freebsd-version`

          [Facter::ResolvedFact.new(FACT_NAME, full: full_value, major: major_value, minor: minor_value, branch: branch_value, patchlevel: patchlevel_value),
           Facter::ResolvedFact.new(ALIASES.first, major_value, :legacy),
           Facter::ResolvedFact.new(ALIASES.last, full_value, :legacy)]
        end
      end
    end
  end
end
}}

Oana Tanasoiu (Jira)

unread,
Mar 25, 2020, 4:11:04 PM3/25/20
to puppe...@googlegroups.com
Oana Tanasoiu updated an issue
Change By: Oana Tanasoiu
Sub-team: ghost
Team: Night's Watch

Bogdan Irimie (Jira)

unread,
Mar 25, 2020, 5:05:04 PM3/25/20
to puppe...@googlegroups.com
Bogdan Irimie assigned an issue to Bogdan Irimie
Change By: Bogdan Irimie
Assignee: Bogdan Irimie

Bogdan Irimie (Jira)

unread,
Mar 26, 2020, 6:04:02 AM3/26/20
to puppe...@googlegroups.com
Bogdan Irimie commented on Bug FACT-2497
 
Re: Facts are resolved multiple times

Romain Tartière thank you for reporting the issue.

There seem to be two distinct problems:

  1. the internal fact loader loads all facts from hierarchy, even facts that are duplicated
  2. facts with aliases are resolved multiple times

I have broken the issue in two subtask.

Bogdan Irimie (Jira)

unread,
Mar 31, 2020, 10:43:04 AM3/31/20
to puppe...@googlegroups.com

Romain Tartière today we merged https://tickets.puppetlabs.com/browse/FACT-2498 into master. This PR resolved the loading order of facts when using a OS hierarchy. You should be able to override facts from Solaris in Bsd, please let me know if it works for you.

Romain Tartière

unread,
Mar 31, 2020, 1:13:03 PM3/31/20
to puppe...@googlegroups.com

Awesome, after rebasing my work on top of master, the right values are collected!

Thanks!

Reply all
Reply to author
Forward
0 new messages