From 68e9ba80b3f36ceb0922799f6f00d6afc94cb746 Mon Sep 17 00:00:00 2001 From: Philippe Caseiro Date: Mon, 15 Oct 2018 16:42:35 +0200 Subject: [PATCH] Adding Tests run and improving reply --- cmd/server/rpc/server.go | 43 +++++++++++++++++++------------ openwrt/uci_wireless_interface.go | 6 ----- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/cmd/server/rpc/server.go b/cmd/server/rpc/server.go index 778e844..6c9a88e 100644 --- a/cmd/server/rpc/server.go +++ b/cmd/server/rpc/server.go @@ -188,7 +188,8 @@ type UpdateOrionBoxResponse struct { Netmask string Synced bool Version string - Errors []string + Status *updater.UpdateStatus + Results *updater.TestResults } // Connect wifi interface to a Orion box wifi hotspot! @@ -204,7 +205,6 @@ func (o *OrionService) connectBox(box *OrionBox, server *OrionServer) error { iface := server.ClientIface cells := iface.Scan() for _, cell := range cells { - fmt.Printf("Cell : %s\n", cell.Ssid) if cell.Ssid == box.SSID { cn := iface.Connect(o.UCI, cell, box.WifiKey) if cn.ReturnCode != 0 { @@ -226,15 +226,7 @@ func (o *OrionService) connectBox(box *OrionBox, server *OrionServer) error { } func (o *OrionService) discoverService() ([]emlid.Service, error) { - service, err := emlid.Discover(20 * time.Second) - if err != nil { - return service, err - } - if len(service) == 0 { - return service, fmt.Errorf("Discovery don't find any Orion Box") - } - return service, err - + return emlid.Discover(20 * time.Second) } // setupMasterWifi connects to the box, add wifi network and join it ! @@ -249,14 +241,16 @@ func (o *OrionService) setupMasterWifi(rqContext context.Context, box *OrionBox, var boxCli *updater.Client service, err := o.discoverService() - if err != nil { + if len(service) == 0 { + boxCli = updater.NewClient( + emlid.WithEndpoint(box.Address, 80), + ) + } else if err != nil { boxCli = updater.NewClient( emlid.WithService(service[0]), ) } else { - boxCli = updater.NewClient( - emlid.WithEndpoint(box.Address, 80), - ) + return err } if err := boxCli.Connect(); err != nil { @@ -264,6 +258,13 @@ func (o *OrionService) setupMasterWifi(rqContext context.Context, box *OrionBox, } defer boxCli.Close() + ctx, testResultsCancel := context.WithTimeout(rqContext, 55*time.Second) + defer testResultsCancel() + _, err = boxCli.TestResults(ctx) + if err != nil { + return errors.Wrap(err, "Minimal test failed") + } + ctx, addWifiCancel := context.WithTimeout(rqContext, 55*time.Second) defer addWifiCancel() @@ -300,7 +301,9 @@ func (o *OrionService) updateAndReboot(rqContext context.Context, box *OrionBox, } if err := boxCli.Connect(); err != nil { - return errors.Wrap(err, "Connecting to Box on master wifi network failed") + if err := boxCli.Connect(); err != nil { + return errors.Wrap(err, "Connecting to Box on master wifi network failed") + } } defer boxCli.Close() @@ -320,6 +323,14 @@ func (o *OrionService) updateAndReboot(rqContext context.Context, box *OrionBox, } reply.Version = version + ctx, updateCancel := context.WithTimeout(rqContext, 55*time.Second) + defer updateCancel() + status, err := boxCli.Update(ctx) + if err != nil { + return errors.Wrap(err, "System update failed") + } + reply.Status = status + ctx, rebootCancel := context.WithTimeout(rqContext, 55*time.Second) defer rebootCancel() return boxCli.RebootNow(ctx, true) diff --git a/openwrt/uci_wireless_interface.go b/openwrt/uci_wireless_interface.go index 3b08247..42a5c58 100644 --- a/openwrt/uci_wireless_interface.go +++ b/openwrt/uci_wireless_interface.go @@ -50,7 +50,6 @@ func (wi *UCIWirelessInterface) GetSysDevName(sysDir string) string { patt := fmt.Sprintf("%s/%s/.*/address", wi.DevicePath, "net") r, err := regexp.MatchString(patt, path) if err == nil && r { - fmt.Println(path) res := strings.Split(path, "/") idx := len(res) - 2 found = res[idx] @@ -60,7 +59,6 @@ func (wi *UCIWirelessInterface) GetSysDevName(sysDir string) string { if err != nil { return err.Error() } - fmt.Println(found) wi.SysDevName = found return found } @@ -72,7 +70,6 @@ func (wi *UCIWirelessInterface) Create(uci *UCI) *Action { if addRes.ReturnCode != 0 { return addRes } - fmt.Println(wi.Index) if wi.Index <= 0 { confPrefix = fmt.Sprintf("wireless.@wifi-iface[%d]", len(uci.Wireless.Interfaces)) } else { @@ -183,8 +180,6 @@ func (wi *UCIWirelessInterface) Delete(uci *UCI) *Action { // Update add a new entry for wifi interface in UCI Configuration func (wi *UCIWirelessInterface) Update(uci *UCI) *Action { wi.Delete(uci) - fmt.Println("IN UPDATE !") - fmt.Println(wi) create := wi.Create(uci) if create.ReturnCode != 0 { return create @@ -207,7 +202,6 @@ func (wi *UCIWirelessInterface) Connect(uci *UCI, cell *WifiCell, secret string) wi.Encryption = cell.Encryption wi.Mode = "sta" wi.Key = secret - fmt.Println(wi) res := wi.Update(uci) if res.ReturnCode != 0 { return res