From c1017e8e27e4b4227de5f47ec0cb7a890262f663 Mon Sep 17 00:00:00 2001 From: Thodoris Greasidis Date: Wed, 5 Apr 2023 09:23:00 +0300 Subject: [PATCH] Add support for device restarts in open-balena Update balena-sdk from 16.28.2 to 16.40.0 Change-type: minor --- npm-shrinkwrap.json | 58 ++++++++++++++++++++++----------- package.json | 4 +-- tests/commands/env/envs.spec.ts | 47 +++++++++++++------------- tests/nock/balena-api-mock.ts | 9 ++++- 4 files changed, 74 insertions(+), 44 deletions(-) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 3e697f69..37b92aa3 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -3921,9 +3921,9 @@ } }, "balena-errors": { - "version": "4.7.1", - "resolved": "https://registry.npmjs.org/balena-errors/-/balena-errors-4.7.1.tgz", - "integrity": "sha512-g21kf6N5tMZYDietZNLHCbqhmAxPX9gRmJQgMuIjMZWvjzCQxcqaELNYTtDwXwEbXLhbhF6QV2IJDZul+5X6nQ==", + "version": "4.7.3", + "resolved": "https://registry.npmjs.org/balena-errors/-/balena-errors-4.7.3.tgz", + "integrity": "sha512-9PvKEtPUsoDm6qVGtb6ikdVc3yd3t82TJBIC4foQSnyHCCCAj18BBVIYfq+zkPw4kdhPOULgPyBpxQb4J2fIuQ==", "requires": { "tslib": "^2.0.0", "typed-error": "^3.0.0" @@ -4116,40 +4116,30 @@ "progress-stream": "^2.0.0", "qs": "^6.9.4", "tslib": "^2.0.0" - }, - "dependencies": { - "balena-errors": { - "version": "4.7.3", - "resolved": "https://registry.npmjs.org/balena-errors/-/balena-errors-4.7.3.tgz", - "integrity": "sha512-9PvKEtPUsoDm6qVGtb6ikdVc3yd3t82TJBIC4foQSnyHCCCAj18BBVIYfq+zkPw4kdhPOULgPyBpxQb4J2fIuQ==", - "requires": { - "tslib": "^2.0.0", - "typed-error": "^3.0.0" - } - } } }, "balena-sdk": { - "version": "16.28.2", - "resolved": "https://registry.npmjs.org/balena-sdk/-/balena-sdk-16.28.2.tgz", - "integrity": "sha512-C7jxSd7TzMMX/+69egj1fkI7tZ62/TBYVIg8j0dR2VyqdQeJVa0IIB1LxJmXbscKmvWtpZUgvxmE0C6phEsWEA==", + "version": "16.40.0", + "resolved": "https://registry.npmjs.org/balena-sdk/-/balena-sdk-16.40.0.tgz", + "integrity": "sha512-w7oP/oESZnymWtngieQrR3YJAR+CLSnys5RllPZBtZ5vYZsSHdrdRRMamlemy5ydCQN4q66Uw95U20bBXigT5g==", "requires": { "@balena/es-version": "^1.0.0", "@types/json-schema": "^7.0.9", "@types/node": "^12.20.50", "abortcontroller-polyfill": "^1.7.1", "balena-auth": "^4.1.0", - "balena-errors": "^4.7.1", + "balena-errors": "^4.7.3", "balena-hup-action-utils": "~4.1.0", "balena-register-device": "^8.0.0", "balena-request": "^11.5.5", "balena-semver": "^2.3.0", "balena-settings-client": "^4.0.6", "date-fns": "^2.29.3", + "handlebars": "^4.7.7", "lodash": "^4.17.21", "memoizee": "^0.4.15", "ndjson": "^2.0.0", - "pinejs-client-core": "^6.9.6", + "pinejs-client-core": "^6.12.0", "tslib": "^2.1.0" }, "dependencies": { @@ -8510,6 +8500,25 @@ "crc32-stream": "^4.0.0" } }, + "handlebars": { + "version": "4.7.7", + "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.7.tgz", + "integrity": "sha512-aAcXm5OAfE/8IXkcZvCepKU3VzW1/39Fb5ZuqMtgI/hT8X2YgoMvBY5dLhq/cpOvw7Lk1nK/UF71aLG/ZnVYRA==", + "requires": { + "minimist": "^1.2.5", + "neo-async": "^2.6.0", + "source-map": "^0.6.1", + "uglify-js": "^3.1.4", + "wordwrap": "^1.0.0" + }, + "dependencies": { + "wordwrap": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz", + "integrity": "sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q==" + } + } + }, "har-schema": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz", @@ -11670,6 +11679,11 @@ "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz", "integrity": "sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw==" }, + "neo-async": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.2.tgz", + "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==" + }, "nested-error-stacks": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/nested-error-stacks/-/nested-error-stacks-1.0.2.tgz", @@ -16821,6 +16835,12 @@ "integrity": "sha512-wVORMBGO/FAs/++blGNeAVdbNKtIh1rbBL2EyQ1+J9lClJ93KiiKe8PmFIVdXhHcyv44SL9oglmfeSsndo0jRw==", "dev": true }, + "uglify-js": { + "version": "3.17.4", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.17.4.tgz", + "integrity": "sha512-T9q82TJI9e/C1TAxYvfb16xO120tMVFZrGA3f9/P4424DNu6ypK103y0GPFVa17yotwSyZW5iYXgjYHkGrJW/g==", + "optional": true + }, "unbox-primitive": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.1.tgz", diff --git a/package.json b/package.json index 65cacb36..68ffbaf4 100644 --- a/package.json +++ b/package.json @@ -203,11 +203,11 @@ "JSONStream": "^1.0.3", "balena-config-json": "^4.2.0", "balena-device-init": "^6.0.0", - "balena-errors": "^4.7.1", + "balena-errors": "^4.7.3", "balena-image-fs": "^7.0.6", "balena-image-manager": "^8.0.0", "balena-preload": "^13.0.0", - "balena-sdk": "^16.28.2", + "balena-sdk": "^16.40.0", "balena-semver": "^2.3.0", "balena-settings-client": "^4.0.7", "balena-settings-storage": "^7.0.0", diff --git a/tests/commands/env/envs.spec.ts b/tests/commands/env/envs.spec.ts index 6bbef43a..eb9846d7 100644 --- a/tests/commands/env/envs.spec.ts +++ b/tests/commands/env/envs.spec.ts @@ -138,6 +138,7 @@ describe('balena envs', function () { }); it('should successfully list env variables for a test device', async () => { + api.expectGetDevice({ shortUUID, fullUUID }); api.expectGetDevice({ fullUUID }); api.expectGetDeviceEnvVars(); api.expectGetApplication(); @@ -145,20 +146,19 @@ describe('balena envs', function () { api.expectGetAppServiceVars(); api.expectGetDeviceServiceVars(); - const uuid = shortUUID; - const result = await runCommand(`envs -d ${uuid}`); + const result = await runCommand(`envs -d ${shortUUID}`); let { out } = result; let expected = stripIndent` ID NAME VALUE FLEET DEVICE SERVICE 120110 svar1 svar1-value org/test * service1 120111 svar2 svar2-value org/test * service2 - 120120 svar3 svar3-value org/test ${uuid} service1 - 120121 svar4 svar4-value org/test ${uuid} service2 + 120120 svar3 svar3-value org/test ${shortUUID} service1 + 120121 svar4 svar4-value org/test ${shortUUID} service2 120101 var1 var1-val org/test * * 120102 var2 22 org/test * * - 120203 var3 var3-val org/test ${uuid} * - 120204 var4 44 org/test ${uuid} * + 120203 var3 var3-val org/test ${shortUUID} * + 120204 var4 44 org/test ${shortUUID} * ` + '\n'; out = out.map((l) => l.replace(/ +/g, ' ')); @@ -168,6 +168,7 @@ describe('balena envs', function () { }); it('should successfully list env variables for a test device (JSON output)', async () => { + api.expectGetDevice({ shortUUID, fullUUID }); api.expectGetDevice({ fullUUID }); api.expectGetDeviceEnvVars(); api.expectGetApplication(); @@ -192,6 +193,7 @@ describe('balena envs', function () { }); it('should successfully list config variables for a test device', async () => { + api.expectGetDevice({ shortUUID, fullUUID }); api.expectGetDevice({ fullUUID }); api.expectGetDeviceConfigVars(); api.expectGetApplication(); @@ -216,24 +218,24 @@ describe('balena envs', function () { const serviceName = 'service2'; api.expectGetService({ serviceName }); api.expectGetApplication(); + api.expectGetDevice({ shortUUID, fullUUID }); api.expectGetDevice({ fullUUID }); api.expectGetDeviceServiceVars(); api.expectGetAppEnvVars(); api.expectGetAppServiceVars(); api.expectGetDeviceEnvVars(); - const uuid = shortUUID; - const result = await runCommand(`envs -d ${uuid} -s ${serviceName}`); + const result = await runCommand(`envs -d ${shortUUID} -s ${serviceName}`); let { out } = result; let expected = stripIndent` ID NAME VALUE FLEET DEVICE SERVICE 120111 svar2 svar2-value org/test * service2 - 120121 svar4 svar4-value org/test ${uuid} service2 + 120121 svar4 svar4-value org/test ${shortUUID} service2 120101 var1 var1-val org/test * * 120102 var2 22 org/test * * - 120203 var3 var3-val org/test ${uuid} * - 120204 var4 44 org/test ${uuid} * + 120203 var3 var3-val org/test ${shortUUID} * + 120204 var4 44 org/test ${shortUUID} * ` + '\n'; out = out.map((l) => l.replace(/ +/g, ' ')); @@ -243,20 +245,20 @@ describe('balena envs', function () { }); it('should successfully list env and service variables for a test device (unknown fleet)', async () => { + api.expectGetDevice({ shortUUID, fullUUID, inaccessibleApp: true }); api.expectGetDevice({ fullUUID, inaccessibleApp: true }); api.expectGetDeviceEnvVars(); api.expectGetDeviceServiceVars(); - const uuid = shortUUID; - const result = await runCommand(`envs -d ${uuid}`); + const result = await runCommand(`envs -d ${shortUUID}`); let { out } = result; let expected = stripIndent` ID NAME VALUE FLEET DEVICE SERVICE - 120120 svar3 svar3-value N/A ${uuid} service1 - 120121 svar4 svar4-value N/A ${uuid} service2 - 120203 var3 var3-val N/A ${uuid} * - 120204 var4 44 N/A ${uuid} * + 120120 svar3 svar3-value N/A ${shortUUID} service1 + 120121 svar4 svar4-value N/A ${shortUUID} service2 + 120203 var3 var3-val N/A ${shortUUID} * + 120204 var4 44 N/A ${shortUUID} * ` + '\n'; out = out.map((l) => l.replace(/ +/g, ' ')); @@ -271,22 +273,22 @@ describe('balena envs', function () { api.expectGetApplication(); api.expectGetAppEnvVars(); api.expectGetAppServiceVars(); + api.expectGetDevice({ shortUUID, fullUUID }); api.expectGetDevice({ fullUUID }); api.expectGetDeviceEnvVars(); api.expectGetDeviceServiceVars(); - const uuid = shortUUID; - const result = await runCommand(`envs -d ${uuid} -s ${serviceName}`); + const result = await runCommand(`envs -d ${shortUUID} -s ${serviceName}`); let { out } = result; let expected = stripIndent` ID NAME VALUE FLEET DEVICE SERVICE 120110 svar1 svar1-value org/test * ${serviceName} - 120120 svar3 svar3-value org/test ${uuid} ${serviceName} + 120120 svar3 svar3-value org/test ${shortUUID} ${serviceName} 120101 var1 var1-val org/test * * 120102 var2 22 org/test * * - 120203 var3 var3-val org/test ${uuid} * - 120204 var4 44 org/test ${uuid} * + 120203 var3 var3-val org/test ${shortUUID} * + 120204 var4 44 org/test ${shortUUID} * ` + '\n'; out = out.map((l) => l.replace(/ +/g, ' ')); @@ -301,6 +303,7 @@ describe('balena envs', function () { api.expectGetApplication(); api.expectGetAppEnvVars(); api.expectGetAppServiceVars(); + api.expectGetDevice({ shortUUID, fullUUID }); api.expectGetDevice({ fullUUID }); api.expectGetDeviceEnvVars(); api.expectGetDeviceServiceVars(); diff --git a/tests/nock/balena-api-mock.ts b/tests/nock/balena-api-mock.ts index 901ef8ef..bd1fd06c 100644 --- a/tests/nock/balena-api-mock.ts +++ b/tests/nock/balena-api-mock.ts @@ -212,13 +212,20 @@ export class BalenaAPIMock extends NockMock { public expectGetDevice(opts: { fullUUID: string; + shortUUID?: string; inaccessibleApp?: boolean; isOnline?: boolean; optional?: boolean; persist?: boolean; }) { const id = 7654321; - this.optGet(/^\/v\d+\/device($|\?)/, opts).reply(200, { + const providedUuid = opts.shortUUID ?? opts.fullUUID; + this.optGet( + providedUuid.length !== 32 + ? /^\/v\d+\/device($|\?)/ + : /^\/v\d+\/device\(uuid=%27[0-9a-f]{32}%27\)/, + opts, + ).reply(200, { d: [ { id,