Adding Tests run and improving reply
This commit is contained in:
parent
e0a32a2ecb
commit
68e9ba80b3
|
@ -188,7 +188,8 @@ type UpdateOrionBoxResponse struct {
|
||||||
Netmask string
|
Netmask string
|
||||||
Synced bool
|
Synced bool
|
||||||
Version string
|
Version string
|
||||||
Errors []string
|
Status *updater.UpdateStatus
|
||||||
|
Results *updater.TestResults
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connect wifi interface to a Orion box wifi hotspot!
|
// 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
|
iface := server.ClientIface
|
||||||
cells := iface.Scan()
|
cells := iface.Scan()
|
||||||
for _, cell := range cells {
|
for _, cell := range cells {
|
||||||
fmt.Printf("Cell : %s\n", cell.Ssid)
|
|
||||||
if cell.Ssid == box.SSID {
|
if cell.Ssid == box.SSID {
|
||||||
cn := iface.Connect(o.UCI, cell, box.WifiKey)
|
cn := iface.Connect(o.UCI, cell, box.WifiKey)
|
||||||
if cn.ReturnCode != 0 {
|
if cn.ReturnCode != 0 {
|
||||||
|
@ -226,15 +226,7 @@ func (o *OrionService) connectBox(box *OrionBox, server *OrionServer) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *OrionService) discoverService() ([]emlid.Service, error) {
|
func (o *OrionService) discoverService() ([]emlid.Service, error) {
|
||||||
service, err := emlid.Discover(20 * time.Second)
|
return 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
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// setupMasterWifi connects to the box, add wifi network and join it !
|
// 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
|
var boxCli *updater.Client
|
||||||
service, err := o.discoverService()
|
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(
|
boxCli = updater.NewClient(
|
||||||
emlid.WithService(service[0]),
|
emlid.WithService(service[0]),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
boxCli = updater.NewClient(
|
return err
|
||||||
emlid.WithEndpoint(box.Address, 80),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := boxCli.Connect(); err != nil {
|
if err := boxCli.Connect(); err != nil {
|
||||||
|
@ -264,6 +258,13 @@ func (o *OrionService) setupMasterWifi(rqContext context.Context, box *OrionBox,
|
||||||
}
|
}
|
||||||
defer boxCli.Close()
|
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)
|
ctx, addWifiCancel := context.WithTimeout(rqContext, 55*time.Second)
|
||||||
defer addWifiCancel()
|
defer addWifiCancel()
|
||||||
|
|
||||||
|
@ -300,7 +301,9 @@ func (o *OrionService) updateAndReboot(rqContext context.Context, box *OrionBox,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := boxCli.Connect(); err != nil {
|
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()
|
defer boxCli.Close()
|
||||||
|
|
||||||
|
@ -320,6 +323,14 @@ func (o *OrionService) updateAndReboot(rqContext context.Context, box *OrionBox,
|
||||||
}
|
}
|
||||||
reply.Version = version
|
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)
|
ctx, rebootCancel := context.WithTimeout(rqContext, 55*time.Second)
|
||||||
defer rebootCancel()
|
defer rebootCancel()
|
||||||
return boxCli.RebootNow(ctx, true)
|
return boxCli.RebootNow(ctx, true)
|
||||||
|
|
|
@ -50,7 +50,6 @@ func (wi *UCIWirelessInterface) GetSysDevName(sysDir string) string {
|
||||||
patt := fmt.Sprintf("%s/%s/.*/address", wi.DevicePath, "net")
|
patt := fmt.Sprintf("%s/%s/.*/address", wi.DevicePath, "net")
|
||||||
r, err := regexp.MatchString(patt, path)
|
r, err := regexp.MatchString(patt, path)
|
||||||
if err == nil && r {
|
if err == nil && r {
|
||||||
fmt.Println(path)
|
|
||||||
res := strings.Split(path, "/")
|
res := strings.Split(path, "/")
|
||||||
idx := len(res) - 2
|
idx := len(res) - 2
|
||||||
found = res[idx]
|
found = res[idx]
|
||||||
|
@ -60,7 +59,6 @@ func (wi *UCIWirelessInterface) GetSysDevName(sysDir string) string {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err.Error()
|
return err.Error()
|
||||||
}
|
}
|
||||||
fmt.Println(found)
|
|
||||||
wi.SysDevName = found
|
wi.SysDevName = found
|
||||||
return found
|
return found
|
||||||
}
|
}
|
||||||
|
@ -72,7 +70,6 @@ func (wi *UCIWirelessInterface) Create(uci *UCI) *Action {
|
||||||
if addRes.ReturnCode != 0 {
|
if addRes.ReturnCode != 0 {
|
||||||
return addRes
|
return addRes
|
||||||
}
|
}
|
||||||
fmt.Println(wi.Index)
|
|
||||||
if wi.Index <= 0 {
|
if wi.Index <= 0 {
|
||||||
confPrefix = fmt.Sprintf("wireless.@wifi-iface[%d]", len(uci.Wireless.Interfaces))
|
confPrefix = fmt.Sprintf("wireless.@wifi-iface[%d]", len(uci.Wireless.Interfaces))
|
||||||
} else {
|
} else {
|
||||||
|
@ -183,8 +180,6 @@ func (wi *UCIWirelessInterface) Delete(uci *UCI) *Action {
|
||||||
// Update add a new entry for wifi interface in UCI Configuration
|
// Update add a new entry for wifi interface in UCI Configuration
|
||||||
func (wi *UCIWirelessInterface) Update(uci *UCI) *Action {
|
func (wi *UCIWirelessInterface) Update(uci *UCI) *Action {
|
||||||
wi.Delete(uci)
|
wi.Delete(uci)
|
||||||
fmt.Println("IN UPDATE !")
|
|
||||||
fmt.Println(wi)
|
|
||||||
create := wi.Create(uci)
|
create := wi.Create(uci)
|
||||||
if create.ReturnCode != 0 {
|
if create.ReturnCode != 0 {
|
||||||
return create
|
return create
|
||||||
|
@ -207,7 +202,6 @@ func (wi *UCIWirelessInterface) Connect(uci *UCI, cell *WifiCell, secret string)
|
||||||
wi.Encryption = cell.Encryption
|
wi.Encryption = cell.Encryption
|
||||||
wi.Mode = "sta"
|
wi.Mode = "sta"
|
||||||
wi.Key = secret
|
wi.Key = secret
|
||||||
fmt.Println(wi)
|
|
||||||
res := wi.Update(uci)
|
res := wi.Update(uci)
|
||||||
if res.ReturnCode != 0 {
|
if res.ReturnCode != 0 {
|
||||||
return res
|
return res
|
||||||
|
|
Reference in New Issue