-
Notifications
You must be signed in to change notification settings - Fork 146
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
Make mount and staging dir creation flexible #159
Merged
k8s-ci-robot
merged 4 commits into
kubernetes-csi:master
from
darkowlzz:flexible-target-dirs
Mar 20, 2019
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4000ec5
Make mount and staging dir creation flexible
darkowlzz cbc42e8
Add target path checks and rm paths at teardown
darkowlzz a9b0016
Add command line support for custom target paths
darkowlzz 506d128
Add support for custom target path removal
darkowlzz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package apitest2 | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path" | ||
"testing" | ||
|
||
"github.com/kubernetes-csi/csi-test/pkg/sanity" | ||
) | ||
|
||
// TestMyDriverWithCustomTargetPaths verifies that CreateTargetDir and | ||
// CreateStagingDir are called a specific number of times. | ||
func TestMyDriverWithCustomTargetPaths(t *testing.T) { | ||
var createTargetDirCalls, createStagingDirCalls, | ||
removeTargetDirCalls, removeStagingDirCalls int | ||
|
||
wantCreateTargetCalls := 3 | ||
wantCreateStagingCalls := 3 | ||
wantRemoveTargetCalls := 3 | ||
wantRemoveStagingCalls := 3 | ||
|
||
// tmpPath could be a CO specific directory under which all the target dirs | ||
// are created. For k8s, it could be /var/lib/kubelet/pods under which the | ||
// mount directories could be created. | ||
tmpPath := path.Join(os.TempDir(), "csi") | ||
config := &sanity.Config{ | ||
TargetPath: "foo/target/mount", | ||
StagingPath: "foo/staging/mount", | ||
Address: "/tmp/e2e-csi-sanity.sock", | ||
CreateTargetDir: func(targetPath string) (string, error) { | ||
createTargetDirCalls++ | ||
targetPath = path.Join(tmpPath, targetPath) | ||
return targetPath, createTargetDir(targetPath) | ||
}, | ||
CreateStagingDir: func(targetPath string) (string, error) { | ||
createStagingDirCalls++ | ||
targetPath = path.Join(tmpPath, targetPath) | ||
return targetPath, createTargetDir(targetPath) | ||
}, | ||
RemoveTargetPath: func(targetPath string) error { | ||
removeTargetDirCalls++ | ||
return os.RemoveAll(targetPath) | ||
}, | ||
RemoveStagingPath: func(targetPath string) error { | ||
removeStagingDirCalls++ | ||
return os.RemoveAll(targetPath) | ||
}, | ||
} | ||
|
||
sanity.Test(t, config) | ||
|
||
if createTargetDirCalls != wantCreateTargetCalls { | ||
t.Errorf("unexpected number of CreateTargetDir calls:\n(WNT) %d\n(GOT) %d", wantCreateTargetCalls, createTargetDirCalls) | ||
} | ||
|
||
if createStagingDirCalls != wantCreateStagingCalls { | ||
t.Errorf("unexpected number of CreateStagingDir calls:\n(WNT) %d\n(GOT) %d", wantCreateStagingCalls, createStagingDirCalls) | ||
} | ||
|
||
if removeTargetDirCalls != wantRemoveTargetCalls { | ||
t.Errorf("unexpected number of RemoveTargetDir calls:\n(WNT) %d\n(GOT) %d", wantRemoveTargetCalls, removeTargetDirCalls) | ||
} | ||
|
||
if removeStagingDirCalls != wantRemoveStagingCalls { | ||
t.Errorf("unexpected number of RemoveStagingDir calls:\n(WNT) %d\n(GOT) %d", wantRemoveStagingCalls, removeStagingDirCalls) | ||
} | ||
} | ||
|
||
func createTargetDir(targetPath string) error { | ||
fileInfo, err := os.Stat(targetPath) | ||
if err != nil && os.IsNotExist(err) { | ||
return os.MkdirAll(targetPath, 0755) | ||
} else if err != nil { | ||
return err | ||
} | ||
if !fileInfo.IsDir() { | ||
return fmt.Errorf("Target location %s is not a directory", targetPath) | ||
} | ||
|
||
return nil | ||
} |
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
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
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't actually verify that
CreateTargetDir
andCreateStagingDir
are getting used as intended, does it?Admittedly a thorough check is hard, but perhaps record inside
createTargetDir
that it was called and then add some asserts against that aftersanity.Test
returns? If you invoke_apitest2/api_test.go
with-test.run
such that it executes a well-known set of tests, it might even become possible to have a deterministic set of created directories to compare against.