device os-update: allow host OS upgrade with development balenaOS images

also:
fix `device os-update` incorrectly showing 0% progress
convert `device os-update` to use async/await

Change-type: minor
Resolves: #1725
Signed-off-by: Scott Lowe <scott@balena.io>
This commit is contained in:
Scott Lowe
2020-04-15 12:39:27 +02:00
parent 7f79451376
commit 320b4864d9
6 changed files with 105 additions and 83 deletions

View File

@ -293,10 +293,7 @@ export function awaitDeviceOsUpdate(uuid: string, targetOsVersion: string) {
balena.models.device.getOsUpdateStatus(uuid),
balena.models.device.get(uuid).then(getDeviceOsProgress),
]).then(([osUpdateStatus, osUpdateProgress]) => {
if (
osUpdateStatus.status === 'update_done' ||
osUpdateStatus.status === 'done'
) {
if (osUpdateStatus.status === 'done') {
console.info(
`The device ${deviceName} has been updated to v${targetOsVersion} and will restart shortly!`,
);
@ -311,7 +308,10 @@ export function awaitDeviceOsUpdate(uuid: string, targetOsVersion: string) {
return;
}
progressBar.update({ percentage: osUpdateProgress });
if (osUpdateProgress !== null) {
// Avoid resetting to 0% at end of process when device goes offline.
progressBar.update({ percentage: osUpdateProgress });
}
return Bluebird.delay(3000).then(poll);
});
@ -451,6 +451,8 @@ export function printErrorMessage(message: string) {
* "expected" errors (say, a JSON parsing error in a file provided by the user)
* don't warrant reporting through Sentry.io. For such mundane errors, catch
* them and call this function.
*
* DEPRECATED: Use `throw new ExpectedError(<message>)` instead.
*/
export function exitWithExpectedError(message: string | Error): never {
if (message instanceof Error) {