Skip to content

Commit

Permalink
tests:os: Avoid setting apiEndpoint for unmanaged tests
Browse files Browse the repository at this point in the history
When this config.json field has a value, the supervisor will treat the device as managed and will crash and start to boot loop.

On faster device-types we don't seem to notice and the tests pass by chance, but on Pi Zero and similar we consistently see ECONNRESET when hitting local SV endpoints.

Change-type: patch
  • Loading branch information
klutchell committed Sep 6, 2024
1 parent 5310f76 commit 7e589b0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
9 changes: 4 additions & 5 deletions tests/suites/hup/suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ module.exports = {
this.suite.options.balenaOS.network.wired = {
nat: true,
};
}
}
else {
// device has wifi, use wifi hotspot to connect to DUT
delete this.suite.options.balenaOS.network.wired;
Expand All @@ -347,7 +347,7 @@ module.exports = {
psk: `${this.suite.options.id}_psk`,
nat: true,
};
}
}
else {
// no wifi on DUT
delete this.suite.options.balenaOS.network.wireless;
Expand Down Expand Up @@ -378,13 +378,13 @@ module.exports = {
);

const keys = await this.utils.createSSHKey(this.sshKeyPath);

// Authenticating balenaSDK
await this.context
.get()
.sdk.balena.auth.loginWithToken(this.suite.options.balena.apiKey);
this.log(`Logged in with ${await this.context.get().sdk.balena.auth.whoami()}'s account on ${this.suite.options.balena.apiUrl} using balenaSDK`);

await this.sdk.balena.models.key.create(
this.sshKeyLabel,
keys.pubKey
Expand Down Expand Up @@ -417,7 +417,6 @@ module.exports = {
persistentLogging: true,
// Set local mode so we can perform local pushes of containers to the DUT
localMode: true,
apiEndpoint: 'https://api.balena-cloud.com',
developmentMode: true,
installer: {
secureboot: ['1', 'true'].includes(process.env.FLASHER_SECUREBOOT),
Expand Down
32 changes: 18 additions & 14 deletions tests/suites/os/suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ module.exports = {
const BalenaOS = this.require('components/os/balenaos');
const utils = this.require('common/utils');
const worker = new Worker(
this.suite.deviceType.slug,
this.getLogger(),
this.suite.options.workerUrl,
this.suite.options.balena.organization,
this.suite.deviceType.slug,
this.getLogger(),
this.suite.options.workerUrl,
this.suite.options.balena.organization,
join(homedir(), 'id'),
this.suite.options.config.sshConfig
);
Expand Down Expand Up @@ -205,7 +205,7 @@ module.exports = {
} else {
value = JSON.stringify(value);
}

return t.resolves(
worker.executeCommandInHostOS(
[
Expand Down Expand Up @@ -260,7 +260,7 @@ module.exports = {
this.suite.options.balenaOS.network.wired = {
nat: true,
};
}
}
else {
// device has wifi, use wifi hotspot to connect to DUT
delete this.suite.options.balenaOS.network.wired;
Expand All @@ -280,7 +280,7 @@ module.exports = {
psk: `${this.suite.options.id}_psk`,
nat: true,
};
}
}
else {
// no wifi on DUT
delete this.suite.options.balenaOS.network.wireless;
Expand All @@ -299,12 +299,16 @@ module.exports = {
configJson: {
uuid: this.suite.options.balenaOS.config.uuid,
os: {
// Set a connectivity-check URI for HTTPS time sync service
network: {
connectivity: {
uri: 'https://api.balena-cloud.com/connectivity-check'
}
},
sshKeys: [
keys.pubKey
],
},
// Set an API endpoint for the HTTPS time sync service.
apiEndpoint: 'https://api.balena-cloud.com',
// persistentLogging is managed by the supervisor and only read at first boot
persistentLogging: true,
// Set local mode so we can perform local pushes of containers to the DUT
Expand Down Expand Up @@ -359,7 +363,7 @@ module.exports = {
.get()
.cloud.balena.auth.loginWithToken(this.suite.options.balena.apiKey);
this.log(`Logged in with ${await this.context.get().cloud.balena.auth.whoami()}'s account on ${this.suite.options.balena.apiUrl} using balenaSDK`);

await this.cloud.balena.models.key.create(
this.sshKeyLabel,
keys.pubKey
Expand Down Expand Up @@ -390,7 +394,7 @@ module.exports = {
await this.worker.off(); // Ensure DUT is off before starting tests
await this.worker.flash(this.os.image.path);
await this.worker.on();

await this.worker.addSSHKey(this.sshKeyPath);

// create tunnels
Expand All @@ -412,11 +416,11 @@ module.exports = {
`Device ${this.link} should be reachable over local SSH connection`
)

await test.resolves(
await test.resolves(
systemd.waitForServiceState('balena', 'active', this.link),
'balena Engine should be running and healthy'
)

// we want to waitUntil here as the supervisor may take some time to come online.
await test.resolves(
this.utils.waitUntil(async () => {
Expand All @@ -429,7 +433,7 @@ module.exports = {
'Supervisor should be running and healthy'
)


// Retrieving journalctl logs: register teardown after device is reachable
this.suite.teardown.register(async () => {
await this.context
Expand Down

0 comments on commit 7e589b0

Please sign in to comment.