Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ping node utils and update tests #1258

Merged
merged 3 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .github/workflows/grid_client_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 0 additions & 2 deletions packages/grid_client/tests/modules/contracts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ test("TC1271 - Contracts: Get Node Contract By Node ID & Contract Hash", async (
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 = {
Expand Down Expand Up @@ -149,7 +148,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 = {
Expand Down
14 changes: 7 additions & 7 deletions packages/grid_client/tests/modules/gateways.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 { generateInt, getOnlineNode, log, splitIP } from "../utils";

jest.setTimeout(300000);

Expand Down Expand Up @@ -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 getOnlineNode(gatewayNodes);
if (gatewayNodeId == -1) throw new Error("no nodes available to complete this test");

//Node Selection
let nodes;
Expand Down Expand Up @@ -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 getOnlineNode(nodes);
if (nodeId == -1) throw new Error("no nodes available to complete this test");

//VM Model
const vms: MachinesModel = {
Expand Down Expand Up @@ -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) {
Expand Down
44 changes: 31 additions & 13 deletions packages/grid_client/tests/modules/kubernetes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, generateInt, getOnlineNode, k8sWait, log, RemoteRun, splitIP } from "../utils";

jest.setTimeout(500000);

Expand Down Expand Up @@ -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 getOnlineNode(masterNode);
if (masterNodeId == -1) throw new Error("no nodes available to complete this test");
let workerNodeId = await getOnlineNode(workerNode);
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) throw new Error("no nodes available to complete this test");
maxCount--;
}

//K8s Model
Expand Down Expand Up @@ -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 getOnlineNode(masterNode);
if (masterNodeId == -1) throw new Error("no nodes available to complete this test");
let workerNodeId = await getOnlineNode(workerNode);
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) throw new Error("no nodes available to complete this test");
maxCount--;
}

//K8s Model
Expand Down Expand Up @@ -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 getOnlineNode(masterNode);
if (masterNodeId == -1) throw new Error("no nodes available to complete this test");
let workerNodeId = await getOnlineNode(workerNode);
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) throw new Error("no nodes available to complete this test");
maxCount--;
}

//K8s Model
Expand Down
72 changes: 48 additions & 24 deletions packages/grid_client/tests/modules/qsfs.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { setTimeout } from "timers/promises";

import {
FilterOptions,
generateString,
Expand All @@ -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, generateInt, getOnlineNode, k8sWait, log, RemoteRun, splitIP } from "../utils";

jest.setTimeout(300000);

Expand Down Expand Up @@ -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 getOnlineNode(allNodes);
if (qsfsNode1 == -1) throw new Error("no nodes available to complete this test");
let qsfsNode2 = await getOnlineNode(allNodes);
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) throw new Error("no nodes available to complete this test");
maxCount--;
}
qsfsNodes.push(qsfsNode1, qsfsNode2);
} else {
Expand All @@ -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 getOnlineNode(allNodes);
if (qsfsNode1 == -1) throw new Error("no nodes available to complete this test");
let qsfsNode2 = await getOnlineNode(allNodes);
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) throw new Error("no nodes available to complete this test");
maxCount--;
}
qsfsNodes.push(qsfsNode1, qsfsNode2);
} else {
Expand Down Expand Up @@ -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 getOnlineNode(nodes);
if (nodeId == -1) throw new Error("no nodes available to complete this test");

//QSFS Model
const qsfs: QSFSZDBSModel = {
Expand Down Expand Up @@ -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 getOnlineNode(allNodes);
if (qsfsNode1 == -1) throw new Error("no nodes available to complete this test");
let qsfsNode2 = await getOnlineNode(allNodes);
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) throw new Error("no nodes available to complete this test");
maxCount--;
}
qsfsNodes.push(qsfsNode1, qsfsNode2);
} else {
Expand All @@ -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 getOnlineNode(allNodes);
if (qsfsNode1 == -1) throw new Error("no nodes available to complete this test");
let qsfsNode2 = await getOnlineNode(allNodes);
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) throw new Error("no nodes available to complete this test");
maxCount--;
}
qsfsNodes.push(qsfsNode1, qsfsNode2);
} else {
Expand Down Expand Up @@ -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 getOnlineNode(masterNode);
if (masterNodeId == -1) throw new Error("no nodes available to complete this test");
let workerNodeId = await getOnlineNode(workerNode);
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) throw new Error("no nodes available to complete this test");
maxCount--;
}

//QSFS Config
Expand Down
21 changes: 14 additions & 7 deletions packages/grid_client/tests/modules/vm.test.ts
Original file line number Diff line number Diff line change
@@ -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, generateInt, getOnlineNode, log, RemoteRun, splitIP } from "../utils";

jest.setTimeout(300000);

Expand Down Expand Up @@ -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 getOnlineNode(nodes);
if (nodeId == -1) throw new Error("no nodes available to complete this test");

//VM Model
const vms: MachinesModel = {
Expand Down Expand Up @@ -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 getOnlineNode(nodes);
if (nodeId == -1) throw new Error("no nodes available to complete this test");

//VM Model
const vms: MachinesModel = {
Expand Down Expand Up @@ -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 getOnlineNode(vm1Nodes);
if (vm1NodeId == -1) throw new Error("no nodes available to complete this test");
let vm2NodeId = await getOnlineNode(vm2Nodes);
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) throw new Error("no nodes available to complete this test");
maxCount--;
}
const vmNodes = [vm1NodeId, vm2NodeId];

Expand Down
7 changes: 4 additions & 3 deletions packages/grid_client/tests/modules/zdb.test.ts
Original file line number Diff line number Diff line change
@@ -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, generateInt, getOnlineNode, log } from "../utils";

jest.setTimeout(300000);

Expand Down Expand Up @@ -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 getOnlineNode(nodes);
if (nodeId == -1) throw new Error("no nodes available to complete this test");

//Zdb Model
const zdb: ZDBModel = {
Expand Down
23 changes: 22 additions & 1 deletion packages/grid_client/tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -80,4 +81,24 @@ async function k8sWait(masterSSHClient, k8sMasterName, k8sWorkerName, waitTime,
}
}

export { log, generateHash, generateInt, splitIP, bytesToGB, RemoteRun, returnRelay, k8sWait };
async function getOnlineNode(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, getOnlineNode };
Loading