mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Merge pull request #15475 from jijun2/fix-cni_test
Auto commit by PR queue bot
This commit is contained in:
commit
c4779fbc4f
@ -42,10 +42,15 @@ import (
|
||||
)
|
||||
|
||||
// The temp dir where test plugins will be stored.
|
||||
const testNetworkConfigPath = "/tmp/fake/plugins/net/cni"
|
||||
const testVendorCNIDirPrefix = "/tmp"
|
||||
func tmpDirOrDie() string {
|
||||
dir, err := ioutil.TempDir(os.TempDir(), "cni-test")
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("error creating tmp dir: %v", err))
|
||||
}
|
||||
return dir
|
||||
}
|
||||
|
||||
func installPluginUnderTest(t *testing.T, vendorName string, plugName string) {
|
||||
func installPluginUnderTest(t *testing.T, testVendorCNIDirPrefix, testNetworkConfigPath, vendorName string, plugName string) {
|
||||
pluginDir := path.Join(testNetworkConfigPath, plugName)
|
||||
err := os.MkdirAll(pluginDir, 0777)
|
||||
if err != nil {
|
||||
@ -106,13 +111,8 @@ echo -n "{ \"ip4\": { \"ip\": \"10.1.0.23/24\" } }"
|
||||
f.Close()
|
||||
}
|
||||
|
||||
func tearDownPlugin(plugName string, vendorName string) {
|
||||
err := os.RemoveAll(testNetworkConfigPath)
|
||||
if err != nil {
|
||||
fmt.Printf("Error in cleaning up test: %v", err)
|
||||
}
|
||||
vendorCNIDir := fmt.Sprintf(VendorCNIDirTemplate, testVendorCNIDirPrefix, vendorName)
|
||||
err = os.RemoveAll(vendorCNIDir)
|
||||
func tearDownPlugin(tmpDir string) {
|
||||
err := os.RemoveAll(tmpDir)
|
||||
if err != nil {
|
||||
fmt.Printf("Error in cleaning up test: %v", err)
|
||||
}
|
||||
@ -170,8 +170,12 @@ func TestCNIPlugin(t *testing.T) {
|
||||
// install some random plugin
|
||||
pluginName := fmt.Sprintf("test%d", rand.Intn(1000))
|
||||
vendorName := fmt.Sprintf("test_vendor%d", rand.Intn(1000))
|
||||
defer tearDownPlugin(pluginName, vendorName)
|
||||
installPluginUnderTest(t, vendorName, pluginName)
|
||||
|
||||
tmpDir := tmpDirOrDie()
|
||||
testNetworkConfigPath := path.Join(tmpDir, "plugins", "net", "cni")
|
||||
testVendorCNIDirPrefix := tmpDir
|
||||
defer tearDownPlugin(tmpDir)
|
||||
installPluginUnderTest(t, testVendorCNIDirPrefix, testNetworkConfigPath, vendorName, pluginName)
|
||||
|
||||
np := probeNetworkPluginsWithVendorCNIDirPrefix(path.Join(testNetworkConfigPath, pluginName), testVendorCNIDirPrefix)
|
||||
plug, err := network.InitNetworkPlugin(np, "cni", NewFakeHost(nil))
|
||||
|
@ -17,6 +17,8 @@ limitations under the License.
|
||||
package kubelet
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -36,9 +38,13 @@ func TestRunOnce(t *testing.T) {
|
||||
podManager := kubepod.NewBasicPodManager(kubepod.NewFakeMirrorClient())
|
||||
diskSpaceManager, _ := newDiskSpaceManager(cadvisor, DiskSpacePolicy{})
|
||||
fakeRuntime := &kubecontainer.FakeRuntime{}
|
||||
|
||||
basePath, err := ioutil.TempDir(os.TempDir(), "kubelet")
|
||||
if err != nil {
|
||||
t.Fatalf("can't make a temp rootdir %v", err)
|
||||
}
|
||||
defer os.RemoveAll(basePath)
|
||||
kb := &Kubelet{
|
||||
rootDirectory: "/tmp/kubelet",
|
||||
rootDirectory: basePath,
|
||||
recorder: &record.FakeRecorder{},
|
||||
cadvisor: cadvisor,
|
||||
nodeLister: testNodeLister{},
|
||||
|
@ -17,7 +17,9 @@ limitations under the License.
|
||||
package aws_ebs
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
@ -29,8 +31,13 @@ import (
|
||||
)
|
||||
|
||||
func TestCanSupport(t *testing.T) {
|
||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "awsebsTest")
|
||||
if err != nil {
|
||||
t.Fatalf("can't make a temp dir: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
plugMgr := volume.VolumePluginMgr{}
|
||||
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", nil, nil))
|
||||
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost(tmpDir, nil, nil))
|
||||
|
||||
plug, err := plugMgr.FindPluginByName("kubernetes.io/aws-ebs")
|
||||
if err != nil {
|
||||
@ -48,8 +55,13 @@ func TestCanSupport(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetAccessModes(t *testing.T) {
|
||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "awsebsTest")
|
||||
if err != nil {
|
||||
t.Fatalf("can't make a temp dir: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
plugMgr := volume.VolumePluginMgr{}
|
||||
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", nil, nil))
|
||||
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost(tmpDir, nil, nil))
|
||||
|
||||
plug, err := plugMgr.FindPersistentPluginByName("kubernetes.io/aws-ebs")
|
||||
if err != nil {
|
||||
@ -95,8 +107,13 @@ func (fake *fakePDManager) DetachDisk(c *awsElasticBlockStoreCleaner) error {
|
||||
}
|
||||
|
||||
func TestPlugin(t *testing.T) {
|
||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "awsebsTest")
|
||||
if err != nil {
|
||||
t.Fatalf("can't make a temp dir: %v")
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
plugMgr := volume.VolumePluginMgr{}
|
||||
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", nil, nil))
|
||||
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost(tmpDir, nil, nil))
|
||||
|
||||
plug, err := plugMgr.FindPluginByName("kubernetes.io/aws-ebs")
|
||||
if err != nil {
|
||||
@ -118,9 +135,9 @@ func TestPlugin(t *testing.T) {
|
||||
if builder == nil {
|
||||
t.Errorf("Got a nil Builder")
|
||||
}
|
||||
|
||||
volPath := path.Join(tmpDir, "pods/poduid/volumes/kubernetes.io~aws-ebs/vol1")
|
||||
path := builder.GetPath()
|
||||
if path != "/tmp/fake/pods/poduid/volumes/kubernetes.io~aws-ebs/vol1" {
|
||||
if path != volPath {
|
||||
t.Errorf("Got unexpected path: %s", path)
|
||||
}
|
||||
|
||||
@ -194,8 +211,13 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
|
||||
client := &testclient.Fake{}
|
||||
client.AddReactor("*", "*", testclient.ObjectReaction(o, testapi.Default.RESTMapper()))
|
||||
|
||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "awsebsTest")
|
||||
if err != nil {
|
||||
t.Fatalf("can't make a temp dir: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
plugMgr := volume.VolumePluginMgr{}
|
||||
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", client, nil))
|
||||
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost(tmpDir, client, nil))
|
||||
plug, _ := plugMgr.FindPluginByName(awsElasticBlockStorePluginName)
|
||||
|
||||
// readOnly bool is supplied by persistent-claim volume source when its builder creates other volumes
|
||||
@ -209,8 +231,13 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBuilderAndCleanerTypeAssert(t *testing.T) {
|
||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "awsebsTest")
|
||||
if err != nil {
|
||||
t.Fatalf("can't make a temp dir: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
plugMgr := volume.VolumePluginMgr{}
|
||||
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", nil, nil))
|
||||
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost(tmpDir, nil, nil))
|
||||
|
||||
plug, err := plugMgr.FindPluginByName("kubernetes.io/aws-ebs")
|
||||
if err != nil {
|
||||
|
@ -17,7 +17,9 @@ limitations under the License.
|
||||
package cephfs
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
@ -27,8 +29,13 @@ import (
|
||||
)
|
||||
|
||||
func TestCanSupport(t *testing.T) {
|
||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "cephTest")
|
||||
if err != nil {
|
||||
t.Fatalf("can't make a temp dir: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
plugMgr := volume.VolumePluginMgr{}
|
||||
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("fake", nil, nil))
|
||||
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost(tmpDir, nil, nil))
|
||||
plug, err := plugMgr.FindPluginByName("kubernetes.io/cephfs")
|
||||
if err != nil {
|
||||
t.Errorf("Can't find the plugin by name")
|
||||
@ -45,8 +52,13 @@ func TestCanSupport(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPlugin(t *testing.T) {
|
||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "cephTest")
|
||||
if err != nil {
|
||||
t.Fatalf("can't make a temp dir: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
plugMgr := volume.VolumePluginMgr{}
|
||||
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", nil, nil))
|
||||
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost(tmpDir, nil, nil))
|
||||
plug, err := plugMgr.FindPluginByName("kubernetes.io/cephfs")
|
||||
if err != nil {
|
||||
t.Errorf("Can't find the plugin by name")
|
||||
@ -71,8 +83,9 @@ func TestPlugin(t *testing.T) {
|
||||
if builder == nil {
|
||||
t.Errorf("Got a nil Builder: %v")
|
||||
}
|
||||
volpath := path.Join(tmpDir, "pods/poduid/volumes/kubernetes.io~cephfs/vol1")
|
||||
path := builder.GetPath()
|
||||
if path != "/tmp/fake/pods/poduid/volumes/kubernetes.io~cephfs/vol1" {
|
||||
if path != volpath {
|
||||
t.Errorf("Got unexpected path: %s", path)
|
||||
}
|
||||
if err := builder.SetUp(); err != nil {
|
||||
|
@ -17,7 +17,9 @@ limitations under the License.
|
||||
package cinder
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
@ -27,8 +29,13 @@ import (
|
||||
)
|
||||
|
||||
func TestCanSupport(t *testing.T) {
|
||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "cinderTest")
|
||||
if err != nil {
|
||||
t.Fatalf("can't make a temp dir: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
plugMgr := volume.VolumePluginMgr{}
|
||||
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", nil, nil))
|
||||
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost(tmpDir, nil, nil))
|
||||
|
||||
plug, err := plugMgr.FindPluginByName("kubernetes.io/cinder")
|
||||
if err != nil {
|
||||
@ -67,8 +74,13 @@ func (fake *fakePDManager) DetachDisk(c *cinderVolumeCleaner) error {
|
||||
}
|
||||
|
||||
func TestPlugin(t *testing.T) {
|
||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "cinderTest")
|
||||
if err != nil {
|
||||
t.Fatalf("can't make a temp dir: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
plugMgr := volume.VolumePluginMgr{}
|
||||
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", nil, nil))
|
||||
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost(tmpDir, nil, nil))
|
||||
|
||||
plug, err := plugMgr.FindPluginByName("kubernetes.io/cinder")
|
||||
if err != nil {
|
||||
@ -90,9 +102,9 @@ func TestPlugin(t *testing.T) {
|
||||
if builder == nil {
|
||||
t.Errorf("Got a nil Builder: %v")
|
||||
}
|
||||
|
||||
volPath := path.Join(tmpDir, "pods/poduid/volumes/kubernetes.io~cinder/vol1")
|
||||
path := builder.GetPath()
|
||||
if path != "/tmp/fake/pods/poduid/volumes/kubernetes.io~cinder/vol1" {
|
||||
if path != volPath {
|
||||
t.Errorf("Got unexpected path: %s", path)
|
||||
}
|
||||
|
||||
|
@ -31,8 +31,6 @@ import (
|
||||
"k8s.io/kubernetes/pkg/volume/empty_dir"
|
||||
)
|
||||
|
||||
const basePath = "/tmp/fake"
|
||||
|
||||
func formatMap(m map[string]string) (fmtstr string) {
|
||||
for key, value := range m {
|
||||
fmtstr += fmt.Sprintf("%v=%q\n", key, value)
|
||||
@ -41,7 +39,7 @@ func formatMap(m map[string]string) (fmtstr string) {
|
||||
return
|
||||
}
|
||||
|
||||
func newTestHost(t *testing.T, client client.Interface) volume.VolumeHost {
|
||||
func newTestHost(t *testing.T, client client.Interface, basePath string) volume.VolumeHost {
|
||||
tempDir, err := ioutil.TempDir(basePath, "downwardApi_volume_test.")
|
||||
if err != nil {
|
||||
t.Fatalf("can't make a temp rootdir: %v", err)
|
||||
@ -50,8 +48,13 @@ func newTestHost(t *testing.T, client client.Interface) volume.VolumeHost {
|
||||
}
|
||||
|
||||
func TestCanSupport(t *testing.T) {
|
||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "downwardapiTest")
|
||||
if err != nil {
|
||||
t.Fatalf("can't make a temp dir: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
pluginMgr := volume.VolumePluginMgr{}
|
||||
pluginMgr.InitPlugins(ProbeVolumePlugins(), newTestHost(t, nil))
|
||||
pluginMgr.InitPlugins(ProbeVolumePlugins(), newTestHost(t, nil, tmpDir))
|
||||
|
||||
plugin, err := pluginMgr.FindPluginByName(downwardAPIPluginName)
|
||||
if err != nil {
|
||||
@ -100,8 +103,14 @@ func TestLabels(t *testing.T) {
|
||||
Labels: labels,
|
||||
},
|
||||
})
|
||||
|
||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "downwardapiTest")
|
||||
if err != nil {
|
||||
t.Fatalf("can't make a temp dir: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
pluginMgr := volume.VolumePluginMgr{}
|
||||
pluginMgr.InitPlugins(ProbeVolumePlugins(), newTestHost(t, fake))
|
||||
pluginMgr.InitPlugins(ProbeVolumePlugins(), newTestHost(t, fake, tmpDir))
|
||||
plugin, err := pluginMgr.FindPluginByName(downwardAPIPluginName)
|
||||
volumeSpec := &api.Volume{
|
||||
Name: testVolumeName,
|
||||
@ -174,8 +183,13 @@ func TestAnnotations(t *testing.T) {
|
||||
},
|
||||
})
|
||||
|
||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "downwardapiTest")
|
||||
if err != nil {
|
||||
t.Fatalf("can't make a temp dir: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
pluginMgr := volume.VolumePluginMgr{}
|
||||
pluginMgr.InitPlugins(ProbeVolumePlugins(), newTestHost(t, fake))
|
||||
pluginMgr.InitPlugins(ProbeVolumePlugins(), newTestHost(t, fake, tmpDir))
|
||||
plugin, err := pluginMgr.FindPluginByName(downwardAPIPluginName)
|
||||
if err != nil {
|
||||
t.Errorf("Can't find the plugin by name")
|
||||
@ -234,8 +248,13 @@ func TestName(t *testing.T) {
|
||||
},
|
||||
})
|
||||
|
||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "downwardapiTest")
|
||||
if err != nil {
|
||||
t.Fatalf("can't make a temp dir: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
pluginMgr := volume.VolumePluginMgr{}
|
||||
pluginMgr.InitPlugins(ProbeVolumePlugins(), newTestHost(t, fake))
|
||||
pluginMgr.InitPlugins(ProbeVolumePlugins(), newTestHost(t, fake, tmpDir))
|
||||
plugin, err := pluginMgr.FindPluginByName(downwardAPIPluginName)
|
||||
if err != nil {
|
||||
t.Errorf("Can't find the plugin by name")
|
||||
@ -295,8 +314,13 @@ func TestNamespace(t *testing.T) {
|
||||
},
|
||||
})
|
||||
|
||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "downwardapiTest")
|
||||
if err != nil {
|
||||
t.Fatalf("can't make a temp dir: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
pluginMgr := volume.VolumePluginMgr{}
|
||||
pluginMgr.InitPlugins(ProbeVolumePlugins(), newTestHost(t, fake))
|
||||
pluginMgr.InitPlugins(ProbeVolumePlugins(), newTestHost(t, fake, tmpDir))
|
||||
plugin, err := pluginMgr.FindPluginByName(downwardAPIPluginName)
|
||||
if err != nil {
|
||||
t.Errorf("Can't find the plugin by name")
|
||||
@ -349,8 +373,13 @@ func TestWriteTwiceNoUpdate(t *testing.T) {
|
||||
Labels: labels,
|
||||
},
|
||||
})
|
||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "downwardapiTest")
|
||||
if err != nil {
|
||||
t.Fatalf("can't make a temp dir: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
pluginMgr := volume.VolumePluginMgr{}
|
||||
pluginMgr.InitPlugins(ProbeVolumePlugins(), newTestHost(t, fake))
|
||||
pluginMgr.InitPlugins(ProbeVolumePlugins(), newTestHost(t, fake, tmpDir))
|
||||
plugin, err := pluginMgr.FindPluginByName(downwardAPIPluginName)
|
||||
volumeSpec := &api.Volume{
|
||||
Name: testVolumeName,
|
||||
@ -433,8 +462,13 @@ func TestWriteTwiceWithUpdate(t *testing.T) {
|
||||
Labels: labels,
|
||||
},
|
||||
})
|
||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "downwardapiTest")
|
||||
if err != nil {
|
||||
t.Fatalf("can't make a temp dir: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
pluginMgr := volume.VolumePluginMgr{}
|
||||
pluginMgr.InitPlugins(ProbeVolumePlugins(), newTestHost(t, fake))
|
||||
pluginMgr.InitPlugins(ProbeVolumePlugins(), newTestHost(t, fake, tmpDir))
|
||||
plugin, err := pluginMgr.FindPluginByName(downwardAPIPluginName)
|
||||
volumeSpec := &api.Volume{
|
||||
Name: testVolumeName,
|
||||
@ -537,8 +571,13 @@ func TestWriteWithUnixPath(t *testing.T) {
|
||||
},
|
||||
})
|
||||
|
||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "downwardapiTest")
|
||||
if err != nil {
|
||||
t.Fatalf("can't make a temp dir: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
pluginMgr := volume.VolumePluginMgr{}
|
||||
pluginMgr.InitPlugins(ProbeVolumePlugins(), newTestHost(t, fake))
|
||||
pluginMgr.InitPlugins(ProbeVolumePlugins(), newTestHost(t, fake, tmpDir))
|
||||
plugin, err := pluginMgr.FindPluginByName(downwardAPIPluginName)
|
||||
volumeSpec := &api.Volume{
|
||||
Name: testVolumeName,
|
||||
@ -611,8 +650,13 @@ func TestWriteWithUnixPathBadPath(t *testing.T) {
|
||||
},
|
||||
})
|
||||
|
||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "downwardapiTest")
|
||||
if err != nil {
|
||||
t.Fatalf("can't make a temp dir")
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
pluginMgr := volume.VolumePluginMgr{}
|
||||
pluginMgr.InitPlugins(ProbeVolumePlugins(), newTestHost(t, fake))
|
||||
pluginMgr.InitPlugins(ProbeVolumePlugins(), newTestHost(t, fake, tmpDir))
|
||||
plugin, err := pluginMgr.FindPluginByName(downwardAPIPluginName)
|
||||
if err != nil {
|
||||
t.Errorf("Can't find the plugin by name")
|
||||
|
@ -42,7 +42,12 @@ func makePluginUnderTest(t *testing.T, plugName, basePath string) volume.VolumeP
|
||||
}
|
||||
|
||||
func TestCanSupport(t *testing.T) {
|
||||
plug := makePluginUnderTest(t, "kubernetes.io/empty-dir", "/tmp/fake")
|
||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "emptydirTest")
|
||||
if err != nil {
|
||||
t.Fatalf("can't make a temp dir: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
plug := makePluginUnderTest(t, "kubernetes.io/empty-dir", tmpDir)
|
||||
|
||||
if plug.Name() != "kubernetes.io/empty-dir" {
|
||||
t.Errorf("Wrong name: %s", plug.Name())
|
||||
@ -135,10 +140,11 @@ type pluginTestConfig struct {
|
||||
|
||||
// doTestPlugin sets up a volume and tears it back down.
|
||||
func doTestPlugin(t *testing.T, config pluginTestConfig) {
|
||||
basePath, err := ioutil.TempDir("/tmp", "emptydir_volume_test")
|
||||
basePath, err := ioutil.TempDir(os.TempDir(), "emptydir_volume_test")
|
||||
if err != nil {
|
||||
t.Fatalf("can't make a temp rootdir")
|
||||
t.Fatalf("can't make a temp rootdir: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(basePath)
|
||||
|
||||
var (
|
||||
volumePath = path.Join(basePath, "pods/poduid/volumes/kubernetes.io~empty-dir/test-volume")
|
||||
@ -281,7 +287,12 @@ func doTestPlugin(t *testing.T, config pluginTestConfig) {
|
||||
}
|
||||
|
||||
func TestPluginBackCompat(t *testing.T) {
|
||||
basePath := "/tmp/fake"
|
||||
basePath, err := ioutil.TempDir(os.TempDir(), "emptydirTest")
|
||||
if err != nil {
|
||||
t.Fatalf("can't make a temp dir: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(basePath)
|
||||
|
||||
plug := makePluginUnderTest(t, "kubernetes.io/empty-dir", basePath)
|
||||
|
||||
spec := &api.Volume{
|
||||
|
@ -17,7 +17,9 @@ limitations under the License.
|
||||
package gce_pd
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
@ -29,8 +31,13 @@ import (
|
||||
)
|
||||
|
||||
func TestCanSupport(t *testing.T) {
|
||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "gcepdTest")
|
||||
if err != nil {
|
||||
t.Fatalf("can't make a temp dir: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
plugMgr := volume.VolumePluginMgr{}
|
||||
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", nil, nil))
|
||||
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost(tmpDir, nil, nil))
|
||||
|
||||
plug, err := plugMgr.FindPluginByName("kubernetes.io/gce-pd")
|
||||
if err != nil {
|
||||
@ -48,8 +55,13 @@ func TestCanSupport(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetAccessModes(t *testing.T) {
|
||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "gcepdTest")
|
||||
if err != nil {
|
||||
t.Fatalf("can't make a temp dir: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
plugMgr := volume.VolumePluginMgr{}
|
||||
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", nil, nil))
|
||||
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost(tmpDir, nil, nil))
|
||||
|
||||
plug, err := plugMgr.FindPersistentPluginByName("kubernetes.io/gce-pd")
|
||||
if err != nil {
|
||||
@ -100,8 +112,13 @@ func (fake *fakePDManager) DetachDisk(c *gcePersistentDiskCleaner) error {
|
||||
}
|
||||
|
||||
func TestPlugin(t *testing.T) {
|
||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "gcepdTest")
|
||||
if err != nil {
|
||||
t.Fatalf("can't make a temp dir: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
plugMgr := volume.VolumePluginMgr{}
|
||||
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", nil, nil))
|
||||
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost(tmpDir, nil, nil))
|
||||
|
||||
plug, err := plugMgr.FindPluginByName("kubernetes.io/gce-pd")
|
||||
if err != nil {
|
||||
@ -126,8 +143,9 @@ func TestPlugin(t *testing.T) {
|
||||
t.Errorf("Got a nil Builder")
|
||||
}
|
||||
|
||||
volPath := path.Join(tmpDir, "pods/poduid/volumes/kubernetes.io~gce-pd/vol1")
|
||||
path := builder.GetPath()
|
||||
if path != "/tmp/fake/pods/poduid/volumes/kubernetes.io~gce-pd/vol1" {
|
||||
if path != volPath {
|
||||
t.Errorf("Got unexpected path: %s", path)
|
||||
}
|
||||
|
||||
@ -208,8 +226,13 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
|
||||
client := &testclient.Fake{}
|
||||
client.AddReactor("*", "*", testclient.ObjectReaction(o, testapi.Default.RESTMapper()))
|
||||
|
||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "gcepdTest")
|
||||
if err != nil {
|
||||
t.Fatalf("can't make a temp dir: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
plugMgr := volume.VolumePluginMgr{}
|
||||
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", client, nil))
|
||||
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost(tmpDir, client, nil))
|
||||
plug, _ := plugMgr.FindPluginByName(gcePersistentDiskPluginName)
|
||||
|
||||
// readOnly bool is supplied by persistent-claim volume source when its builder creates other volumes
|
||||
|
Loading…
Reference in New Issue
Block a user