Skip to content

Commit

Permalink
Fix switch status still not updated properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 committed Aug 1, 2023
1 parent 5c657fc commit 1f05957
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cmd/metal-api/internal/datastore/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (rs *RethinkStore) ConnectMachineWithSwitches(m *metal.Machine) error {
func (rs *RethinkStore) GetSwitchStatus(id string) (*metal.SwitchStatus, error) {
var ss metal.SwitchStatus
err := rs.findEntityByID(rs.switchStatusTable(), &ss, id)
if err != nil && !metal.IsNotFound(err) {
if err != nil {
return nil, err
}
return &ss, nil
Expand Down
21 changes: 12 additions & 9 deletions cmd/metal-api/internal/service/switch-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,25 +223,28 @@ func (r *switchResource) notifySwitch(request *restful.Request, response *restfu
}
}

sync := &metal.SwitchSync{
Time: time.Now(),
Duration: requestPayload.Duration,
}
newSS := *ss

if requestPayload.Error == nil {
ss.LastSync = sync
newSS.LastSync = &metal.SwitchSync{
Time: time.Now(),
Duration: requestPayload.Duration,
}
} else {
ss.LastSyncError = sync
ss.LastSyncError.Error = requestPayload.Error
newSS.LastSyncError = &metal.SwitchSync{
Time: time.Now(),
Duration: requestPayload.Duration,
Error: requestPayload.Error,
}
}

err = r.ds.SetSwitchStatus(ss)
err = r.ds.SetSwitchStatus(&newSS)
if err != nil {
r.sendError(request, response, defaultError(err))
return
}

r.send(request, response, http.StatusOK, v1.NewSwitchNotifyResponse(ss))
r.send(request, response, http.StatusOK, v1.NewSwitchNotifyResponse(&newSS))
}

func (r *switchResource) updateSwitch(request *restful.Request, response *restful.Response) {
Expand Down

0 comments on commit 1f05957

Please sign in to comment.