From 5403664922e454d332515e6ef37d922ef5938055 Mon Sep 17 00:00:00 2001 From: Jeffrey Tang Date: Mon, 9 Dec 2024 21:11:36 -0600 Subject: [PATCH 01/10] save Signed-off-by: Jeffrey Tang --- src/commands/cluster.ts | 6 +- test/unit/commands/cluster.test.ts | 116 +++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 test/unit/commands/cluster.test.ts diff --git a/src/commands/cluster.ts b/src/commands/cluster.ts index 4d8978e78..f2a2ce068 100644 --- a/src/commands/cluster.ts +++ b/src/commands/cluster.ts @@ -78,6 +78,8 @@ export class ClusterCommand extends BaseCommand { title: 'Initialize', task: async (ctx, task) => { self.configManager.update(argv); + flags.disablePrompts([flags.chartDirectory]); + await self.configManager.executePrompt(task, [ flags.chartDirectory, flags.clusterSetupNamespace, @@ -125,7 +127,9 @@ export class ClusterCommand extends BaseCommand { const clusterSetupNamespace = ctx.config.clusterSetupNamespace; const version = ctx.config.soloChartVersion; - const chartPath = constants.SOLO_TESTING_CHART_URL + constants.SOLO_CLUSTER_SETUP_CHART; + const chartPath = ctx.chartPath + ? ctx.chartPath + : constants.SOLO_TESTING_CHART_URL + constants.SOLO_CLUSTER_SETUP_CHART; const valuesArg = ctx.valuesArg; try { diff --git a/test/unit/commands/cluster.test.ts b/test/unit/commands/cluster.test.ts new file mode 100644 index 000000000..b940a0d64 --- /dev/null +++ b/test/unit/commands/cluster.test.ts @@ -0,0 +1,116 @@ +/** + * Copyright (C) 2024 Hedera Hashgraph, LLC + * + * Licensed under the Apache License, Version 2.0 (the ""License""); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an ""AS IS"" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +import sinon from 'sinon'; +import {describe, it, beforeEach} from 'mocha'; +import {expect} from 'chai'; + +import {ClusterCommand} from '../../../src/commands/cluster.js'; +import {getDefaultArgv, HEDERA_PLATFORM_VERSION_TAG, TEST_CLUSTER} from '../../test_util.js'; +import {Flags as flags} from '../../../src/commands/flags.js'; +import * as version from '../../../version.js'; +import * as constants from '../../../src/core/constants.js'; +import {ConfigManager} from '../../../src/core/config_manager.js'; +import {SoloLogger} from '../../../src/core/logging.js'; +import {ChartManager} from '../../../src/core/chart_manager.js'; +import {Helm} from '../../../src/core/helm.js'; +import {ROOT_DIR, SOLO_HOME_DIR, SOLO_TESTING_CHART, SOLO_TESTING_CHART_URL} from '../../../src/core/constants.js'; +import path from 'path'; + +const getBaseCommandOpts = () => ({ + logger: sinon.stub(), + helm: sinon.stub(), + k8: sinon.stub(), + chartManager: sinon.stub(), + configManager: sinon.stub(), + depManager: sinon.stub(), + localConfig: sinon.stub(), +}); + +const testName = 'cluster-cmd-unit'; +const namespace = testName; +const argv = getDefaultArgv(); + +argv[flags.namespace.name] = namespace; +argv[flags.releaseTag.name] = HEDERA_PLATFORM_VERSION_TAG; +argv[flags.nodeAliasesUnparsed.name] = 'node1'; +argv[flags.generateGossipKeys.name] = true; +argv[flags.generateTlsKeys.name] = true; +argv[flags.clusterName.name] = TEST_CLUSTER; +argv[flags.soloChartVersion.name] = version.SOLO_CHART_VERSION; +argv[flags.force.name] = true; +argv[flags.clusterSetupNamespace.name] = constants.SOLO_SETUP_NAMESPACE; + +describe('ClusterCommand unit tests', () => { + describe('constructor error handling', () => { + let opts: any; + + beforeEach(() => { + opts = getBaseCommandOpts(); + }); + + it('Install function is called with expected parameters', async () => { + opts.logger = new SoloLogger(); + opts.helm = new Helm(opts.logger); + opts.k8 = sinon.stub(); + opts.chartManager = sinon.stub(); + opts.chartManager = new ChartManager(opts.helm, opts.logger); + opts.chartManager.isChartInstalled = sinon.stub().returns(false); + opts.chartManager.install = sinon.stub().returns(true); + + opts.configManager = new ConfigManager(opts.logger); + opts.depManager = sinon.stub(); + opts.localConfig = sinon.stub(); + opts.remoteConfigManager = sinon.stub(); + + const clusterCommand = new ClusterCommand(opts); + await clusterCommand.setup(argv); + expect(opts.chartManager.install.args[0][0]).to.equal(constants.SOLO_SETUP_NAMESPACE); + expect(opts.chartManager.install.args[0][1]).to.equal(constants.SOLO_CLUSTER_SETUP_CHART); + expect(opts.chartManager.install.args[0][2]).to.equal( + path.join(constants.SOLO_TESTING_CHART, constants.SOLO_CLUSTER_SETUP_CHART), + ); + expect(opts.chartManager.install.args[0][3]).to.equal(version.SOLO_CHART_VERSION); + }); + + it('Should use local chart directory', async () => { + opts.logger = new SoloLogger(); + opts.helm = new Helm(opts.logger); + opts.helm.dependency = sinon.stub(); + opts.k8 = sinon.stub(); + opts.chartManager = sinon.stub(); + opts.chartManager = new ChartManager(opts.helm, opts.logger); + opts.chartManager.isChartInstalled = sinon.stub().returns(false); + opts.chartManager.install = sinon.stub().returns(true); + + opts.configManager = new ConfigManager(opts.logger); + opts.depManager = sinon.stub(); + opts.localConfig = sinon.stub(); + opts.remoteConfigManager = sinon.stub(); + + const clusterCommand = new ClusterCommand(opts); + argv[flags.chartDirectory.name] = 'test-directory'; + argv[flags.force.name] = true; + await clusterCommand.setup(argv); + expect(opts.chartManager.install.args[0][0]).to.equal(constants.SOLO_SETUP_NAMESPACE); + expect(opts.chartManager.install.args[0][1]).to.equal(constants.SOLO_CLUSTER_SETUP_CHART); + expect(opts.chartManager.install.args[0][2]).to.equal( + path.join(ROOT_DIR, 'test-directory', constants.SOLO_CLUSTER_SETUP_CHART), + ); + expect(opts.chartManager.install.args[0][3]).to.equal(version.SOLO_CHART_VERSION); + }); + }); +}); From 7c6d9c8b69be375f700ef35681b6e0ecfaf798dc Mon Sep 17 00:00:00 2001 From: Jeffrey Tang Date: Mon, 9 Dec 2024 21:13:00 -0600 Subject: [PATCH 02/10] save Signed-off-by: Jeffrey Tang --- test/unit/commands/cluster.test.ts | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/test/unit/commands/cluster.test.ts b/test/unit/commands/cluster.test.ts index b940a0d64..89091e34c 100644 --- a/test/unit/commands/cluster.test.ts +++ b/test/unit/commands/cluster.test.ts @@ -60,11 +60,9 @@ describe('ClusterCommand unit tests', () => { beforeEach(() => { opts = getBaseCommandOpts(); - }); - - it('Install function is called with expected parameters', async () => { opts.logger = new SoloLogger(); opts.helm = new Helm(opts.logger); + opts.helm.dependency = sinon.stub(); opts.k8 = sinon.stub(); opts.chartManager = sinon.stub(); opts.chartManager = new ChartManager(opts.helm, opts.logger); @@ -75,7 +73,9 @@ describe('ClusterCommand unit tests', () => { opts.depManager = sinon.stub(); opts.localConfig = sinon.stub(); opts.remoteConfigManager = sinon.stub(); + }); + it('Install function is called with expected parameters', async () => { const clusterCommand = new ClusterCommand(opts); await clusterCommand.setup(argv); expect(opts.chartManager.install.args[0][0]).to.equal(constants.SOLO_SETUP_NAMESPACE); @@ -87,23 +87,11 @@ describe('ClusterCommand unit tests', () => { }); it('Should use local chart directory', async () => { - opts.logger = new SoloLogger(); - opts.helm = new Helm(opts.logger); - opts.helm.dependency = sinon.stub(); - opts.k8 = sinon.stub(); - opts.chartManager = sinon.stub(); - opts.chartManager = new ChartManager(opts.helm, opts.logger); - opts.chartManager.isChartInstalled = sinon.stub().returns(false); - opts.chartManager.install = sinon.stub().returns(true); - - opts.configManager = new ConfigManager(opts.logger); - opts.depManager = sinon.stub(); - opts.localConfig = sinon.stub(); - opts.remoteConfigManager = sinon.stub(); - const clusterCommand = new ClusterCommand(opts); + argv[flags.chartDirectory.name] = 'test-directory'; argv[flags.force.name] = true; + await clusterCommand.setup(argv); expect(opts.chartManager.install.args[0][0]).to.equal(constants.SOLO_SETUP_NAMESPACE); expect(opts.chartManager.install.args[0][1]).to.equal(constants.SOLO_CLUSTER_SETUP_CHART); From 62b7a176bbeeadcea601e6b572bc809138e9989a Mon Sep 17 00:00:00 2001 From: Jeffrey Tang Date: Tue, 10 Dec 2024 10:51:04 -0600 Subject: [PATCH 03/10] save Signed-off-by: Jeffrey Tang --- src/commands/network.ts | 4 +- test/unit/commands/cluster.test.ts | 10 +-- test/unit/commands/network.test.ts | 138 +++++++++++++++++++++++++++++ 3 files changed, 145 insertions(+), 7 deletions(-) create mode 100644 test/unit/commands/network.test.ts diff --git a/src/commands/network.ts b/src/commands/network.ts index 28956f465..4ba7cd908 100644 --- a/src/commands/network.ts +++ b/src/commands/network.ts @@ -408,7 +408,9 @@ export class NetworkCommand extends BaseCommand { await this.chartManager.install( config.namespace, constants.SOLO_DEPLOYMENT_CHART, - constants.SOLO_TESTING_CHART_URL + constants.SOLO_DEPLOYMENT_CHART, + ctx.config.chartPath + ? ctx.config.chartPath + : constants.SOLO_TESTING_CHART_URL + constants.SOLO_DEPLOYMENT_CHART, config.soloChartVersion, config.valuesArg, ); diff --git a/test/unit/commands/cluster.test.ts b/test/unit/commands/cluster.test.ts index 89091e34c..7ebfaeb41 100644 --- a/test/unit/commands/cluster.test.ts +++ b/test/unit/commands/cluster.test.ts @@ -55,7 +55,7 @@ argv[flags.force.name] = true; argv[flags.clusterSetupNamespace.name] = constants.SOLO_SETUP_NAMESPACE; describe('ClusterCommand unit tests', () => { - describe('constructor error handling', () => { + describe('Chart Install Function is called correctly', () => { let opts: any; beforeEach(() => { @@ -78,6 +78,7 @@ describe('ClusterCommand unit tests', () => { it('Install function is called with expected parameters', async () => { const clusterCommand = new ClusterCommand(opts); await clusterCommand.setup(argv); + expect(opts.chartManager.install.args[0][0]).to.equal(constants.SOLO_SETUP_NAMESPACE); expect(opts.chartManager.install.args[0][1]).to.equal(constants.SOLO_CLUSTER_SETUP_CHART); expect(opts.chartManager.install.args[0][2]).to.equal( @@ -87,18 +88,15 @@ describe('ClusterCommand unit tests', () => { }); it('Should use local chart directory', async () => { - const clusterCommand = new ClusterCommand(opts); - argv[flags.chartDirectory.name] = 'test-directory'; argv[flags.force.name] = true; + const clusterCommand = new ClusterCommand(opts); await clusterCommand.setup(argv); - expect(opts.chartManager.install.args[0][0]).to.equal(constants.SOLO_SETUP_NAMESPACE); - expect(opts.chartManager.install.args[0][1]).to.equal(constants.SOLO_CLUSTER_SETUP_CHART); + expect(opts.chartManager.install.args[0][2]).to.equal( path.join(ROOT_DIR, 'test-directory', constants.SOLO_CLUSTER_SETUP_CHART), ); - expect(opts.chartManager.install.args[0][3]).to.equal(version.SOLO_CHART_VERSION); }); }); }); diff --git a/test/unit/commands/network.test.ts b/test/unit/commands/network.test.ts new file mode 100644 index 000000000..e1a50c729 --- /dev/null +++ b/test/unit/commands/network.test.ts @@ -0,0 +1,138 @@ +/** + * Copyright (C) 2024 Hedera Hashgraph, LLC + * + * Licensed under the Apache License, Version 2.0 (the ""License""); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an ""AS IS"" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +import sinon from 'sinon'; +import {describe, it, beforeEach} from 'mocha'; +import {expect} from 'chai'; + +import {ClusterCommand} from '../../../src/commands/cluster.js'; +import { + BASE_TEST_DIR, + bootstrapTestVariables, + getDefaultArgv, + HEDERA_PLATFORM_VERSION_TAG, + TEST_CLUSTER, + testLogger +} from '../../test_util.js'; +import {Flags as flags} from '../../../src/commands/flags.js'; +import * as version from '../../../version.js'; +import * as constants from '../../../src/core/constants.js'; +import {ConfigManager} from '../../../src/core/config_manager.js'; +import {SoloLogger} from '../../../src/core/logging.js'; +import {ChartManager} from '../../../src/core/chart_manager.js'; +import {Helm} from '../../../src/core/helm.js'; +import {ROOT_DIR, SOLO_HOME_DIR, SOLO_TESTING_CHART, SOLO_TESTING_CHART_URL} from '../../../src/core/constants.js'; +import path from 'path'; +import {NetworkCommand} from '../../../src/commands/network.js'; +import {LeaseManager} from "../../../src/core/lease/lease_manager.js"; +import {IntervalLeaseRenewalService} from "../../../src/core/lease/interval_lease_renewal.js"; +import chalk from "chalk"; +import {RemoteConfigValidator} from "../../../src/core/config/remote/remote_config_validator.js"; +import {RemoteConfigManager} from "../../../src/core/config/remote/remote_config_manager.js"; +import {LocalConfig} from "../../../src/core/config/local_config.js"; +import * as k8s from "@kubernetes/client-node"; + +const getBaseCommandOpts = () => ({ + logger: sinon.stub(), + helm: sinon.stub(), + k8: sinon.stub(), + chartManager: sinon.stub(), + configManager: sinon.stub(), + depManager: sinon.stub(), + localConfig: sinon.stub(), +}); + +const testName = 'network-cmd-unit'; +const namespace = testName; +const argv = getDefaultArgv(); + +argv[flags.namespace.name] = namespace; +argv[flags.releaseTag.name] = HEDERA_PLATFORM_VERSION_TAG; +argv[flags.nodeAliasesUnparsed.name] = 'node1'; +argv[flags.generateGossipKeys.name] = true; +argv[flags.generateTlsKeys.name] = true; +argv[flags.clusterName.name] = TEST_CLUSTER; +argv[flags.soloChartVersion.name] = version.SOLO_CHART_VERSION; +argv[flags.force.name] = true; +argv[flags.clusterSetupNamespace.name] = constants.SOLO_SETUP_NAMESPACE; +argv[flags.chartDirectory.name] = undefined; + +describe('NetworkCommand unit tests', () => { + describe('Chart Install Function is called correctly', () => { + let opts: any; + + const bootstrapResp = bootstrapTestVariables(testName, argv); + + beforeEach(() => { + // opts = getBaseCommandOpts(); + // opts.logger = new SoloLogger(); + // opts.helm = new Helm(opts.logger); + // opts.helm.dependency = sinon.stub(); + // opts.k8 = sinon.stub(); + // opts.k8.readNamespacedLease = sinon.stub().returns(k8s.V1Lease); + // opts.chartManager = sinon.stub(); + // opts.keyManager = sinon.stub(); + // opts.platformInstaller = sinon.stub(); + // opts.profileManager = sinon.stub(); + // opts.certificateManager = sinon.stub(); + // + // opts.chartManager = new ChartManager(opts.helm, opts.logger); + // opts.chartManager.isChartInstalled = sinon.stub().returns(false); + // opts.chartManager.install = sinon.stub().returns(true); + // const localConfig = new LocalConfig(path.join(BASE_TEST_DIR, 'local-config.yaml'), opts.logger, opts.configManager); + // opts.remoteConfigManager = new RemoteConfigManager(opts.k8, opts.logger, localConfig, opts.configManager); + // + // // opts.remoteConfigManager.buildLoadTask = sinon.stub().returns({ + // // title: 'Load remote config', + // // task: async (_, task): Promise => { + // // task.output = 'Remote config loaded'; + // // }, + // // }); + // + // opts.configManager = new ConfigManager(opts.logger); + // opts.leaseManager = new LeaseManager(opts.k8, opts.configManager, opts.logger, new IntervalLeaseRenewalService()); + // opts.leaseManager.currentNamespace = sinon.stub().returns(testName); + // opts.depManager = sinon.stub(); + // opts.localConfig = sinon.stub(); + // // opts.remoteConfigManager = sinon.stub(); + }); + + it('Install function is called with expected parameters', async () => { + const networkCommand = bootstrapResp.cmd.networkCmd; + await networkCommand.deploy(argv); + expect(opts.chartManager.install.args[0][0]).to.equal(constants.SOLO_SETUP_NAMESPACE); + expect(opts.chartManager.install.args[0][1]).to.equal(constants.SOLO_CLUSTER_SETUP_CHART); + expect(opts.chartManager.install.args[0][2]).to.equal( + path.join(constants.SOLO_TESTING_CHART, constants.SOLO_CLUSTER_SETUP_CHART), + ); + expect(opts.chartManager.install.args[0][3]).to.equal(version.SOLO_CHART_VERSION); + }); + + // it('Should use local chart directory', async () => { + // argv[flags.chartDirectory.name] = 'test-directory'; + // argv[flags.force.name] = true; + // + // const networkCommand = new NetworkCommand(opts); + // await networkCommand.deploy(argv); + // expect(opts.chartManager.install.args[0][0]).to.equal(constants.SOLO_SETUP_NAMESPACE); + // expect(opts.chartManager.install.args[0][1]).to.equal(constants.SOLO_CLUSTER_SETUP_CHART); + // expect(opts.chartManager.install.args[0][2]).to.equal( + // path.join(ROOT_DIR, 'test-directory', constants.SOLO_CLUSTER_SETUP_CHART), + // ); + // expect(opts.chartManager.install.args[0][3]).to.equal(version.SOLO_CHART_VERSION); + // }); + }); +}); From 810bbc2bc4ea8789b74e6ee05c9a3a0dc22d245a Mon Sep 17 00:00:00 2001 From: Jeffrey Tang Date: Tue, 10 Dec 2024 13:42:59 -0600 Subject: [PATCH 04/10] save Signed-off-by: Jeffrey Tang --- test/unit/commands/network.test.ts | 77 ++++++++++++++++++------------ 1 file changed, 47 insertions(+), 30 deletions(-) diff --git a/test/unit/commands/network.test.ts b/test/unit/commands/network.test.ts index e1a50c729..e54a32bb9 100644 --- a/test/unit/commands/network.test.ts +++ b/test/unit/commands/network.test.ts @@ -44,6 +44,9 @@ import {RemoteConfigValidator} from "../../../src/core/config/remote/remote_conf import {RemoteConfigManager} from "../../../src/core/config/remote/remote_config_manager.js"; import {LocalConfig} from "../../../src/core/config/local_config.js"; import * as k8s from "@kubernetes/client-node"; +import {K8} from "../../../src/core/k8.js"; +import {ProfileManager} from "../../../src/core/profile_manager.js"; +import {KeyManager} from "../../../src/core/key_manager.js"; const getBaseCommandOpts = () => ({ logger: sinon.stub(), @@ -77,42 +80,56 @@ describe('NetworkCommand unit tests', () => { const bootstrapResp = bootstrapTestVariables(testName, argv); beforeEach(() => { - // opts = getBaseCommandOpts(); - // opts.logger = new SoloLogger(); - // opts.helm = new Helm(opts.logger); - // opts.helm.dependency = sinon.stub(); + opts = getBaseCommandOpts(); + opts.logger = testLogger; + opts.helm = new Helm(opts.logger); + opts.helm.dependency = sinon.stub(); // opts.k8 = sinon.stub(); - // opts.k8.readNamespacedLease = sinon.stub().returns(k8s.V1Lease); + opts.configManager = new ConfigManager(testLogger); + opts.configManager.update(argv); + opts.k8 = new K8(opts.configManager, testLogger); // inon.stub().returns(k8s.V1Lease); + opts.k8.waitForPods = sinon.stub(); // opts.chartManager = sinon.stub(); - // opts.keyManager = sinon.stub(); - // opts.platformInstaller = sinon.stub(); - // opts.profileManager = sinon.stub(); - // opts.certificateManager = sinon.stub(); - // - // opts.chartManager = new ChartManager(opts.helm, opts.logger); - // opts.chartManager.isChartInstalled = sinon.stub().returns(false); - // opts.chartManager.install = sinon.stub().returns(true); - // const localConfig = new LocalConfig(path.join(BASE_TEST_DIR, 'local-config.yaml'), opts.logger, opts.configManager); - // opts.remoteConfigManager = new RemoteConfigManager(opts.k8, opts.logger, localConfig, opts.configManager); - // - // // opts.remoteConfigManager.buildLoadTask = sinon.stub().returns({ - // // title: 'Load remote config', - // // task: async (_, task): Promise => { - // // task.output = 'Remote config loaded'; - // // }, - // // }); - // - // opts.configManager = new ConfigManager(opts.logger); - // opts.leaseManager = new LeaseManager(opts.k8, opts.configManager, opts.logger, new IntervalLeaseRenewalService()); - // opts.leaseManager.currentNamespace = sinon.stub().returns(testName); - // opts.depManager = sinon.stub(); - // opts.localConfig = sinon.stub(); - // // opts.remoteConfigManager = sinon.stub(); + opts.keyManager = new KeyManager(testLogger); + opts.platformInstaller = sinon.stub(); + opts.platformInstaller.copyNodeKeys = sinon.stub(); + opts.profileManager = new ProfileManager(testLogger, opts.configManager); //sinon.stub(); + opts.certificateManager = sinon.stub(); + + opts.chartManager = sinon.stub(); + opts.chartManager = new ChartManager(opts.helm, opts.logger); + opts.chartManager.isChartInstalled = sinon.stub().returns(true); + opts.chartManager.isChartInstalled.onSecondCall().returns(false); + + opts.chartManager.install = sinon.stub().returns(true); + const localConfig = new LocalConfig( + path.join(BASE_TEST_DIR, 'local-config.yaml'), + opts.logger, + opts.configManager, + ); + opts.remoteConfigManager = new RemoteConfigManager(opts.k8, opts.logger, localConfig, opts.configManager); + + // opts.remoteConfigManager.buildLoadTask = sinon.stub().returns({ + // title: 'Load remote config', + // task: async (_, task): Promise => { + // task.output = 'Remote config loaded'; + // }, + // }); + + opts.configManager = new ConfigManager(opts.logger); + opts.leaseManager = new LeaseManager(opts.k8, opts.configManager, opts.logger, new IntervalLeaseRenewalService()); + opts.leaseManager.currentNamespace = sinon.stub().returns(testName); + opts.depManager = sinon.stub(); + opts.localConfig = sinon.stub(); + // opts.remoteConfigManager = sinon.stub(); }); it('Install function is called with expected parameters', async () => { - const networkCommand = bootstrapResp.cmd.networkCmd; + const networkCommand = new NetworkCommand(opts); + networkCommand.addNodesAndProxies = sinon.stub(); + await networkCommand.deploy(argv); + expect(opts.chartManager.install.args[0][0]).to.equal(constants.SOLO_SETUP_NAMESPACE); expect(opts.chartManager.install.args[0][1]).to.equal(constants.SOLO_CLUSTER_SETUP_CHART); expect(opts.chartManager.install.args[0][2]).to.equal( From 3602e4edf360883c31c480698a5b0311dafe9109 Mon Sep 17 00:00:00 2001 From: Jeffrey Tang Date: Wed, 11 Dec 2024 10:45:25 -0600 Subject: [PATCH 05/10] add network unit test Signed-off-by: Jeffrey Tang --- src/commands/network.ts | 1 + test/unit/commands/cluster.test.ts | 4 -- test/unit/commands/network.test.ts | 82 +++++++++++------------------- 3 files changed, 31 insertions(+), 56 deletions(-) diff --git a/src/commands/network.ts b/src/commands/network.ts index 4ba7cd908..d5dc19d36 100644 --- a/src/commands/network.ts +++ b/src/commands/network.ts @@ -214,6 +214,7 @@ export class NetworkCommand extends BaseCommand { flags.bootstrapProperties, flags.cacheDir, flags.chainId, + flags.chartDirectory, flags.debugNodeAlias, flags.log4j2Xml, flags.persistentVolumeClaims, diff --git a/test/unit/commands/cluster.test.ts b/test/unit/commands/cluster.test.ts index 7ebfaeb41..fe91cc193 100644 --- a/test/unit/commands/cluster.test.ts +++ b/test/unit/commands/cluster.test.ts @@ -63,15 +63,11 @@ describe('ClusterCommand unit tests', () => { opts.logger = new SoloLogger(); opts.helm = new Helm(opts.logger); opts.helm.dependency = sinon.stub(); - opts.k8 = sinon.stub(); - opts.chartManager = sinon.stub(); opts.chartManager = new ChartManager(opts.helm, opts.logger); opts.chartManager.isChartInstalled = sinon.stub().returns(false); opts.chartManager.install = sinon.stub().returns(true); opts.configManager = new ConfigManager(opts.logger); - opts.depManager = sinon.stub(); - opts.localConfig = sinon.stub(); opts.remoteConfigManager = sinon.stub(); }); diff --git a/test/unit/commands/network.test.ts b/test/unit/commands/network.test.ts index e54a32bb9..81466b03a 100644 --- a/test/unit/commands/network.test.ts +++ b/test/unit/commands/network.test.ts @@ -18,35 +18,32 @@ import sinon from 'sinon'; import {describe, it, beforeEach} from 'mocha'; import {expect} from 'chai'; -import {ClusterCommand} from '../../../src/commands/cluster.js'; import { - BASE_TEST_DIR, bootstrapTestVariables, getDefaultArgv, HEDERA_PLATFORM_VERSION_TAG, TEST_CLUSTER, - testLogger + testLogger, } from '../../test_util.js'; import {Flags as flags} from '../../../src/commands/flags.js'; import * as version from '../../../version.js'; import * as constants from '../../../src/core/constants.js'; import {ConfigManager} from '../../../src/core/config_manager.js'; -import {SoloLogger} from '../../../src/core/logging.js'; import {ChartManager} from '../../../src/core/chart_manager.js'; import {Helm} from '../../../src/core/helm.js'; -import {ROOT_DIR, SOLO_HOME_DIR, SOLO_TESTING_CHART, SOLO_TESTING_CHART_URL} from '../../../src/core/constants.js'; import path from 'path'; import {NetworkCommand} from '../../../src/commands/network.js'; -import {LeaseManager} from "../../../src/core/lease/lease_manager.js"; -import {IntervalLeaseRenewalService} from "../../../src/core/lease/interval_lease_renewal.js"; -import chalk from "chalk"; -import {RemoteConfigValidator} from "../../../src/core/config/remote/remote_config_validator.js"; -import {RemoteConfigManager} from "../../../src/core/config/remote/remote_config_manager.js"; -import {LocalConfig} from "../../../src/core/config/local_config.js"; -import * as k8s from "@kubernetes/client-node"; -import {K8} from "../../../src/core/k8.js"; -import {ProfileManager} from "../../../src/core/profile_manager.js"; -import {KeyManager} from "../../../src/core/key_manager.js"; +import {LeaseManager} from '../../../src/core/lease/lease_manager.js'; +import {IntervalLeaseRenewalService} from '../../../src/core/lease/interval_lease_renewal.js'; +import chalk from 'chalk'; +import {RemoteConfigValidator} from '../../../src/core/config/remote/remote_config_validator.js'; +import {RemoteConfigManager} from '../../../src/core/config/remote/remote_config_manager.js'; +import {LocalConfig} from '../../../src/core/config/local_config.js'; +import * as k8s from '@kubernetes/client-node'; +import {K8} from '../../../src/core/k8.js'; +import {ProfileManager} from '../../../src/core/profile_manager.js'; +import {KeyManager} from '../../../src/core/key_manager.js'; +import {ROOT_DIR} from '../../../src/core/constants.js'; const getBaseCommandOpts = () => ({ logger: sinon.stub(), @@ -84,72 +81,53 @@ describe('NetworkCommand unit tests', () => { opts.logger = testLogger; opts.helm = new Helm(opts.logger); opts.helm.dependency = sinon.stub(); - // opts.k8 = sinon.stub(); + opts.configManager = new ConfigManager(testLogger); opts.configManager.update(argv); opts.k8 = new K8(opts.configManager, testLogger); // inon.stub().returns(k8s.V1Lease); opts.k8.waitForPods = sinon.stub(); - // opts.chartManager = sinon.stub(); opts.keyManager = new KeyManager(testLogger); opts.platformInstaller = sinon.stub(); opts.platformInstaller.copyNodeKeys = sinon.stub(); opts.profileManager = new ProfileManager(testLogger, opts.configManager); //sinon.stub(); opts.certificateManager = sinon.stub(); - opts.chartManager = sinon.stub(); opts.chartManager = new ChartManager(opts.helm, opts.logger); opts.chartManager.isChartInstalled = sinon.stub().returns(true); opts.chartManager.isChartInstalled.onSecondCall().returns(false); opts.chartManager.install = sinon.stub().returns(true); - const localConfig = new LocalConfig( - path.join(BASE_TEST_DIR, 'local-config.yaml'), - opts.logger, - opts.configManager, - ); - opts.remoteConfigManager = new RemoteConfigManager(opts.k8, opts.logger, localConfig, opts.configManager); - - // opts.remoteConfigManager.buildLoadTask = sinon.stub().returns({ - // title: 'Load remote config', - // task: async (_, task): Promise => { - // task.output = 'Remote config loaded'; - // }, - // }); + opts.remoteConfigManager = new RemoteConfigManager(opts.k8, opts.logger, opts.localConfig, opts.configManager); opts.configManager = new ConfigManager(opts.logger); opts.leaseManager = new LeaseManager(opts.k8, opts.configManager, opts.logger, new IntervalLeaseRenewalService()); opts.leaseManager.currentNamespace = sinon.stub().returns(testName); - opts.depManager = sinon.stub(); - opts.localConfig = sinon.stub(); - // opts.remoteConfigManager = sinon.stub(); }); it('Install function is called with expected parameters', async () => { const networkCommand = new NetworkCommand(opts); - networkCommand.addNodesAndProxies = sinon.stub(); - await networkCommand.deploy(argv); - expect(opts.chartManager.install.args[0][0]).to.equal(constants.SOLO_SETUP_NAMESPACE); - expect(opts.chartManager.install.args[0][1]).to.equal(constants.SOLO_CLUSTER_SETUP_CHART); + expect(opts.chartManager.install.args[0][0]).to.equal(testName); + expect(opts.chartManager.install.args[0][1]).to.equal(constants.SOLO_DEPLOYMENT_CHART); expect(opts.chartManager.install.args[0][2]).to.equal( - path.join(constants.SOLO_TESTING_CHART, constants.SOLO_CLUSTER_SETUP_CHART), + path.join(constants.SOLO_TESTING_CHART, constants.SOLO_DEPLOYMENT_CHART), ); expect(opts.chartManager.install.args[0][3]).to.equal(version.SOLO_CHART_VERSION); }); - // it('Should use local chart directory', async () => { - // argv[flags.chartDirectory.name] = 'test-directory'; - // argv[flags.force.name] = true; - // - // const networkCommand = new NetworkCommand(opts); - // await networkCommand.deploy(argv); - // expect(opts.chartManager.install.args[0][0]).to.equal(constants.SOLO_SETUP_NAMESPACE); - // expect(opts.chartManager.install.args[0][1]).to.equal(constants.SOLO_CLUSTER_SETUP_CHART); - // expect(opts.chartManager.install.args[0][2]).to.equal( - // path.join(ROOT_DIR, 'test-directory', constants.SOLO_CLUSTER_SETUP_CHART), - // ); - // expect(opts.chartManager.install.args[0][3]).to.equal(version.SOLO_CHART_VERSION); - // }); + it('Should use local chart directory', async () => { + argv[flags.chartDirectory.name] = 'test-directory'; + argv[flags.force.name] = true; + + const networkCommand = new NetworkCommand(opts); + await networkCommand.deploy(argv); + expect(opts.chartManager.install.args[0][0]).to.equal(testName); + expect(opts.chartManager.install.args[0][1]).to.equal(constants.SOLO_DEPLOYMENT_CHART); + expect(opts.chartManager.install.args[0][2]).to.equal( + path.join(ROOT_DIR, 'test-directory', constants.SOLO_DEPLOYMENT_CHART), + ); + expect(opts.chartManager.install.args[0][3]).to.equal(version.SOLO_CHART_VERSION); + }); }); }); From 4c56be2a622c5c15912729f26b426b471fcfd8e4 Mon Sep 17 00:00:00 2001 From: Jeffrey Tang Date: Wed, 11 Dec 2024 11:25:01 -0600 Subject: [PATCH 06/10] update path calculation Signed-off-by: Jeffrey Tang --- examples/performance-tuning/README.md | 21 ++++++++++++--------- src/commands/cluster.ts | 24 +++++++----------------- src/commands/network.ts | 6 ++---- src/core/constants.ts | 2 +- test/unit/commands/cluster.test.ts | 2 +- test/unit/commands/network.test.ts | 2 +- 6 files changed, 24 insertions(+), 33 deletions(-) diff --git a/examples/performance-tuning/README.md b/examples/performance-tuning/README.md index 80a4e56af..85aecce11 100644 --- a/examples/performance-tuning/README.md +++ b/examples/performance-tuning/README.md @@ -1,16 +1,18 @@ -# The usage of resources in Solo -## Modify Taskfile.yml, task "network:deploy" +# The usage of resources in Solo + +## Modify Taskfile.yml, task "network:deploy" + add "--values-file init-containers-values.yaml" Example: -> solo:network:deploy: -> internal: true -> cmds: -> - npm run solo-test -- network deploy --namespace "\${SOLO_NAMESPACE}" --node-aliases-unparsed {{.node_identifiers}} --solo-chart-version "\${SOLO_CHART_VERSION}" --settings-txt settings.txt --log4j2-xml log4j2.xml --values-file init-containers-values.yaml --application-properties application.properties - +> solo:network:deploy: +> internal: true +> cmds: +> \- npm run solo-test -- network deploy --namespace "${SOLO\_NAMESPACE}" --node-aliases-unparsed {{.node\_identifiers}} --solo-chart-version "${SOLO\_CHART\_VERSION}" --settings-txt settings.txt --log4j2-xml log4j2.xml --values-file init-containers-values.yaml --application-properties application.properties ## Provided examples for Consensus nodes: + * HashSphere/init-containers-values.yaml (HashSphere on Google Cloud, for 4-core/32Gb 7-node ) * Latitude/init-containers-values.yaml (Latitude, 128Gb, 10-node) @@ -18,5 +20,6 @@ Example: * HashSphere/nlg-values.yaml * Latitude/nlg-values.yaml -Start as the following: -> helm upgrade --install nlg oci://swirldslabs.jfrog.io/load-generator-helm-release-local/network-load-generator --version 0.2.1 --values nlg-values.yaml -n solo-hashsphere1 + Start as the following: + +> helm upgrade --install nlg oci://swirldslabs.jfrog.io/load-generator-helm-release-local/network-load-generator --version 0.2.1 --values nlg-values.yaml -n solo-hashsphere1 diff --git a/src/commands/cluster.ts b/src/commands/cluster.ts index f2a2ce068..0d26b60ec 100644 --- a/src/commands/cluster.ts +++ b/src/commands/cluster.ts @@ -110,7 +110,11 @@ export class ClusterCommand extends BaseCommand { { title: 'Prepare chart values', task: async (ctx, _) => { - ctx.chartPath = await this.prepareChartPath(ctx.config.chartDir); + ctx.chartPath = await this.prepareChartPath( + ctx.config.chartDir, + constants.SOLO_TESTING_CHART_URL, + constants.SOLO_CLUSTER_SETUP_CHART, + ); ctx.valuesArg = this.prepareValuesArg( ctx.config.chartDir, ctx.config.deployPrometheusStack, @@ -133,11 +137,11 @@ export class ClusterCommand extends BaseCommand { const valuesArg = ctx.valuesArg; try { - self.logger.debug(`Installing chart chartPath = ${chartPath}, version = ${version}`); + self.logger.debug(`Installing chart chartPath = ${ctx.chartPath}, version = ${version}`); await self.chartManager.install( clusterSetupNamespace, constants.SOLO_CLUSTER_SETUP_CHART, - chartPath, + ctx.chartPath, version, valuesArg, ); @@ -385,20 +389,6 @@ export class ClusterCommand extends BaseCommand { return valuesArg; } - /** - * Prepare chart path - * @param [chartDir] - local charts directory (default is empty) - */ - async prepareChartPath(chartDir = flags.chartDirectory.definition.defaultValue as string) { - let chartPath = 'solo-charts/solo-cluster-setup'; - if (chartDir) { - chartPath = path.join(chartDir, 'solo-cluster-setup'); - await this.helm.dependency('update', chartPath); - } - - return chartPath; - } - close(): Promise { // no-op return Promise.resolve(); diff --git a/src/commands/network.ts b/src/commands/network.ts index b6d469cd4..4048a84a7 100644 --- a/src/commands/network.ts +++ b/src/commands/network.ts @@ -254,7 +254,7 @@ export class NetworkCommand extends BaseCommand { // compute values config.chartPath = await this.prepareChartPath( config.chartDirectory, - constants.SOLO_TESTING_CHART, + constants.SOLO_TESTING_CHART_URL, constants.SOLO_DEPLOYMENT_CHART, ); @@ -409,9 +409,7 @@ export class NetworkCommand extends BaseCommand { await this.chartManager.install( config.namespace, constants.SOLO_DEPLOYMENT_CHART, - ctx.config.chartPath - ? ctx.config.chartPath - : constants.SOLO_TESTING_CHART_URL + constants.SOLO_DEPLOYMENT_CHART, + ctx.config.chartPath, config.soloChartVersion, config.valuesArg, ); diff --git a/src/core/constants.ts b/src/core/constants.ts index db5e71dd1..538d98a27 100644 --- a/src/core/constants.ts +++ b/src/core/constants.ts @@ -53,7 +53,7 @@ export const HEDERA_NODE_DEFAULT_STAKE_AMOUNT = +process.env.SOLO_NODE_DEFAULT_S // --------------- Charts related constants ---------------------------------------------------------------------------- export const SOLO_SETUP_NAMESPACE = 'solo-setup'; -export const SOLO_TESTING_CHART_URL = 'oci://ghcr.io/hashgraph/solo-charts/'; +export const SOLO_TESTING_CHART_URL = 'oci://ghcr.io/hashgraph/solo-charts'; export const SOLO_TESTING_CHART = 'solo-charts'; export const SOLO_CLUSTER_SETUP_CHART = 'solo-cluster-setup'; export const SOLO_DEPLOYMENT_CHART = 'solo-deployment'; diff --git a/test/unit/commands/cluster.test.ts b/test/unit/commands/cluster.test.ts index fe91cc193..8b42324b0 100644 --- a/test/unit/commands/cluster.test.ts +++ b/test/unit/commands/cluster.test.ts @@ -78,7 +78,7 @@ describe('ClusterCommand unit tests', () => { expect(opts.chartManager.install.args[0][0]).to.equal(constants.SOLO_SETUP_NAMESPACE); expect(opts.chartManager.install.args[0][1]).to.equal(constants.SOLO_CLUSTER_SETUP_CHART); expect(opts.chartManager.install.args[0][2]).to.equal( - path.join(constants.SOLO_TESTING_CHART, constants.SOLO_CLUSTER_SETUP_CHART), + constants.SOLO_TESTING_CHART_URL + '/' + constants.SOLO_CLUSTER_SETUP_CHART, ); expect(opts.chartManager.install.args[0][3]).to.equal(version.SOLO_CHART_VERSION); }); diff --git a/test/unit/commands/network.test.ts b/test/unit/commands/network.test.ts index 81466b03a..531b9af11 100644 --- a/test/unit/commands/network.test.ts +++ b/test/unit/commands/network.test.ts @@ -111,7 +111,7 @@ describe('NetworkCommand unit tests', () => { expect(opts.chartManager.install.args[0][0]).to.equal(testName); expect(opts.chartManager.install.args[0][1]).to.equal(constants.SOLO_DEPLOYMENT_CHART); expect(opts.chartManager.install.args[0][2]).to.equal( - path.join(constants.SOLO_TESTING_CHART, constants.SOLO_DEPLOYMENT_CHART), + constants.SOLO_TESTING_CHART_URL + '/' + constants.SOLO_DEPLOYMENT_CHART, ); expect(opts.chartManager.install.args[0][3]).to.equal(version.SOLO_CHART_VERSION); }); From 632e266f5bc51fc3cc35a911131d3c788b3c275b Mon Sep 17 00:00:00 2001 From: Jeffrey Tang Date: Wed, 11 Dec 2024 11:26:51 -0600 Subject: [PATCH 07/10] update expect Signed-off-by: Jeffrey Tang --- test/e2e/commands/network.test.ts | 1 - test/e2e/commands/separate_node_add.test.ts | 1 - test/test_add.ts | 1 - test/test_util.ts | 1 - 4 files changed, 4 deletions(-) diff --git a/test/e2e/commands/network.test.ts b/test/e2e/commands/network.test.ts index fdb4139ce..f0a5bc974 100644 --- a/test/e2e/commands/network.test.ts +++ b/test/e2e/commands/network.test.ts @@ -102,7 +102,6 @@ describe('NetworkCommand', () => { flags.settingTxt.constName, flags.grpcTlsKeyPath.constName, flags.grpcWebTlsKeyPath.constName, - 'chartPath', ]); } catch (e) { networkCmd.logger.showUserError(e); diff --git a/test/e2e/commands/separate_node_add.test.ts b/test/e2e/commands/separate_node_add.test.ts index 74b82dded..6587faace 100644 --- a/test/e2e/commands/separate_node_add.test.ts +++ b/test/e2e/commands/separate_node_add.test.ts @@ -101,7 +101,6 @@ e2eTestSuite(namespace, argv, undefined, undefined, undefined, undefined, undefi flags.devMode.constName, flags.force.constName, flags.quiet.constName, - 'chartPath', 'curDate', 'freezeAdminPrivateKey', ]); diff --git a/test/test_add.ts b/test/test_add.ts index f6ca4af32..0cf7de96f 100644 --- a/test/test_add.ts +++ b/test/test_add.ts @@ -105,7 +105,6 @@ export function testNodeAdd( flags.force.constName, flags.quiet.constName, flags.adminKey.constName, - 'chartPath', ]); await bootstrapResp.opts.accountManager.close(); }).timeout(Duration.ofMinutes(12).toMillis()); diff --git a/test/test_util.ts b/test/test_util.ts index 4a9d96391..eda7b91c3 100644 --- a/test/test_util.ts +++ b/test/test_util.ts @@ -288,7 +288,6 @@ export function e2eTestSuite( flags.settingTxt.constName, flags.grpcTlsKeyPath.constName, flags.grpcWebTlsKeyPath.constName, - 'chartPath', ]); }).timeout(Duration.ofMinutes(5).toMillis()); From 80335b95c0702aed75fed43fab4e0bc643233b3a Mon Sep 17 00:00:00 2001 From: Jeffrey Tang Date: Wed, 11 Dec 2024 12:06:40 -0600 Subject: [PATCH 08/10] Fix unit test Signed-off-by: Jeffrey Tang --- src/commands/cluster.ts | 4 ---- src/commands/network.ts | 2 +- src/commands/node/configs.ts | 6 +++--- src/commands/node/tasks.ts | 2 +- src/core/constants.ts | 1 - test/unit/commands/cluster.test.ts | 2 +- test/unit/commands/network.test.ts | 12 ++++++------ 7 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/commands/cluster.ts b/src/commands/cluster.ts index 0d26b60ec..512f55bcc 100644 --- a/src/commands/cluster.ts +++ b/src/commands/cluster.ts @@ -130,10 +130,6 @@ export class ClusterCommand extends BaseCommand { task: async (ctx, _) => { const clusterSetupNamespace = ctx.config.clusterSetupNamespace; const version = ctx.config.soloChartVersion; - - const chartPath = ctx.chartPath - ? ctx.chartPath - : constants.SOLO_TESTING_CHART_URL + constants.SOLO_CLUSTER_SETUP_CHART; const valuesArg = ctx.valuesArg; try { diff --git a/src/commands/network.ts b/src/commands/network.ts index 4048a84a7..bfb3e1030 100644 --- a/src/commands/network.ts +++ b/src/commands/network.ts @@ -646,7 +646,7 @@ export class NetworkCommand extends BaseCommand { await this.chartManager.upgrade( config.namespace, constants.SOLO_DEPLOYMENT_CHART, - constants.SOLO_TESTING_CHART_URL + constants.SOLO_DEPLOYMENT_CHART, + ctx.config.chartPath, config.soloChartVersion, config.valuesArg, ); diff --git a/src/commands/node/configs.ts b/src/commands/node/configs.ts index e1a234c39..3e6222baa 100644 --- a/src/commands/node/configs.ts +++ b/src/commands/node/configs.ts @@ -110,7 +110,7 @@ export const updateConfigBuilder = async function (argv, ctx, task) { ctx.config.chartPath = await this.prepareChartPath( ctx.config.chartDirectory, - constants.SOLO_TESTING_CHART, + constants.SOLO_TESTING_CHART_URL, constants.SOLO_DEPLOYMENT_CHART, ); @@ -152,7 +152,7 @@ export const deleteConfigBuilder = async function (argv, ctx, task) { ctx.config.chartPath = await this.prepareChartPath( ctx.config.chartDirectory, - constants.SOLO_TESTING_CHART, + constants.SOLO_TESTING_CHART_URL, constants.SOLO_DEPLOYMENT_CHART, ); @@ -199,7 +199,7 @@ export const addConfigBuilder = async function (argv, ctx, task) { ctx.config.chartPath = await this.prepareChartPath( ctx.config.chartDirectory, - constants.SOLO_TESTING_CHART, + constants.SOLO_TESTING_CHART_URL, constants.SOLO_DEPLOYMENT_CHART, ); diff --git a/src/commands/node/tasks.ts b/src/commands/node/tasks.ts index 9b5292b93..7aed45870 100644 --- a/src/commands/node/tasks.ts +++ b/src/commands/node/tasks.ts @@ -1423,7 +1423,7 @@ export class NodeCommandTasks { await self.chartManager.upgrade( config.namespace, constants.SOLO_DEPLOYMENT_CHART, - constants.SOLO_TESTING_CHART_URL + constants.SOLO_DEPLOYMENT_CHART, + ctx.config.chartPath, config.soloChartVersion, valuesArg, ); diff --git a/src/core/constants.ts b/src/core/constants.ts index 538d98a27..1ab880c73 100644 --- a/src/core/constants.ts +++ b/src/core/constants.ts @@ -54,7 +54,6 @@ export const HEDERA_NODE_DEFAULT_STAKE_AMOUNT = +process.env.SOLO_NODE_DEFAULT_S // --------------- Charts related constants ---------------------------------------------------------------------------- export const SOLO_SETUP_NAMESPACE = 'solo-setup'; export const SOLO_TESTING_CHART_URL = 'oci://ghcr.io/hashgraph/solo-charts'; -export const SOLO_TESTING_CHART = 'solo-charts'; export const SOLO_CLUSTER_SETUP_CHART = 'solo-cluster-setup'; export const SOLO_DEPLOYMENT_CHART = 'solo-deployment'; export const JSON_RPC_RELAY_CHART_URL = 'https://hashgraph.github.io/hedera-json-rpc-relay/charts'; diff --git a/test/unit/commands/cluster.test.ts b/test/unit/commands/cluster.test.ts index 8b42324b0..5eb726bbc 100644 --- a/test/unit/commands/cluster.test.ts +++ b/test/unit/commands/cluster.test.ts @@ -27,7 +27,7 @@ import {ConfigManager} from '../../../src/core/config_manager.js'; import {SoloLogger} from '../../../src/core/logging.js'; import {ChartManager} from '../../../src/core/chart_manager.js'; import {Helm} from '../../../src/core/helm.js'; -import {ROOT_DIR, SOLO_HOME_DIR, SOLO_TESTING_CHART, SOLO_TESTING_CHART_URL} from '../../../src/core/constants.js'; +import {ROOT_DIR} from '../../../src/core/constants.js'; import path from 'path'; const getBaseCommandOpts = () => ({ diff --git a/test/unit/commands/network.test.ts b/test/unit/commands/network.test.ts index 531b9af11..8962d634f 100644 --- a/test/unit/commands/network.test.ts +++ b/test/unit/commands/network.test.ts @@ -35,11 +35,7 @@ import path from 'path'; import {NetworkCommand} from '../../../src/commands/network.js'; import {LeaseManager} from '../../../src/core/lease/lease_manager.js'; import {IntervalLeaseRenewalService} from '../../../src/core/lease/interval_lease_renewal.js'; -import chalk from 'chalk'; -import {RemoteConfigValidator} from '../../../src/core/config/remote/remote_config_validator.js'; import {RemoteConfigManager} from '../../../src/core/config/remote/remote_config_manager.js'; -import {LocalConfig} from '../../../src/core/config/local_config.js'; -import * as k8s from '@kubernetes/client-node'; import {K8} from '../../../src/core/k8.js'; import {ProfileManager} from '../../../src/core/profile_manager.js'; import {KeyManager} from '../../../src/core/key_manager.js'; @@ -84,12 +80,16 @@ describe('NetworkCommand unit tests', () => { opts.configManager = new ConfigManager(testLogger); opts.configManager.update(argv); - opts.k8 = new K8(opts.configManager, testLogger); // inon.stub().returns(k8s.V1Lease); + opts.k8 = new K8(opts.configManager, testLogger); opts.k8.waitForPods = sinon.stub(); opts.keyManager = new KeyManager(testLogger); + opts.keyManager.copyGossipKeysToStaging = sinon.stub(); + opts.keyManager.copyNodeKeysToStaging = sinon.stub(); opts.platformInstaller = sinon.stub(); opts.platformInstaller.copyNodeKeys = sinon.stub(); - opts.profileManager = new ProfileManager(testLogger, opts.configManager); //sinon.stub(); + + opts.profileManager = new ProfileManager(testLogger, opts.configManager); + opts.profileManager.prepareValuesForSoloChart = sinon.stub(); opts.certificateManager = sinon.stub(); opts.chartManager = new ChartManager(opts.helm, opts.logger); From cea313eb28357a4ef98d72fd258f9de0b059b4c0 Mon Sep 17 00:00:00 2001 From: Jeffrey Tang Date: Wed, 11 Dec 2024 20:14:16 -0600 Subject: [PATCH 09/10] Save Signed-off-by: Jeffrey Tang --- test/unit/commands/network.test.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/test/unit/commands/network.test.ts b/test/unit/commands/network.test.ts index 8962d634f..71b2549d6 100644 --- a/test/unit/commands/network.test.ts +++ b/test/unit/commands/network.test.ts @@ -36,10 +36,10 @@ import {NetworkCommand} from '../../../src/commands/network.js'; import {LeaseManager} from '../../../src/core/lease/lease_manager.js'; import {IntervalLeaseRenewalService} from '../../../src/core/lease/interval_lease_renewal.js'; import {RemoteConfigManager} from '../../../src/core/config/remote/remote_config_manager.js'; -import {K8} from '../../../src/core/k8.js'; import {ProfileManager} from '../../../src/core/profile_manager.js'; import {KeyManager} from '../../../src/core/key_manager.js'; import {ROOT_DIR} from '../../../src/core/constants.js'; +import {ListrLease} from '../../../src/core/lease/listr_lease.js'; const getBaseCommandOpts = () => ({ logger: sinon.stub(), @@ -80,8 +80,17 @@ describe('NetworkCommand unit tests', () => { opts.configManager = new ConfigManager(testLogger); opts.configManager.update(argv); - opts.k8 = new K8(opts.configManager, testLogger); + opts.k8 = sinon.stub(); + opts.k8.hasNamespace = sinon.stub().returns(true); + opts.k8.getNamespacedConfigMap = sinon.stub().returns(null); + opts.k8.waitForPodReady = sinon.stub(); opts.k8.waitForPods = sinon.stub(); + opts.k8.readNamespacedLease = sinon.stub(); + + ListrLease.newAcquireLeaseTask = sinon.stub().returns({ + run: sinon.stub().returns({}), + }); + opts.keyManager = new KeyManager(testLogger); opts.keyManager.copyGossipKeysToStaging = sinon.stub(); opts.keyManager.copyNodeKeysToStaging = sinon.stub(); From 300a60027323262d991e49980b3a8dd65aaa0ed4 Mon Sep 17 00:00:00 2001 From: Jeffrey Tang Date: Thu, 12 Dec 2024 11:18:00 -0600 Subject: [PATCH 10/10] Avoid failing on windows due to different separator Signed-off-by: Jeffrey Tang --- src/commands/base.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/commands/base.ts b/src/commands/base.ts index ee3e60650..2b26a13ef 100644 --- a/src/commands/base.ts +++ b/src/commands/base.ts @@ -30,6 +30,7 @@ import {type Opts} from '../types/command_types.js'; import {type CommandFlag} from '../types/flag_types.js'; import {type Lease} from '../core/lease/lease.js'; import {Listr} from 'listr2'; +import path from 'path'; export interface CommandHandlers { parent: BaseCommand; @@ -74,7 +75,7 @@ export abstract class BaseCommand extends ShellRunner { if (!chartReleaseName) throw new MissingArgumentError('chart release name is required'); if (chartDir) { - const chartPath = `${chartDir}/${chartReleaseName}`; + const chartPath = path.join(chartDir, chartReleaseName); await this.helm.dependency('update', chartPath); return chartPath; }