[How] ansible_stats_openeuler < ${job_output}
wcl@crystal ~/lkp-tests/stats% ./ansible_test < /srv/result/ansible_test/2021-02-04/ vm-2p16g--wcl/openeuler-20.03-aarch64/jgeusebroek-ansible-role-docker/crystal.974042/ansible_test
error.Failed-to-download-metadata-for-repo-dockerrepo: 1 error.Failed-to-download-metadata-for-repo-dockerrepo.message: {"ansible_loop_var": "item", "changed": false, "item": "docker-engine", "msg": "Failed to download metadata for repo 'dockerrepo': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried", "rc": 1, "results": []}
Signed-off-by: Wang Chenglong 18509160991@163.com --- stats/ansible_test | 138 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 127 insertions(+), 11 deletions(-)
diff --git a/stats/ansible_test b/stats/ansible_test index 4c7d07b3e..67e312f47 100755 --- a/stats/ansible_test +++ b/stats/ansible_test @@ -1,15 +1,131 @@ #!/usr/bin/env ruby
-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 +require 'json' + +def output_error(error_msg) + error_id = common_error_id error_msg + puts "error.#{error_id}: 1" + puts "error.#{error_id}.message: #{@ansible_failed_info}" +end + +def parse_msg_1(ansible_failed_json) + case ansible_failed_json.chomp + + # When running some plug-in, the file was not found + when /(No file was found when using (.+))./ + output_error $1 + + # {"changed": false, "cmd": "csf -v", "msg": "[Errno 2] No such file or directory: b'csf': b'csf'", "rc": 2} + when /(No such file or directory: b'.+')/ + output_error $1 + + # The task includes an option with an undefined variable + # {"msg": "The task includes an option with an undefined variable. The error was: '__mysql_packages' is undefined + # The error appears to be in '/root/.ansible/roles/ansible-role-mysql/tasks/variables.yml': line 11, column 3, + # but may be elsewhere in the file depending on the exact syntax problem. The offending line appears to be: - name: + # Define mysql_packages. here"} + when /(.+ is undefined)/ + output_error $1 + + # {"changed": true, "cmd": ["packaging/installer/install-required-packages.sh", "--non-interactive", "netdata"], + # "msg": "non-zero return code", "rc": 1} + when /(non-zero return code)/ + output_error $1 + + # Some service could not find the requested host + when /(Could not find the requested service .+): host/ + output_error $1 + + # Unable to start some services + when /(Unable to start service .+):/ + output_error $1 + end +end + +def parse_msg_2(ansible_failed_json) + case ansible_failed_json.chomp + + # {"changed": false, "msg": "Failed to download packages: Cannot download 7.10.2/filebeat-7.10.2-aarch64.rpm: + # All mirrors were tried", "results": []} + when /(Failed to download packages: Cannot download .+):/ + output_error $1 + + when /(Failure downloading .+) / + output_error $1 + + # Failed to download the yum repodata + # {"changed": false, "msg": "Failed to download metadata for repo 'docker-ce-stable': Cannot download repomd.xml", + # "rc": 1, "results": []} + when /(Failed to download metadata for repo.+)':/ + output_error $1 + + # Some role in not sipported this system + # {"changed": false, "msg": "Distribution openEuler is not supported by this role!"} + when /(.+ is not supported .+)/ + output_error $1 + + # failed to create temporary content file: The read operation timed out. + when /(.+ The read operation timed out)/ + output_error $1 + + # {"msg": "The conditional check 'java_version is defined' failed. The error was: error while evaluating conditional + # (java_version is defined): {{ java_default_version }}: {{ _java_default_version[ansible_distribution ~ '-' ~ + # ansible_distribution_major_version] | default(_java_default_version[ansible_distribution]) }}: 'dict object' has + # no attribute 'openEuler'\n\nThe error appears to be in '/root/.ansible/roles/ansible-role-java/tasks/assert.yml': + # line 19, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line + # appears to be:\n\n\n- name: test if java_version is set correctly\n ^ here\n"} + when /(The conditional check .+ failed)/ + output_error $1 + end +end + +def parse_failures(ansible_failed_json) + ansible_failed_json.each do |items| + case items.chomp + # Failed to install some of the specified packages. + # {"changed": false, "failures": ["No package erlang available."], "msg": + # "Failed to install some of the specified packages", "rc": 1, "results": []} + when /(No package .+ available)/ + output_error $1 + end + end +end + +def parse_message(ansible_failed_json) + case ansible_failed_json.chomp + + # Could not find or access ansible yaml + # {"ansible_facts": {}, "ansible_included_var_files": [], "changed": false, "message": + # "Could not find or access 'openEuler.yml' Searched in: + # /root/.ansible/roles/ansible-unzip/vars/openEuler.yml /root/.ansible/roles/ansible-unzip/openEuler.yml i + # /root/.ansible/roles/ansible-unzip/tasks/vars/openEuler.yml /root/.ansible/roles/ansible-unzip/tasks/openEuler.yml + # /root/.ansible/vars/openEuler.yml /root/.ansible/openEuler.yml on the Ansible Controller. + # If you are using a module and expect the file to exist on the remote, see the remote_src option"} + when /(Could not find or access .+')/ + output_error $1 end end + +def common_error_id(line) + line = line.chomp + line.gsub!(/ /, '-') + line.gsub!(/:/, '') # error.:-'__mysql_packages'-is-undefined: 1 + line.gsub!(/,/, '') + line.gsub!(/'/, '') # Failed-to-download-metadata-for-repo-'dockerrepo: 1 + line.gsub!(/!/, '') # Distribution-openEuler-is-not-supported-by-this-role!: 1 + line +end + +while (line = STDIN.gets) + next unless line =~ /(FAILED!|failed:).*=>(.*)/ + + @ansible_failed_info = $2 + next if @ansible_failed_info.empty? + + ansible_failed_json = JSON.parse @ansible_failed_info + + parse_msg_1 ansible_failed_json['msg'] unless ansible_failed_json['msg'].nil? + parse_msg_2 ansible_failed_json['msg'] unless ansible_failed_json['msg'].nil? + parse_failures ansible_failed_json['failures'] unless ansible_failed_json['failures'].nil? + parse_message ansible_failed_json['message'] unless ansible_failed_json['message'].nil? +end
- # {"changed": true, "cmd": ["packaging/installer/install-required-packages.sh", "--non-interactive", "netdata"],
- # "msg": "non-zero return code", "rc": 1}
- when /(non-zero return code)/
- output_error $1
Here we can add cmd to error id to make it more useful.
Thanks, Fengguang
On Mon, Feb 22, 2021 at 03:02:03PM +0800, Wu Fengguang wrote:
- # {"changed": true, "cmd": ["packaging/installer/install-required-packages.sh", "--non-interactive", "netdata"],
- # "msg": "non-zero return code", "rc": 1}
- when /(non-zero return code)/
- output_error $1
Here we can add cmd to error id to make it more useful.
But only a few of the message have 'cmd' keys.
Thanks, Chenglong
Thanks, Fengguang
- # {"changed": false, "cmd": "csf -v", "msg": "[Errno 2] No such file or directory: b'csf': b'csf'", "rc": 2}
- when /(No such file or directory: b'.+')/
- output_error $1
我估计这样匹配会漏掉一些问题。 包括其它的很多when pattern,貌似这样根据输出结果case by case做解析,很难把各种情况覆盖全。
建议去看一下ansible源代码,以便更全面和彻底的设计这里的解析逻辑.
Thanks, Fengguang
On Mon, Feb 22, 2021 at 03:10:17PM +0800, Wu Fengguang wrote:
- # {"changed": false, "cmd": "csf -v", "msg": "[Errno 2] No such file or directory: b'csf': b'csf'", "rc": 2}
- when /(No such file or directory: b'.+')/
- output_error $1
我估计这样匹配会漏掉一些问题。 包括其它的很多when pattern,貌似这样根据输出结果case by case做解析,很难把各种情况覆盖全。
建议去看一下ansible源代码,以便更全面和彻底的设计这里的解析逻辑.
Ok. git it.
Thanks, Chenglong
Thanks, Fengguang