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

(FACT-2590) No facts are displayed on Redhat 5 and Centos6 #484

Merged
merged 4 commits into from
Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Comment on lines +44 to +51
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you write a test for these new messages?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added tests for debug messages.


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
30 changes: 30 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 Expand Up @@ -169,6 +171,26 @@
expect(OsDetector.instance.identifier).to eq(:my_linux_distro)
end

context 'when no hierarchy for os identifier' do
it 'logs debug message' do
OsDetector.instance

expect(logger)
.to have_received(:debug)
.with('Could not detect hierarchy using os identifier: my_linux_distro , trying with family')
end
end

context 'when no os family detected' do
it 'logs debug message' do
OsDetector.instance

expect(logger)
.to have_received(:debug)
.with('Could not detect hierarchy using family , falling back to Linux')
end
end

it 'constructs hierarchy with linux' do
expect(OsDetector.instance.hierarchy).to eq(['linux'])
end
Expand All @@ -183,6 +205,14 @@
it 'constructs hierarchy with linux' do
expect(OsDetector.instance.hierarchy).to eq(%w[Linux Debian Ubuntu])
end

it 'logs debug message' do
OsDetector.instance

expect(logger)
.to have_received(:debug)
.with('Could not detect hierarchy using os identifier: my_linux_distro , trying with family')
end
end
end
end
Expand Down