Skip to content
This repository has been archived by the owner on Jun 19, 2020. It is now read-only.

Commit

Permalink
(FACT-2590) Add Rhel to hierarchy.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bogdan Irimie committed Apr 29, 2020
1 parent 3eae28e commit 97b0219
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
12 changes: 10 additions & 2 deletions lib/framework/detector/os_detector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class OsDetector
attr_reader :identifier, :version, :hierarchy

def initialize(*_args)
@log = Facter::Log.new(self)
@os_hierarchy = Facter::OsHierarchy.new
@identifier = detect
end
Expand Down Expand Up @@ -39,8 +40,15 @@ def detect

def detect_hierarchy(identifier)
hierarchy = @os_hierarchy.construct_hierarchy(identifier)
hierarchy = @os_hierarchy.construct_hierarchy(detect_family) if hierarchy.empty?
hierarchy = @os_hierarchy.construct_hierarchy(:linux) if hierarchy.empty?
if hierarchy.empty?
@log.debug("Could not detect hierarchy using os identifier: #{identifier} , trying with family")
hierarchy = @os_hierarchy.construct_hierarchy(detect_family)
end

if hierarchy.empty?
@log.debug("Could not detect hierarchy using family #{detect_family}, falling back to Linux")
hierarchy = @os_hierarchy.construct_hierarchy(:linux)
end

hierarchy
end
Expand Down
3 changes: 2 additions & 1 deletion os_hierarchy.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"El": [
"Fedora",
"Amzn",
"Centos"
"Centos",
"Rhel"
]
},
{
Expand Down
2 changes: 2 additions & 0 deletions spec/framework/detector/os_detector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

describe OsDetector do
let(:os_hierarchy) { instance_spy(Facter::OsHierarchy) }
let(:logger) { instance_spy(Facter::Log) }

before do
Singleton.__init__(OsDetector)

allow(Facter::Log).to receive(:new).and_return(logger)
allow(Facter::OsHierarchy).to receive(:new).and_return(os_hierarchy)
end

Expand Down

0 comments on commit 97b0219

Please sign in to comment.