鲲鹏社区首页
中文
注册
我要评分
文档获取效率
文档正确性
内容完整性
文档易理解
在线提单
论坛求助

Jenkins流水线兼容性测试示例代码

运行兼容性测试工具之前需要配置参数。

  1. 配置工具参数。

    要运行工具需要配置参数,在安装目录${HOME}/.local/compatibility_testing/Chinese/compatibility_testing.conf中配置参数。

    vim ${HOME}/.local/compatibility_testing/Chinese/compatibility_testing.conf

    文件内容如下:

    ##################################################################################
    #功能描述: 提供给用户进行兼容性测试、性能测试的指标日志采集工具
    #版本信息: 华为技术有限公司,版权所有(C) 2020-2024
    #修改记录: 2024-08-31 修改
    #使用方法:自动化采集开始前,请用户先配置compatibility_testing.conf,
    #         填写待测试应用名称application_names,
    #         待测试应用启动命令start_app_commands,
    #         待测试应用停止命令stop_app_commands
    #         被测应用软件的压力测试工具启动命令start_performance_scripts,
    #         确认填写后
    #         CentOS/中标麒麟/SUSE/openEuler:使用root用户执行,sh compatibility_testing.sh。
    #         Ubuntu/银河麒麟/UOS:使用root用户执行,bash compatibility_testing.sh。
    #         多节点集群部署,在每台节点服务器上配置对自身节点和其他所有节点的SSH免密登录。并在控制节点(主节点)执行脚本。
    ###################################################################################
     
    # 待测试应用软件进程名称。
    # 可通过ps或者docker top 命令CMD所在列查找后台进程名称, Kubernetes集群环境下填写Pod名称。
    application_names=test_app
    # 待测试应用软件启动命令。
    start_app_commands=nohup python3 /root/test/test_app.py &
    # 空载采集时间(分钟)
    idle_performance_time=1
    # 待测试应用软件停止命令。
    stop_app_commands=
    # 被测应用软件的压力测试工具启动命令。
    start_performance_scripts=
    # 被测应用软件的压力测试工具运行时间(分钟)
    start_performance_time=
    # Kubernetes集群填写"Y"。其他环境可置空。
    kubernetes_env=
    # 以下为多节点集群部署填写,单机(单节点)部署不需要填写。
    # 集群环境的IP地址列表,多个IP地址以逗号隔开,列表不应包括当前脚本所在服务器IP地址,请勿增加。
    cluster_ip_lists=
    # 以下为Validated认证测试填写,Compatible认证测试不需要填写。
    # CVE漏洞扫描目录,多个目录以逗号隔开,Validated认证测试有自己的CVE漏洞检查工具不需要填写。
    # 集群环境下, 非当前脚本所在服务器的目录填写为"IP:目录", 如192.168.2.2:/root/tomcat
    cve_scan_path=
    # clamav防病毒扫描目录,多个目录以逗号隔开,Validated认证测试有自己的商用杀毒软件不需要填写。
    # 集群环境下, 非当前脚本所在服务器的目录填写为"IP:目录", 如192.168.2.2:/root/tomcat
    clamav_scan_path=
    # 以下为HPC应用方案认证填写,HPC应用测试填写"Y",其他应用认证测试可置空。
    hpc_certificate=
    # 以下为C/C++编译的应用填写,请填写待测试应用二进制文件的绝对路径。
    binary_file=

    应用软件进程名称为test_app,启动命令为nohup python3 /root/test/test_app.py &,请用户根据实际应用软件进程名称和启动命令进行替换。

  2. 运行兼容性测试工具。
    ${HOME}/.local/compatibility_testing/bin/compatibility_test
    • 业务应用为K8S集群时,测试报告中“Reliablity_Exception_Kill”测试项的运行结果会为空。
    • 启动compatibility_test过程中,若提示有以下日志信息,为正常现象。
      1. 数据目录下的日志文件data/test/performance/test_perf_cpu_1.log不存在。
      2. 数据目录下的日志文件data/test/performance/test_perf_disk_1.log不存在。
      3. 数据目录下的日志文件data/test/performance/test_perf_mem_1.log不存在。
      4. 数据目录下的日志文件data/test/performance/test_perf_net_1.log不存在。
  3. 查看结果。在${HOME}/.local/compatibility_testing/目录下查看是否产生新的html文件,若有则表示兼容性测试工具运行成功。
  4. 提供Jenkins流水线示例代码,可参考示例代码运行Jenkins流水线任务。

    示例代码如下:

    pipeline {
        agent any
        options {
            timeout(time: 1, unit: 'HOURS')
            }
        parameters {
            string(name: 'GIT_URL', defaultValue: 'https://github.com/ruanjue/wtdbg2.git', description: '--> git url <--')
            string(name: 'GIT_BRANCH', defaultValue: 'v2.5', description: '--> code branch <--')
            string(name: 'GIT_TARGET_DIR_NAME', defaultValue: 'wtdbg2', description: '--> code branch <--')
        }
        stages{
            stage('Git   Code') {
                steps {
                 agent { 
                    label 'kunpeng_scanner' //对应添加节点时的标签,可选择多个
                } 
                    echo '====== 获取源码 ======'
                    checkout scmGit(branches: [[name: "${params.GIT_BRANCH}"]],
                                    browser: github("${params.GIT_URL}"),
                                    extensions: [[$class: 'RelativeTargetDirectory',
                                    relativeTargetDir: "${params.GIT_TARGET_DIR_NAME}"],
                                    cleanBeforeCheckout(deleteUntrackedNestedRepositories: true)],
                                    userRemoteConfigs: [[url: "${params.GIT_URL}"]])
                }
            }
            stage('compatibility testing') {
                agent {
                    label 'kunpeng_compatibility'
                }
                steps {
                    script{
                        echo '====== compatibility testing ======'
                        sh '''
                            if [ ! -d "./report_dir" ]; then mkdir -p ./report_dir; fi
                                /usr/bin/rm -rf ./report_dir/*.html
                            /bin/cp -rf /root/.local/compatibility_testing/template.html.template /root/.local/compatibility_testing/template.html
                            //请在运行兼容性测试工具之前根据用户实际应用软件进程配置工具参数。
                            /bin/bash /root/.local/compatibility_testing/bin/compatibility_test
                            //若为普通用户执行,请添加sudo命令,例如:sudo /bin/bash /root/.local/compatibility_testing/bin/compatibility_test
                            /bin/cp -rf /root/.local/compatibility_testing/compatibility_report.html ./report_dir
                        '''
                   }
                }
                post {
                    always {
                        publishHTML(target: [allowMissing: false,
                                                alwaysLinkToLastBuild: false,
                                                keepAll              : true,
                                                reportDir            : './report_dir',
                                                reportFiles          : 'compatibility_report.html',
                                                reportName           : 'compatibility test Report']
                        )
                    }
                }        
            }
        }
    }