-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Utilities] Add #disk_usage #155
Merged
Fryguy
merged 1 commit into
ManageIQ:master
from
NickLaMuro:remove-miq-system-requirement
Mar 11, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
describe ManageIQ::ApplianceConsole::Utilities do | ||
context ".disk_usage(file)" do | ||
require 'fileutils' | ||
|
||
let(:file) { Pathname.new(__dir__).join("empty file").to_s } | ||
|
||
before do | ||
FileUtils.touch(file) | ||
end | ||
|
||
after do | ||
FileUtils.rm_f(file) | ||
end | ||
|
||
it "handles file with a space" do | ||
usage_hash = described_class.disk_usage(file).first | ||
expect(usage_hash[:filesystem]).to be_kind_of String | ||
expect(usage_hash[:filesystem]).to be_present | ||
expect(usage_hash[:total_bytes]).to be > 0 | ||
end | ||
end | ||
|
||
context ".disk_usage" do | ||
it "linux" do | ||
linux_df_output_bytes = <<EOF | ||
Filesystem Type 1024-blocks Used Available Capacity Mounted on | ||
/dev/mapper/fedora-root ext4 40185208 5932800 32188024 16% / | ||
devtmpfs devtmpfs 3961576 0 3961576 0% /dev | ||
tmpfs tmpfs 3969532 7332 3962200 1% /dev/shm | ||
tmpfs tmpfs 3969532 1144 3968388 1% /run | ||
tmpfs tmpfs 3969532 0 3969532 0% /sys/fs/cgroup | ||
tmpfs tmpfs 3969532 348 3969184 1% /tmp | ||
/dev/sda1 ext4 487652 131515 326441 29% /boot | ||
/dev/mapper/fedora-home ext4 192360020 9325732 173239936 6% /home | ||
EOF | ||
linux_df_output_inodes = <<EOF | ||
Filesystem Type Inodes IUsed IFree IUse% Mounted on | ||
/dev/mapper/fedora-root ext4 2564096 146929 2417167 6% / | ||
devtmpfs devtmpfs 990394 549 989845 1% /dev | ||
tmpfs tmpfs 992383 31 992352 1% /dev/shm | ||
tmpfs tmpfs 992383 726 991657 1% /run | ||
tmpfs tmpfs 992383 13 992370 1% /sys/fs/cgroup | ||
tmpfs tmpfs 992383 38 992345 1% /tmp | ||
/dev/sda1 ext4 128016 385 127631 1% /boot | ||
/dev/mapper/fedora-home ext4 12222464 488787 11733677 4% /home | ||
EOF | ||
expected = [ | ||
{ | ||
:filesystem => "/dev/mapper/fedora-root", | ||
:type => "ext4", | ||
:total_bytes => 41149652992, | ||
:used_bytes => 6075187200, | ||
:available_bytes => 32960536576, | ||
:used_bytes_percent => 16, | ||
:mount_point => "/", | ||
:total_inodes => 2564096, | ||
:used_inodes => 146929, | ||
:available_inodes => 2417167, | ||
:used_inodes_percent => 6 | ||
}, | ||
{ | ||
:filesystem => "devtmpfs", | ||
:type => "devtmpfs", | ||
:total_bytes => 4056653824, | ||
:used_bytes => 0, | ||
:available_bytes => 4056653824, | ||
:used_bytes_percent => 0, | ||
:mount_point => "/dev", | ||
:total_inodes => 990394, | ||
:used_inodes => 549, | ||
:available_inodes => 989845, | ||
:used_inodes_percent => 1 | ||
}, | ||
{ | ||
:filesystem => "tmpfs", | ||
:type => "tmpfs", | ||
:total_bytes => 4064800768, | ||
:used_bytes => 7507968, | ||
:available_bytes => 4057292800, | ||
:used_bytes_percent => 1, | ||
:mount_point => "/dev/shm", | ||
:total_inodes => 992383, | ||
:used_inodes => 38, | ||
:available_inodes => 992345, | ||
:used_inodes_percent => 1 | ||
}, | ||
{ | ||
:filesystem => "/dev/sda1", | ||
:type => "ext4", | ||
:total_bytes => 499355648, | ||
:used_bytes => 134671360, | ||
:available_bytes => 334275584, | ||
:used_bytes_percent => 29, | ||
:mount_point => "/boot", | ||
:total_inodes => 128016, | ||
:used_inodes => 385, | ||
:available_inodes => 127631, | ||
:used_inodes_percent => 1 | ||
}, | ||
{ | ||
:filesystem => "/dev/mapper/fedora-home", | ||
:type => "ext4", | ||
:total_bytes => 196976660480, | ||
:used_bytes => 9549549568, | ||
:available_bytes => 177397694464, | ||
:used_bytes_percent => 6, | ||
:mount_point => "/home", | ||
:total_inodes => 12222464, | ||
:used_inodes => 488787, | ||
:available_inodes => 11733677, | ||
:used_inodes_percent => 4 | ||
} | ||
] | ||
|
||
expect(AwesomeSpawn).to receive(:run!) | ||
.with("df", :params => ["-T", "-P", "-l"]) | ||
.and_return(double(:output => linux_df_output_bytes)) | ||
expect(AwesomeSpawn).to receive(:run!) | ||
.with("df", :params => ["-T", "-P", "-i", "-l"]) | ||
.and_return(double(:output => linux_df_output_inodes)) | ||
|
||
expect(described_class.disk_usage).to eq(expected) | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of note: These tests won't pass on MacOS since the versions of
df
are different, but for now I am just ignoring that problem, as I hope these tests will pass just fine in CI.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, the specs for this were completely ripped from here:
https://github.com/ManageIQ/manageiq-gems-pending/blob/fbcaf76d5894407dd1b25f58e4f02faac361428e/spec/util/miq-system_spec.rb#L26-L148
So nothing new is added, besides the omission of the
:macosx
specific specs.