Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle errors in additionalItemBackupper #512

Merged
merged 2 commits into from
May 23, 2018

Conversation

carlpett
Copy link
Contributor

Fixes #509.

Currently the corresponding test fails, which I think is because of #511.

@carlpett carlpett force-pushed the additional-backup-error branch from 922f7be to 1859063 Compare May 22, 2018 13:43
snapshotService = &arktest.FakeSnapshotService{
SnapshottableVolumes: test.snapshottableVolumes,
VolumeID: "vol-abc123",
if test.snapshotError != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit of a mess - would appreciate some ideas on how to make this clearer

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment below

@@ -89,3 +89,31 @@ func (s *FakeSnapshotService) SetVolumeID(pv runtime.Unstructured, volumeID stri
s.VolumeIDSet = volumeID
return pv, nil
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is the right place?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of creating a new type, please add err error to FakeSnapshotService and return s.err wherever we need to return an error.

@@ -206,7 +206,10 @@ func (ib *defaultItemBackupper) backupItem(logger logrus.FieldLogger, obj runtim
return err
}

ib.additionalItemBackupper.backupItem(log, additionalItem, gvr.GroupResource())
err = ib.additionalItemBackupper.backupItem(log, additionalItem, gvr.GroupResource())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we are only checking the returned error and aren't doing anything else with it, we usually use the syntax if err := foo(); err != nil {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. I'll do the same for the three if:s above at the same time, then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry. That doesn't work though, since they set other vars. Never mind, then, just fixing this one :)

@@ -89,3 +89,31 @@ func (s *FakeSnapshotService) SetVolumeID(pv runtime.Unstructured, volumeID stri
s.VolumeIDSet = volumeID
return pv, nil
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of creating a new type, please add err error to FakeSnapshotService and return s.err wherever we need to return an error.

snapshotService = &arktest.FakeSnapshotService{
SnapshottableVolumes: test.snapshottableVolumes,
VolumeID: "vol-abc123",
if test.snapshotError != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment below

@carlpett carlpett force-pushed the additional-backup-error branch from 1859063 to 24dfef6 Compare May 22, 2018 16:33
@@ -242,6 +243,17 @@ func TestBackupItemNoSkips(t *testing.T) {
"vol-abc123": {SnapshotID: "snapshot-1", AvailabilityZone: "us-east-1c"},
},
},
{
name: "backup fails when takePVSnapshot fails",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To test your change to item_backupper.go, we need a test case that has this mocked behavior return a non-nil error: additionalItemBackupper.On("backupItem", mock.AnythingOfType("*logrus.Entry"), test.customActionAdditionalItems[i], item.GroupResource).Return(nil).

The test case you've added here is valuable too, so we should keep it, but it doesn't cover your fix: namely, that when we call ib.additionalItemBackupper.backupItem(log, additionalItem, gvr.GroupResource()), it checks the returned error and returns it if it's non-nil.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this would cover your change: https://gist.github.com/ncdc/12c3b6b6f4db0e5c60f4ecf77e8d85c2

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Updated with this, will ask some questions on Slack too :)

Signed-off-by: Calle Pettersson <[email protected]>
@ncdc ncdc added this to the v0.9.0 milestone May 23, 2018
@ncdc ncdc assigned ncdc and skriss May 23, 2018
@ncdc
Copy link
Contributor

ncdc commented May 23, 2018

LGTM. @skriss ptal

Copy link
Contributor

@skriss skriss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@skriss skriss merged commit fb33d93 into vmware-tanzu:master May 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants