Skip to content

Commit

Permalink
Merge pull request #89 from balena-io-hardware/acostach-power-off-dut…
Browse files Browse the repository at this point in the history
…-on-failure

flashing/index: Power off Jetson DUT on container flash failure
  • Loading branch information
flowzone-app[bot] authored Jul 9, 2024
2 parents 9444e87 + 1c4a2b7 commit 11e919a
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions lib/flashing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,11 +429,13 @@ async function flashJetson(filename: string, autoKit: Autokit, deviceType: strin
if (code === 0) {
resolve();
} else {
reject(new Error(`Docker build exit code was: ${code}`));
autoKit.power.off();
reject(new Error(`Docker build exit code was: ${code}. Powered off DUT.`));
}
});
build.on('error', (err) => {
reject(new Error(`Error with docker build: ${err.message}`));
autoKit.power.off();
reject(new Error(`Error with docker build: ${err.message}. Powered off DUT.`));
});
});
} else {
Expand All @@ -454,19 +456,24 @@ async function flashJetson(filename: string, autoKit: Autokit, deviceType: strin
if (code === 0) {
resolve();
} else {
console.log(`Got exit code ${code}.. error`);
autoKit.power.off();
console.log(`Got exit code ${code}.. error. Powered off DUT.`);
reject(new Error(`Docker build exit code was: ${code}`));
}
});
buildAndRun.on('error', (err) => {
reject(new Error(`Error with docker build: ${err.message}`));
autoKit.power.off();
reject(new Error(`Error with docker build: ${err.message}. Powered off DUT.`));
});
});
}
} catch (err: any){
throw new Error(`Failed during jetson-flash container build: ${err.message}`);
await autoKit.power.off();
throw new Error(`Failed during jetson-flash container build: ${err.message}. Powered off DUT`);
}

await autoKit.power.on();
await delay(5 * 1000);
// run flash container
console.log(`File path: ${filename}`)
// Then run container
Expand Down Expand Up @@ -498,16 +505,19 @@ async function flashJetson(filename: string, autoKit: Autokit, deviceType: strin
if (code === 0) {
resolve();
} else {
console.log(`Got exit code ${code}.. error`);
autoKit.power.off();
console.log(`Got exit code ${code}.. error. Powered off DUT.`);
reject(new Error(`Docker run exit code was: ${code}`))
}
});
flash.on('error', (err) => {
reject(new Error(`Error with docker run: ${err.message}`));
autoKit.power.off();
reject(new Error(`Error with docker run: ${err.message}. Powered off DUT.`));
});
});
} catch(err:any){
throw new Error(`Failed during jetson-flash container run: ${err.message}`)
await autoKit.power.off();
throw new Error(`Failed during jetson-flash container run: ${err.message}. Powered off DUT.`)
}


Expand Down Expand Up @@ -544,7 +554,8 @@ async function flashJetson(filename: string, autoKit: Autokit, deviceType: strin
}
attempt += 1;
if (attempt === TIMEOUT_COUNT){
throw new Error(`Timed out while trying to flash internal storage!!`)
await autoKit.power.off();
throw new Error(`Timed out while trying to flash internal storage!!. Powered off DUT.`)
}
}
console.log('Internally flashed - powering off DUT');
Expand Down Expand Up @@ -669,4 +680,4 @@ async function flash(filename: string, deviceType: string, autoKit: Autokit, por
}
}

export { flash }
export { flash }

0 comments on commit 11e919a

Please sign in to comment.