From 1128c3cc840704b8904f2702e99e2a70c9aab506 Mon Sep 17 00:00:00 2001 From: Ole Petter Date: Wed, 28 Jun 2017 14:35:12 +0200 Subject: [PATCH] MEN-1215: Now throws an error when artifact-file cannot be found during 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 (cherry picked from commit d4d85a2af9d9c2d2380f48c5766f7cd3d1d18fe8) --- state.go | 4 +++- state_test.go | 12 +++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/state.go b/state.go index 306834efa..4fb76563e 100644 --- a/state.go +++ b/state.go @@ -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) diff --git a/state_test.go b/state_test.go index d57b07ba5..e4bd4444b 100644 --- a/state_test.go +++ b/state_test.go @@ -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 { @@ -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,