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

Commit

Permalink
Merge pull request #53 from petems/update_fact_to_handle_partitions
Browse files Browse the repository at this point in the history
Updates swap file fact to only show swap files
  • Loading branch information
petems committed Apr 22, 2016
2 parents 043af82 + 9ecea6f commit a0b4715
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
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

0 comments on commit a0b4715

Please sign in to comment.