Skip to content
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

Avoid direct float comparisons with 0.0 in storage.rb #20871

Merged
merged 3 commits into from
Jan 6, 2021
Merged
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
16 changes: 8 additions & 8 deletions app/models/storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -581,12 +581,12 @@ def used_space
alias_method :v_used_space, :used_space

def used_space_percent_of_total
total_space.to_f == 0.0 ? 0.0 : (used_space.to_f / total_space.to_f * 1000.0).round / 10.0
total_space.zero? ? 0.0 : (used_space.to_f / total_space * 1000.0).round / 10.0
end
alias_method :v_used_space_percent_of_total, :used_space_percent_of_total

def free_space_percent_of_total
total_space.to_f == 0.0 ? 0.0 : (free_space.to_f / total_space.to_f * 1000.0).round / 10.0
total_space.zero? ? 0.0 : (free_space.to_f / total_space * 1000.0).round / 10.0
end
alias_method :v_free_space_percent_of_total, :free_space_percent_of_total

Expand Down Expand Up @@ -618,31 +618,31 @@ def v_total_vms
alias_method :v_total_disk_size, :disk_size

def v_debris_percent_of_used
used_space.to_f == 0.0 ? 0.0 : (debris_size.to_f / used_space.to_f * 1000.0).round / 10.0
used_space.zero? ? 0.0 : (debris_size.to_f / used_space * 1000.0).round / 10.0
end

def v_snapshot_percent_of_used
used_space.to_f == 0.0 ? 0.0 : (snapshot_size.to_f / used_space.to_f * 1000.0).round / 10.0
used_space.zero? ? 0.0 : (snapshot_size.to_f / used_space * 1000.0).round / 10.0
end

def v_memory_percent_of_used
used_space.to_f == 0.0 ? 0.0 : (vm_ram_size.to_f / used_space.to_f * 1000.0).round / 10.0
used_space.zero? ? 0.0 : (vm_ram_size.to_f / used_space * 1000.0).round / 10.0
end

def v_vm_misc_percent_of_used
used_space.to_f == 0.0 ? 0.0 : (vm_misc_size.to_f / used_space.to_f * 1000.0).round / 10.0
used_space.zero? ? 0.0 : (vm_misc_size.to_f / used_space * 1000.0).round / 10.0
end

def v_disk_percent_of_used
used_space.to_f == 0.0 ? 0.0 : (disk_size.to_f / used_space.to_f * 1000.0).round / 10.0
used_space.zero? ? 0.0 : (disk_size.to_f / used_space * 1000.0).round / 10.0
end

def v_total_provisioned
used_space + uncommitted.to_i
end

def v_provisioned_percent_of_total
total_space.to_f == 0 ? 0.0 : (v_total_provisioned.to_f / total_space.to_f * 1000.0).round / 10.0
total_space.zero? ? 0.0 : (v_total_provisioned.to_f / total_space * 1000.0).round / 10.0
end

#
Expand Down