From 0c9c2dc293c704e4311eb5d6f75b2def4a32c127 Mon Sep 17 00:00:00 2001 From: xieqiyu Date: Tue, 26 Dec 2023 20:22:46 +0800 Subject: [PATCH] * Add the test file of createSnapshot. --- module/zanode/test/model/createsnapshot.php | 23 ++++++++++++++ .../test/model/yaml/createsnapshot/host.yaml | 31 +++++++++++++++++++ module/zanode/test/zanode.class.php | 30 ++++++++++++++++++ module/zanode/zen.php | 2 +- 4 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 module/zanode/test/model/createsnapshot.php create mode 100644 module/zanode/test/model/yaml/createsnapshot/host.yaml diff --git a/module/zanode/test/model/createsnapshot.php b/module/zanode/test/model/createsnapshot.php new file mode 100644 index 0000000000..035447dce9 --- /dev/null +++ b/module/zanode/test/model/createsnapshot.php @@ -0,0 +1,23 @@ +#!/usr/bin/env php +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('失败'); //因为没有固定的服务器连接结果均失败 diff --git a/module/zanode/test/model/yaml/createsnapshot/host.yaml b/module/zanode/test/model/yaml/createsnapshot/host.yaml new file mode 100644 index 0000000000..98e60b6b6f --- /dev/null +++ b/module/zanode/test/model/yaml/createsnapshot/host.yaml @@ -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`' diff --git a/module/zanode/test/zanode.class.php b/module/zanode/test/zanode.class.php index d9756e7573..a833d0c555 100644 --- a/module/zanode/test/zanode.class.php +++ b/module/zanode/test/zanode.class.php @@ -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(); + } } diff --git a/module/zanode/zen.php b/module/zanode/zen.php index 2b399ebc2d..0238ff12a7 100644 --- a/module/zanode/zen.php +++ b/module/zanode/zen.php @@ -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'))) {