* Add the test file of createSnapshot.
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
|
||||
title=测试 zanodeModel->createSnapshot().
|
||||
cid=1
|
||||
|
||||
- 因为没有固定的服务器连接结果均失败 @失败
|
||||
|
||||
*/
|
||||
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/zanode.class.php';
|
||||
|
||||
zdTable('host')->config('host')->gen(5);
|
||||
zdTable('user')->gen(5);
|
||||
su('admin');
|
||||
|
||||
$zanode = new zanodeTest();
|
||||
|
||||
$snapshot = array('name' => 'snapshot1', 'desc' => '这是快照1的描述');
|
||||
r($zanode->createSnapshotTest(1, $snapshot)) && p(0) && e('失败'); //因为没有固定的服务器连接结果均失败
|
||||
@@ -0,0 +1,31 @@
|
||||
title: zt_host
|
||||
author: Wang XuePeng
|
||||
version: "1.0"
|
||||
fields:
|
||||
- field: id
|
||||
range: 1-1000
|
||||
- field: name
|
||||
fields:
|
||||
- field: field1
|
||||
range: node{5},physics{5}
|
||||
- field: field2
|
||||
range: 1-4{2},aa{2}
|
||||
- field: image
|
||||
range: 1-10
|
||||
- field: mac
|
||||
prefix: mac
|
||||
range: 1-10
|
||||
- field: type
|
||||
range: node
|
||||
- field: parent
|
||||
range: 0{3},1-3{3},100
|
||||
- field: hostType
|
||||
range: virtual{3},``{10}
|
||||
- field: heartbeat
|
||||
range: "(-10D)-(+10D):-70S"
|
||||
type: timestamp
|
||||
format: "YYYY-MM-DD hh:mm:ss"
|
||||
- field: status
|
||||
range: running,ready,wait,running{3},wait{3},ready{3},running
|
||||
- field: extranet
|
||||
range: '`127.0.0.1`'
|
||||
@@ -108,4 +108,34 @@ class zanodeTest
|
||||
foreach($snapshotList as $name => $snapshot) $return .= "{$snapshot->id}:{$name},{$snapshot->status};";
|
||||
return trim($return, ';');
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试创建快照。
|
||||
* Test create snapshot.
|
||||
*
|
||||
* @param int $nodeID
|
||||
* @param array $snapshot
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function createSnapshotTest(int $nodeID, array $data): object|array
|
||||
{
|
||||
$node = $this->getNodeByID($nodeID);
|
||||
|
||||
$snapshot = new stdClass();
|
||||
$snapshot->host = $node->id;
|
||||
$snapshot->name = $data['name'];
|
||||
$snapshot->desc = $data['desc'];
|
||||
$snapshot->status = 'creating';
|
||||
$snapshot->osName = $node->osName;
|
||||
$snapshot->memory = 0;
|
||||
$snapshot->disk = 0;
|
||||
$snapshot->fileSize = 0;
|
||||
$snapshot->from = 'snapshot';
|
||||
|
||||
$snapshotID = $this->createSnapshot($node, $snapshot);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $this->objectModel->dao->select('*')->from(TABLE_IMAGE)->where('id')->eq($snapshotID)->fetch();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ class zanodeZen extends zanode
|
||||
*/
|
||||
protected function handleNode(int $nodeID, string $type)
|
||||
{
|
||||
$node = $this->getNodeByID($nodeID);
|
||||
$node = $this->zanode->getNodeByID($nodeID);
|
||||
|
||||
if(in_array($node->status, array('restoring', 'creating_img', 'creating_snap')))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user