diff --git a/lib/framework/detector/os_detector.rb b/lib/framework/detector/os_detector.rb index 1a1ad8fb1..01a5baab5 100644 --- a/lib/framework/detector/os_detector.rb +++ b/lib/framework/detector/os_detector.rb @@ -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 @@ -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 diff --git a/os_hierarchy.json b/os_hierarchy.json index f8f523596..5fa482fc2 100644 --- a/os_hierarchy.json +++ b/os_hierarchy.json @@ -12,7 +12,8 @@ "El": [ "Fedora", "Amzn", - "Centos" + "Centos", + "Rhel" ] }, { diff --git a/spec/framework/detector/os_detector_spec.rb b/spec/framework/detector/os_detector_spec.rb index 190156255..a354876e7 100644 --- a/spec/framework/detector/os_detector_spec.rb +++ b/spec/framework/detector/os_detector_spec.rb @@ -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 @@ -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 @@ -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