diff --git a/core/lib/common/worker.js b/core/lib/common/worker.js index 83ccd53d1..8576f1961 100644 --- a/core/lib/common/worker.js +++ b/core/lib/common/worker.js @@ -79,6 +79,7 @@ module.exports = class Worker { url, username, sshKey, + sshConfig = {} ) { this.deviceType = deviceType; this.url = url; @@ -87,8 +88,8 @@ module.exports = class Worker { this.sshKey = sshKey; this.dutSshKey = `/tmp/id`; this.logger = logger; - this.workerHost = new URL(this.url).hostname; - this.workerPort = '22222'; + this.workerHost = sshConfig.host || 'ssh.balena-devices.com' + this.workerPort = sshConfig.port || 22; this.workerUser = 'root'; this.sshPrefix = ''; this.uuid = ''; @@ -96,16 +97,13 @@ module.exports = class Worker { this.url.includes(`worker`) || this.url.includes('unix:') ); - if (this.url.includes(`balena-devices.com`)) { - // worker is a testbot connected to balena cloud - we ssh into it via the vpn + if(!this.directConnect){ this.uuid = this.url.match( - /(?<=https:\/\/)(.*)(?=.balena-devices.com)/, + /https:\/\/([^\.]+)\./, )[1]; - this.workerHost = `ssh.balena-devices.com`; - this.workerUser = this.username; - this.workerPort = '22'; this.sshPrefix = `host ${this.uuid} `; - } + this.workerUser = this.username; + } } /** @@ -331,10 +329,12 @@ module.exports = class Worker { }; } else { config = { - host: 'ssh.balena-devices.com', - port: '22', + host: this.workerHost, + port: this.workerPort, username: this.username, }; + console.log('local ssh attempt') + console.log(config) command = `host ${target} ${command}`; } diff --git a/core/lib/components/balena/sdk.js b/core/lib/components/balena/sdk.js index 5f8332146..274538843 100644 --- a/core/lib/components/balena/sdk.js +++ b/core/lib/components/balena/sdk.js @@ -65,12 +65,18 @@ module.exports = class BalenaSDK { constructor( apiUrl, logger = { log: console.log, status: console.log, info: console.log }, + sshConfig = {} ) { this.balena = getSdk({ apiUrl: `https://api.${apiUrl}`, }); + this.apiUrl = apiUrl this.pine = this.balena.pine; this.logger = logger; + this.sshConfig = { + host: sshConfig.host || 'ssh.balena-devices.com', + port: sshConfig.port || 22 + } } /** @@ -91,7 +97,6 @@ module.exports = class BalenaSDK { tries: 600, }, ) { - const sshPort = 22; return retry( async () => { @@ -102,9 +107,9 @@ module.exports = class BalenaSDK { const result = await utils.executeCommandOverSSH( `host -s ${device} source /etc/profile ; ${command}`, { - host: `ssh.${await this.balena.settings.get('proxyUrl')}`, + host: this.sshConfig.host, username: await this.balena.auth.whoami(), - port: sshPort, + port: this.sshConfig.port, }, ); @@ -126,7 +131,7 @@ module.exports = class BalenaSDK { /** * Creates application for a devicetype with the required config - * + * * @param {string} name Name of the application that needs to be created * @param {string} deviceType The device type for which application needs to be created * @param {object} config specify configuration needed for the application @@ -157,9 +162,9 @@ module.exports = class BalenaSDK { /** * Removes SSH key from balenaCloud account - * - * @param {string} label SSH key label - * + * + * @param {string} label SSH key label + * * @category helper */ async removeSSHKey(label) { @@ -336,7 +341,11 @@ module.exports = class BalenaSDK { */ async fetchOS(versionOrRange = 'latest', deviceType, osType = 'default') { // normalize the version string/range, supports 'latest', 'recommended', etc - let version = await this.balena.models.os.getMaxSatisfyingVersion( + const balenaSdkProd = getSdk({ + apiUrl: "https://api.balena-cloud.com", + }); + + let version = await balenaSdkProd.models.os.getMaxSatisfyingVersion( deviceType, versionOrRange, osType, @@ -352,15 +361,15 @@ module.exports = class BalenaSDK { ); // Caching implementation if needed - Check https://github.com/balena-os/leviathan/issues/441 - let attempt = 0; const downloadLatestOS = async () => { attempt++; this.logger.log( `Fetching balenaOS version ${version}, attempt ${attempt}...`, ); + return await new Promise(async (resolve, reject) => { - await this.balena.models.os.download( + await balenaSdkProd.models.os.download( deviceType, version, function (error, stream) { diff --git a/suites/e2e/suite.js b/suites/e2e/suite.js index 5dcd46647..8f60cafe1 100644 --- a/suites/e2e/suite.js +++ b/suites/e2e/suite.js @@ -75,7 +75,7 @@ module.exports = { utils: this.require('common/utils'), sshKeyPath: join(homedir(), 'id'), sshKeyLabel: this.suite.options.id, - sdk: new Balena(this.suite.options.balena.apiUrl, this.getLogger()), + sdk: new Balena(this.suite.options.balena.apiUrl, this.getLogger(), this.suite.options.config.sshConfig), link: `${this.suite.options.balenaOS.config.uuid.slice(0, 7)}.local`, worker: new Worker( this.suite.deviceType.slug, @@ -83,6 +83,7 @@ module.exports = { this.suite.options.workerUrl, this.suite.options.balena.organization, join(homedir(), 'id'), + this.suite.options.config.sshConfig ), });