Signed-off-by: Wang Chenglong 18509160991@163.com --- tests/ansible_test | 217 ++++++++++++++++++--------------------------- 1 file changed, 84 insertions(+), 133 deletions(-)
diff --git a/tests/ansible_test b/tests/ansible_test index bb2ee9bbc..36164bcae 100755 --- a/tests/ansible_test +++ b/tests/ansible_test @@ -1,133 +1,84 @@ -#!/usr/bin/env ruby - -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.gsub!(/{%/, ' ') - line.gsub!(/%}/, ' ') - 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 +#!/bin/bash +# - ansible_repo + +. $LKP_SRC/lib/debug.sh + +check_vars() +{ + ansible_host=localhost + echo $ansible_host + + [ -n "$ansible_repo" ] || die "ansible_repo is empty" + benchmark=${ansible_repo##*/} + + ansible_path=/root/.ansible + [ -d "$ansible_path" ] || mkdir -p /root/.ansible +} + +install_ansible() +{ + if [ "$os" == "openeuler" ]; then + yum -y reinstall git + yum -y install python3 + pip3 install ansible + elif [ "$os" == "centos" ]; then + yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm + yum -y reinstall git + yum -y install ansible + elif [ "$os" == "debian" ]; then + apt-get install -y ansible + fi + + command -v ansible > /dev/null && { + ansible localhost -m ping + [ $? -eq 0 ] && { + echo "Ansible is successfully deployed!" + } + } +} + +download_ansible_role() +{ + + ansible_roles_path=$ansible_path/roles + [ -d $ansible_roles_path ] || mkdir -p $ansible_roles_path + cd $ansible_roles_path + git clone git://github.com/$ansible_repo.git || exit 1 + # git clone git://$GIT_SERVER/$ansible_repo.git || exit + # ansible-galaxy install $username.$rolename + if [ $? -eq 0 ]; then + echo "$benchmark is successfully installed" + else + echo "Please check whether your ansible_repo is correct!" + fi +} + +ansible_playbook_run() +{ + cat <<-EOF > "$ansible_path"/site.yml + - hosts: $ansible_host + roles: + - role: $benchmark + EOF + [ $? -eq 0 ] && { + echo "Playbook has been generated!" + } + + ansible-playbook "$ansible_path"/site.yml + + if [ $? -eq 0 ]; then + echo "Your playbook is running successfully!" + else + echo "Your playbook failed to run!" && exit 1 + fi +} + +main() +{ + check_vars + install_ansible + download_ansible_role + ansible_playbook_run +} + +main
Pls ingore this email.
On Wed, Mar 10, 2021 at 03:21:37PM +0800, Wang Chenglong wrote:
Signed-off-by: Wang Chenglong 18509160991@163.com
tests/ansible_test | 217 ++++++++++++++++++--------------------------- 1 file changed, 84 insertions(+), 133 deletions(-)
diff --git a/tests/ansible_test b/tests/ansible_test index bb2ee9bbc..36164bcae 100755 --- a/tests/ansible_test +++ b/tests/ansible_test @@ -1,133 +1,84 @@ -#!/usr/bin/env ruby
-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.gsub!(/{%/, ' ')
- line.gsub!(/%}/, ' ')
- 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 +#!/bin/bash +# - ansible_repo
+. $LKP_SRC/lib/debug.sh
+check_vars() +{
- ansible_host=localhost
- echo $ansible_host
- [ -n "$ansible_repo" ] || die "ansible_repo is empty"
- benchmark=${ansible_repo##*/}
- ansible_path=/root/.ansible
- [ -d "$ansible_path" ] || mkdir -p /root/.ansible
+}
+install_ansible() +{
- if [ "$os" == "openeuler" ]; then
yum -y reinstall git
yum -y install python3
pip3 install ansible
- elif [ "$os" == "centos" ]; then
yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum -y reinstall git
yum -y install ansible
- elif [ "$os" == "debian" ]; then
apt-get install -y ansible
- fi
- command -v ansible > /dev/null && {
ansible localhost -m ping
[ $? -eq 0 ] && {
echo "Ansible is successfully deployed!"
}
- }
+}
+download_ansible_role() +{
- ansible_roles_path=$ansible_path/roles
- [ -d $ansible_roles_path ] || mkdir -p $ansible_roles_path
- cd $ansible_roles_path
- git clone git://github.com/$ansible_repo.git || exit 1
- # git clone git://$GIT_SERVER/$ansible_repo.git || exit
- # ansible-galaxy install $username.$rolename
- if [ $? -eq 0 ]; then
echo "$benchmark is successfully installed"
- else
echo "Please check whether your ansible_repo is correct!"
- fi
+}
+ansible_playbook_run() +{
- cat <<-EOF > "$ansible_path"/site.yml
- hosts: $ansible_host
roles:
- role: $benchmark
- EOF
- [ $? -eq 0 ] && {
echo "Playbook has been generated!"
}
ansible-playbook "$ansible_path"/site.yml
- if [ $? -eq 0 ]; then
echo "Your playbook is running successfully!"
- else
echo "Your playbook failed to run!" && exit 1
- fi
+}
+main() +{
- check_vars
- install_ansible
- download_ansible_role
- ansible_playbook_run
+}
+main
2.23.0