[How] ansible_stats_openeuler < ${job_output}
Signed-off-by: Wang Chenglong 18509160991@163.com --- stats/ansible_test | 95 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 85 insertions(+), 10 deletions(-)
diff --git a/stats/ansible_test b/stats/ansible_test index 4c7d07b3e..bfb0c2f11 100755 --- a/stats/ansible_test +++ b/stats/ansible_test @@ -1,15 +1,90 @@ #!/usr/bin/env ruby
+require 'json' + while (line = STDIN.gets) - case line.chomp! - when /ok=(\d+)\s+changed=(\d+)\s+unreachable=(\d+)\s+failed=(\d+)\s+skipped=(\d+)\s+rescued=(\d+)\s+ignored=(\d+)/ - puts "ansible_test.total.nr_ok: #{$1}" - puts "ansible_test.total.nr_changed: #{$2}" - puts "ansible_test.total.nr_failed: #{$4}" - puts "ansible_test.total.nr_skipped: #{$5}" - puts "ansible_test.total.nr_rescued: #{$6}" - puts "ansible_test.total.nr_ignored: #{$7}" - when /playbook_run_on_fail/ - puts line + line = line.gsub(/'/, ' ') + ansible_stats_error = `echo '#{line}' | grep -E 'FAILED! |failed: .*}$' | awk -F'=>' '{$1="";print $0}'` + next if ansible_stats_error.empty? + + a = JSON.load(ansible_stats_error) + unless a['msg'].nil? + case a['msg'].chomp + + # When running some plug-in, the file was not found + when /No file was found when using (.+)./ + puts "files.error.no-file-was-found-when-using.#{$1}: 1" + puts "files.error.no-file-was-found-when-using.#{$1}.message: #{ansible_stats_error}" + + # No such command + when /No such file or directory: b (.+) :/ + puts "command.error.no-such-file-or-directory.#{$1}: 1" + puts "command.error.no-such-file-or-directory.#{a['cmd']}.message: #{ansible_stats_error}" + + # The URL of the RPM is invalid + when /Failure downloading (.+), / + puts "download.error.http-error-404 [#{$1}]: 1" + puts "download.error.http-error-404 [#{$1}]: #{ansible_stats_error}" + + # Failed to download the yum repodata + when /Failed to download metadata for repo (.+) :/ + puts "download.error.failed-to-download-metadata.#{$1}: 1" + puts "download.error.failed-to-download-metadata.#{$1}.message: #{ansible_stats_error}" + + when /Failed to download packages: Cannot download (.+):/ + puts "download.error.failed-to-download-package.#{$1}: 1" + puts "download.error.failed-to-download-package.#{$1}.message: #{ansible_stats_error}" + + # The task includes an option with an undefined variable + when /: (.+) is undefined/ + puts "syntax.error.an-undefined-variable.#{$1}: 1" + puts "syntax.error.an-undefined-variable.#{$1}.message: #{ansible_stats_error}" + + # The command runing error + when /non-zero return code/ + puts "command.error[#{a['cmd']}]: 1" + puts "command.error [#{a['cmd']}].message: #{ansible_stats_error}" + + # Some service could not find the requested host + when /Could not find the requested service (.+): host/ + puts "request.error.could-not-find-service-host.#{$1}: 1" + puts "request.error.could-not-find-service-host.#{$1}.messgae: #{ansible_stats_error}" + + # Unable to start some services + when /Unable to start service (.+):/ + puts "service.error.unable-to-start-service.#{$1}: 1" + puts "service.error.unable-to-start-service.#{$1}.message: #{ansible_stats_error}" + + # Some role in not sipported this system + when /(.+) is not supported/ + puts "system.error.not-supported.#{$1.gsub(/ /, '-')}: 1" + puts "system.error.not-supported.message: #{ansible_stats_error}" + + # failed to create temporary content file: The read operation timed out. + when /The read operation timed out/ + puts 'connection.error.read-timed-out: 1' + puts "connection.error.read-timed-out.message: #{ansible_stats_error}" + end + end + + unless a['failures'].nil? + a['failures'].each do |items| + case items.chomp + # Failed to install some of the specified packages. + when /No package (.+) available/ + puts "yum.error.no-package-match.#{$1}: 1" + puts "yum.error.no-package-match.#{$1}.message: #{line}" + end + end + end + + next if a['message'].nil? + + case a['message'].chomp + + # Could not find or access ansible yaml + when /Could not find or access (.+) / + puts "yaml.error.not-find-yml.#{$1}: 1" + puts "yaml.error.not-find-yml.#{$1}.message: #{ansible_stats_error}" end end
tests/xxx => exit !0 on fail stats/xxx catch errors => error id
submit 1000 jobs group_id=xxx es-jobs group_id=xxx | grep failed, exit != 0 failed, but no error id? => improve stats/xxx
- catch all kind errors - make sure no 漏网之鱼
On Thu, Feb 18, 2021 at 03:19:53PM +0800, Wang Chenglong wrote:
[How] ansible_stats_openeuler < ${job_output}
Signed-off-by: Wang Chenglong 18509160991@163.com
stats/ansible_test | 95 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 85 insertions(+), 10 deletions(-)
diff --git a/stats/ansible_test b/stats/ansible_test index 4c7d07b3e..bfb0c2f11 100755 --- a/stats/ansible_test +++ b/stats/ansible_test @@ -1,15 +1,90 @@ #!/usr/bin/env ruby
+require 'json'
while (line = STDIN.gets)
- case line.chomp!
- when /ok=(\d+)\s+changed=(\d+)\s+unreachable=(\d+)\s+failed=(\d+)\s+skipped=(\d+)\s+rescued=(\d+)\s+ignored=(\d+)/
- puts "ansible_test.total.nr_ok: #{$1}"
- puts "ansible_test.total.nr_changed: #{$2}"
- puts "ansible_test.total.nr_failed: #{$4}"
- puts "ansible_test.total.nr_skipped: #{$5}"
- puts "ansible_test.total.nr_rescued: #{$6}"
- puts "ansible_test.total.nr_ignored: #{$7}"
- when /playbook_run_on_fail/
- puts line
- line = line.gsub(/'/, ' ')
cryptic code
- ansible_stats_error = `echo '#{line}' | grep -E 'FAILED! |failed: .*}$' | awk -F'=>' '{$1="";print $0}'`
ansible_stats_error => ansible_failed_json
if line =~ /FAILED!|failed: ({".*"})/ ansible_failed_json = $1 else next end
- next if ansible_stats_error.empty?
- a = JSON.load(ansible_stats_error)
func() { return if a['msg'].nil?
- case a['msg'].chomp
}
- # When running some plug-in, the file was not found
- when /No file was found when using (.+)./
puts "files.error.no-file-was-found-when-using.#{$1}: 1"
puts "files.error.no-file-was-found-when-using.#{$1}.message: #{ansible_stats_error}"
{"changed": false, "cmd": "csf -v", "msg": "[Errno 2] err1\nerr2\nNo such \nasdfasdf\nfile or directory: b'csf': b'csf'", "rc": 2}
- # No such command
# original error message
- when /No such file or directory: b (.+) :/
puts "{cmd}:no-such-file-or-directory.#{$1}: 1"
puts "no-such-file-or-directory.#{a['cmd']}.message: #{ansible_stats_error}"
- # The URL of the RPM is invalid
{"changed": false, "msg": "Failure downloading\nhttps://dl.fedoraproject.org/pub/epel/epel-release-latest-20.noarch.rpm,%5Cn... Error 405: Per"}
- when /Failure downloading (.+), xxx/
puts "download.error.Failure-downloading-#{$1}: 1"
puts "download.error.http-error-404 [#{$1}]: #{ansible_stats_error}"
- # Failed to download the yum repodata
- when /Failed to download metadata for repo (.+) :/
puts "download.error.failed-to-download-metadata.#{$1}: 1"
puts "download.error.failed-to-download-metadata.#{$1}.message: #{ansible_stats_error}"
/fail message/
- when /Failed to download packages: Cannot download (.+):/
puts "download.error.failed-to-download-package.#{$1}: 1"
puts "download.error.failed-to-download-package.#{$1}.message: #{ansible_stats_error}"
- # The task includes an option with an undefined variable
- when /: (.+) is undefined/
puts "syntax.error.an-undefined-variable.#{$1}: 1"
puts "syntax.error.an-undefined-variable.#{$1}.message: #{ansible_stats_error}"
- # The command runing error
- when /non-zero return code/
puts "command.error[#{a['cmd']}]: 1"
puts "command.error [#{a['cmd']}].message: #{ansible_stats_error}"
- # Some service could not find the requested host
- when /Could not find the requested service (.+): host/
puts "request.error.could-not-find-service-host.#{$1}: 1"
puts "request.error.could-not-find-service-host.#{$1}.messgae: #{ansible_stats_error}"
- # Unable to start some services
- when /Unable to start service (.+):/
puts "service.error.unable-to-start-service.#{$1}: 1"
puts "service.error.unable-to-start-service.#{$1}.message: #{ansible_stats_error}"
- # Some role in not sipported this system
- when /(.+) is not supported/
puts "system.error.not-supported.#{$1.gsub(/ /, '-')}: 1"
puts "system.error.not-supported.message: #{ansible_stats_error}"
- # failed to create temporary content file: The read operation timed out.
- when /The read operation timed out/
puts 'connection.error.read-timed-out: 1'
puts "connection.error.read-timed-out.message: #{ansible_stats_error}"
- end
- end
- unless a['failures'].nil?
- a['failures'].each do |items|
case items.chomp
# Failed to install some of the specified packages.
when /No package (.+) available/
puts "yum.error.no-package-match.#{$1}: 1"
puts "yum.error.no-package-match.#{$1}.message: #{line}"
end
{"changed": false, "failures": ["No package python-passlib available.", "No package munin available."], "msg": "Failed to install some of the specified packages", "rc": 1, "results": []}
- end
- end
- next if a['message'].nil?
- case a['message'].chomp
- # Could not find or access ansible yaml
- when /Could not find or access (.+) /
- puts "yaml.error.not-find-yml.#{$1}: 1"
- puts "yaml.error.not-find-yml.#{$1}.message: #{ansible_stats_error}" end
end
2.23.0