Rename free to free_kb

Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
This commit is contained in:
Clinton Wolfe 2019-02-01 00:46:18 -05:00
parent 5bbd4c16d6
commit 02cb799ee6
3 changed files with 15 additions and 13 deletions

View file

@ -19,6 +19,8 @@ This resource is distributed along with InSpec itself. You can use it automatica
This resource first became available in v1.51.0 of InSpec. This resource first became available in v1.51.0 of InSpec.
The `free_kb`, `size_kb`, and `type` properties became available in v3.6 of InSpec.
### Note ### Note
Versions of this resource in InSpec prior to 3.5.x offered a property `size`, which returned a value in GB when on Windows and a value in KB on Linux, though it was documented to always return KB. All new code should use `size_kb` which is unit-stable. Versions of this resource in InSpec prior to 3.5.x offered a property `size`, which returned a value in GB when on Windows and a value in KB on Linux, though it was documented to always return KB. All new code should use `size_kb` which is unit-stable.
@ -28,8 +30,8 @@ Versions of this resource in InSpec prior to 3.5.x offered a property `size`, wh
A `filesystem` resource block declares tests for disk space in a partition: A `filesystem` resource block declares tests for disk space in a partition:
describe filesystem('/') do describe filesystem('/') do
its('size_kb') { should be >= 32000 } its('size_kb') { should be >= 32 * 1024 * 1024}
its('free') { should be >= 5000000 } its('free_kb') { should be >= 50 * 1024 }
its('percent_free') { should be >= 20 } its('percent_free') { should be >= 20 }
its('type') { should cmp 'ext4' } its('type') { should cmp 'ext4' }
end end
@ -38,7 +40,7 @@ where
* `filesystem('/')` states that the resource will look at the root (/) partition. * `filesystem('/')` states that the resource will look at the root (/) partition.
* `size_kb` is the total partition size and is measured in kilobytes (KB). * `size_kb` is the total partition size and is measured in kilobytes (KB).
* `free` is the available space on the partition and is measured in kilobytes (KB). * `free_kb` is the available space on the partition and is measured in kilobytes (KB).
* `percent_free` is the percentage of available free space, and ranges from 0 to 100. * `percent_free` is the percentage of available free space, and ranges from 0 to 100.
<br> <br>
@ -58,7 +60,7 @@ The following examples show how to use this InSpec audit resource.
### Test that the root partition has more than 5GB free ### Test that the root partition has more than 5GB free
describe filesystem('/') do describe filesystem('/') do
its('free') { should be >= 5000000 } its('free_kb') { should be >= 5000000 }
end end
<br> <br>

View file

@ -6,14 +6,14 @@ module Inspec::Resources
desc 'Use the filesystem InSpec resource to test file system' desc 'Use the filesystem InSpec resource to test file system'
example " example "
describe filesystem('/') do describe filesystem('/') do
its('size') { should be >= 32000 } its('size_kb') { should be >= 32000 }
its('free') { should be >= 3200 } its('free_kb') { should be >= 3200 }
its('type') { should cmp 'ext4' } its('type') { should cmp 'ext4' }
its('percent_free') { should be >= 20 } its('percent_free') { should be >= 20 }
end end
describe filesystem('c:') do describe filesystem('c:') do
its('size') { should be >= 90 } its('size_kb') { should be >= 9000 }
its('free') { should be >= 3200 } its('free_kb') { should be >= 3200 }
its('type') { should cmp 'NTFS' } its('type') { should cmp 'NTFS' }
its('percent_free') { should be >= 20 } its('percent_free') { should be >= 20 }
end end
@ -63,13 +63,13 @@ module Inspec::Resources
end end
end end
def free def free_kb
info = @fsman.info(@partition) info = @fsman.info(@partition)
info[:free_kb] info[:free_kb]
end end
def percent_free def percent_free
100 * free / size_kb 100 * free_kb / size_kb
end end
def type def type

View file

@ -9,18 +9,18 @@ describe 'Inspec::Resources::FileSystemResource' do
_(resource.size).must_equal 30428648 _(resource.size).must_equal 30428648
_(resource.name).must_equal '/' _(resource.name).must_equal '/'
_(resource.type).must_equal 'ext4' _(resource.type).must_equal 'ext4'
_(resource.free).must_equal 20760728 _(resource.free_kb).must_equal 20760728
_(resource.percent_free).must_equal 68 _(resource.percent_free).must_equal 68
end end
# arch windows # windows
it 'verify filesystem on windows' do it 'verify filesystem on windows' do
resource = MockLoader.new(:windows).load_resource('filesystem','c:') resource = MockLoader.new(:windows).load_resource('filesystem','c:')
_(resource.size).must_equal 38 # Windows size() had a bug that turned it into GB, not KB _(resource.size).must_equal 38 # Windows size() had a bug that turned it into GB, not KB
_(resource.size_kb).must_equal 40000000 # approx 38 GB _(resource.size_kb).must_equal 40000000 # approx 38 GB
_(resource.name).must_equal 'c:' _(resource.name).must_equal 'c:'
_(resource.type).must_equal 'NTFS' _(resource.type).must_equal 'NTFS'
_(resource.free).must_equal 30000000 _(resource.free_kb).must_equal 30000000
_(resource.percent_free).must_equal 75 _(resource.percent_free).must_equal 75
end end