Skip to content

Commit

Permalink
Add exit code to in case of error in test script (#1710)
Browse files Browse the repository at this point in the history
* Add exit code to in case of error in test script

* update catch with console error

* fix typo

* remove try and catch from test scripts

* apply same changes to the other scripts

* add checker for the clean up process

* add sleep to wait for deleting process

* change deprecated set output to new github output

* fix read arrays

* fix typo in set output

* change to github env

* fix deletion checker and change job time

* update yggdrasil version and print for the failing to delete cases

* update yggdrasil config file location

* update comment

* fix printing in deletion checker

* print all the file

* update condition with grep -q for more accurate searching

* update task comments
  • Loading branch information
A-Harby authored Jan 10, 2024
1 parent aac2542 commit b63bcc4
Show file tree
Hide file tree
Showing 41 changed files with 472 additions and 888 deletions.
25 changes: 23 additions & 2 deletions .github/workflows/grid_client_nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: Grid Client Nightly

on:
schedule:
- cron: "0 6 * * *"
- cron: "0 4 * * *"
workflow_dispatch:
jobs:
deployment-scripts:
Expand Down Expand Up @@ -46,6 +46,7 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install -y git libtool tmux redis net-tools
- name: Install
run: |
yarn
Expand Down Expand Up @@ -86,11 +87,30 @@ jobs:
continue-on-error: true
run: |
yarn run ts-node --project packages/grid_client/tsconfig-node.json packages/grid_client/scripts/zdb.ts
- name: Cleanup - Delete all contracts
id: deleteall
run: |
yarn run ts-node --project packages/grid_client/tsconfig-node.json packages/grid_client/scripts/delete_all_contracts.ts
- name: Run check up - List all contracts
id: command_step
run: |
sleep 15
yarn run ts-node --project packages/grid_client/tsconfig-node.json packages/grid_client/scripts/list_all_contracts.ts > output.txt
- name: Check if contracts are Empty
run: |
# print the file content
cat output.txt
# Check if Node contracts are empty
if grep -q "nodeContracts: \[\]" output.txt && ! grep -q "nodeContracts: \[[[:space:]]*\]" output.txt; then
echo "Deletion failed; The Node Contract is not empty."
# Print the contract that couldn't be deleted
exit 1
fi
- name: Test Results
run: |
echo Dynamic Single Vm: ${{ steps.dynamicsinglevm.outcome }}
Expand All @@ -110,5 +130,6 @@ jobs:
steps.vmqsfs.outcome != 'success' ||
steps.kubernetesqsfs.outcome != 'success' ||
steps.kvstore.outcome != 'success' ||
steps.zdb.outcome != 'success'
steps.zdb.outcome != 'success' ||
steps.deleteall.outcome != 'success'
run: exit 1
6 changes: 3 additions & 3 deletions .github/workflows/grid_client_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ jobs:
gpg --export 569130E8CA20FBC4CB3FDE555898470A764B32C9 | sudo apt-key add -
echo 'deb http://neilalexander.s3.dualstack.eu-west-2.amazonaws.com/deb/ debian yggdrasil' | sudo tee /etc/apt/sources.list.d/yggdrasil.list
sudo apt-get update
wget https://github.com/yggdrasil-network/yggdrasil-go/releases/download/v0.4.7/yggdrasil-0.4.7-amd64.deb
sudo dpkg -i yggdrasil-0.4.7-amd64.deb
wget https://github.com/yggdrasil-network/yggdrasil-go/releases/download/v0.5.4/yggdrasil-0.5.4-amd64.deb
sudo dpkg -i yggdrasil-0.5.4-amd64.deb
sudo systemctl enable yggdrasil
PEERS=$(curl https://raw.githubusercontent.com/threefoldtech/zos-config/main/development.json | jq '.yggdrasil.peers[]' -r | sed 's/\//\\\//g' | sed -z 's/\n/\\n/g')
sudo sed -i -- 's/Peers\: \[\]/Peers: [\n'"$PEERS"']/g' /etc/yggdrasil.conf
sudo sed -i -- 's/Peers\: \[\]/Peers: [\n'"$PEERS"']/g' /etc/yggdrasil/yggdrasil.conf
sudo systemctl start yggdrasil
- name: Generate SSH Key
run: |
Expand Down
12 changes: 4 additions & 8 deletions packages/grid_client/scripts/add_node_to_network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ import { getClient } from "./client_loader";
import { log } from "./utils";

async function addNode(client, node) {
try {
const res = await client.networks.addNode(node);
log("================= Adding node =================");
log(res);
log("================= Adding node =================");
} catch (error) {
log("Error while adding node " + error);
}
const res = await client.networks.addNode(node);
log("================= Adding node =================");
log(res);
log("================= Adding node =================");
}

async function main() {
Expand Down
36 changes: 12 additions & 24 deletions packages/grid_client/scripts/add_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,24 @@ import { log } from "./utils";
// Please run kubernetes script first before running this one to create the cluster.

async function addWorker(client, worker) {
try {
const res = await client.k8s.add_worker(worker);
log("================= Adding worker =================");
log(res);
log("================= Adding worker =================");
} catch (error) {
log("Error while adding the worker" + error);
}
const res = await client.k8s.add_worker(worker);
log("================= Adding worker =================");
log(res);
log("================= Adding worker =================");
}

async function getWorker(client, worker) {
try {
const res = await client.k8s.getObj(worker);
log("================= Getting worker information =================");
log(res);
log("================= Getting worker information =================");
} catch (error) {
log("Error while getting the worker" + error);
}
const res = await client.k8s.getObj(worker);
log("================= Getting worker information =================");
log(res);
log("================= Getting worker information =================");
}

async function deleteWorker(client, worker) {
try {
const res = await client.k8s.delete_worker(worker);
log("================= Deleting the worker =================");
log(res);
log("================= Deleting the worker =================");
} catch (error) {
log("Error while deleting the worker" + error);
}
const res = await client.k8s.delete_worker(worker);
log("================= Deleting the worker =================");
log(res);
log("================= Deleting the worker =================");
}

async function main() {
Expand Down
72 changes: 24 additions & 48 deletions packages/grid_client/scripts/calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,69 +3,45 @@ import { getClient } from "./client_loader";
import { log } from "./utils";

async function calculateCU(client, CUModel) {
try {
const res = await client.calculator.calCU(CUModel);
log("================= Calculating CU =================");
log(res);
log("================= Calculating CU =================");
} catch (error) {
log("Error while calculating CU " + error);
}
const res = await client.calculator.calCU(CUModel);
log("================= Calculating CU =================");
log(res);
log("================= Calculating CU =================");
}

async function calculateSU(client, SUModel) {
try {
const res = await client.calculator.calSU(SUModel);
log("================= Calculating SU =================");
log(res);
log("================= Calculating SU =================");
} catch (error) {
log("Error while calculating SU " + error);
}
const res = await client.calculator.calSU(SUModel);
log("================= Calculating SU =================");
log(res);
log("================= Calculating SU =================");
}

async function getTFTPrice(client) {
try {
const res = await client.calculator.tftPrice();
log("================= TFT Price =================");
log(res);
log("================= TFT Price =================");
} catch (error) {
log("Error while getting TFT price " + error);
}
const res = await client.calculator.tftPrice();
log("================= TFT Price =================");
log(res);
log("================= TFT Price =================");
}

async function getPricingPolicy(client) {
try {
const res = await client.calculator.getPrices();
log("================= Pricing Policy =================");
log(res);
log("================= Pricing Policy =================");
} catch (error) {
log("Error while getting pricing policy " + error);
}
const res = await client.calculator.getPrices();
log("================= Pricing Policy =================");
log(res);
log("================= Pricing Policy =================");
}

async function calculateDeployment(client, CalculatorModel) {
try {
const res = await client.calculator.calculate(CalculatorModel);
log("================= Deployment Cost =================");
log(res);
log("================= Deployment Cost =================");
} catch (error) {
log("Error while calculating deployment cost " + error);
}
const res = await client.calculator.calculate(CalculatorModel);
log("================= Deployment Cost =================");
log(res);
log("================= Deployment Cost =================");
}

async function calculateDeploymentWithCurrentBalance(client, CalculatorModel) {
try {
const res = await client.calculator.calculateWithMyBalance(CalculatorModel);
log("================= Deployment Cost with current balance =================");
log(res);
log("================= Deployment Cost with current balance =================");
} catch (error) {
log("Error while calculating deployment cost " + error);
}
const res = await client.calculator.calculateWithMyBalance(CalculatorModel);
log("================= Deployment Cost with current balance =================");
log(res);
log("================= Deployment Cost with current balance =================");
}

async function main() {
Expand Down
38 changes: 13 additions & 25 deletions packages/grid_client/scripts/caprover_leader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,25 @@ import { config, getClient } from "./client_loader";
import { log } from "./utils";

async function deploy(client, vms) {
try {
const res = await client.machines.deploy(vms);
log("================= Deploying Caprover cluster =================");
log(res);
log("================= Deploying Caprover cluster =================");
} catch (error) {
log("Error while Deploying the VM " + error);
}
const res = await client.machines.deploy(vms);
log("================= Deploying Caprover cluster =================");
log(res);
log("================= Deploying Caprover cluster =================");
}

async function getDeployment(client, vms) {
try {
const res = await client.machines.getObj(vms);
log("================= Getting deployment information =================");
log(res);
log(`You can access Caprover via the browser using: http://captain.${res[0].env.CAPROVER_ROOT_DOMAIN}`);
log("================= Getting deployment information =================");
} catch (error) {
log("Error while getting the deployment " + error);
}
const res = await client.machines.getObj(vms);
log("================= Getting deployment information =================");
log(res);
log(`You can access Caprover via the browser using: http://captain.${res[0].env.CAPROVER_ROOT_DOMAIN}`);
log("================= Getting deployment information =================");
}

async function cancel(client, vms) {
try {
const res = await client.machines.delete(vms);
log("================= Canceling the deployment =================");
log(res);
log("================= Canceling the deployment =================");
} catch (error) {
log("Error while canceling the deployment " + error);
}
const res = await client.machines.delete(vms);
log("================= Canceling the deployment =================");
log(res);
log("================= Canceling the deployment =================");
}

async function main() {
Expand Down
36 changes: 12 additions & 24 deletions packages/grid_client/scripts/caprover_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,24 @@ import { config, getClient } from "./client_loader";
import { log } from "./utils";

async function deploy(client, vms) {
try {
const res = await client.machines.deploy(vms);
log("================= Deploying Worker =================");
log(res);
log("================= Deploying Worker =================");
} catch (error) {
log("Error while Deploying the VM " + error);
}
const res = await client.machines.deploy(vms);
log("================= Deploying Worker =================");
log(res);
log("================= Deploying Worker =================");
}

async function getDeployment(client, vms) {
try {
const res = await client.machines.getObj(vms);
log("================= Getting deployment information =================");
log(res);
log("================= Getting deployment information =================");
} catch (error) {
log("Error while getting the deployment " + error);
}
const res = await client.machines.getObj(vms);
log("================= Getting deployment information =================");
log(res);
log("================= Getting deployment information =================");
}

async function cancel(client, vms) {
try {
const res = await client.machines.delete(vms);
log("================= Canceling the deployment =================");
log(res);
log("================= Canceling the deployment =================");
} catch (error) {
log("Error while canceling the deployment " + error);
}
const res = await client.machines.delete(vms);
log("================= Canceling the deployment =================");
log(res);
log("================= Canceling the deployment =================");
}

async function main() {
Expand Down
12 changes: 4 additions & 8 deletions packages/grid_client/scripts/checkNodeAlive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ import { getClient } from "./client_loader";
import { log } from "./utils";

async function pingNode(client, nodeId) {
try {
const res = await client.zos.pingNode(nodeId);
log("================= Ping result =================");
log(res);
log("================= Ping result =================");
} catch (error) {
log(`Node ${nodeId.nodeId} is offline`);
}
const res = await client.zos.pingNode(nodeId);
log("================= Ping result =================");
log(res);
log("================= Ping result =================");
}

async function main() {
Expand Down
12 changes: 4 additions & 8 deletions packages/grid_client/scripts/create_account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ import config from "./config.json";
import { log } from "./utils";

async function createAccount(client, relay) {
try {
const res = await client.tfchain.createAccount(relay, true);
log("================= Creating account =================");
log(res);
log("================= Creating account =================");
} catch (error) {
log("Error while creating account " + error);
}
const res = await client.tfchain.createAccount(relay, true);
log("================= Creating account =================");
log(res);
log("================= Creating account =================");
}

async function main() {
Expand Down
12 changes: 4 additions & 8 deletions packages/grid_client/scripts/delete_all_contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@ import { getClient } from "./client_loader";
import { log } from "./utils";

async function deleteAllContracts(client) {
try {
const res = await client.contracts.cancelMyContracts();
log("================= Deleting all contracts =================");
log(res);
log("================= Deleting all contracts =================");
} catch (error) {
log("Error while deleting contracts " + error);
}
const res = await client.contracts.cancelMyContracts();
log("================= Deleting all contracts =================");
log(res);
log("================= Deleting all contracts =================");
}

async function main() {
Expand Down
Loading

0 comments on commit b63bcc4

Please sign in to comment.