Add support for device restarts in open-balena

Update balena-sdk from 16.28.2 to 16.40.0

Change-type: minor
This commit is contained in:
Thodoris Greasidis 2023-04-05 09:23:00 +03:00
parent 7ad9e685f6
commit c1017e8e27
4 changed files with 74 additions and 44 deletions

58
npm-shrinkwrap.json generated
View File

@ -3921,9 +3921,9 @@
} }
}, },
"balena-errors": { "balena-errors": {
"version": "4.7.1", "version": "4.7.3",
"resolved": "https://registry.npmjs.org/balena-errors/-/balena-errors-4.7.1.tgz", "resolved": "https://registry.npmjs.org/balena-errors/-/balena-errors-4.7.3.tgz",
"integrity": "sha512-g21kf6N5tMZYDietZNLHCbqhmAxPX9gRmJQgMuIjMZWvjzCQxcqaELNYTtDwXwEbXLhbhF6QV2IJDZul+5X6nQ==", "integrity": "sha512-9PvKEtPUsoDm6qVGtb6ikdVc3yd3t82TJBIC4foQSnyHCCCAj18BBVIYfq+zkPw4kdhPOULgPyBpxQb4J2fIuQ==",
"requires": { "requires": {
"tslib": "^2.0.0", "tslib": "^2.0.0",
"typed-error": "^3.0.0" "typed-error": "^3.0.0"
@ -4116,40 +4116,30 @@
"progress-stream": "^2.0.0", "progress-stream": "^2.0.0",
"qs": "^6.9.4", "qs": "^6.9.4",
"tslib": "^2.0.0" "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": { "balena-sdk": {
"version": "16.28.2", "version": "16.40.0",
"resolved": "https://registry.npmjs.org/balena-sdk/-/balena-sdk-16.28.2.tgz", "resolved": "https://registry.npmjs.org/balena-sdk/-/balena-sdk-16.40.0.tgz",
"integrity": "sha512-C7jxSd7TzMMX/+69egj1fkI7tZ62/TBYVIg8j0dR2VyqdQeJVa0IIB1LxJmXbscKmvWtpZUgvxmE0C6phEsWEA==", "integrity": "sha512-w7oP/oESZnymWtngieQrR3YJAR+CLSnys5RllPZBtZ5vYZsSHdrdRRMamlemy5ydCQN4q66Uw95U20bBXigT5g==",
"requires": { "requires": {
"@balena/es-version": "^1.0.0", "@balena/es-version": "^1.0.0",
"@types/json-schema": "^7.0.9", "@types/json-schema": "^7.0.9",
"@types/node": "^12.20.50", "@types/node": "^12.20.50",
"abortcontroller-polyfill": "^1.7.1", "abortcontroller-polyfill": "^1.7.1",
"balena-auth": "^4.1.0", "balena-auth": "^4.1.0",
"balena-errors": "^4.7.1", "balena-errors": "^4.7.3",
"balena-hup-action-utils": "~4.1.0", "balena-hup-action-utils": "~4.1.0",
"balena-register-device": "^8.0.0", "balena-register-device": "^8.0.0",
"balena-request": "^11.5.5", "balena-request": "^11.5.5",
"balena-semver": "^2.3.0", "balena-semver": "^2.3.0",
"balena-settings-client": "^4.0.6", "balena-settings-client": "^4.0.6",
"date-fns": "^2.29.3", "date-fns": "^2.29.3",
"handlebars": "^4.7.7",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"memoizee": "^0.4.15", "memoizee": "^0.4.15",
"ndjson": "^2.0.0", "ndjson": "^2.0.0",
"pinejs-client-core": "^6.9.6", "pinejs-client-core": "^6.12.0",
"tslib": "^2.1.0" "tslib": "^2.1.0"
}, },
"dependencies": { "dependencies": {
@ -8510,6 +8500,25 @@
"crc32-stream": "^4.0.0" "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": { "har-schema": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz", "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", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz",
"integrity": "sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw==" "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": { "nested-error-stacks": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/nested-error-stacks/-/nested-error-stacks-1.0.2.tgz", "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==", "integrity": "sha512-wVORMBGO/FAs/++blGNeAVdbNKtIh1rbBL2EyQ1+J9lClJ93KiiKe8PmFIVdXhHcyv44SL9oglmfeSsndo0jRw==",
"dev": true "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": { "unbox-primitive": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.1.tgz", "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.1.tgz",

View File

@ -203,11 +203,11 @@
"JSONStream": "^1.0.3", "JSONStream": "^1.0.3",
"balena-config-json": "^4.2.0", "balena-config-json": "^4.2.0",
"balena-device-init": "^6.0.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-fs": "^7.0.6",
"balena-image-manager": "^8.0.0", "balena-image-manager": "^8.0.0",
"balena-preload": "^13.0.0", "balena-preload": "^13.0.0",
"balena-sdk": "^16.28.2", "balena-sdk": "^16.40.0",
"balena-semver": "^2.3.0", "balena-semver": "^2.3.0",
"balena-settings-client": "^4.0.7", "balena-settings-client": "^4.0.7",
"balena-settings-storage": "^7.0.0", "balena-settings-storage": "^7.0.0",

View File

@ -138,6 +138,7 @@ describe('balena envs', function () {
}); });
it('should successfully list env variables for a test device', async () => { it('should successfully list env variables for a test device', async () => {
api.expectGetDevice({ shortUUID, fullUUID });
api.expectGetDevice({ fullUUID }); api.expectGetDevice({ fullUUID });
api.expectGetDeviceEnvVars(); api.expectGetDeviceEnvVars();
api.expectGetApplication(); api.expectGetApplication();
@ -145,20 +146,19 @@ describe('balena envs', function () {
api.expectGetAppServiceVars(); api.expectGetAppServiceVars();
api.expectGetDeviceServiceVars(); api.expectGetDeviceServiceVars();
const uuid = shortUUID; const result = await runCommand(`envs -d ${shortUUID}`);
const result = await runCommand(`envs -d ${uuid}`);
let { out } = result; let { out } = result;
let expected = let expected =
stripIndent` stripIndent`
ID NAME VALUE FLEET DEVICE SERVICE ID NAME VALUE FLEET DEVICE SERVICE
120110 svar1 svar1-value org/test * service1 120110 svar1 svar1-value org/test * service1
120111 svar2 svar2-value org/test * service2 120111 svar2 svar2-value org/test * service2
120120 svar3 svar3-value org/test ${uuid} service1 120120 svar3 svar3-value org/test ${shortUUID} service1
120121 svar4 svar4-value org/test ${uuid} service2 120121 svar4 svar4-value org/test ${shortUUID} service2
120101 var1 var1-val org/test * * 120101 var1 var1-val org/test * *
120102 var2 22 org/test * * 120102 var2 22 org/test * *
120203 var3 var3-val org/test ${uuid} * 120203 var3 var3-val org/test ${shortUUID} *
120204 var4 44 org/test ${uuid} * 120204 var4 44 org/test ${shortUUID} *
` + '\n'; ` + '\n';
out = out.map((l) => l.replace(/ +/g, ' ')); 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 () => { it('should successfully list env variables for a test device (JSON output)', async () => {
api.expectGetDevice({ shortUUID, fullUUID });
api.expectGetDevice({ fullUUID }); api.expectGetDevice({ fullUUID });
api.expectGetDeviceEnvVars(); api.expectGetDeviceEnvVars();
api.expectGetApplication(); api.expectGetApplication();
@ -192,6 +193,7 @@ describe('balena envs', function () {
}); });
it('should successfully list config variables for a test device', async () => { it('should successfully list config variables for a test device', async () => {
api.expectGetDevice({ shortUUID, fullUUID });
api.expectGetDevice({ fullUUID }); api.expectGetDevice({ fullUUID });
api.expectGetDeviceConfigVars(); api.expectGetDeviceConfigVars();
api.expectGetApplication(); api.expectGetApplication();
@ -216,24 +218,24 @@ describe('balena envs', function () {
const serviceName = 'service2'; const serviceName = 'service2';
api.expectGetService({ serviceName }); api.expectGetService({ serviceName });
api.expectGetApplication(); api.expectGetApplication();
api.expectGetDevice({ shortUUID, fullUUID });
api.expectGetDevice({ fullUUID }); api.expectGetDevice({ fullUUID });
api.expectGetDeviceServiceVars(); api.expectGetDeviceServiceVars();
api.expectGetAppEnvVars(); api.expectGetAppEnvVars();
api.expectGetAppServiceVars(); api.expectGetAppServiceVars();
api.expectGetDeviceEnvVars(); api.expectGetDeviceEnvVars();
const uuid = shortUUID; const result = await runCommand(`envs -d ${shortUUID} -s ${serviceName}`);
const result = await runCommand(`envs -d ${uuid} -s ${serviceName}`);
let { out } = result; let { out } = result;
let expected = let expected =
stripIndent` stripIndent`
ID NAME VALUE FLEET DEVICE SERVICE ID NAME VALUE FLEET DEVICE SERVICE
120111 svar2 svar2-value org/test * service2 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 * * 120101 var1 var1-val org/test * *
120102 var2 22 org/test * * 120102 var2 22 org/test * *
120203 var3 var3-val org/test ${uuid} * 120203 var3 var3-val org/test ${shortUUID} *
120204 var4 44 org/test ${uuid} * 120204 var4 44 org/test ${shortUUID} *
` + '\n'; ` + '\n';
out = out.map((l) => l.replace(/ +/g, ' ')); 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 () => { 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.expectGetDevice({ fullUUID, inaccessibleApp: true });
api.expectGetDeviceEnvVars(); api.expectGetDeviceEnvVars();
api.expectGetDeviceServiceVars(); api.expectGetDeviceServiceVars();
const uuid = shortUUID; const result = await runCommand(`envs -d ${shortUUID}`);
const result = await runCommand(`envs -d ${uuid}`);
let { out } = result; let { out } = result;
let expected = let expected =
stripIndent` stripIndent`
ID NAME VALUE FLEET DEVICE SERVICE ID NAME VALUE FLEET DEVICE SERVICE
120120 svar3 svar3-value N/A ${uuid} service1 120120 svar3 svar3-value N/A ${shortUUID} service1
120121 svar4 svar4-value N/A ${uuid} service2 120121 svar4 svar4-value N/A ${shortUUID} service2
120203 var3 var3-val N/A ${uuid} * 120203 var3 var3-val N/A ${shortUUID} *
120204 var4 44 N/A ${uuid} * 120204 var4 44 N/A ${shortUUID} *
` + '\n'; ` + '\n';
out = out.map((l) => l.replace(/ +/g, ' ')); out = out.map((l) => l.replace(/ +/g, ' '));
@ -271,22 +273,22 @@ describe('balena envs', function () {
api.expectGetApplication(); api.expectGetApplication();
api.expectGetAppEnvVars(); api.expectGetAppEnvVars();
api.expectGetAppServiceVars(); api.expectGetAppServiceVars();
api.expectGetDevice({ shortUUID, fullUUID });
api.expectGetDevice({ fullUUID }); api.expectGetDevice({ fullUUID });
api.expectGetDeviceEnvVars(); api.expectGetDeviceEnvVars();
api.expectGetDeviceServiceVars(); api.expectGetDeviceServiceVars();
const uuid = shortUUID; const result = await runCommand(`envs -d ${shortUUID} -s ${serviceName}`);
const result = await runCommand(`envs -d ${uuid} -s ${serviceName}`);
let { out } = result; let { out } = result;
let expected = let expected =
stripIndent` stripIndent`
ID NAME VALUE FLEET DEVICE SERVICE ID NAME VALUE FLEET DEVICE SERVICE
120110 svar1 svar1-value org/test * ${serviceName} 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 * * 120101 var1 var1-val org/test * *
120102 var2 22 org/test * * 120102 var2 22 org/test * *
120203 var3 var3-val org/test ${uuid} * 120203 var3 var3-val org/test ${shortUUID} *
120204 var4 44 org/test ${uuid} * 120204 var4 44 org/test ${shortUUID} *
` + '\n'; ` + '\n';
out = out.map((l) => l.replace(/ +/g, ' ')); out = out.map((l) => l.replace(/ +/g, ' '));
@ -301,6 +303,7 @@ describe('balena envs', function () {
api.expectGetApplication(); api.expectGetApplication();
api.expectGetAppEnvVars(); api.expectGetAppEnvVars();
api.expectGetAppServiceVars(); api.expectGetAppServiceVars();
api.expectGetDevice({ shortUUID, fullUUID });
api.expectGetDevice({ fullUUID }); api.expectGetDevice({ fullUUID });
api.expectGetDeviceEnvVars(); api.expectGetDeviceEnvVars();
api.expectGetDeviceServiceVars(); api.expectGetDeviceServiceVars();

View File

@ -212,13 +212,20 @@ export class BalenaAPIMock extends NockMock {
public expectGetDevice(opts: { public expectGetDevice(opts: {
fullUUID: string; fullUUID: string;
shortUUID?: string;
inaccessibleApp?: boolean; inaccessibleApp?: boolean;
isOnline?: boolean; isOnline?: boolean;
optional?: boolean; optional?: boolean;
persist?: boolean; persist?: boolean;
}) { }) {
const id = 7654321; 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: [ d: [
{ {
id, id,