Skip to content
Open
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
3 changes: 2 additions & 1 deletion lib/facter/lldp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions spec/unit/facter/lldp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down