コード例 #1
0
def run(file_name, image, dev, project, conan_argv, com, cc_port):
    from KubeApi.app import KubeClient
    excute_status = 'True'
    sysstr = platform.system()
    if sysstr == "Windows":
        file_name = r'%s' % (file_name)
    createData = [{                      # 构造参数
    "image" : image,
    "command" : '/usr/bin/AutoStart',
    "cpu" : 850,
    "memory" : 800,
    "ephemeral_storage" : 10,
    "node_labels": {
    
         "app" : "jenkins",
    
    },
    "ports": [22,3306,4200,8270]
}]
    uid = 'common_user'
    kubeClient = KubeClient(uid)     # 初始化
    content = kubeClient.handle('deployment','CREATE',createData)

    for pod_name,body in content['datas']['deps'].items():
        domain = body['pod_ip']
        port = 8270
        ssh_port = 22
        name = body['name']
        print('创建容器成功 %s'%(pod_name))
        try:
            if excute_status == 'True':
                exe_data = {
                    "cmd_list": ['cd /home/x86rgos && source x86-env-setup && bash /home/x86rgos/conan.sh %s' % (
                        conan_argv.replace(';', ' ')), 'bash /home/change_dev.sh %s %s' % (dev, project.split('_')[-1]),
                                 'bash /home/x86rgos/normal_init.sh'],
                    "pod_name": name,
                    "namespace": "ceshi"
                }
                print("exe exe_data %s" % (exe_data))
                print("check_port %s %s %s doing"%(domain,ssh_port,file_name))
                check_port(domain, port=ssh_port)
                print("check_port %s %s %s done"%(domain,ssh_port,file_name))
                print('remote_shell doing %s  %s'%(exe_data,file_name))
                remote_shell(domain, exe_data, password='******',ssh_port=ssh_port)
                print('remote_shell done %s  %s'%(exe_data,file_name))
                update_ip('http://' + domain + ':' + str(port), file_name)
                case_name = file_name.split('/', file_name.count("/"))[-1][:-6]
                filename_with_dev = file_name.replace(case_name, dev + '_' + case_name)
                print('remote_shell_cmd_get_output %s'%('cp %s %s' % (file_name, filename_with_dev)))
                output = remote_shell_cmd_get_output('cp %s %s' % (file_name, filename_with_dev), timeout=5400)
                print('remote_shell_cmd_get_output',str(output))
                check_port(domain, port=port)
                r_cmd='ls %s ;robot --loglevel DEBUG -T -l %s_%s_log.html -o %s_%s_output.xml -r %s_%s_report.html  %s' % (
                filename_with_dev,dev, case_name, dev, case_name, dev, case_name, filename_with_dev)
                print('用例%s r_cmd %s doing'%(case_name,r_cmd))
                output = subprocess.call(r_cmd, shell=True,timeout=7200)
                print('用例%s r_cmd %s done'%(case_name,r_cmd))
                print('用例执行结果result:%s'%(str(output)))

            if conan_argv != 'none':
                print('用例%s 覆盖率统计开始'%(case_name))
                gen_info(domain, ssh_port, com, cc_port)
                print('用例%s 覆盖率统计结束'%(case_name))

            if name != []:
                data = [
                     {
                           "name" : name

                     },
                ]
                print("data %s"%(data))
                result = kubeClient.handle('deployment','DELETE',data)
                if result['status'] is True:
                    print('用例%s 删除容器成功 %s'%(case_name,data))
                else:
                    print('用例%s 删除容器失败 %s'%(case_name,data))
        except Exception as e:
            if name != []:
                data = [
                    {
                        "name": name

                    },
                ]
                print("data %s"%(data))
                result = kubeClient.handle('deployment', 'DELETE', data)
                if result['status'] is True:
                    print('用例%s 删除容器成功 %s' % (case_name, data))
                else:
                    print('用例%s 删除容器失败 %s' % (case_name, data))
コード例 #2
0
def createOpsTopoByTempId():
    kubeClient = KubeClient(uid)
    res = kubeClient.handle('server','CREATE_TOPO_BY_TEMP',templateCfg)
    print(res,type(res))
コード例 #3
0
def switchOpsTopo():
    kubeClient = KubeClient(uid)
    res = kubeClient.handle('server','SWITCH_TOPO',switchCfg)
    print(res,type(res))
コード例 #4
0
def getPodByUid():
    kubeClient = KubeClient(uid)
    res = kubeClient.handle('deployment','GET_DEPS_BY_UID')
    print(res,type(res))
コード例 #5
0
def getPodsIp():
    kubeClient = KubeClient(uid)
    res = kubeClient.handle('deployment','GET_PODS_IP',depNames)
    print(res,type(res))
コード例 #6
0
def getPodList():
    kubeClient = KubeClient(uid)
    res = kubeClient.handle('deployment','GET_NAMES')
    print(res,type(res))
コード例 #7
0
def deleteDeps():
    kubeClient = KubeClient(uid)
    res = kubeClient.handle('deployment','DELETE',depList)
    print(res,type(res))
コード例 #8
0
def createDeps():
    kubeClient = KubeClient(uid)
    res = kubeClient.handle('deployment','CREATE',configList)
    print(res,type(res))