From 3f365a404f95f3db5747ede9927dbfb6f975ee86 Mon Sep 17 00:00:00 2001 From: A-Harby Date: Sun, 22 Oct 2023 18:18:52 +0300 Subject: [PATCH 1/3] add ping node utils and update tests --- .../tests/modules/contracts.test.ts | 14 ++-- .../tests/modules/gateways.test.ts | 14 ++-- .../tests/modules/kubernetes.test.ts | 44 ++++++++---- .../grid_client/tests/modules/qsfs.test.ts | 72 ++++++++++++------- packages/grid_client/tests/modules/vm.test.ts | 21 ++++-- .../grid_client/tests/modules/zdb.test.ts | 7 +- packages/grid_client/tests/utils.ts | 23 +++++- 7 files changed, 133 insertions(+), 62 deletions(-) diff --git a/packages/grid_client/tests/modules/contracts.test.ts b/packages/grid_client/tests/modules/contracts.test.ts index fbf5741f8d..70ccf657df 100644 --- a/packages/grid_client/tests/modules/contracts.test.ts +++ b/packages/grid_client/tests/modules/contracts.test.ts @@ -7,10 +7,9 @@ import { NameContractGetModel, NodeContractCreateModel, NodeContractUpdateModel, - randomChoice, } from "../../src"; import { getClient } from "../client_loader"; -import { generateHash, log } from "../utils"; +import { checkNodeAvail, generateHash, log } from "../utils"; jest.setTimeout(300000); @@ -36,7 +35,8 @@ test("TC1269 - Contracts: Create Node Contract", async () => { availableFor: await gridClient.twins.get_my_twin_id(), farmId: 1, } as FilterOptions); - const nodeId = +randomChoice(nodes).nodeId; + const nodeId = await checkNodeAvail(nodes); + if (nodeId == -1) return; const hash = generateHash(generateString(8)); const data = generateString(64); const publicIp = 0; @@ -106,11 +106,11 @@ test("TC1271 - Contracts: Get Node Contract By Node ID & Contract Hash", async ( availableFor: await gridClient.twins.get_my_twin_id(), farmId: 1, } as FilterOptions); - const nodeId = +randomChoice(nodes).nodeId; + const nodeId = await checkNodeAvail(nodes); + if (nodeId == -1) return; const hash = generateHash(generateString(8)); const data = generateString(64); const publicIp = 0; - const twinId = await gridClient.twins.get_my_twin_id(); // Create Contract const contract: NodeContractCreateModel = { @@ -149,7 +149,6 @@ test("TC1272 - Contracts: Get Name Contract", async () => { //TestData const name = generateString(15).toLowerCase(); - const twinId = await gridClient.twins.get_my_twin_id(); //Create Contract const contract: NameContractCreateModel = { @@ -189,7 +188,8 @@ test("TC1273 - Contracts: Update Node Contract", async () => { availableFor: await gridClient.twins.get_my_twin_id(), farmId: 1, } as FilterOptions); - const nodeId = +randomChoice(nodes).nodeId; + const nodeId = await checkNodeAvail(nodes); + if (nodeId == -1) return; const hash = generateHash(generateString(8)); const data = generateString(64); const newHash = generateHash(generateString(8)); diff --git a/packages/grid_client/tests/modules/gateways.test.ts b/packages/grid_client/tests/modules/gateways.test.ts index 55e753862e..38219d40bf 100644 --- a/packages/grid_client/tests/modules/gateways.test.ts +++ b/packages/grid_client/tests/modules/gateways.test.ts @@ -3,9 +3,7 @@ import { setTimeout } from "timers/promises"; import { FilterOptions, GatewayNameModel, generateString, GridClient, MachinesModel, randomChoice } from "../../src"; import { config, getClient } from "../client_loader"; -import { generateInt, log, splitIP } from "../utils"; - -const exec = require("child_process").exec; +import { checkNodeAvail, generateInt, log, splitIP } from "../utils"; jest.setTimeout(300000); @@ -65,7 +63,8 @@ test("TC1237 - Gateways: Expose a VM Over Gateway", async () => { farmId: 1, availableFor: await gridClient.twins.get_my_twin_id(), } as FilterOptions); - const gatewayNodeId = +randomChoice(gatewayNodes).nodeId; + const gatewayNodeId = await checkNodeAvail(gatewayNodes); + if (gatewayNodeId == -1) return; //Node Selection let nodes; @@ -96,7 +95,8 @@ test("TC1237 - Gateways: Expose a VM Over Gateway", async () => { availableFor: await gridClient.twins.get_my_twin_id(), } as FilterOptions); } - const nodeId = +randomChoice(nodes).nodeId; + const nodeId = await checkNodeAvail(nodes); + if (nodeId == -1) return; //VM Model const vms: MachinesModel = { @@ -198,11 +198,11 @@ test("TC1237 - Gateways: Expose a VM Over Gateway", async () => { for (let i = 0; i < 30; i++) { axios .get(domain) - .then(res => { + .then(() => { log("gateway is reachable"); reachable = true; }) - .catch(err => { + .catch(() => { log("gateway is not reachable"); }); if (reachable) { diff --git a/packages/grid_client/tests/modules/kubernetes.test.ts b/packages/grid_client/tests/modules/kubernetes.test.ts index f33b42953b..ead677694a 100644 --- a/packages/grid_client/tests/modules/kubernetes.test.ts +++ b/packages/grid_client/tests/modules/kubernetes.test.ts @@ -8,7 +8,7 @@ import { randomChoice, } from "../../src"; import { config, getClient } from "../client_loader"; -import { bytesToGB, generateInt, k8sWait, log, RemoteRun, splitIP } from "../utils"; +import { bytesToGB, checkNodeAvail, generateInt, k8sWait, log, RemoteRun, splitIP } from "../utils"; jest.setTimeout(500000); @@ -123,10 +123,16 @@ test("TC1231 - Kubernetes: Deploy a Kubernetes Cluster", async () => { availableFor: await gridClient.twins.get_my_twin_id(), } as FilterOptions); } - const masterNodeId = +randomChoice(masterNode).nodeId; - let workerNodeId = +randomChoice(workerNode).nodeId; - while (masterNodeId == workerNodeId) { - workerNodeId = +randomChoice(workerNode).nodeId; + const masterNodeId = await checkNodeAvail(masterNode); + if (masterNodeId == -1) return; + let workerNodeId = await checkNodeAvail(workerNode); + if (workerNodeId == -1) return; + + let maxCount = 3; + while (masterNodeId == workerNodeId && maxCount > 0) { + workerNodeId = await checkNodeAvail(workerNode); + if (workerNodeId == -1) return; + maxCount--; } //K8s Model @@ -383,10 +389,16 @@ test("TC1232 - Kubernetes: Add Worker", async () => { availableFor: await gridClient.twins.get_my_twin_id(), } as FilterOptions); } - const masterNodeId = +randomChoice(masterNode).nodeId; - let workerNodeId = +randomChoice(workerNode).nodeId; - while (masterNodeId == workerNodeId) { - workerNodeId = +randomChoice(workerNode).nodeId; + const masterNodeId = await checkNodeAvail(masterNode); + if (masterNodeId == -1) return; + let workerNodeId = await checkNodeAvail(workerNode); + if (workerNodeId == -1) return; + + let maxCount = 3; + while (masterNodeId == workerNodeId && maxCount > 0) { + workerNodeId = await checkNodeAvail(workerNode); + if (workerNodeId == -1) return; + maxCount--; } //K8s Model @@ -630,10 +642,16 @@ test("TC1233 - Kubernetes: Delete Worker", async () => { availableFor: await gridClient.twins.get_my_twin_id(), } as FilterOptions); } - const masterNodeId = +randomChoice(masterNode).nodeId; - let workerNodeId = +randomChoice(workerNode).nodeId; - while (masterNodeId == workerNodeId) { - workerNodeId = +randomChoice(workerNode).nodeId; + const masterNodeId = await checkNodeAvail(masterNode); + if (masterNodeId == -1) return; + let workerNodeId = await checkNodeAvail(workerNode); + if (workerNodeId == -1) return; + + let maxCount = 3; + while (masterNodeId == workerNodeId && maxCount > 0) { + workerNodeId = await checkNodeAvail(workerNode); + if (workerNodeId == -1) return; + maxCount--; } //K8s Model diff --git a/packages/grid_client/tests/modules/qsfs.test.ts b/packages/grid_client/tests/modules/qsfs.test.ts index c5ce6871ae..83f35c20c9 100644 --- a/packages/grid_client/tests/modules/qsfs.test.ts +++ b/packages/grid_client/tests/modules/qsfs.test.ts @@ -1,5 +1,3 @@ -import { setTimeout } from "timers/promises"; - import { FilterOptions, generateString, @@ -10,7 +8,7 @@ import { randomChoice, } from "../../src"; import { config, getClient } from "../client_loader"; -import { bytesToGB, generateInt, k8sWait, log, RemoteRun, splitIP } from "../utils"; +import { bytesToGB, checkNodeAvail, generateInt, k8sWait, log, RemoteRun, splitIP } from "../utils"; jest.setTimeout(300000); @@ -81,10 +79,15 @@ test("TC1234 - QSFS: Deploy QSFS underneath a VM", async () => { availableFor: await gridClient.twins.get_my_twin_id(), } as FilterOptions); if (allNodes.length >= 2) { - const qsfsNode1 = +randomChoice(allNodes).nodeId; - let qsfsNode2 = +randomChoice(allNodes).nodeId; - while (qsfsNode1 == qsfsNode2) { - qsfsNode2 = +randomChoice(allNodes).nodeId; + const qsfsNode1 = await checkNodeAvail(allNodes); + if (qsfsNode1 == -1) return; + let qsfsNode2 = await checkNodeAvail(allNodes); + if (qsfsNode2 == -1) return; + let maxCount = 3; + while (qsfsNode1 == qsfsNode2 && maxCount > 0) { + qsfsNode2 = await checkNodeAvail(allNodes); + if (qsfsNode2 == -1) return; + maxCount--; } qsfsNodes.push(qsfsNode1, qsfsNode2); } else { @@ -106,10 +109,15 @@ test("TC1234 - QSFS: Deploy QSFS underneath a VM", async () => { availableFor: await gridClient.twins.get_my_twin_id(), } as FilterOptions); if (allNodes.length >= 2) { - const qsfsNode1 = +randomChoice(allNodes).nodeId; - let qsfsNode2 = +randomChoice(allNodes).nodeId; - while (qsfsNode1 == qsfsNode2) { - qsfsNode2 = +randomChoice(allNodes).nodeId; + const qsfsNode1 = await checkNodeAvail(allNodes); + if (qsfsNode1 == -1) return; + let qsfsNode2 = await checkNodeAvail(allNodes); + if (qsfsNode2 == -1) return; + let maxCount = 3; + while (qsfsNode1 == qsfsNode2 && maxCount > 0) { + qsfsNode2 = await checkNodeAvail(allNodes); + if (qsfsNode2 == -1) return; + maxCount--; } qsfsNodes.push(qsfsNode1, qsfsNode2); } else { @@ -146,7 +154,8 @@ test("TC1234 - QSFS: Deploy QSFS underneath a VM", async () => { availableFor: await gridClient.twins.get_my_twin_id(), } as FilterOptions); } - const nodeId = +randomChoice(nodes).nodeId; + const nodeId = await checkNodeAvail(nodes); + if (nodeId == -1) return; //QSFS Model const qsfs: QSFSZDBSModel = { @@ -355,10 +364,15 @@ test("TC1235 - QSFS: Deploy QSFS Underneath a Kubernetes Cluster", async () => { availableFor: await gridClient.twins.get_my_twin_id(), } as FilterOptions); if (allNodes.length >= 2) { - const qsfsNode1 = +randomChoice(allNodes).nodeId; - let qsfsNode2 = +randomChoice(allNodes).nodeId; - while (qsfsNode1 == qsfsNode2) { - qsfsNode2 = +randomChoice(allNodes).nodeId; + const qsfsNode1 = await checkNodeAvail(allNodes); + if (qsfsNode1 == -1) return; + let qsfsNode2 = await checkNodeAvail(allNodes); + if (qsfsNode2 == -1) return; + let maxCount = 3; + while (qsfsNode1 == qsfsNode2 && maxCount > 0) { + qsfsNode2 = await checkNodeAvail(allNodes); + if (qsfsNode2 == -1) return; + maxCount--; } qsfsNodes.push(qsfsNode1, qsfsNode2); } else { @@ -380,10 +394,15 @@ test("TC1235 - QSFS: Deploy QSFS Underneath a Kubernetes Cluster", async () => { availableFor: await gridClient.twins.get_my_twin_id(), } as FilterOptions); if (allNodes.length >= 2) { - const qsfsNode1 = +randomChoice(allNodes).nodeId; - let qsfsNode2 = +randomChoice(allNodes).nodeId; - while (qsfsNode1 == qsfsNode2) { - qsfsNode2 = +randomChoice(allNodes).nodeId; + const qsfsNode1 = await checkNodeAvail(allNodes); + if (qsfsNode1 == -1) return; + let qsfsNode2 = await checkNodeAvail(allNodes); + if (qsfsNode2 == -1) return; + let maxCount = 3; + while (qsfsNode1 == qsfsNode2 && maxCount > 0) { + qsfsNode2 = await checkNodeAvail(allNodes); + if (qsfsNode2 == -1) return; + maxCount--; } qsfsNodes.push(qsfsNode1, qsfsNode2); } else { @@ -452,10 +471,15 @@ test("TC1235 - QSFS: Deploy QSFS Underneath a Kubernetes Cluster", async () => { availableFor: await gridClient.twins.get_my_twin_id(), } as FilterOptions); } - const masterNodeId = +randomChoice(masterNode).nodeId; - let workerNodeId = +randomChoice(workerNode).nodeId; - while (masterNodeId == workerNodeId) { - workerNodeId = +randomChoice(workerNode).nodeId; + const masterNodeId = await checkNodeAvail(masterNode); + if (masterNodeId == -1) return; + let workerNodeId = await checkNodeAvail(workerNode); + if (workerNodeId == -1) return; + let maxCount = 3; + while (masterNodeId == workerNodeId && maxCount > 0) { + workerNodeId = await checkNodeAvail(workerNode); + if (workerNodeId == -1) return; + maxCount--; } //QSFS Config diff --git a/packages/grid_client/tests/modules/vm.test.ts b/packages/grid_client/tests/modules/vm.test.ts index c8a4a22604..ad5f624692 100644 --- a/packages/grid_client/tests/modules/vm.test.ts +++ b/packages/grid_client/tests/modules/vm.test.ts @@ -1,6 +1,6 @@ import { FilterOptions, generateString, GridClient, MachineModel, MachinesModel, randomChoice } from "../../src"; import { config, getClient } from "../client_loader"; -import { bytesToGB, generateInt, log, RemoteRun, splitIP } from "../utils"; +import { bytesToGB, checkNodeAvail, generateInt, log, RemoteRun, splitIP } from "../utils"; jest.setTimeout(300000); @@ -76,7 +76,8 @@ test("TC1228 - VM: Deploy a VM", async () => { availableFor: await gridClient.twins.get_my_twin_id(), } as FilterOptions); } - const nodeId = +randomChoice(nodes).nodeId; + const nodeId = await checkNodeAvail(nodes); + if (nodeId == -1) return; //VM Model const vms: MachinesModel = { @@ -243,7 +244,8 @@ test("TC1229 - VM: Deploy a VM With a Disk", async () => { availableFor: await gridClient.twins.get_my_twin_id(), } as FilterOptions); } - const nodeId = +randomChoice(nodes).nodeId; + const nodeId = await checkNodeAvail(nodes); + if (nodeId == -1) return; //VM Model const vms: MachinesModel = { @@ -419,10 +421,15 @@ test("TC1230 - VM: Deploy Multiple VMs on Different Nodes", async () => { } as FilterOptions); } - const vm1NodeId = +randomChoice(vm1Nodes).nodeId; - let vm2NodeId = +randomChoice(vm2Nodes).nodeId; - while (vm1NodeId == vm2NodeId) { - vm2NodeId = +randomChoice(vm2Nodes).nodeId; + const vm1NodeId = await checkNodeAvail(vm1Nodes); + if (vm1NodeId == -1) return; + let vm2NodeId = await checkNodeAvail(vm2Nodes); + if (vm2NodeId == -1) return; + let maxCount = 3; + while (vm1NodeId == vm2NodeId && maxCount > 0) { + vm2NodeId = await checkNodeAvail(vm2Nodes); + if (vm2NodeId == -1) return; + maxCount--; } const vmNodes = [vm1NodeId, vm2NodeId]; diff --git a/packages/grid_client/tests/modules/zdb.test.ts b/packages/grid_client/tests/modules/zdb.test.ts index faea26de79..0697e92035 100644 --- a/packages/grid_client/tests/modules/zdb.test.ts +++ b/packages/grid_client/tests/modules/zdb.test.ts @@ -1,8 +1,8 @@ import { createClient } from "redis"; -import { FilterOptions, generateString, GridClient, randomChoice, ZDBModel, ZdbModes, ZDBSModel } from "../../src"; +import { FilterOptions, generateString, GridClient, ZDBModel, ZdbModes, ZDBSModel } from "../../src"; import { getClient } from "../client_loader"; -import { bytesToGB, generateInt, log } from "../utils"; +import { bytesToGB, checkNodeAvail, generateInt, log } from "../utils"; jest.setTimeout(300000); @@ -70,7 +70,8 @@ test("TC1236 - ZDB: Deploy ZDBs", async () => { availableFor: await gridClient.twins.get_my_twin_id(), } as FilterOptions); } - const nodeId = +randomChoice(nodes).nodeId; + const nodeId = await checkNodeAvail(nodes); + if (nodeId == -1) return; //Zdb Model const zdb: ZDBModel = { diff --git a/packages/grid_client/tests/utils.ts b/packages/grid_client/tests/utils.ts index b4161d168c..2b1dd94db4 100644 --- a/packages/grid_client/tests/utils.ts +++ b/packages/grid_client/tests/utils.ts @@ -3,6 +3,7 @@ import { setTimeout } from "timers/promises"; import { default as urlParser } from "url-parse"; import { inspect } from "util"; +import { randomChoice } from "../src"; import { getClient } from "./client_loader"; const os = require("os"); @@ -80,4 +81,24 @@ async function k8sWait(masterSSHClient, k8sMasterName, k8sWorkerName, waitTime, } } -export { log, generateHash, generateInt, splitIP, bytesToGB, RemoteRun, returnRelay, k8sWait }; +async function checkNodeAvail(Nodes) { + const gridClient = await getClient(); + let node; + while (Nodes.length > 0) { + node = randomChoice(Nodes); + try { + log(await gridClient.zos.pingNode({ nodeId: node.nodeId })); + break; + } catch (error) { + log("node " + node.nodeId + " is not responding, trying different node."); + Nodes.splice(+[Nodes.indexOf(node)], 1); + } + } + if (Nodes.length == 0) { + log("No nodes available with the needed resources for this test"); + return -1; + } + return node.nodeId; +} + +export { log, generateHash, generateInt, splitIP, bytesToGB, RemoteRun, returnRelay, k8sWait, checkNodeAvail }; From 30e3cb2a9dc9df986464eaa9c7c11b6719b59021 Mon Sep 17 00:00:00 2001 From: A-Harby Date: Mon, 23 Oct 2023 10:37:27 +0300 Subject: [PATCH 2/3] update function name --- .../tests/modules/contracts.test.ts | 8 ++--- .../tests/modules/gateways.test.ts | 6 ++-- .../tests/modules/kubernetes.test.ts | 20 +++++------ .../grid_client/tests/modules/qsfs.test.ts | 34 +++++++++---------- packages/grid_client/tests/modules/vm.test.ts | 12 +++---- .../grid_client/tests/modules/zdb.test.ts | 4 +-- packages/grid_client/tests/utils.ts | 4 +-- 7 files changed, 44 insertions(+), 44 deletions(-) diff --git a/packages/grid_client/tests/modules/contracts.test.ts b/packages/grid_client/tests/modules/contracts.test.ts index 70ccf657df..0b79b17a35 100644 --- a/packages/grid_client/tests/modules/contracts.test.ts +++ b/packages/grid_client/tests/modules/contracts.test.ts @@ -9,7 +9,7 @@ import { NodeContractUpdateModel, } from "../../src"; import { getClient } from "../client_loader"; -import { checkNodeAvail, generateHash, log } from "../utils"; +import { generateHash, getOnlineNode, log } from "../utils"; jest.setTimeout(300000); @@ -35,7 +35,7 @@ test("TC1269 - Contracts: Create Node Contract", async () => { availableFor: await gridClient.twins.get_my_twin_id(), farmId: 1, } as FilterOptions); - const nodeId = await checkNodeAvail(nodes); + const nodeId = await getOnlineNode(nodes); if (nodeId == -1) return; const hash = generateHash(generateString(8)); const data = generateString(64); @@ -106,7 +106,7 @@ test("TC1271 - Contracts: Get Node Contract By Node ID & Contract Hash", async ( availableFor: await gridClient.twins.get_my_twin_id(), farmId: 1, } as FilterOptions); - const nodeId = await checkNodeAvail(nodes); + const nodeId = await getOnlineNode(nodes); if (nodeId == -1) return; const hash = generateHash(generateString(8)); const data = generateString(64); @@ -188,7 +188,7 @@ test("TC1273 - Contracts: Update Node Contract", async () => { availableFor: await gridClient.twins.get_my_twin_id(), farmId: 1, } as FilterOptions); - const nodeId = await checkNodeAvail(nodes); + const nodeId = await getOnlineNode(nodes); if (nodeId == -1) return; const hash = generateHash(generateString(8)); const data = generateString(64); diff --git a/packages/grid_client/tests/modules/gateways.test.ts b/packages/grid_client/tests/modules/gateways.test.ts index 38219d40bf..bbcfac06d1 100644 --- a/packages/grid_client/tests/modules/gateways.test.ts +++ b/packages/grid_client/tests/modules/gateways.test.ts @@ -3,7 +3,7 @@ import { setTimeout } from "timers/promises"; import { FilterOptions, GatewayNameModel, generateString, GridClient, MachinesModel, randomChoice } from "../../src"; import { config, getClient } from "../client_loader"; -import { checkNodeAvail, generateInt, log, splitIP } from "../utils"; +import { generateInt, getOnlineNode, log, splitIP } from "../utils"; jest.setTimeout(300000); @@ -63,7 +63,7 @@ test("TC1237 - Gateways: Expose a VM Over Gateway", async () => { farmId: 1, availableFor: await gridClient.twins.get_my_twin_id(), } as FilterOptions); - const gatewayNodeId = await checkNodeAvail(gatewayNodes); + const gatewayNodeId = await getOnlineNode(gatewayNodes); if (gatewayNodeId == -1) return; //Node Selection @@ -95,7 +95,7 @@ test("TC1237 - Gateways: Expose a VM Over Gateway", async () => { availableFor: await gridClient.twins.get_my_twin_id(), } as FilterOptions); } - const nodeId = await checkNodeAvail(nodes); + const nodeId = await getOnlineNode(nodes); if (nodeId == -1) return; //VM Model diff --git a/packages/grid_client/tests/modules/kubernetes.test.ts b/packages/grid_client/tests/modules/kubernetes.test.ts index ead677694a..208823aa6e 100644 --- a/packages/grid_client/tests/modules/kubernetes.test.ts +++ b/packages/grid_client/tests/modules/kubernetes.test.ts @@ -8,7 +8,7 @@ import { randomChoice, } from "../../src"; import { config, getClient } from "../client_loader"; -import { bytesToGB, checkNodeAvail, generateInt, k8sWait, log, RemoteRun, splitIP } from "../utils"; +import { bytesToGB, generateInt, getOnlineNode, k8sWait, log, RemoteRun, splitIP } from "../utils"; jest.setTimeout(500000); @@ -123,14 +123,14 @@ test("TC1231 - Kubernetes: Deploy a Kubernetes Cluster", async () => { availableFor: await gridClient.twins.get_my_twin_id(), } as FilterOptions); } - const masterNodeId = await checkNodeAvail(masterNode); + const masterNodeId = await getOnlineNode(masterNode); if (masterNodeId == -1) return; - let workerNodeId = await checkNodeAvail(workerNode); + let workerNodeId = await getOnlineNode(workerNode); if (workerNodeId == -1) return; let maxCount = 3; while (masterNodeId == workerNodeId && maxCount > 0) { - workerNodeId = await checkNodeAvail(workerNode); + workerNodeId = await getOnlineNode(workerNode); if (workerNodeId == -1) return; maxCount--; } @@ -389,14 +389,14 @@ test("TC1232 - Kubernetes: Add Worker", async () => { availableFor: await gridClient.twins.get_my_twin_id(), } as FilterOptions); } - const masterNodeId = await checkNodeAvail(masterNode); + const masterNodeId = await getOnlineNode(masterNode); if (masterNodeId == -1) return; - let workerNodeId = await checkNodeAvail(workerNode); + let workerNodeId = await getOnlineNode(workerNode); if (workerNodeId == -1) return; let maxCount = 3; while (masterNodeId == workerNodeId && maxCount > 0) { - workerNodeId = await checkNodeAvail(workerNode); + workerNodeId = await getOnlineNode(workerNode); if (workerNodeId == -1) return; maxCount--; } @@ -642,14 +642,14 @@ test("TC1233 - Kubernetes: Delete Worker", async () => { availableFor: await gridClient.twins.get_my_twin_id(), } as FilterOptions); } - const masterNodeId = await checkNodeAvail(masterNode); + const masterNodeId = await getOnlineNode(masterNode); if (masterNodeId == -1) return; - let workerNodeId = await checkNodeAvail(workerNode); + let workerNodeId = await getOnlineNode(workerNode); if (workerNodeId == -1) return; let maxCount = 3; while (masterNodeId == workerNodeId && maxCount > 0) { - workerNodeId = await checkNodeAvail(workerNode); + workerNodeId = await getOnlineNode(workerNode); if (workerNodeId == -1) return; maxCount--; } diff --git a/packages/grid_client/tests/modules/qsfs.test.ts b/packages/grid_client/tests/modules/qsfs.test.ts index 83f35c20c9..1f2e17191f 100644 --- a/packages/grid_client/tests/modules/qsfs.test.ts +++ b/packages/grid_client/tests/modules/qsfs.test.ts @@ -8,7 +8,7 @@ import { randomChoice, } from "../../src"; import { config, getClient } from "../client_loader"; -import { bytesToGB, checkNodeAvail, generateInt, k8sWait, log, RemoteRun, splitIP } from "../utils"; +import { bytesToGB, generateInt, getOnlineNode, k8sWait, log, RemoteRun, splitIP } from "../utils"; jest.setTimeout(300000); @@ -79,13 +79,13 @@ test("TC1234 - QSFS: Deploy QSFS underneath a VM", async () => { availableFor: await gridClient.twins.get_my_twin_id(), } as FilterOptions); if (allNodes.length >= 2) { - const qsfsNode1 = await checkNodeAvail(allNodes); + const qsfsNode1 = await getOnlineNode(allNodes); if (qsfsNode1 == -1) return; - let qsfsNode2 = await checkNodeAvail(allNodes); + let qsfsNode2 = await getOnlineNode(allNodes); if (qsfsNode2 == -1) return; let maxCount = 3; while (qsfsNode1 == qsfsNode2 && maxCount > 0) { - qsfsNode2 = await checkNodeAvail(allNodes); + qsfsNode2 = await getOnlineNode(allNodes); if (qsfsNode2 == -1) return; maxCount--; } @@ -109,13 +109,13 @@ test("TC1234 - QSFS: Deploy QSFS underneath a VM", async () => { availableFor: await gridClient.twins.get_my_twin_id(), } as FilterOptions); if (allNodes.length >= 2) { - const qsfsNode1 = await checkNodeAvail(allNodes); + const qsfsNode1 = await getOnlineNode(allNodes); if (qsfsNode1 == -1) return; - let qsfsNode2 = await checkNodeAvail(allNodes); + let qsfsNode2 = await getOnlineNode(allNodes); if (qsfsNode2 == -1) return; let maxCount = 3; while (qsfsNode1 == qsfsNode2 && maxCount > 0) { - qsfsNode2 = await checkNodeAvail(allNodes); + qsfsNode2 = await getOnlineNode(allNodes); if (qsfsNode2 == -1) return; maxCount--; } @@ -154,7 +154,7 @@ test("TC1234 - QSFS: Deploy QSFS underneath a VM", async () => { availableFor: await gridClient.twins.get_my_twin_id(), } as FilterOptions); } - const nodeId = await checkNodeAvail(nodes); + const nodeId = await getOnlineNode(nodes); if (nodeId == -1) return; //QSFS Model @@ -364,13 +364,13 @@ test("TC1235 - QSFS: Deploy QSFS Underneath a Kubernetes Cluster", async () => { availableFor: await gridClient.twins.get_my_twin_id(), } as FilterOptions); if (allNodes.length >= 2) { - const qsfsNode1 = await checkNodeAvail(allNodes); + const qsfsNode1 = await getOnlineNode(allNodes); if (qsfsNode1 == -1) return; - let qsfsNode2 = await checkNodeAvail(allNodes); + let qsfsNode2 = await getOnlineNode(allNodes); if (qsfsNode2 == -1) return; let maxCount = 3; while (qsfsNode1 == qsfsNode2 && maxCount > 0) { - qsfsNode2 = await checkNodeAvail(allNodes); + qsfsNode2 = await getOnlineNode(allNodes); if (qsfsNode2 == -1) return; maxCount--; } @@ -394,13 +394,13 @@ test("TC1235 - QSFS: Deploy QSFS Underneath a Kubernetes Cluster", async () => { availableFor: await gridClient.twins.get_my_twin_id(), } as FilterOptions); if (allNodes.length >= 2) { - const qsfsNode1 = await checkNodeAvail(allNodes); + const qsfsNode1 = await getOnlineNode(allNodes); if (qsfsNode1 == -1) return; - let qsfsNode2 = await checkNodeAvail(allNodes); + let qsfsNode2 = await getOnlineNode(allNodes); if (qsfsNode2 == -1) return; let maxCount = 3; while (qsfsNode1 == qsfsNode2 && maxCount > 0) { - qsfsNode2 = await checkNodeAvail(allNodes); + qsfsNode2 = await getOnlineNode(allNodes); if (qsfsNode2 == -1) return; maxCount--; } @@ -471,13 +471,13 @@ test("TC1235 - QSFS: Deploy QSFS Underneath a Kubernetes Cluster", async () => { availableFor: await gridClient.twins.get_my_twin_id(), } as FilterOptions); } - const masterNodeId = await checkNodeAvail(masterNode); + const masterNodeId = await getOnlineNode(masterNode); if (masterNodeId == -1) return; - let workerNodeId = await checkNodeAvail(workerNode); + let workerNodeId = await getOnlineNode(workerNode); if (workerNodeId == -1) return; let maxCount = 3; while (masterNodeId == workerNodeId && maxCount > 0) { - workerNodeId = await checkNodeAvail(workerNode); + workerNodeId = await getOnlineNode(workerNode); if (workerNodeId == -1) return; maxCount--; } diff --git a/packages/grid_client/tests/modules/vm.test.ts b/packages/grid_client/tests/modules/vm.test.ts index ad5f624692..fece04f473 100644 --- a/packages/grid_client/tests/modules/vm.test.ts +++ b/packages/grid_client/tests/modules/vm.test.ts @@ -1,6 +1,6 @@ import { FilterOptions, generateString, GridClient, MachineModel, MachinesModel, randomChoice } from "../../src"; import { config, getClient } from "../client_loader"; -import { bytesToGB, checkNodeAvail, generateInt, log, RemoteRun, splitIP } from "../utils"; +import { bytesToGB, generateInt, getOnlineNode, log, RemoteRun, splitIP } from "../utils"; jest.setTimeout(300000); @@ -76,7 +76,7 @@ test("TC1228 - VM: Deploy a VM", async () => { availableFor: await gridClient.twins.get_my_twin_id(), } as FilterOptions); } - const nodeId = await checkNodeAvail(nodes); + const nodeId = await getOnlineNode(nodes); if (nodeId == -1) return; //VM Model @@ -244,7 +244,7 @@ test("TC1229 - VM: Deploy a VM With a Disk", async () => { availableFor: await gridClient.twins.get_my_twin_id(), } as FilterOptions); } - const nodeId = await checkNodeAvail(nodes); + const nodeId = await getOnlineNode(nodes); if (nodeId == -1) return; //VM Model @@ -421,13 +421,13 @@ test("TC1230 - VM: Deploy Multiple VMs on Different Nodes", async () => { } as FilterOptions); } - const vm1NodeId = await checkNodeAvail(vm1Nodes); + const vm1NodeId = await getOnlineNode(vm1Nodes); if (vm1NodeId == -1) return; - let vm2NodeId = await checkNodeAvail(vm2Nodes); + let vm2NodeId = await getOnlineNode(vm2Nodes); if (vm2NodeId == -1) return; let maxCount = 3; while (vm1NodeId == vm2NodeId && maxCount > 0) { - vm2NodeId = await checkNodeAvail(vm2Nodes); + vm2NodeId = await getOnlineNode(vm2Nodes); if (vm2NodeId == -1) return; maxCount--; } diff --git a/packages/grid_client/tests/modules/zdb.test.ts b/packages/grid_client/tests/modules/zdb.test.ts index 0697e92035..1c43ee3c11 100644 --- a/packages/grid_client/tests/modules/zdb.test.ts +++ b/packages/grid_client/tests/modules/zdb.test.ts @@ -2,7 +2,7 @@ import { createClient } from "redis"; import { FilterOptions, generateString, GridClient, ZDBModel, ZdbModes, ZDBSModel } from "../../src"; import { getClient } from "../client_loader"; -import { bytesToGB, checkNodeAvail, generateInt, log } from "../utils"; +import { bytesToGB, generateInt, getOnlineNode, log } from "../utils"; jest.setTimeout(300000); @@ -70,7 +70,7 @@ test("TC1236 - ZDB: Deploy ZDBs", async () => { availableFor: await gridClient.twins.get_my_twin_id(), } as FilterOptions); } - const nodeId = await checkNodeAvail(nodes); + const nodeId = await getOnlineNode(nodes); if (nodeId == -1) return; //Zdb Model diff --git a/packages/grid_client/tests/utils.ts b/packages/grid_client/tests/utils.ts index 2b1dd94db4..ceaa370efe 100644 --- a/packages/grid_client/tests/utils.ts +++ b/packages/grid_client/tests/utils.ts @@ -81,7 +81,7 @@ async function k8sWait(masterSSHClient, k8sMasterName, k8sWorkerName, waitTime, } } -async function checkNodeAvail(Nodes) { +async function getOnlineNode(Nodes) { const gridClient = await getClient(); let node; while (Nodes.length > 0) { @@ -101,4 +101,4 @@ async function checkNodeAvail(Nodes) { return node.nodeId; } -export { log, generateHash, generateInt, splitIP, bytesToGB, RemoteRun, returnRelay, k8sWait, checkNodeAvail }; +export { log, generateHash, generateInt, splitIP, bytesToGB, RemoteRun, returnRelay, k8sWait, getOnlineNode }; From b7b9cae265696cd97e1c1921df79950251d5d34d Mon Sep 17 00:00:00 2001 From: A-Harby Date: Mon, 13 Nov 2023 16:41:06 +0200 Subject: [PATCH 3/3] update no node case and add networks option --- .github/workflows/grid_client_tests.yml | 13 +++++++- .../tests/modules/contracts.test.ts | 12 +++---- .../tests/modules/gateways.test.ts | 4 +-- .../tests/modules/kubernetes.test.ts | 18 +++++------ .../grid_client/tests/modules/qsfs.test.ts | 32 +++++++++---------- packages/grid_client/tests/modules/vm.test.ts | 10 +++--- .../grid_client/tests/modules/zdb.test.ts | 2 +- 7 files changed, 50 insertions(+), 41 deletions(-) diff --git a/.github/workflows/grid_client_tests.yml b/.github/workflows/grid_client_tests.yml index 0bac9608e7..5b9e67c994 100644 --- a/.github/workflows/grid_client_tests.yml +++ b/.github/workflows/grid_client_tests.yml @@ -4,12 +4,23 @@ on: schedule: - cron: "0 0 * * *" workflow_dispatch: + inputs: + network: + type: choice + description: 'which network to run tests on' + required: true + default: 'dev' + options: + - 'dev' + - 'qa' + - 'test' + - 'main' jobs: tests: runs-on: ubuntu-20.04 env: - NETWORK: ${{ secrets.NETWORK }} + NETWORK: ${{ github.event.inputs.network }} RMB_PROXY: true STORE_SECRET: secret MNEMONIC: ${{ secrets.MNEMONIC }} diff --git a/packages/grid_client/tests/modules/contracts.test.ts b/packages/grid_client/tests/modules/contracts.test.ts index 0b79b17a35..ca749d88fc 100644 --- a/packages/grid_client/tests/modules/contracts.test.ts +++ b/packages/grid_client/tests/modules/contracts.test.ts @@ -7,9 +7,10 @@ import { NameContractGetModel, NodeContractCreateModel, NodeContractUpdateModel, + randomChoice, } from "../../src"; import { getClient } from "../client_loader"; -import { generateHash, getOnlineNode, log } from "../utils"; +import { generateHash, log } from "../utils"; jest.setTimeout(300000); @@ -35,8 +36,7 @@ test("TC1269 - Contracts: Create Node Contract", async () => { availableFor: await gridClient.twins.get_my_twin_id(), farmId: 1, } as FilterOptions); - const nodeId = await getOnlineNode(nodes); - if (nodeId == -1) return; + const nodeId = +randomChoice(nodes).nodeId; const hash = generateHash(generateString(8)); const data = generateString(64); const publicIp = 0; @@ -106,8 +106,7 @@ test("TC1271 - Contracts: Get Node Contract By Node ID & Contract Hash", async ( availableFor: await gridClient.twins.get_my_twin_id(), farmId: 1, } as FilterOptions); - const nodeId = await getOnlineNode(nodes); - if (nodeId == -1) return; + const nodeId = +randomChoice(nodes).nodeId; const hash = generateHash(generateString(8)); const data = generateString(64); const publicIp = 0; @@ -188,8 +187,7 @@ test("TC1273 - Contracts: Update Node Contract", async () => { availableFor: await gridClient.twins.get_my_twin_id(), farmId: 1, } as FilterOptions); - const nodeId = await getOnlineNode(nodes); - if (nodeId == -1) return; + const nodeId = +randomChoice(nodes).nodeId; const hash = generateHash(generateString(8)); const data = generateString(64); const newHash = generateHash(generateString(8)); diff --git a/packages/grid_client/tests/modules/gateways.test.ts b/packages/grid_client/tests/modules/gateways.test.ts index bbcfac06d1..9067a0c15b 100644 --- a/packages/grid_client/tests/modules/gateways.test.ts +++ b/packages/grid_client/tests/modules/gateways.test.ts @@ -64,7 +64,7 @@ test("TC1237 - Gateways: Expose a VM Over Gateway", async () => { availableFor: await gridClient.twins.get_my_twin_id(), } as FilterOptions); const gatewayNodeId = await getOnlineNode(gatewayNodes); - if (gatewayNodeId == -1) return; + if (gatewayNodeId == -1) throw new Error("no nodes available to complete this test"); //Node Selection let nodes; @@ -96,7 +96,7 @@ test("TC1237 - Gateways: Expose a VM Over Gateway", async () => { } as FilterOptions); } const nodeId = await getOnlineNode(nodes); - if (nodeId == -1) return; + if (nodeId == -1) throw new Error("no nodes available to complete this test"); //VM Model const vms: MachinesModel = { diff --git a/packages/grid_client/tests/modules/kubernetes.test.ts b/packages/grid_client/tests/modules/kubernetes.test.ts index 208823aa6e..519f746f9a 100644 --- a/packages/grid_client/tests/modules/kubernetes.test.ts +++ b/packages/grid_client/tests/modules/kubernetes.test.ts @@ -124,14 +124,14 @@ test("TC1231 - Kubernetes: Deploy a Kubernetes Cluster", async () => { } as FilterOptions); } const masterNodeId = await getOnlineNode(masterNode); - if (masterNodeId == -1) return; + if (masterNodeId == -1) throw new Error("no nodes available to complete this test"); let workerNodeId = await getOnlineNode(workerNode); - if (workerNodeId == -1) return; + if (workerNodeId == -1) throw new Error("no nodes available to complete this test"); let maxCount = 3; while (masterNodeId == workerNodeId && maxCount > 0) { workerNodeId = await getOnlineNode(workerNode); - if (workerNodeId == -1) return; + if (workerNodeId == -1) throw new Error("no nodes available to complete this test"); maxCount--; } @@ -390,14 +390,14 @@ test("TC1232 - Kubernetes: Add Worker", async () => { } as FilterOptions); } const masterNodeId = await getOnlineNode(masterNode); - if (masterNodeId == -1) return; + if (masterNodeId == -1) throw new Error("no nodes available to complete this test"); let workerNodeId = await getOnlineNode(workerNode); - if (workerNodeId == -1) return; + if (workerNodeId == -1) throw new Error("no nodes available to complete this test"); let maxCount = 3; while (masterNodeId == workerNodeId && maxCount > 0) { workerNodeId = await getOnlineNode(workerNode); - if (workerNodeId == -1) return; + if (workerNodeId == -1) throw new Error("no nodes available to complete this test"); maxCount--; } @@ -643,14 +643,14 @@ test("TC1233 - Kubernetes: Delete Worker", async () => { } as FilterOptions); } const masterNodeId = await getOnlineNode(masterNode); - if (masterNodeId == -1) return; + if (masterNodeId == -1) throw new Error("no nodes available to complete this test"); let workerNodeId = await getOnlineNode(workerNode); - if (workerNodeId == -1) return; + if (workerNodeId == -1) throw new Error("no nodes available to complete this test"); let maxCount = 3; while (masterNodeId == workerNodeId && maxCount > 0) { workerNodeId = await getOnlineNode(workerNode); - if (workerNodeId == -1) return; + if (workerNodeId == -1) throw new Error("no nodes available to complete this test"); maxCount--; } diff --git a/packages/grid_client/tests/modules/qsfs.test.ts b/packages/grid_client/tests/modules/qsfs.test.ts index 1f2e17191f..f93a245758 100644 --- a/packages/grid_client/tests/modules/qsfs.test.ts +++ b/packages/grid_client/tests/modules/qsfs.test.ts @@ -80,13 +80,13 @@ test("TC1234 - QSFS: Deploy QSFS underneath a VM", async () => { } as FilterOptions); if (allNodes.length >= 2) { const qsfsNode1 = await getOnlineNode(allNodes); - if (qsfsNode1 == -1) return; + if (qsfsNode1 == -1) throw new Error("no nodes available to complete this test"); let qsfsNode2 = await getOnlineNode(allNodes); - if (qsfsNode2 == -1) return; + if (qsfsNode2 == -1) throw new Error("no nodes available to complete this test"); let maxCount = 3; while (qsfsNode1 == qsfsNode2 && maxCount > 0) { qsfsNode2 = await getOnlineNode(allNodes); - if (qsfsNode2 == -1) return; + if (qsfsNode2 == -1) throw new Error("no nodes available to complete this test"); maxCount--; } qsfsNodes.push(qsfsNode1, qsfsNode2); @@ -110,13 +110,13 @@ test("TC1234 - QSFS: Deploy QSFS underneath a VM", async () => { } as FilterOptions); if (allNodes.length >= 2) { const qsfsNode1 = await getOnlineNode(allNodes); - if (qsfsNode1 == -1) return; + if (qsfsNode1 == -1) throw new Error("no nodes available to complete this test"); let qsfsNode2 = await getOnlineNode(allNodes); - if (qsfsNode2 == -1) return; + if (qsfsNode2 == -1) throw new Error("no nodes available to complete this test"); let maxCount = 3; while (qsfsNode1 == qsfsNode2 && maxCount > 0) { qsfsNode2 = await getOnlineNode(allNodes); - if (qsfsNode2 == -1) return; + if (qsfsNode2 == -1) throw new Error("no nodes available to complete this test"); maxCount--; } qsfsNodes.push(qsfsNode1, qsfsNode2); @@ -155,7 +155,7 @@ test("TC1234 - QSFS: Deploy QSFS underneath a VM", async () => { } as FilterOptions); } const nodeId = await getOnlineNode(nodes); - if (nodeId == -1) return; + if (nodeId == -1) throw new Error("no nodes available to complete this test"); //QSFS Model const qsfs: QSFSZDBSModel = { @@ -365,13 +365,13 @@ test("TC1235 - QSFS: Deploy QSFS Underneath a Kubernetes Cluster", async () => { } as FilterOptions); if (allNodes.length >= 2) { const qsfsNode1 = await getOnlineNode(allNodes); - if (qsfsNode1 == -1) return; + if (qsfsNode1 == -1) throw new Error("no nodes available to complete this test"); let qsfsNode2 = await getOnlineNode(allNodes); - if (qsfsNode2 == -1) return; + if (qsfsNode2 == -1) throw new Error("no nodes available to complete this test"); let maxCount = 3; while (qsfsNode1 == qsfsNode2 && maxCount > 0) { qsfsNode2 = await getOnlineNode(allNodes); - if (qsfsNode2 == -1) return; + if (qsfsNode2 == -1) throw new Error("no nodes available to complete this test"); maxCount--; } qsfsNodes.push(qsfsNode1, qsfsNode2); @@ -395,13 +395,13 @@ test("TC1235 - QSFS: Deploy QSFS Underneath a Kubernetes Cluster", async () => { } as FilterOptions); if (allNodes.length >= 2) { const qsfsNode1 = await getOnlineNode(allNodes); - if (qsfsNode1 == -1) return; + if (qsfsNode1 == -1) throw new Error("no nodes available to complete this test"); let qsfsNode2 = await getOnlineNode(allNodes); - if (qsfsNode2 == -1) return; + if (qsfsNode2 == -1) throw new Error("no nodes available to complete this test"); let maxCount = 3; while (qsfsNode1 == qsfsNode2 && maxCount > 0) { qsfsNode2 = await getOnlineNode(allNodes); - if (qsfsNode2 == -1) return; + if (qsfsNode2 == -1) throw new Error("no nodes available to complete this test"); maxCount--; } qsfsNodes.push(qsfsNode1, qsfsNode2); @@ -472,13 +472,13 @@ test("TC1235 - QSFS: Deploy QSFS Underneath a Kubernetes Cluster", async () => { } as FilterOptions); } const masterNodeId = await getOnlineNode(masterNode); - if (masterNodeId == -1) return; + if (masterNodeId == -1) throw new Error("no nodes available to complete this test"); let workerNodeId = await getOnlineNode(workerNode); - if (workerNodeId == -1) return; + if (workerNodeId == -1) throw new Error("no nodes available to complete this test"); let maxCount = 3; while (masterNodeId == workerNodeId && maxCount > 0) { workerNodeId = await getOnlineNode(workerNode); - if (workerNodeId == -1) return; + if (workerNodeId == -1) throw new Error("no nodes available to complete this test"); maxCount--; } diff --git a/packages/grid_client/tests/modules/vm.test.ts b/packages/grid_client/tests/modules/vm.test.ts index fece04f473..33bb6bbbda 100644 --- a/packages/grid_client/tests/modules/vm.test.ts +++ b/packages/grid_client/tests/modules/vm.test.ts @@ -77,7 +77,7 @@ test("TC1228 - VM: Deploy a VM", async () => { } as FilterOptions); } const nodeId = await getOnlineNode(nodes); - if (nodeId == -1) return; + if (nodeId == -1) throw new Error("no nodes available to complete this test"); //VM Model const vms: MachinesModel = { @@ -245,7 +245,7 @@ test("TC1229 - VM: Deploy a VM With a Disk", async () => { } as FilterOptions); } const nodeId = await getOnlineNode(nodes); - if (nodeId == -1) return; + if (nodeId == -1) throw new Error("no nodes available to complete this test"); //VM Model const vms: MachinesModel = { @@ -422,13 +422,13 @@ test("TC1230 - VM: Deploy Multiple VMs on Different Nodes", async () => { } const vm1NodeId = await getOnlineNode(vm1Nodes); - if (vm1NodeId == -1) return; + if (vm1NodeId == -1) throw new Error("no nodes available to complete this test"); let vm2NodeId = await getOnlineNode(vm2Nodes); - if (vm2NodeId == -1) return; + if (vm2NodeId == -1) throw new Error("no nodes available to complete this test"); let maxCount = 3; while (vm1NodeId == vm2NodeId && maxCount > 0) { vm2NodeId = await getOnlineNode(vm2Nodes); - if (vm2NodeId == -1) return; + if (vm2NodeId == -1) throw new Error("no nodes available to complete this test"); maxCount--; } const vmNodes = [vm1NodeId, vm2NodeId]; diff --git a/packages/grid_client/tests/modules/zdb.test.ts b/packages/grid_client/tests/modules/zdb.test.ts index 1c43ee3c11..7b30450c05 100644 --- a/packages/grid_client/tests/modules/zdb.test.ts +++ b/packages/grid_client/tests/modules/zdb.test.ts @@ -71,7 +71,7 @@ test("TC1236 - ZDB: Deploy ZDBs", async () => { } as FilterOptions); } const nodeId = await getOnlineNode(nodes); - if (nodeId == -1) return; + if (nodeId == -1) throw new Error("no nodes available to complete this test"); //Zdb Model const zdb: ZDBModel = {