Add SkipUpdate() Updater method
Allow to skip the update step and reboot to ReachView
This commit is contained in:
parent
68e9ba80b3
commit
ec2fd846cc
|
@ -3,6 +3,7 @@ package rpc
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
|
@ -331,6 +332,10 @@ func (o *OrionService) updateAndReboot(rqContext context.Context, box *OrionBox,
|
|||
}
|
||||
reply.Status = status
|
||||
|
||||
if err := boxCli.SkipUpdate(); err != nil {
|
||||
log.Fatalf("error while skipping update: %s", err)
|
||||
}
|
||||
|
||||
ctx, rebootCancel := context.WithTimeout(rqContext, 55*time.Second)
|
||||
defer rebootCancel()
|
||||
return boxCli.RebootNow(ctx, true)
|
||||
|
|
|
@ -5,6 +5,7 @@ import "context"
|
|||
const (
|
||||
eventUpdate = "update"
|
||||
eventOPKGUpdateResult = "opkg update result"
|
||||
eventSkipUpdate = "skip update"
|
||||
)
|
||||
|
||||
// UpdateStatus embeds informations about update status
|
||||
|
@ -26,3 +27,8 @@ func (c *Client) Update(ctx context.Context) (*UpdateStatus, error) {
|
|||
)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// SkipUpdate asks the ReachRS module to skip the update
|
||||
func (c *Client) SkipUpdate() error {
|
||||
return c.Emit(eventSkipUpdate, nil)
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@ import (
|
|||
"forge.cadoles.com/Pyxis/orion/emlid/updater"
|
||||
)
|
||||
|
||||
const stepSleep = 5
|
||||
|
||||
const (
|
||||
phaseConfigureWifi = "configure-wifi"
|
||||
phaseUpdateThenReboot = "update-then-reboot"
|
||||
|
@ -97,6 +99,8 @@ func configureWifi() {
|
|||
log.Printf("stc activated ? %v", results.STC)
|
||||
log.Printf("ublox activated ? %v", results.UBlox)
|
||||
|
||||
sleep(stepSleep)
|
||||
|
||||
log.Printf("adding wifi network '%s'", ssid)
|
||||
|
||||
ctx, addWifiCancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
|
@ -110,6 +114,8 @@ func configureWifi() {
|
|||
log.Fatal("couldnt add wifi network")
|
||||
}
|
||||
|
||||
sleep(stepSleep)
|
||||
|
||||
log.Println("connecting module to wifi network")
|
||||
ctx, joinWifiCancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer joinWifiCancel()
|
||||
|
@ -125,47 +131,71 @@ func updateThenReboot() {
|
|||
c := connect()
|
||||
defer c.Close()
|
||||
|
||||
ctx := context.Background()
|
||||
log.Println("checking module status")
|
||||
ctx, testResultsCancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer testResultsCancel()
|
||||
results, err := c.TestResults(ctx)
|
||||
if err != nil {
|
||||
log.Fatalf("error while checking device state: %s", err)
|
||||
}
|
||||
|
||||
log.Printf("device: '%s'", results.Device)
|
||||
log.Printf("lora activated ? %v", results.Lora)
|
||||
log.Printf("mpu activated ? %v", results.MPU)
|
||||
log.Printf("stc activated ? %v", results.STC)
|
||||
log.Printf("ublox activated ? %v", results.UBlox)
|
||||
|
||||
sleep(stepSleep)
|
||||
|
||||
log.Println("checking time sync")
|
||||
ctx, timeSyncedCancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
ctx, timeSyncedCancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer timeSyncedCancel()
|
||||
synced, err := c.TimeSynced(ctx)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Fatalf("error while checking time sync status: %s", err)
|
||||
}
|
||||
log.Printf("time synced ? %v", synced)
|
||||
|
||||
sleep(stepSleep)
|
||||
|
||||
log.Println("checking for upgrade")
|
||||
ctx, upgradeAvailableCancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer upgradeAvailableCancel()
|
||||
_, _, err = c.ReceiverUpgradeAvailable(ctx)
|
||||
if err != nil {
|
||||
log.Fatalf("error while checking for upgrade: %s", err)
|
||||
}
|
||||
|
||||
sleep(stepSleep)
|
||||
|
||||
log.Println("checking reachview version")
|
||||
ctx, reachviewVersionCancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
ctx, reachviewVersionCancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer reachviewVersionCancel()
|
||||
version, err := c.ReachViewVersion(ctx)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Fatalf("error while checking version: %s", err)
|
||||
}
|
||||
log.Printf("reachview version ? '%s'", version)
|
||||
|
||||
log.Println("checking for update")
|
||||
ctx, updateCancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer updateCancel()
|
||||
status, err := c.Update(ctx)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
sleep(stepSleep)
|
||||
|
||||
log.Println("skipping update")
|
||||
if err := c.SkipUpdate(); err != nil {
|
||||
log.Fatalf("error while skipping update: %s", err)
|
||||
}
|
||||
|
||||
log.Printf("is update running ? %v", status.Active)
|
||||
log.Printf("is update locked ? %v", status.Locked)
|
||||
log.Printf("last update state ? '%s'", status.State)
|
||||
|
||||
if status.Active {
|
||||
log.Fatal("cannot reboot while an update is active")
|
||||
}
|
||||
sleep(stepSleep)
|
||||
|
||||
log.Println("rebooting device")
|
||||
ctx, rebootCancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
ctx, rebootCancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer rebootCancel()
|
||||
if err := c.RebootNow(ctx, true); err != nil {
|
||||
log.Fatal(err)
|
||||
log.Fatalf("error while rebooting: %s", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func sleep(seconds int) {
|
||||
log.Printf("sleeping for %d seconds...", seconds)
|
||||
time.Sleep(time.Duration(seconds) * time.Second)
|
||||
}
|
||||
|
|
|
@ -169,7 +169,6 @@ func (wi *UCIWirelessInterface) Up(uci *UCI) *Action {
|
|||
// Delete remove wifi interface from UCI Configuration
|
||||
func (wi *UCIWirelessInterface) Delete(uci *UCI) *Action {
|
||||
toDelete := fmt.Sprintf("wireless.@wifi-iface[%d]", wi.Index)
|
||||
fmt.Printf("DEBUG\n%s\nDEBUG", toDelete)
|
||||
del := uci.Delete(toDelete)
|
||||
if del.ReturnCode != 0 {
|
||||
return del
|
||||
|
|
Reference in New Issue