Skip to content

Commit

Permalink
make installing equal versions a no-op (#46)
Browse files Browse the repository at this point in the history
* make installing equal versions a no-op

Here we introduce a "non-error" `sm.ErrNoAction` to signal to the task
handler that there is nothing more to do (as though there were a real
error condition), but that the task handler should continue processing
additional firmware install tasks.

The result of this change is that attempting to install firmware at a
version already installed will not fail the task. This should avoid the
need to force install a firmware set which may overwrite firmware
already at the correct version and thus cost more time to apply a
condition.

* remove ErrNoAction but keep the tests
  • Loading branch information
DoctorVin authored Jul 31, 2023
1 parent 5b7e899 commit 4fd4f9a
Show file tree
Hide file tree
Showing 6 changed files with 445 additions and 9 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ require (
github.com/goccy/go-json v0.10.2 // indirect
github.com/gofrs/uuid v4.4.0+incompatible // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/googleapis/gax-go/v2 v2.11.0 // indirect
github.com/gosimple/slug v1.13.1 // indirect
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,7 @@ github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt
github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand Down
154 changes: 154 additions & 0 deletions internal/model/test/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 23 additions & 9 deletions internal/outofband/action_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,25 @@ func (h *actionHandler) checkCurrentFirmware(a sw.StateSwitch, c sw.TransitionAr
"vendor": action.Firmware.Vendor,
"models": action.Firmware.Models,
"err": ErrComponentNotFound,
}).Error("none matched given slug, vendor, model attributes")
}).Error("no component found for given component/vendor/model")

return errors.Wrap(ErrComponentNotFound, "no match based on given slug, vendor, model attributes")
return errors.Wrap(ErrComponentNotFound,
fmt.Sprintf("component: %s, vendor: %s, model: %s", action.Firmware.Component,
action.Firmware.Vendor,
action.Firmware.Models,
),
)
}

tctx.Logger.WithFields(
logrus.Fields{
"component": component.Slug,
"vendor": component.Vendor,
"model": component.Model,
"serial": component.Serial,
"firmware.version": component.FirmwareInstalled,
}).Debug("found component")

if component.FirmwareInstalled == "" {
return errors.Wrap(ErrInstalledVersionUnknown, "set TaskParameters.Force=true to skip this check")
}
Expand All @@ -210,13 +224,13 @@ func (h *actionHandler) checkCurrentFirmware(a sw.StateSwitch, c sw.TransitionAr
if equal {
tctx.Logger.WithFields(
logrus.Fields{
"component": action.Firmware.Component,
"vendor": action.Firmware.Vendor,
"models": action.Firmware.Models,
"expectedVersion": action.Firmware.Version,
"installedVersion": component.FirmwareInstalled,
}).Error("Installed firmware version equals expected - set TaskParameters.Force=true to disable this check")

"action id": action.ID,
"condition id": action.TaskID,
"component": action.Firmware.Component,
"vendor": action.Firmware.Vendor,
"models": action.Firmware.Models,
"expectedVersion": action.Firmware.Version,
}).Warn("Installed firmware version equals expected")
return ErrInstalledFirmwareEqual
}

Expand Down
Loading

0 comments on commit 4fd4f9a

Please sign in to comment.