Merge branch 'zenops_46_tanghucheng' into zenops_46

This commit is contained in:
tanghucheng
2022-12-16 20:21:01 +08:00
19 changed files with 138 additions and 17 deletions
+3 -2
View File
@@ -16,8 +16,9 @@
<div class="modal-body">
<p>
<i class="icon-check-circle icon"></i><?php echo $notice;?>
<?php $modalLink = !empty($modalLink) ? $modalLink : '';?>
<?php echo html::a($modalLink, $buttonName, '', 'id="modalLink"');?>
<?php $modalLink = !empty($modalLink) ? $modalLink : '';?>
<?php $class = !empty($modalClass) ? $modalClass : '';?>
<?php echo html::a($modalLink, $buttonName, '', "id='modalLink' class='$class'");?>
</p>
</div>
</div>
+3 -1
View File
@@ -2375,7 +2375,7 @@ class testcase extends control
* @access public
* @return void
*/
public function automation($productID)
public function automation($productID = 0)
{
$this->loadModel('zanode');
$nodeList = $this->zanode->getPairs();
@@ -2397,6 +2397,8 @@ class testcase extends control
$this->view->automation = $automation;
$this->view->nodeList = $nodeList;
$this->view->productID = $productID;
$this->view->products = $this->product->getPairs('', 0, '', 'all');
$this->display();
}
+35 -1
View File
@@ -20,6 +20,12 @@
</div>
<form method='post' target='hiddenwin'>
<table class='table table-form'>
<?php if(!$productID):?>
<tr>
<th class='w-80px'><?php echo $lang->testcase->product;?></th>
<td class='required'><?php echo html::select('product', $products, '', "class='form-control picker-select' onchange='loadProduct(this.value)'");?></td>
</tr>
<?php endif;?>
<tr>
<th class='w-80px'><?php echo $lang->zanode->common;?></th>
<td class='required'><?php echo html::select('node', $nodeList, !empty($automation->node) ? $automation->node : '', "class='form-control picker-select'");?></td>
@@ -34,7 +40,7 @@
</tr>
<tr>
<td colspan='2' class='text-center'>
<?php echo html::hidden('product', $productID);?>
<?php if($productID) echo html::hidden('product', $productID);?>
<?php if($automation) echo html::hidden('id', $automation->id);?>
<?php echo html::submitButton();?>
</td>
@@ -43,4 +49,32 @@
</form>
</div>
</div>
<script>
$(function()
{
if($("#product").length > 0){
$('#product').change();
}
})
function loadProduct(obj)
{
$('#node').data('zui.picker').setValue(<?php echo key($nodeList)?>);
$('#shell').val('');
$('#scriptPath').val('');
var url = createLink('zanode', 'ajaxGetZTFScript', "type=product&objectID=" + obj)
$.get(url, function(result)
{
if(result.result == 'success')
{
data = result.data;
if(!data) return false;
$('#node').data('zui.picker').setValue(data.node)
$('#shell').val(data.shell);
$('#scriptPath').val(data.scriptPath);
$('#submit').before("<input type='hidden' name='id' value='" + data.id + "'>");
}
}, 'json');
}
</script>
<?php include '../../common/view/footer.html.php';?>
+1
View File
@@ -1239,6 +1239,7 @@ class testtask extends control
{
$resultID = $this->testtask->initResult($runID, $caseID, $run->case->version, $automation->node);
if(!dao::isError()) $this->zanode->runZTFScript($automation->id, $caseID, $resultID);
if(dao::isError()) return print(js::error(dao::getError()) . js::locate($this->createLink('zanode', 'browse'), 'parent'));
}
if(!empty($_POST))
+1
View File
@@ -108,6 +108,7 @@ $lang->testtask->caseCount = 'Case Count';
$lang->testtask->passCount = 'Pass';
$lang->testtask->failCount = 'Fail';
$lang->testtask->summary = '%s cases, %s failures, %s time.';
$lang->testtask->stepSummary = 'Total %s steps, %s passes, %s failures.';
$lang->testtask->pageSummary = 'Total testtasks: <strong>%s</strong>.';
$lang->testtask->mySummary = 'Total testtasks: <strong>%s</strong>, Wait: <strong>%s</strong>, Testing: <strong>%s</strong>, Blocked: <strong>%s</strong>.';
$lang->testtask->allSummary = 'Total testtasks: <strong>%s</strong>, Wait: <strong>%s</strong>, Testing: <strong>%s</strong>, Blocked: <strong>%s</strong>, Done: <strong>%s</strong>.';
+1
View File
@@ -108,6 +108,7 @@ $lang->testtask->caseCount = 'Case Count';
$lang->testtask->passCount = 'Pass';
$lang->testtask->failCount = 'Fail';
$lang->testtask->summary = '%s cases, %s failures, %s time.';
$lang->testtask->stepSummary = 'Total %s steps, %s passes, %s failures.';
$lang->testtask->pageSummary = 'Total testtasks: <strong>%s</strong>.';
$lang->testtask->mySummary = 'Total testtasks: <strong>%s</strong>, Wait: <strong>%s</strong>, Testing: <strong>%s</strong>, Blocked: <strong>%s</strong>.';
$lang->testtask->allSummary = 'Total testtasks: <strong>%s</strong>, Wait: <strong>%s</strong>, Testing: <strong>%s</strong>, Blocked: <strong>%s</strong>, Done: <strong>%s</strong>.';
+1
View File
@@ -108,6 +108,7 @@ $lang->testtask->caseCount = 'Compteur CasTest';
$lang->testtask->passCount = 'Pass';
$lang->testtask->failCount = 'Fail';
$lang->testtask->summary = '%s CasTest, %s échecs, %s heures.';
$lang->testtask->stepSummary = 'Total %s steps, %s passes, %s failures.';
$lang->testtask->pageSummary = 'Total testtasks: <strong>%s</strong>.';
$lang->testtask->mySummary = 'Total testtasks: <strong>%s</strong>, Wait: <strong>%s</strong>, Testing: <strong>%s</strong>, Blocked: <strong>%s</strong>.';
$lang->testtask->allSummary = 'Total testtasks: <strong>%s</strong>, Wait: <strong>%s</strong>, Testing: <strong>%s</strong>, Blocked: <strong>%s</strong>, Done: <strong>%s</strong>.';
+1
View File
@@ -97,6 +97,7 @@ $lang->testtask->caseCount = 'Case Count';
$lang->testtask->passCount = 'Pass';
$lang->testtask->failCount = 'Fail';
$lang->testtask->summary = '%s cases, %s failures, %s time.';
$lang->testtask->stepSummary = 'Total %s steps, %s passes, %s failures.';
$lang->testtask->beginAndEnd = 'Thời gian';
$lang->testtask->to = 'Tới';
+1
View File
@@ -108,6 +108,7 @@ $lang->testtask->caseCount = '用例数';
$lang->testtask->passCount = '成功';
$lang->testtask->failCount = '失败';
$lang->testtask->summary = '有%s个用例,失败%s个,耗时%s。';
$lang->testtask->stepSummary = '共有%s个步骤,%s个通过,%s个失败。';
$lang->testtask->pageSummary = '本页共 <strong>%s</strong> 个测试单。';
$lang->testtask->mySummary = '本页共 <strong>%s</strong> 个测试单,待测试测试单 <strong>%s</strong>,测试中测试单 <strong>%s</strong>,被阻塞测试单 <strong>%s</strong>。';
$lang->testtask->allSummary = '本页共 <strong>%s</strong> 个测试单,待测试测试单 <strong>%s</strong>,测试中测试单 <strong>%s</strong>,被阻塞测试单 <strong>%s</strong>,已测测试单 <strong>%s</strong>。';
+55 -4
View File
@@ -1448,12 +1448,10 @@ class testtaskModel extends model
if(!empty($result->ZTFResult))
{
$result->ZTFResult = json_decode($result->ZTFResult);
$result->ZTFResult = empty($result->ZTFResult->log) ? '' : $result->ZTFResult->log;
$result->ZTFResult = "<li>" . str_replace(array("\r", "\n", "\r\n"), "</li><li>", $result->ZTFResult) . "</li>";
$result->ZTFResult = $this->formatZtfLog($result->ZTFResult, $result->stepResults);
}
$result->files = zget($resultFiles, $resultID, array()); //Get files of case result.
$result->files = zget($resultFiles, $resultID, array()); //Get files of case result.
if(isset($relatedSteps[$result->version]))
{
$relatedStep = $relatedSteps[$result->version];
@@ -1477,6 +1475,59 @@ class testtaskModel extends model
return $results;
}
/**
* Format ztf log.
*
* @param string $log
* @access public
* @return string
*/
public function formatZtfLog($result, $stepResults)
{
$logObj = json_decode($result);
$logs = empty($logObj->log) ? '' : $logObj->log;
if(empty($logs)) return '';
$logs = str_replace(array("\r", "\n", "\r\n"), "\n", $logs);
$logList = explode("\n", $logs);
$logHtml = "";
foreach($logList as $log)
{
$log = preg_replace("/^[\d\-:.\x20]+/", '', $log);
$log = trim($log);
if(empty($log)) continue;
$log = preg_replace(array("/:\x20失败/", "/:\x20fail/", "/:\x20成功/", "/:\x20pass/"), array(': <strong class="result-testcase fail">失败</strong>',': <strong class="result-testcase fail">fail</strong>',': <strong class="result-testcase pass">成功</strong>',': <strong class="result-testcase fail">pass</strong>'), $log);
$logHtml .= "<li>" . $log . "</li>";
}
if(!empty($stepResults))
{
$total = count($stepResults);
$failCount = $passCount = 0;
foreach($stepResults as $step)
{
if($step['result'] == 'pass')
{
$passCount++;
}
elseif($step['result'] == 'fail')
{
$failCount++;
}
}
$caseResult = $passCount ? 'pass':'fail';
$logHtml .= "<li class='result-testcase {$caseResult}'>"
. sprintf($this->lang->testtask->stepSummary, $total, $passCount, $failCount)
. "</li>";
}
return $logHtml;
}
/**
* Judge an action is clickable or not.
*
+1
View File
@@ -41,6 +41,7 @@ $lang->zahost->initNotice = 'Save successfully, initialize the ZAhost o
$lang->zahost->createZanodeNotice = 'Initialization successful, ready to create the zanode';
$lang->zahost->downloadImageNotice = 'Initialization successful, download the image to create zanode';
$lang->zahost->undeletedNotice = "The host has nodes that cannot be deleted.";
$lang->zahost->uninitNotice = 'Please init the host first';
$lang->zahost->netError = 'Unable to connect to the host, please check the network and try again.';
$lang->zahost->init = new stdclass;
+1
View File
@@ -41,6 +41,7 @@ $lang->zahost->initNotice = 'Save successfully, initialize the ZAhost o
$lang->zahost->createZanodeNotice = 'Initialization successful, ready to create the zanode';
$lang->zahost->downloadImageNotice = 'Initialization successful, download the image to create zanode';
$lang->zahost->undeletedNotice = "The host has nodes that cannot be deleted.";
$lang->zahost->uninitNotice = 'Please init the host first';
$lang->zahost->netError = 'Unable to connect to the host, please check the network and try again.';
$lang->zahost->init = new stdclass;
+1
View File
@@ -41,6 +41,7 @@ $lang->zahost->initNotice = 'Save successfully, initialize the ZAhost o
$lang->zahost->createZanodeNotice = 'Initialization successful, ready to create the zanode';
$lang->zahost->downloadImageNotice = 'Initialization successful, download the image to create zanode';
$lang->zahost->undeletedNotice = "The host has nodes that cannot be deleted.";
$lang->zahost->uninitNotice = 'Please init the host first';
$lang->zahost->netError = 'Unable to connect to the host, please check the network and try again.';
$lang->zahost->init = new stdclass;
+1
View File
@@ -41,6 +41,7 @@ $lang->zahost->initNotice = '保存成功,请您初始化宿主机或
$lang->zahost->createZanodeNotice = '初始化成功,您现在可以创建执行节点了。';
$lang->zahost->downloadImageNotice = '初始化成功,请下载镜像用于创建执行节点。';
$lang->zahost->undeletedNotice = "宿主机下存在执行节点无法删除。";
$lang->zahost->uninitNotice = '请先初始化宿主机';
$lang->zahost->netError = '无法连接到宿主机,请检查网络后重试。';
$lang->zahost->init = new stdclass;
+4 -2
View File
@@ -70,10 +70,12 @@
<td><?php echo helper::isZeroDate($host->heartbeat) ? '' : $host->heartbeat;?></td>
<td class='c-actions'>
<?php $disabled = !empty($nodeList[$host->hostID]) ? 'disabled' : '';?>
<?php $title = !empty($nodeList[$host->hostID]) ? $lang->zahost->delete : $lang->zahost->undeletedNotice;?>
<?php $title = !empty($nodeList[$host->hostID]) ? $lang->zahost->undeletedNotice : $lang->zahost->delete;?>
<?php common::printIcon('zahost', 'edit', "hostID={$host->hostID}", $host, 'list');?>
<?php echo html::a($this->createLink('zahost', 'delete', "hostID={$host->id}"), '<i class="icon-trash"></i>', 'hiddenwin', "title='$title' class='btn $disabled'");;?>
<?php common::printIcon('zahost', 'browseImage', "hostID={$host->hostID}", $host, 'list', 'snap-house', '', 'iframe', true, "data-width='60%'", $lang->zahost->image->list);?>
<?php $disabled = ($host->status == 'wait') ? 'disabled' : '';?>
<?php $title = ($host->status == 'wait') ? $lang->zahost->uninitNotice: $lang->zahost->image->list;?>
<?php common::printIcon('zahost', 'browseImage', "hostID={$host->hostID}", $host, 'list', 'snap-house', '', "iframe $disabled", true, "data-width='60%'", $title);?>
<?php common::printIcon('zahost', 'init', "hostID={$host->hostID}", $host, 'list', 'refresh', '', ' init', false, "data-placement='bottom'", $lang->zahost->init->title);?>
</td>
</tr>
+17 -3
View File
@@ -142,8 +142,8 @@ class zanode extends control
$this->view->node = $this->zanode->getNodeById($nodeID);
$this->view->notice = $this->lang->zanode->init->initSuccessNoticeTitle;
$this->view->buttonName = $this->lang->zanode->init->button;
$productID = $this->session->product ? $this->session->product : 0;
$this->view->modalLink = $this->createLink('testcase', 'browse', "productID={$productID}");
$this->view->modalLink = $this->createLink('testcase', 'automation', 0, '', true);
$this->view->modalClass = 'iframe';
$this->view->closeLink = $this->createLink('zanode', 'browse');
$this->display();
@@ -381,7 +381,21 @@ class zanode extends control
}
/**
* ajaxRunZTFScript
* Ajax: get ZTF script.
*
* @access public
* @return void
*/
public function ajaxGetZTFScript($type = 'product', $objectID = 0)
{
$script = array();
if($type == '') $script = $this->zanode->getAutomationByID($objectID);
if($type == 'product') $script = $this->zanode->getAutomationByProduct($objectID);
return $this->send(array('result' => 'success', 'data' => $script));
}
/**
* Ajax: run ZTF script.
*
* @param int $scriptID
* @access public
+8 -1
View File
@@ -725,6 +725,13 @@ class zanodemodel extends model
{
$automation = $this->getAutomationByID($scriptID);
$node = $this->getNodeByID($automation->node);
if(empty($node) or $node->status != 'running' or !$node->ip or !$node->ztf or !$node->tokenSN)
{
$this->dao->delete()->from(TABLE_TESTRESULT)->where('id')->eq($task)->exec();
return dao::$errors = $this->lang->zanode->runTimeout;
}
$params = array(
'cmd' => $automation->shell,
'ids' => strval($caseID),
@@ -733,7 +740,7 @@ class zanodemodel extends model
);
$result = json_decode(commonModel::http("http://{$node->ip}:{$node->ztf}/api/v1/jobs/add", json_encode($params), array(), array("Authorization:$node->tokenSN")));
if($result->code != 0)
if(empty($result) or $result->code != 0)
{
$this->dao->delete()->from(TABLE_TESTRESULT)->where('id')->eq($task)->exec();
return dao::$errors = $this->lang->zanode->runTimeout;
+2 -2
View File
@@ -23,11 +23,11 @@
<tr>
<th><?php echo $lang->zanode->hostName;?></th>
<td><?php echo html::select('parent', $hostPairs, '', "class='form-control chosen'")?></td>
<td></td>
</tr>
<tr>
<th class='w-120px'><?php echo $lang->zanode->name;?></th>
<td class='p-25f'><?php echo html::input('name', '', "class='form-control' placeholder=\"{$lang->zanode->nameValid}\"");?></td>
<td></td>
</tr>
<tr>
<th><?php echo $lang->zanode->image;?></th>
@@ -67,7 +67,7 @@
<td></td>
</tr>
<tr>
<td colspan="2" class='text-center form-actions'>
<td colspan="3" class='text-center form-actions'>
<?php echo html::submitButton();?>
<?php echo html::a(inlink('browse'), $lang->goback, '', "class='btn btn-wide btn-back'");?>
</td>
+1 -1
View File
@@ -67,7 +67,7 @@
<td></td>
</tr>
<tr>
<td colspan="2" class='text-center form-actions'>
<td colspan="3" class='text-center form-actions'>
<?php echo html::submitButton();?>
<?php echo html::a(inlink('browse'), $lang->goback, '', "class='btn btn-wide btn-back'");?>
</td>