diff --git a/appStore/testCase/models.py b/appStore/testCase/models.py index 870d0ddfb9c7b4174437926e82c3fd0a37798642..d865f71817fdbbd130305ffe5ea3336d77f27f6f 100644 --- a/appStore/testCase/models.py +++ b/appStore/testCase/models.py @@ -1,10 +1,3 @@ -""" - * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. - * PilotGo-plugin licensed under the Mulan Permissive Software License, Version 2. - * See LICENSE file for more details. - * Author: wangqingzheng - * Date: Fri Mar 1 10:09:12 2024 +0800 -""" from django.db import models @@ -27,6 +20,7 @@ class TestCase(models.Model): cpu2017 = models.IntegerField(default=0, verbose_name='几组cpu2017数据') user_name = models.CharField(max_length=255, verbose_name='测试人员', ) test_result = models.CharField(max_length=255, verbose_name='测试结果反馈', null=True, blank=True) # 如果有多项也是拼接 + result_log_name = models.CharField(max_length=255, verbose_name='日志文件名称的base部分') class Meta: db_table = 'testCase' diff --git a/appStore/utils/common.py b/appStore/utils/common.py index 85ac26626378674f047a6aaeabb04ef7bf05cf6b..ed9de490df32178648bd3b6aab9cadb1f17f0c8b 100644 --- a/appStore/utils/common.py +++ b/appStore/utils/common.py @@ -12,11 +12,16 @@ @author: Wqz @time: 11/6/19 4:33 PM """ +import glob +import os +import tarfile import subprocess from django.core.paginator import Paginator, EmptyPage from django.http import JsonResponse from rest_framework import pagination, status +from appStore.utils.constants import RESULT_LOG_FILE + def json_response(data=None, code=None, message=None): """ @@ -101,22 +106,61 @@ def get_page(data, objs): list = paginator.page(1) # 当输入的page是不存在的时候就会报错 return list -# 定义远程服务器的IP地址、用户名和密码 -remote_host = 'IP地址' -remote_username = '用户名' -remote_password = '密码' -def test_case(remote_host,remote_username,remote_password): - # 使用scp命令将安装包发送到远程服务器 - scp_command = f'sshpass -p {remote_password} scp -o StrictHostKeyChecking=no -r /root/run_kytuning-ffdev/ {remote_username}@{remote_host}:/root/run_kytuning-ffdev' - return_result = subprocess.run(scp_command, shell=True) - if return_result.returncode == 5: - return_result.stderr = "请确认测试机器的账号密码是否正确" - return return_result - elif return_result.returncode: - return_result.stderr = "scp 命令出错" + +def test_case(test_ip, test_username, test_password, test_case_names, user_config_path, result_log_name): + """ + + :param test_ip: 测试机器的ip + :param test_username: 测试机器的用户名 + :param test_password: 测试机器的密码 + :param result_log_name: 存放日志文件路径 + :param test_case_names: 需要哪几项 + :param run_kytuning_temp: run_kytuning存放的临时文件 + :return: + """ + # 下载run_kytuning代码 + wget_command = f'sshpass -p {test_password} ssh {test_username}@{test_ip} "rm -rf /root/run_kytuning-ffdev/;wget -O /root/run_kytuning-ffdev.zip http://localhost:9000/tools/run_kytuning-ffdev.zip;unzip /root/run_kytuning-ffdev.zip -d /root/;rm -rf /root/run_kytuning-ffdev/conf/user.cfg;rm -rf /root/run_kytuning-ffdev/yaml-base/"' + wget_result = subprocess.run(wget_command, shell=True) + if wget_result.returncode: + wget_result.stderr = "测试端下载run_kytuning代码出错,请检查账号、密码是否正确,网络是否可用" + return wget_result + + # # 复制配置文件conf文件和yaml文件 + scp_command = f'sshpass -p {test_password} scp -o StrictHostKeyChecking=no -r {user_config_path}/conf {user_config_path}/yaml-base {test_username}@{test_ip}:/root/run_kytuning-ffdev/' + scp_result = subprocess.run(scp_command, shell=True) + + if scp_result.returncode: + scp_result.stderr = "复制配置文件出错" + return scp_result + + # 保存性能测试的打印日志 + with open(result_log_name + '_outp.log', 'w') as f: + # 在远程服务器上运行run.sh脚本 + ssh_command = f'sshpass -p {test_password} ssh {test_username}@{test_ip} "cd /root/run_kytuning-ffdev/;sh /root/run_kytuning-ffdev/run.sh"' + return_result = subprocess.run(ssh_command, stdout=f, stderr=f, encoding='utf-8', shell=True) + + + # 保存kytuning的日志,先获取此次测试测试了哪几项,在获取对应的kytuning.log文件 + for test_case_name in test_case_names: + klog_command = f'sshpass -p {test_password} scp -o StrictHostKeyChecking=no -r {test_username}@{test_ip}:/root/kytuning/run/{test_case_name}/kytuning.log {result_log_name}_{test_case_name}_kytuning.log' + klog_result = subprocess.run(klog_command, shell=True) + + # 打包日志文件,方便户下载 + tar_file_path = result_log_name + '.tar' + # 获取以指定前缀的所有文件路径 + file_paths = glob.glob(result_log_name + '*') + + # 打包文件 + with tarfile.open(tar_file_path, "w") as tar: + for file_path in file_paths: + tar.add(file_path, arcname=file_path.replace(RESULT_LOG_FILE, '')) + + # 删除旧文件 + for file_path in file_paths: + if os.path.exists(file_path): + os.remove(file_path) + if return_result.returncode: + return_result.stderr = "sh run.sh 命令出错,请查看详细日志" return return_result - # 在远程服务器上运行脚本 - ssh_command = f'sshpass -p {remote_password} ssh {remote_username}@{remote_host} "cd /root/run_kytuning-ffdev/;sh /root/run_kytuning-ffdev/run.sh"' - return_result = subprocess.run(ssh_command, stderr=subprocess.PIPE, encoding='utf-8', shell=True) - return return_result \ No newline at end of file + return klog_result diff --git a/appStore/utils/constants.py b/appStore/utils/constants.py index 6ddd40b8829f5324f3ea15479f149baa296fdafc..3caf766e65167da8ebe15275928b5744bb2fe328 100644 --- a/appStore/utils/constants.py +++ b/appStore/utils/constants.py @@ -5,12 +5,7 @@ * Author: wangqingzheng * Date: Fri Feb 23 10:00:37 2024 +0800 """ -# 是否记录对应数据,默认为 -CPU2006_BOOL = False -CPU2017_BOOL = False -FIO_BOOL = False -IOZONE_BOOL = False -JVM2008_BOOL = False -LMBENCH_BOOL = False -STREAM_BOOL = False -UNIXBENCH_BOOL = False +# 服务端记录测试端的测试日志路径 +RESULT_LOG_FILE = '/var/www/html/result_log_file/' +#用户配置文件路径 +RUN_KYTUNING_CONFIG_TEMP = '/var/www/html/run_kytuning_config_temp/' diff --git a/kytuningProject/settings.py b/kytuningProject/settings.py index 43e52cdab71ed4c9590a05812f255059a87632c4..449d06a7794205d39a6fcccc58f65e43d458a541 100644 --- a/kytuningProject/settings.py +++ b/kytuningProject/settings.py @@ -81,8 +81,7 @@ MIDDLEWARE = [ ROOT_URLCONF = 'djangoProject.urls' CORS_ORIGIN_ALLOW_ALL = True CORS_ALLOWED_ORIGINS = [ - 'http://172.29.220.200:8080', # 允许从这个地址发出跨域请求 - 'http://172.29.220.94:8080', # 允许从这个地址发出跨域请求 + 'http://localhost:8080', # 允许从这个地址发出跨域请求 # ... ] diff --git a/templates/front-project/src/api/api.js b/templates/front-project/src/api/api.js index aac032f2e8e47ba04bfef445f261c0be60beac42..bfdc4175aa3b8734b8ce48877a6a58a1cf715c9f 100644 --- a/templates/front-project/src/api/api.js +++ b/templates/front-project/src/api/api.js @@ -20,15 +20,24 @@ export function login(data) { // 测试管理列表 -export function test_case(params) { +export function test_case(type,data) { return service({ - method: 'get', + method: type, url: '/test_case/', + data + }) +} +//测试日志导出 +export function down_message(params) { + return service({ + method: 'get', + url: '/down_message/', + responseType: 'blob', params }) } -// project +// 获取指定的project组 export function get_project(params) { return service({ method: 'get', diff --git a/templates/front-project/src/components/AllMenu.vue b/templates/front-project/src/components/AllMenu.vue index 7e67f563e5b86a7639e953fc38b07f347c07d7a7..7870b41eb50fbcbe056d881dfde21337122d36ec 100644 --- a/templates/front-project/src/components/AllMenu.vue +++ b/templates/front-project/src/components/AllMenu.vue @@ -12,7 +12,7 @@ router :default-active="activePath" class="el-menu-vertical-demo" - background-color="#409EFF" + background-color="#2578b5" text-color="#fff" active-text-color="#ffd04b">