Skip to content

Commit

Permalink
Fixes #31210 - add check for diskusage in cp-dir
Browse files Browse the repository at this point in the history
(cherry picked from commit 9f63e71)
  • Loading branch information
m-bucher authored and upadhyeammit committed Mar 8, 2021
1 parent a27c9cc commit 83e9a31
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
27 changes: 27 additions & 0 deletions definitions/checks/disk/available_space_candlepin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module Checks
module Disk
class AvailableSpaceCandlepin < ForemanMaintain::Check
metadata do
label :available_space_cp
description 'Check to make sure /var/lib/candlepin has enough space'
tags :pre_upgrade
confine do
feature(:candlepin) && check_min_version('candlepin', '3.1')
end
end

MAX_USAGE_IN_PERCENT = 90

def run
assert(enough_space?, "System has more than #{MAX_USAGE_IN_PERCENT}% space used"\
" on #{feature(:candlepin).work_dir}.\n"\
'See https://bugzilla.redhat.com/show_bug.cgi?id=1898605')
end

def enough_space?
io_obj = ForemanMaintain::Utils::Disk::IODevice.new(feature(:candlepin).work_dir)
io_obj.space_used_in_percent < MAX_USAGE_IN_PERCENT
end
end
end
end
4 changes: 4 additions & 0 deletions definitions/features/candlepin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ class Features::Candlepin < ForemanMaintain::Feature
end
end

def work_dir
'/var/lib/candlepin'
end

def services
[
system_service('tomcat', 20),
Expand Down
4 changes: 4 additions & 0 deletions lib/foreman_maintain/utils/disk/io_device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def available_space
convert_kb_to_mb(execute!("df #{dir}|awk {'print $4'}|tail -1").to_i)
end

def space_used_in_percent
execute!("df #{dir}|awk {'print $5'}|tail -1").to_i
end

private

# In fio command, --direct option bypass the cache page
Expand Down

0 comments on commit 83e9a31

Please sign in to comment.