-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Centralize cleanup of created resources
This change revamps the way resources (like volumes and now also snapshots) are managed in tests with regards to cleaning up. Instead of putting the onus of cleaning up on the test author, we extend Cleanup to automatically (un-)register resources as they are being used. Cleanup now exposes a single API that implements both ControllerClient and NodeClient to make it easier for all garbage collection-worthy requests to be funnelled through the new API. The way this is implemented in Cleanup is by embedding both ControllerClient and NodeClient, and proxying to the actual methods before registering cleanup tasks and returning the results. Consequently, we can throw away large chunks of cleanup test code and unify all {Controller,Node}Client access to the Cleanup variable. In essence, this makes it much easier to do the right thing as a test author since each existing Describe context will provide a single interaction point to the CSI APIs only. For frequently used resource creation operations, we also provide Must* equivalents that fail the test if the results are unexpected. This makes our test code even more streamlined by DRYing out the number of assertions called. List of other changes: cleanup.go: - Key volume and snapshot objects by ID instead of name. We have a few tests that omit or reuse the name, which makes it impossible to do automatic cleanup. Not printing the name of the resource as we clean up is a small price we have to pay for this adjustment, though. - Fail tests when cleanup operations error out, except when we see error codes indicating that the resource is already cleaned up. - Rename DeleteVolumes to Cleanup. - Provide convenience method MustCreateSnapshotFromVolumeRequest to create a sourcing volume and a snapshot in one go. controller.go, node.go: - Change all tests to use the API exposed by Cleanup only. (That is, do not offer ControllerClient and NodeClient directly anymore.) - Register Cleanup.Cleanup in AfterEach where missing. - Drop cleanup steps from various tests as this is now being taken care of by Cleanup. - Use Must* equivalents were applicable. - Use HaveLen to simplify length assertions. - Make order of Cleanup variable initialization consistent. - Minor cosmetic improvements.
- Loading branch information
1 parent
b91f254
commit 92973ec
Showing
3 changed files
with
376 additions
and
823 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.