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

Error when using -d option #770

Merged
merged 10 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
8 changes: 4 additions & 4 deletions javascript/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion javascript/packages/orchestrator/src/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export class Network {
async dumpLogs(showLogPath: boolean = true): Promise<string> {
const logsPath = this.tmpDir + "/logs";
// create dump directory in local temp
fs.mkdirSync(logsPath);
if (!fs.existsSync(logsPath)) fs.mkdirSync(logsPath);
const paraNodes: NetworkNode[] = Object.values(this.paras).reduce(
(memo: NetworkNode[], value) => memo.concat(value.nodes),
[],
Expand Down
6 changes: 3 additions & 3 deletions javascript/packages/orchestrator/src/orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ export async function start(

// Check if the chain spec is in raw format
// Could be if the chain_spec_path was set
const chainSpecContent = require(chainSpecFullPathPlain);
const chainSpecContent = readAndParseChainSpec(chainSpecFullPathPlain);
client.chainId = chainSpecContent.id;

const parachainFilesPromiseGenerator = async (parachain: Parachain) => {
Expand Down Expand Up @@ -375,7 +375,8 @@ export async function start(

// ensure chain raw is ok
try {
const chainRawContent = require(chainSpecFullPath);
const chainsSpecString = fs.readFileSync(chainSpecFullPath).toString();
const chainRawContent = JSON.parse(chainsSpecString);
wirednkod marked this conversation as resolved.
Show resolved Hide resolved
debug(`Chain name: ${chainRawContent.name}`);

new CreateLogTable({ colWidths: [120], doubleBorder: true }).pushToPrint([
Expand Down Expand Up @@ -660,7 +661,6 @@ export async function start(
// add bootnodes to chain spec
await addBootNodes(chainSpecFullPath, bootnodes);
// flush require cache since we change the chain-spec
delete require.cache[require.resolve(chainSpecFullPath)];

if (client.providerName === "kubernetes") {
// cache the chainSpec with bootnodes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getClient } from "../client";
import { createTempNodeDef, genNodeDef } from "./dynResourceDefinition";
const debug = require("debug")("zombie::kube::chain-spec");

const fs = require("fs").promises;
const { writeFileSync, promises } = require("fs");
wirednkod marked this conversation as resolved.
Show resolved Hide resolved

export async function setupChainSpec(
namespace: string,
Expand All @@ -21,7 +21,7 @@ export async function setupChainSpec(
// 2: User provide the chainSpecCommand (without the --raw option)
const client = getClient();
if (chainConfig.chainSpecPath) {
await fs.copyFile(chainConfig.chainSpecPath, chainFullPath);
await promises.copyFile(chainConfig.chainSpecPath, chainFullPath);
} else {
if (chainConfig.chainSpecCommand) {
const { defaultImage, chainSpecCommand } = chainConfig;
Expand Down Expand Up @@ -139,7 +139,7 @@ export async function getChainSpecRaw(
if (result.exitCode === 0 && result.stdout.length > 0) {
// TODO: remove this debug when we get this fixed.
debug(result.stdout);
fs.writeFileSync(chainFullPath, result.stdout);
writeFileSync(chainFullPath, result.stdout);
isValid = true;
}
} catch (_) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getClient } from "../client";
import { createTempNodeDef, genNodeDef } from "./dynResourceDefinition";
const debug = require("debug")("zombie::native::chain-spec");

const fs = require("fs").promises;
const { readFileSync, promises } = require("fs");

export async function setupChainSpec(
namespace: string,
Expand All @@ -22,7 +22,7 @@ export async function setupChainSpec(
const client = getClient();
if (chainConfig.chainSpecPath) {
// copy file to temp to use
await fs.copyFile(chainConfig.chainSpecPath, chainFullPath);
await promises.copyFile(chainConfig.chainSpecPath, chainFullPath);
} else {
if (chainConfig.chainSpecCommand) {
const { defaultImage, chainSpecCommand } = chainConfig;
Expand All @@ -41,7 +41,7 @@ export async function setupChainSpec(

const podDef = await genNodeDef(namespace, node);
await client.spawnFromDef(podDef);
await fs.copyFile(plainChainSpecOutputFilePath, chainFullPath);
await promises.copyFile(plainChainSpecOutputFilePath, chainFullPath);
}
}
}
Expand Down Expand Up @@ -90,7 +90,7 @@ export async function getChainSpecRaw(
// let's add some extra checks here to ensure we are ok.
let isValid = false;
try {
require(chainFullPath);
JSON.parse(readFileSync(chainFullPath).toString());
wirednkod marked this conversation as resolved.
Show resolved Hide resolved
isValid = true;
} catch (e) {
debug(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,17 @@ export class NativeClient extends Client {
return memo;
}, memo);

if (pids.length > 0) {
args.push(`kill -9 ${pids.join(" ")}`);
const result = await this.runCommand(
["bash", "-c", `ps ax| awk '{print $1}'| grep -E '${pids.join("|")}'`],
{ allowFail: true },
);
if (result.exitCode === 0) {
const pidsToKill = result.stdout.split("\n");
if (pidsToKill.length > 0) {
args.push(`kill -9 ${pids.join(" ")}`);

await this.runCommand(args);
await this.runCommand(args);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getClient } from "../client";
import { createTempNodeDef, genNodeDef } from "./dynResourceDefinition";
const debug = require("debug")("zombie::podman::chain-spec");

const fs = require("fs").promises;
const { copyFileSync, readFileSync, promises } = require("fs");

export async function setupChainSpec(
namespace: string,
Expand All @@ -22,7 +22,7 @@ export async function setupChainSpec(
const client = getClient();
if (chainConfig.chainSpecPath) {
// copy file to temp to use
await fs.copyFile(chainConfig.chainSpecPath, chainFullPath);
copyFileSync(chainConfig.chainSpecPath, chainFullPath);
} else {
if (chainConfig.chainSpecCommand) {
const { defaultImage, chainSpecCommand } = chainConfig;
Expand All @@ -46,7 +46,7 @@ export async function setupChainSpec(
debug("copy file from pod");

const podChainPath = `${client.tmpDir}/${podName}${plainChainSpecOutputFilePath}`;
await fs.copyFile(podChainPath, chainFullPath);
copyFileSync(podChainPath, chainFullPath);
}
}
}
Expand Down Expand Up @@ -103,8 +103,12 @@ export async function getChainSpecRaw(
let isValid = false;
try {
let content = require(chainFullPath);
const chainSpecContentTest = readFileSync(chainFullPath);
JSON.parse(chainSpecContentTest.toString());
isValid = true;
} catch (_) {}
} catch (e) {
debug(e);
}

if (!isValid) {
try {
Expand All @@ -117,10 +121,12 @@ export async function getChainSpecRaw(
if (result.exitCode === 0 && result.stdout.length > 0) {
// TODO: remove this debug when we get this fixed.
debug(result.stdout);
fs.writeFileSync(chainFullPath, result.stdout);
promises.writeFileSync(chainFullPath, result.stdout);
isValid = true;
}
} catch (_) {}
} catch (e) {
debug(e);
}
}

if (!isValid) throw new Error(`Invalid chain spec raw file generated.`);
Expand Down