Skip to content

Instantly share code, notes, and snippets.

@mbacovsky
Created November 30, 2018 14:02
Show Gist options
  • Save mbacovsky/889459a71244d04135bcd71cd62fd692 to your computer and use it in GitHub Desktop.
Save mbacovsky/889459a71244d04135bcd71cd62fd692 to your computer and use it in GitHub Desktop.
My take on repoqueries
diff --git a/definitions/checks/check_hotfix_installed.rb b/definitions/checks/check_hotfix_installed.rb
index 7f13caa..4cdb8bd 100644
--- a/definitions/checks/check_hotfix_installed.rb
+++ b/definitions/checks/check_hotfix_installed.rb
@@ -25,9 +25,9 @@ class Checks::CheckHotfixInstalled < ForemanMaintain::Check
else
with_spinner('Checking for presence of hotfix(es). It may takes some time to verify.') do
hotfix_rpmlist = []
-
+ repolist = feature(:downstream).repolist_for_hotfix_verify(@version)
hotfix_rpmlist = find_hotfix_rpms_installed if feature(:downstream)
- files_modifications = rpm_verify_command(@version)
+ files_modifications = installed_packages(repolist).flat_map { |pkg| modified_files(pkg) }
assert(hotfix_rpmlist.empty? && files_modifications.empty?,
warning_message(hotfix_rpmlist, files_modifications))
end
@@ -62,31 +62,25 @@ class Checks::CheckHotfixInstalled < ForemanMaintain::Check
output.split("\n")
end
- def rpm_verify_command(version)
- cmd = "rpm -V `#{find_installed_packages(version)}` | grep -E '#{regex_for_files_check}'"
- cmd += " | awk '{print $2}' "
- return [] unless execute?(cmd) # handle echo $? = 1
-
- output = execute!(cmd).strip
- return [] if output.empty?
-
- output.strip.split("\n")
- end
-
- def find_installed_packages(version)
- repolist_regexstr = feature(:downstream).repolist_for_hotfix_verify(version).join('|')
-
- # IO.popen(" awk '/#{repolist_regexstr}/ {print $2}'", "w").write (
- # IO.popen("repoquery -a --installed --qf '%{ui_from_repo} %{name}'").read
- # )
-
- repoquery_cmd = "repoquery -a --installed --qf '%{ui_from_repo} %{name}'"
- repoquery_cmd += " | awk '/#{repolist_regexstr}/ {print $2}'"
- execute!(repoquery_cmd)
- repoquery_cmd
+ def modified_files(package)
+ changed_files = []
+ IO.popen(['rpm', '-V', package]) do |pipe|
+ while (line = pipe.gets) do
+ flags, type, filename = line.chomp.split
+ changed_files << filename if flags.include?('5') && filename =~ /\.(rb|py|erb|js)$/
+ end
+ end
+ changed_files
end
- def regex_for_files_check
- '^(..5....T.){1}(.{2}[^c])+.+\.(rb|py|erb|js)$'
+ def installed_packages(repolist)
+ packages = []
+ IO.popen(['/bin/repoquery', '-a', '--installed', '--qf', '%{ui_from_repo} %{name}']) do |io|
+ while (line = io.gets) do
+ repo, pkg = line.chomp.split
+ packages << pkg if repolist.include? repo[1..-1]
+ end
+ end
+ packages
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment