Skip to content

Commit 16e2ded

Browse files
committed
pushing current code
Signed-off-by: Jeromy Cannon <[email protected]>
1 parent 0690cff commit 16e2ded

File tree

8 files changed

+86
-40
lines changed

8 files changed

+86
-40
lines changed

src/core/k8.mjs

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -394,27 +394,33 @@ export class K8 {
394394
const parentDir = path.dirname(destPath)
395395
const fileName = path.basename(destPath)
396396
const filterMap = new Map(Object.entries(filters))
397-
const entries = await this.listDir(podName, containerName, parentDir)
398-
399-
for (const item of entries) {
400-
if (item.name === fileName && !item.directory) {
401-
let found = true
402-
403-
for (const entry of filterMap.entries()) {
404-
const field = entry[0]
405-
const value = entry[1]
406-
this.logger.debug(`Checking file ${podName}:${containerName} ${destPath}; ${field} expected ${value}, found ${item[field]}`, { filters })
407-
if (`${value}` !== `${item[field]}`) {
408-
found = false
409-
break
397+
398+
try {
399+
const entries = await this.listDir(podName, containerName, parentDir)
400+
401+
for (const item of entries) {
402+
if (item.name === fileName && !item.directory) {
403+
let found = true
404+
405+
for (const entry of filterMap.entries()) {
406+
const field = entry[0]
407+
const value = entry[1]
408+
this.logger.debug(`Checking file ${podName}:${containerName} ${destPath}; ${field} expected ${value}, found ${item[field]}`, { filters })
409+
if (`${value}` !== `${item[field]}`) {
410+
found = false
411+
break
412+
}
410413
}
411-
}
412414

413-
if (found) {
414-
this.logger.debug(`File check succeeded ${podName}:${containerName} ${destPath}`, { filters })
415-
return true
415+
if (found) {
416+
this.logger.debug(`File check succeeded ${podName}:${containerName} ${destPath}`, { filters })
417+
return true
418+
}
416419
}
417420
}
421+
} catch (e) {
422+
this.logger.error(e.message, e)
423+
throw e
418424
}
419425

420426
return false

src/core/platform_installer.mjs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,25 @@ import * as semver from 'semver'
2222
import { FullstackTestingError, IllegalArgumentError, MissingArgumentError } from './errors.mjs'
2323
import { constants } from './index.mjs'
2424
import { Templates } from './templates.mjs'
25+
import { flags } from '../commands/index.mjs'
2526

2627
/**
2728
* PlatformInstaller install platform code in the root-container of a network pod
2829
*/
2930
export class PlatformInstaller {
30-
constructor (logger, k8) {
31+
constructor (logger, k8, configManager) {
3132
if (!logger) throw new MissingArgumentError('an instance of core/Logger is required')
3233
if (!k8) throw new MissingArgumentError('an instance of core/K8 is required')
3334

3435
this.logger = logger
3536
this.k8 = k8
37+
this.configManager = configManager
38+
}
39+
40+
_getNamespace () {
41+
const ns = this.configManager.getFlag(flags.namespace)
42+
if (!ns) throw new MissingArgumentError('namespace is not set')
43+
return ns
3644
}
3745

3846
async validatePlatformReleaseDir (releaseDir) {
@@ -290,14 +298,11 @@ export class PlatformInstaller {
290298
let nodeSeq = 0
291299
let accountIdSeq = parseInt(startAccountId.num.toString(), 10)
292300
for (const nodeId of nodeIDs) {
293-
const podName = Templates.renderNetworkPodName(nodeId)
294-
const svcName = Templates.renderNetworkSvcName(nodeId)
295-
296301
const nodeName = nodeId
297302
const nodeNickName = nodeId
298303

299-
const internalIP = await self.k8.getPodIP(podName)
300-
const externalIP = await self.k8.getClusterIP(svcName)
304+
const internalIP = Templates.renderFullyQualifiedNetworkPodName(this._getNamespace(), nodeId)
305+
const externalIP = Templates.renderFullyQualifiedNetworkSvcName(this._getNamespace(), nodeId)
301306

302307
const account = `${accountIdPrefix}.${accountIdSeq}`
303308
if (releaseVersion.minor >= 40) {

src/core/templates.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,12 @@ export class Templates {
163163
throw new FullstackTestingError(`unknown dep: ${dep}`)
164164
}
165165
}
166+
167+
static renderFullyQualifiedNetworkPodName (namespace, nodeId) {
168+
return `${Templates.renderNetworkPodName(nodeId)}.network-${nodeId}.${namespace}.svc.cluster.local`
169+
}
170+
171+
static renderFullyQualifiedNetworkSvcName (namespace, nodeId) {
172+
return `${Templates.renderNetworkSvcName(nodeId)}.${namespace}.svc.cluster.local`
173+
}
166174
}

src/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export function main (argv) {
5151
const chartManager = new ChartManager(helm, logger)
5252
const configManager = new ConfigManager(logger)
5353
const k8 = new K8(configManager, logger)
54-
const platformInstaller = new PlatformInstaller(logger, k8)
54+
const platformInstaller = new PlatformInstaller(logger, k8, configManager)
5555
const keyManager = new KeyManager(logger)
5656
const accountManager = new AccountManager(logger, k8)
5757

test/e2e/commands/node.test.mjs

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ import {
2828
import {
2929
bootstrapNetwork,
3030
getDefaultArgv,
31+
getTestConfigManager,
3132
TEST_CLUSTER
3233
} from '../../test_util.js'
3334

3435
describe.each([
35-
{ releaseTag: 'v0.47.0-alpha.0', keyFormat: constants.KEY_FORMAT_PFX, testName: 'node-cmd-e2e-pfx' },
36+
// { releaseTag: 'v0.47.0-alpha.0', keyFormat: constants.KEY_FORMAT_PFX, testName: 'node-cmd-e2e-pfx' },
3637
{ releaseTag: 'v0.47.0-alpha.0', keyFormat: constants.KEY_FORMAT_PEM, testName: 'node-cmd-e2e-pem' }
3738
])('NodeCommand', (input) => {
3839
const testName = input.testName
@@ -51,11 +52,11 @@ describe.each([
5152
const nodeCmd = bootstrapResp.cmd.nodeCmd
5253

5354
afterAll(async () => {
54-
await k8.deleteNamespace(namespace)
55+
// await k8.deleteNamespace(namespace) // TODO renable this line
5556
await accountManager.close()
5657
})
5758

58-
describe(`Node should start successfully [release ${input.keyFormat}, keyFormat: ${input.releaseTag}]`, () => {
59+
describe(`Node should start successfully [release ${input.releaseTag}, keyFormat: ${input.keyFormat}]`, () => {
5960
it('Balance query should succeed', async () => {
6061
expect.assertions(2)
6162

@@ -102,7 +103,7 @@ describe.each([
102103
expect.assertions(1)
103104

104105
try {
105-
await expect(nodeCmd.checkNetworkNodeProxyUp('node0', 30313)).resolves.toBeTruthy()
106+
await expect(nodeCmd.checkNetworkNodeProxyUp('node0', 30399)).resolves.toBeTruthy()
106107
} catch (e) {
107108
nodeCmd.logger.showUserError(e)
108109
expect(e).toBeNull()
@@ -112,10 +113,14 @@ describe.each([
112113
}, 20000)
113114
})
114115

115-
describe(`Node should refresh successfully [release ${input.keyFormat}, keyFormat: ${input.releaseTag}]`, () => {
116+
describe(`Node should refresh successfully [release ${input.releaseTag}, keyFormat: ${input.keyFormat}]`, () => {
116117
let podName = ''
117118
beforeAll(async () => {
118-
const podArray = await k8.getPodsByLabel(['app=haproxy-node0', 'fullstack.hedera.com/type=haproxy'])
119+
argv[flags.nodeIDs.name] = 'node0'
120+
const configManager = getTestConfigManager(`${testName}-solo.config`)
121+
configManager.update(argv, true)
122+
123+
const podArray = await k8.getPodsByLabel(['app=network-node0', 'fullstack.hedera.com/type=network-node'])
119124

120125
if (podArray.length > 0) {
121126
podName = podArray[0].metadata.name
@@ -124,15 +129,37 @@ describe.each([
124129
} else {
125130
throw new Error('pod for node0 not found')
126131
}
127-
})
132+
}, 20000)
133+
134+
it('Node0 should be running', async () => {
135+
expect(podName).toContain('node0')
136+
try {
137+
await expect(nodeCmd.checkNetworkNodePod(namespace, 'node0')).resolves.toBeTruthy()
138+
} catch (e) {
139+
nodeCmd.logger.showUserError(e)
140+
expect(e).toBeNull()
141+
} finally {
142+
await nodeCmd.close()
143+
}
144+
}, 20000)
128145

129-
it('Node 0 should not be running', async () => {
146+
it('Node0 should not be ACTIVE', async () => {
147+
expect(3)
130148
expect(podName).toContain('node0')
131-
const podArray = await this.k8.getPodsByLabel(['app=haproxy-node0', 'fullstack.hedera.com/type=haproxy'])
132-
console.log(podArray)
133-
})
134-
it('Node refresh should succeed', async () => {
135-
})
149+
try {
150+
await expect(nodeCmd.stop(argv)).resolves.toBeTruthy()
151+
await expect(nodeCmd.checkNetworkNodeStarted('node0', 5)).rejects.toThrowError()
152+
} catch (e) {
153+
nodeCmd.logger.showUserError(e)
154+
expect(e).not.toBeNull()
155+
} finally {
156+
await nodeCmd.close()
157+
}
158+
}, 20000)
159+
160+
it('Node0 refresh should succeed', async () => {
161+
await expect(nodeCmd.refresh(argv)).resolves.toBeTruthy()
162+
}, 1200000)
136163
// TODO need to test with PVCs
137164
// TODO will have changes when configMap/secrets are implemented
138165
})

test/e2e/core/platform_installer_e2e.test.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { getTestCacheDir, getTmpDir, testLogger } from '../../test_util.js'
2929
describe('PackageInstallerE2E', () => {
3030
const configManager = new ConfigManager(testLogger)
3131
const k8 = new K8(configManager, testLogger)
32-
const installer = new PlatformInstaller(testLogger, k8)
32+
const installer = new PlatformInstaller(testLogger, k8, configManager)
3333
const testCacheDir = getTestCacheDir()
3434
const podName = 'network-node0-0'
3535
const packageVersion = 'v0.42.5'

test/test_util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export function bootstrapTestVariables (testName, argv,
113113
const helm = new Helm(testLogger)
114114
const chartManager = new ChartManager(helm, testLogger)
115115
const k8 = k8Arg || new K8(configManager, testLogger)
116-
const platformInstaller = new PlatformInstaller(testLogger, k8)
116+
const platformInstaller = new PlatformInstaller(testLogger, k8, configManager)
117117
const accountManager = new AccountManager(testLogger, k8, constants)
118118
const opts = {
119119
logger: testLogger,

test/unit/core/platform_installer.test.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('PackageInstaller', () => {
2828
const testLogger = core.logging.NewLogger('debug')
2929
const configManager = new ConfigManager(testLogger)
3030
const k8 = new core.K8(configManager, testLogger)
31-
const installer = new PlatformInstaller(testLogger, k8)
31+
const installer = new PlatformInstaller(testLogger, k8, configManager)
3232

3333
describe('validatePlatformReleaseDir', () => {
3434
it('should fail for missing path', async () => {

0 commit comments

Comments
 (0)