Add SkipUpdate() Updater method

Allow to skip the update step and reboot to ReachView
This commit is contained in:
wpetit 2018-10-16 12:29:46 +02:00
parent 68e9ba80b3
commit ec2fd846cc
4 changed files with 61 additions and 21 deletions

View File

@ -3,6 +3,7 @@ package rpc
import ( import (
"context" "context"
"fmt" "fmt"
"log"
"net/http" "net/http"
"time" "time"
@ -331,6 +332,10 @@ func (o *OrionService) updateAndReboot(rqContext context.Context, box *OrionBox,
} }
reply.Status = status 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) ctx, rebootCancel := context.WithTimeout(rqContext, 55*time.Second)
defer rebootCancel() defer rebootCancel()
return boxCli.RebootNow(ctx, true) return boxCli.RebootNow(ctx, true)

View File

@ -5,6 +5,7 @@ import "context"
const ( const (
eventUpdate = "update" eventUpdate = "update"
eventOPKGUpdateResult = "opkg update result" eventOPKGUpdateResult = "opkg update result"
eventSkipUpdate = "skip update"
) )
// UpdateStatus embeds informations about update status // UpdateStatus embeds informations about update status
@ -26,3 +27,8 @@ func (c *Client) Update(ctx context.Context) (*UpdateStatus, error) {
) )
return res, nil return res, nil
} }
// SkipUpdate asks the ReachRS module to skip the update
func (c *Client) SkipUpdate() error {
return c.Emit(eventSkipUpdate, nil)
}

View File

@ -12,6 +12,8 @@ import (
"forge.cadoles.com/Pyxis/orion/emlid/updater" "forge.cadoles.com/Pyxis/orion/emlid/updater"
) )
const stepSleep = 5
const ( const (
phaseConfigureWifi = "configure-wifi" phaseConfigureWifi = "configure-wifi"
phaseUpdateThenReboot = "update-then-reboot" phaseUpdateThenReboot = "update-then-reboot"
@ -97,6 +99,8 @@ func configureWifi() {
log.Printf("stc activated ? %v", results.STC) log.Printf("stc activated ? %v", results.STC)
log.Printf("ublox activated ? %v", results.UBlox) log.Printf("ublox activated ? %v", results.UBlox)
sleep(stepSleep)
log.Printf("adding wifi network '%s'", ssid) log.Printf("adding wifi network '%s'", ssid)
ctx, addWifiCancel := context.WithTimeout(ctx, 5*time.Second) ctx, addWifiCancel := context.WithTimeout(ctx, 5*time.Second)
@ -110,6 +114,8 @@ func configureWifi() {
log.Fatal("couldnt add wifi network") log.Fatal("couldnt add wifi network")
} }
sleep(stepSleep)
log.Println("connecting module to wifi network") log.Println("connecting module to wifi network")
ctx, joinWifiCancel := context.WithTimeout(ctx, 5*time.Second) ctx, joinWifiCancel := context.WithTimeout(ctx, 5*time.Second)
defer joinWifiCancel() defer joinWifiCancel()
@ -125,47 +131,71 @@ func updateThenReboot() {
c := connect() c := connect()
defer c.Close() 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") log.Println("checking time sync")
ctx, timeSyncedCancel := context.WithTimeout(ctx, 5*time.Second) ctx, timeSyncedCancel := context.WithTimeout(context.Background(), 20*time.Second)
defer timeSyncedCancel() defer timeSyncedCancel()
synced, err := c.TimeSynced(ctx) synced, err := c.TimeSynced(ctx)
if err != nil { if err != nil {
log.Fatal(err) log.Fatalf("error while checking time sync status: %s", err)
} }
log.Printf("time synced ? %v", synced) 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") log.Println("checking reachview version")
ctx, reachviewVersionCancel := context.WithTimeout(ctx, 5*time.Second) ctx, reachviewVersionCancel := context.WithTimeout(context.Background(), 20*time.Second)
defer reachviewVersionCancel() defer reachviewVersionCancel()
version, err := c.ReachViewVersion(ctx) version, err := c.ReachViewVersion(ctx)
if err != nil { if err != nil {
log.Fatal(err) log.Fatalf("error while checking version: %s", err)
} }
log.Printf("reachview version ? '%s'", version) log.Printf("reachview version ? '%s'", version)
log.Println("checking for update") sleep(stepSleep)
ctx, updateCancel := context.WithTimeout(ctx, 5*time.Second)
defer updateCancel() log.Println("skipping update")
status, err := c.Update(ctx) if err := c.SkipUpdate(); err != nil {
if err != nil { log.Fatalf("error while skipping update: %s", err)
log.Fatal(err)
} }
log.Printf("is update running ? %v", status.Active) sleep(stepSleep)
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")
}
log.Println("rebooting device") log.Println("rebooting device")
ctx, rebootCancel := context.WithTimeout(ctx, 5*time.Second) ctx, rebootCancel := context.WithTimeout(context.Background(), 20*time.Second)
defer rebootCancel() defer rebootCancel()
if err := c.RebootNow(ctx, true); err != nil { 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)
}

View File

@ -169,7 +169,6 @@ func (wi *UCIWirelessInterface) Up(uci *UCI) *Action {
// Delete remove wifi interface from UCI Configuration // Delete remove wifi interface from UCI Configuration
func (wi *UCIWirelessInterface) Delete(uci *UCI) *Action { func (wi *UCIWirelessInterface) Delete(uci *UCI) *Action {
toDelete := fmt.Sprintf("wireless.@wifi-iface[%d]", wi.Index) toDelete := fmt.Sprintf("wireless.@wifi-iface[%d]", wi.Index)
fmt.Printf("DEBUG\n%s\nDEBUG", toDelete)
del := uci.Delete(toDelete) del := uci.Delete(toDelete)
if del.ReturnCode != 0 { if del.ReturnCode != 0 {
return del return del