diff --git a/lib/facter/lldp.rb b/lib/facter/lldp.rb index af2aa76..44f4e40 100644 --- a/lib/facter/lldp.rb +++ b/lib/facter/lldp.rb @@ -7,7 +7,8 @@ class MalformedDataError < StandardError; end Facter.add(:lldp) do confine do - Facter::Util::Resolution.which('lldpctl') + Facter::Util::Resolution.which('lldpctl') && + File.exist?('/run/lldpd/lldpd.socket') end setcode do diff --git a/spec/unit/facter/lldp_spec.rb b/spec/unit/facter/lldp_spec.rb index d3a10e2..624ca1c 100644 --- a/spec/unit/facter/lldp_spec.rb +++ b/spec/unit/facter/lldp_spec.rb @@ -170,14 +170,25 @@ context 'lldpctl not in path' do before do + allow(File).to receive(:exist?).with('/run/lldpd/lldpd.socket').and_return(true) allow(Facter::Util::Resolution).to receive(:which).with('lldpctl').and_return(nil) end it { expect(Facter.fact(:lldp).value).to eq(nil) } end + context 'lldpd not running' do + before do + allow(File).to receive(:exist?).with('/run/lldpd/lldpd.socket').and_return(false) + allow(Facter::Util::Resolution).to receive(:which).with('lldpctl').and_return('/usr/sbin/lldpctl') + end + + it { expect(Facter.fact(:lldp).value).to eq(nil) } + end + context 'valid run' do before do + allow(File).to receive(:exist?).with('/run/lldpd/lldpd.socket').and_return(true) allow(Facter::Util::Resolution).to receive(:which).with('lldpctl').and_return('/usr/sbin/lldpctl') end