Skip to content
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
4 changes: 2 additions & 2 deletions lib/facter/resolvers/dmi_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ def read_facts(fact_name)

file_content = Util::FileHelper.safe_read("/sys/class/dmi/id/#{fact_name}", nil)
if files.include?(fact_name.to_s) && file_content
@fact_list[fact_name] = file_content.strip
file_content = file_content.strip
@fact_list[fact_name] = file_content unless file_content.empty?
chassis_to_name(@fact_list[fact_name]) if fact_name == :chassis_type

end
@fact_list[fact_name]
end
Expand Down
14 changes: 10 additions & 4 deletions lib/facter/resolvers/networking_linux_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,14 @@ def find_dhcp!(tokens, network_info)
return if !network_info[interface_name] || network_info[interface_name][:dhcp]

index = tokens[0].delete(':')
dhcp = Util::FileHelper.safe_read("/run/systemd/netif/leases/#{index}", nil)
network_info[interface_name][:dhcp] = dhcp.match(/SERVER_ADDRESS=(.*)/)[1] if dhcp
network_info[interface_name][:dhcp] ||= retrieve_from_other_directories(interface_name)
file_content = Util::FileHelper.safe_read("/run/systemd/netif/leases/#{index}", nil)
dhcp = file_content.match(/SERVER_ADDRESS=(.*)/) if file_content
if dhcp
network_info[interface_name][:dhcp] = dhcp[1]
else
alternate_dhcp = retrieve_from_other_directories(interface_name)
network_info[interface_name][:dhcp] = alternate_dhcp if alternate_dhcp
end
end

def retrieve_from_other_directories(interface_name)
Expand All @@ -75,7 +80,8 @@ def retrieve_from_other_directories(interface_name)
content = Util::FileHelper.safe_read("#{dir}#{file}", nil)
next unless content =~ /interface.*#{interface_name}/

return content.match(/dhcp-server-identifier ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/)[1]
dhcp = content.match(/dhcp-server-identifier ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/)
return dhcp[1] if dhcp
end
end
return unless File.readable?('/var/lib/NetworkManager/')
Expand Down
9 changes: 9 additions & 0 deletions spec/facter/resolvers/dmi_resolver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@
end
end

context 'when board_asset_tag file exists but is empty' do
let(:file_content) { "\n" }
let(:file) { 'board_asset_tag' }

it 'returns board_manufacturer' do
expect(resolver.resolve(:board_asset_tag)).to be(nil)
end
end

context 'when board_name file exists' do
let(:file_content) { '440BX Desktop Reference Platform' }
let(:file) { 'board_name' }
Expand Down
2 changes: 0 additions & 2 deletions spec/facter/resolvers/networking_linux_resolver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@
bindings6: [
{ address: '::1', netmask: 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', network: '::1' }
],
dhcp: nil,
ip: '127.0.0.1',
ip6: '::1',
mtu: 65_536,
Expand All @@ -190,7 +189,6 @@
bindings6: [
{ address: 'fe80::250:56ff:fe9a:8481', netmask: 'ffff:ffff:ffff:ffff::', network: 'fe80::' }
],
dhcp: nil,
ip: '10.16.119.155',
ip6: 'fe80::250:56ff:fe9a:8481',
mac: '00:50:56:9a:61:46',
Expand Down