Skip to content

Commit

Permalink
MEN-1215: Now throws an error when artifact-file cannot be found duri…
Browse files Browse the repository at this point in the history
…ng update

Changelog: None

Replaced the log in state-test with an error message + added a test for the
case that GetCurrentArtifact() errors (eg, when no artifact file can be found).

Signed-off-by: Ole Petter <[email protected]>
(cherry picked from commit d4d85a2)
  • Loading branch information
Ole Petter authored and kacf committed Aug 2, 2017
1 parent 70fcf06 commit 1128c3c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion state.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,9 @@ func (uv *UpdateVerifyState) Handle(ctx *StateContext, c Controller) (State, boo
if has {
artifactName, err := c.GetCurrentArtifactName()
if err != nil {
log.Errorf("Cannot determine current artifact. Update will continue anyways: %v : %v", defaultDeviceTypeFile, err)
log.Errorf("Cannot determine name of new artifact. Update will not continue: %v : %v", defaultDeviceTypeFile, err)
me := NewFatalError(errors.Wrapf(err, "Cannot determine name of new artifact. Update will not continue: %v : %v", defaultDeviceTypeFile, err))
return NewUpdateErrorState(me, uv.update), false
}
if uv.update.ArtifactName() == artifactName {
log.Infof("successfully running with new image %v", artifactName)
Expand Down
12 changes: 11 additions & 1 deletion state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ func (s *stateTestController) Bootstrap() menderError {
}

func (s *stateTestController) GetCurrentArtifactName() (string, error) {
return s.artifactName, nil // TODO return an error?
if s.artifactName == "" {
return "", errors.New("open ..., no such file or directory")
}
return s.artifactName, nil
}

func (s *stateTestController) GetUpdatePollInterval() time.Duration {
Expand Down Expand Up @@ -577,6 +580,13 @@ func TestUpdateVerifyState(t *testing.T) {
assert.IsType(t, &RebootState{}, s)
assert.False(t, c)

// Test upgrade available and no artifact-file found
s, c = uvs.Handle(nil, &stateTestController{
hasUpgrade: true,
})
assert.IsType(t, &UpdateErrorState{}, s)
assert.False(t, c)

// artifact name is as expected; update was successful
s, c = uvs.Handle(nil, &stateTestController{
hasUpgrade: true,
Expand Down

0 comments on commit 1128c3c

Please sign in to comment.