Adding Tests run and improving reply

This commit is contained in:
Philippe Caseiro 2018-10-15 16:42:35 +02:00 committed by William Petit
parent e0a32a2ecb
commit 68e9ba80b3
2 changed files with 27 additions and 22 deletions

View File

@ -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)

View File

@ -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