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

Updates swap file fact to only show swap files #53

Merged
merged 1 commit into from
Apr 22, 2016
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
10 changes: 7 additions & 3 deletions lib/facter/swapfile_sizes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

# Sample Output
# Filename Type Size Used Priority
# /mnt/swap.1 file 1019900 0 -1
# /tmp/swapfile.fallocate file 1019900 0 -2
# /dev/dm-1 partition 524284 0 -1
# /mnt/swap.1 file 204796 0 -2
# /tmp/swapfile.fallocate file 204796 0 -3
swap_file_output_array = swap_file_output.split("\n")

# Remove the header line
Expand All @@ -16,7 +17,10 @@

swap_file_line_array = line.gsub(/\s+/m, ' ').strip.split(" ")

swap_file_hash[swap_file_line_array[0]] = swap_file_line_array[2]
# We only want swap-file information, not paritions
if swap_file_line_array[1] == 'file'
swap_file_hash[swap_file_line_array[0]] = swap_file_line_array[2]
end

end

Expand Down
9 changes: 5 additions & 4 deletions spec/unit/facter/swapfiles_fact_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
it do
proc_swap_output = <<-EOS
Filename Type Size Used Priority
/mnt/swap.1 file 1019900 0 -1
/tmp/swapfile.fallocate file 1019900 0 -2
/dev/dm-1 partition 524284 0 -1
/mnt/swap.1 file 204796 0 -2
/tmp/swapfile.fallocate file 204796 0 -3
EOS
Facter::Util::Resolution.expects(:exec).with('cat /proc/swaps').returns(proc_swap_output)
expect(Facter.value(:swapfile_sizes)).to eq(
{
"/mnt/swap.1"=>"1019900",
"/tmp/swapfile.fallocate"=>"1019900"
"/mnt/swap.1"=>"204796",
"/tmp/swapfile.fallocate"=>"204796"
}
)
end
Expand Down