-
Notifications
You must be signed in to change notification settings - Fork 70
/
check_hotfix_installed.rb
87 lines (77 loc) · 2.6 KB
/
check_hotfix_installed.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
class Checks::CheckHotfixInstalled < ForemanMaintain::Check
metadata do
label :check_hotfix_installed
description 'Check to verify if any hotfix installed on system'
preparation_steps do
Procedures::Packages::Install.new(:packages => %w[yum-utils])
end
confine do
feature(:downstream)
end
end
def run
if feature(:downstream).subscribed_using_activationkey?
skip "Your system is subscribed using custom activationkey. Hotfixes can't be detected."
else
with_spinner('Checking for presence of hotfix(es). It may take some time to verify.') do
hotfix_rpmlist = find_hotfix_packages
installed_pkg_list = installed_packages
files_modifications = installed_pkg_list.flat_map { |pkg| modified_files(pkg) }
assert(hotfix_rpmlist.empty? && files_modifications.empty?,
warning_message(hotfix_rpmlist, files_modifications))
end
end
end
private
def modified_files(package)
changed_files = []
IO.popen(['rpm', '-V', package]) do |pipe|
pipe.each do |line|
arr_output = line.chomp.split
flags = arr_output.first
filename = arr_output.last
changed_files << filename if flags.include?('5') && filename =~ /\.(rb|py|erb|js)$/
end
end
changed_files
end
def installed_packages
packages = []
repoquery_cmd = execute!('which repoquery')
IO.popen([repoquery_cmd, '-a', '--installed', '--qf', '%{ui_from_repo} %{nvra}']) do |io|
io.each do |line|
repo, pkg = line.chomp.split
packages << pkg if /satellite|rhscl/ =~ repo[1..-1]
end
end
packages
end
def find_hotfix_packages
output = execute!('rpm -qa release="*HOTFIX*"').strip
return [] if output.empty?
output.split("\n")
end
def warning_message(hotfix_rpmlist, files_modified)
message = "\n"
unless hotfix_rpmlist.empty?
message += msg_for_hotfix_rpms(hotfix_rpmlist)
end
unless files_modified.empty?
message += msg_for_modified_files(files_modified)
end
message += "\n\nBefore update make sure the updated packages contain the listed modifications "\
'otherwise these fixes will be lost. '\
'It is also recommended to backup the modified files prior update.'
message
end
def msg_for_hotfix_rpms(rpms_list)
message = "HOTFIX rpm(s) applied on this system:\n"
message += rpms_list.join(',')
message
end
def msg_for_modified_files(files_modified)
message = "\n\nFound #{files_modified.length} file(s) modified on this system.\n"
message += files_modified.join("\n")
message
end
end