Merge pull request #18445 from resouer/fix-emptydir

Auto commit by PR queue bot
This commit is contained in:
k8s-merge-robot
2016-01-26 02:45:54 -08:00
13 changed files with 334 additions and 65 deletions

View File

@@ -32,17 +32,18 @@ import (
"k8s.io/kubernetes/pkg/volume/empty_dir"
)
func newTestHost(t *testing.T) volume.VolumeHost {
func newTestHost(t *testing.T) (string, volume.VolumeHost) {
tempDir, err := ioutil.TempDir("/tmp", "git_repo_test.")
if err != nil {
t.Fatalf("can't make a temp rootdir: %v", err)
}
return volume.NewFakeVolumeHost(tempDir, nil, empty_dir.ProbeVolumePlugins())
return tempDir, volume.NewFakeVolumeHost(tempDir, nil, empty_dir.ProbeVolumePlugins())
}
func TestCanSupport(t *testing.T) {
plugMgr := volume.VolumePluginMgr{}
plugMgr.InitPlugins(ProbeVolumePlugins(), newTestHost(t))
_, host := newTestHost(t)
plugMgr.InitPlugins(ProbeVolumePlugins(), host)
plug, err := plugMgr.FindPluginByName("kubernetes.io/git-repo")
if err != nil {
@@ -218,7 +219,8 @@ func doTestPlugin(scenario struct {
allErrs := []error{}
plugMgr := volume.VolumePluginMgr{}
plugMgr.InitPlugins(ProbeVolumePlugins(), newTestHost(t))
rootDir, host := newTestHost(t)
plugMgr.InitPlugins(ProbeVolumePlugins(), host)
plug, err := plugMgr.FindPluginByName("kubernetes.io/git-repo")
if err != nil {
@@ -241,7 +243,8 @@ func doTestPlugin(scenario struct {
}
path := builder.GetPath()
if !strings.HasSuffix(path, "pods/poduid/volumes/kubernetes.io~git-repo/vol1") {
suffix := fmt.Sprintf("pods/poduid/volumes/kubernetes.io~git-repo/%v", scenario.vol.Name)
if !strings.HasSuffix(path, suffix) {
allErrs = append(allErrs,
fmt.Errorf("Got unexpected path: %s", path))
return allErrs
@@ -263,6 +266,19 @@ func doTestPlugin(scenario struct {
}
}
// gitRepo volume should create its own empty wrapper path
podWrapperMetadataDir := fmt.Sprintf("%v/pods/poduid/plugins/kubernetes.io~empty-dir/wrapped_%v", rootDir, scenario.vol.Name)
if _, err := os.Stat(podWrapperMetadataDir); err != nil {
if os.IsNotExist(err) {
allErrs = append(allErrs,
fmt.Errorf("SetUp() failed, empty-dir wrapper path is not created: %s", podWrapperMetadataDir))
} else {
allErrs = append(allErrs,
fmt.Errorf("SetUp() failed: %v", err))
}
}
cleaner, err := plug.NewCleaner("vol1", types.UID("poduid"))
if err != nil {
allErrs = append(allErrs,