Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/javascript/types/nod…
Browse files Browse the repository at this point in the history
…e-20.1.1
  • Loading branch information
wirednkod authored May 10, 2023
2 parents a9cd5cd + 05a8c8a commit e66b89c
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 16 deletions.
6 changes: 3 additions & 3 deletions javascript/packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zombienet/cli",
"version": "1.3.50",
"version": "1.3.51",
"description": "ZombieNet aim to be a testing framework for substrate based blockchains, providing a simple cli tool that allow users to spawn and test ephemeral Substrate based networks",
"main": "dist/index.js",
"scripts": {
Expand Down Expand Up @@ -53,8 +53,8 @@
},
"dependencies": {
"@zombienet/dsl-parser-wrapper": "^0.1.7",
"@zombienet/orchestrator": "^0.0.39",
"@zombienet/utils": "^0.0.19",
"@zombienet/orchestrator": "^0.0.40",
"@zombienet/utils": "^0.0.20",
"cli-progress": "^3.12.0",
"commander": "^10.0.1",
"debug": "^4.3.4",
Expand Down
8 changes: 6 additions & 2 deletions javascript/packages/cli/src/actions/spawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export async function spawn(
credsFile: string | undefined,
cmdOpts: any,
program: any,
): Promise<Network> {
setGlobalNetwork: (network: Network) => void,
): Promise<void> {
const opts = { ...program.parent.opts(), ...cmdOpts };
const dir = opts.dir || "";
const force = opts.force || false;
Expand Down Expand Up @@ -93,8 +94,11 @@ export async function spawn(
force,
inCI,
silent: false,
setGlobalNetwork,
};
const network = await start(creds, config, options);
network.showNetworkInfo(config.settings?.provider);
return network;
// keep the process running
// eslint-disable-next-line @typescript-eslint/no-empty-function
setInterval(() => {}, 1000);
}
7 changes: 6 additions & 1 deletion javascript/packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ const program = new Command("zombienet");
let network: Network | undefined;
let alreadyTryToStop = false;

const setGlobalNetwork = (globalNetwork: Network) => {
network = globalNetwork;
};

async function handleTermination(userInterrupted = false) {
process.env.terminating = "1";
if (network && !alreadyTryToStop) {
alreadyTryToStop = true;
if (userInterrupted) console.log("Ctrl+c detected...");
debug("removing namespace: " + network.namespace);
await network.dumpLogs();
console.log(decorators.blue("Tearing down network..."));
await network.stop();
}
}
Expand Down Expand Up @@ -154,7 +159,7 @@ function asyncAction(cmd: Function) {
(async () => {
try {
if (cmd.name == "spawn") {
network = await cmd(...args);
await cmd(...args, setGlobalNetwork);
} else {
await cmd(...args);
}
Expand Down
4 changes: 2 additions & 2 deletions javascript/packages/orchestrator/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zombienet/orchestrator",
"version": "0.0.39",
"version": "0.0.40",
"description": "ZombieNet aim to be a testing framework for substrate based blockchains, providing a simple cli tool that allow users to spawn and test ephemeral Substrate based networks",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -37,7 +37,7 @@
"@polkadot/api": "^10.6.1",
"@polkadot/keyring": "^12.1.2",
"@polkadot/util-crypto": "^12.1.2",
"@zombienet/utils": "^0.0.19",
"@zombienet/utils": "^0.0.20",
"chai": "^4.3.7",
"debug": "^4.3.4",
"execa": "^5.1.1",
Expand Down
4 changes: 4 additions & 0 deletions javascript/packages/orchestrator/src/orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export interface OrcOptionsInterface {
dir?: string;
force?: boolean;
silent?: boolean; // Mute logging output
setGlobalNetwork?: (network: Network) => void;
}

export async function start(
Expand Down Expand Up @@ -161,6 +162,9 @@ export async function start(
if (networkSpec.settings.node_spawn_timeout)
client.timeout = networkSpec.settings.node_spawn_timeout;
network = new Network(client, namespace, tmpDir.path);
if (options?.setGlobalNetwork) {
options.setGlobalNetwork(network);
}

const zombieTable = new CreateLogTable({
head: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export class PodmanClient extends Client {
localMagicFilepath: string;
remoteDir: string;
dataDir: string;
isTearingDown: boolean;

constructor(configPath: string, namespace: string, tmpDir: string) {
super(configPath, namespace, tmpDir, "podman", "podman");
Expand All @@ -66,6 +67,7 @@ export class PodmanClient extends Client {
this.localMagicFilepath = `${tmpDir}/finished.txt`;
this.remoteDir = DEFAULT_REMOTE_DIR;
this.dataDir = DEFAULT_DATA_DIR;
this.isTearingDown = false;
}

async validateAccess(): Promise<boolean> {
Expand Down Expand Up @@ -177,6 +179,7 @@ export class PodmanClient extends Client {
}

async destroyNamespace(): Promise<void> {
this.isTearingDown = true;
// get pod names
let args = [
"pod",
Expand All @@ -189,11 +192,11 @@ export class PodmanClient extends Client {
let result = await this.runCommand(args, { scoped: false });

// now remove the pods
args = ["pod", "rm", "-f", ...result.stdout.split("\n")];
args = ["pod", "rm", "-f", "-i", ...result.stdout.split("\n")];
result = await this.runCommand(args, { scoped: false });

// now remove the pnetwork
args = ["network", "rm", this.namespace];
args = ["network", "rm", "-f", this.namespace];
result = await this.runCommand(args, { scoped: false });
}

Expand Down Expand Up @@ -297,10 +300,14 @@ export class PodmanClient extends Client {
stdout,
};
} catch (error) {
console.log(
`\n ${decorators.red("Error: ")} \t ${decorators.bright(error)}\n`,
);
throw error;
// We prevent previous commands ran to throw error when we are tearing down the network.
if (!this.isTearingDown) {
console.log(
`\n ${decorators.red("Error: ")} \t ${decorators.bright(error)}\n`,
);
throw error;
}
return { exitCode: 0, stdout: "" };
}
}

Expand Down
2 changes: 1 addition & 1 deletion javascript/packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zombienet/utils",
"version": "0.0.19",
"version": "0.0.20",
"description": "Useful utilities for ZombieNet Framework",
"main": "dist/index.js",
"author": "Parity Technologies <admin@parity.io>",
Expand Down
2 changes: 1 addition & 1 deletion javascript/packages/utils/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const LOKI_URL_FOR_NODE =
"https://grafana.parity-mgmt.parity.io/explore?orgId=1&left=%5B%22{{from}}%22,%22{{to}}%22,%22loki.parity-zombienet%22,%7B%22expr%22:%22%7Bpod%3D~%5C%22{{namespace}}%2F{{podName}}%5C%22%7D%22,%22refId%22:%22A%22,%22range%22:true%7D%5D";
"https://grafana.parity-mgmt.parity.io/explore?orgId=1&left=%7B%22datasource%22:%22PCF9DACBDF30E12B3%22,%22queries%22:%5B%7B%22refId%22:%22A%22,%22datasource%22:%7B%22type%22:%22loki%22,%22uid%22:%22PCF9DACBDF30E12B3%22%7D,%22editorMode%22:%22code%22,%22expr%22:%22%7Bpod%3D~%5C%22{{namespace}}%2F{{podName}}%5C%22%7D%22,%22queryType%22:%22range%22%7D%5D,%22range%22:%7B%22from%22:%22{{from}}%22,%22to%22:%22{{to}}%22%7D%7D";

0 comments on commit e66b89c

Please sign in to comment.