mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Merge pull request #20111 from fabioy/fix-tmp-tests
Add temp directory creation method for tests.
This commit is contained in:
commit
eb2c2d1af4
@ -40,6 +40,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/kubelet/dockertools"
|
"k8s.io/kubernetes/pkg/kubelet/dockertools"
|
||||||
"k8s.io/kubernetes/pkg/runtime"
|
"k8s.io/kubernetes/pkg/runtime"
|
||||||
"k8s.io/kubernetes/pkg/util"
|
"k8s.io/kubernetes/pkg/util"
|
||||||
|
utiltesting "k8s.io/kubernetes/pkg/util/testing"
|
||||||
"k8s.io/kubernetes/pkg/watch"
|
"k8s.io/kubernetes/pkg/watch"
|
||||||
|
|
||||||
"github.com/mesos/mesos-go/mesosproto"
|
"github.com/mesos/mesos-go/mesosproto"
|
||||||
@ -288,7 +289,7 @@ func TestExecutorLaunchAndKillTask(t *testing.T) {
|
|||||||
// as a zip archive with pod definitions.
|
// as a zip archive with pod definitions.
|
||||||
func TestExecutorInitializeStaticPodsSource(t *testing.T) {
|
func TestExecutorInitializeStaticPodsSource(t *testing.T) {
|
||||||
// create some zip with static pod definition
|
// create some zip with static pod definition
|
||||||
givenPodsDir, err := ioutil.TempDir("/tmp", "executor-givenpods")
|
givenPodsDir, err := utiltesting.MkTmpdir("executor-givenpods")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer os.RemoveAll(givenPodsDir)
|
defer os.RemoveAll(givenPodsDir)
|
||||||
|
|
||||||
@ -339,7 +340,7 @@ func TestExecutorInitializeStaticPodsSource(t *testing.T) {
|
|||||||
expectedStaticPodsNum := 2 // subdirectories are ignored by FileSource, hence only 2
|
expectedStaticPodsNum := 2 // subdirectories are ignored by FileSource, hence only 2
|
||||||
|
|
||||||
// temporary directory which is normally located in the executor sandbox
|
// temporary directory which is normally located in the executor sandbox
|
||||||
staticPodsConfigPath, err := ioutil.TempDir("/tmp", "executor-k8sm-archive")
|
staticPodsConfigPath, err := utiltesting.MkTmpdir("executor-k8sm-archive")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer os.RemoveAll(staticPodsConfigPath)
|
defer os.RemoveAll(staticPodsConfigPath)
|
||||||
|
|
||||||
|
@ -10,4 +10,4 @@ spec:
|
|||||||
accessModes:
|
accessModes:
|
||||||
- ReadWriteOnce
|
- ReadWriteOnce
|
||||||
hostPath:
|
hostPath:
|
||||||
path: "/tmp/data01"
|
path: "/somepath/data01"
|
||||||
|
@ -10,5 +10,5 @@ spec:
|
|||||||
accessModes:
|
accessModes:
|
||||||
- ReadWriteOnce
|
- ReadWriteOnce
|
||||||
hostPath:
|
hostPath:
|
||||||
path: "/tmp/data02"
|
path: "/somepath/data02"
|
||||||
persistentVolumeReclaimPolicy: Recycle
|
persistentVolumeReclaimPolicy: Recycle
|
||||||
|
@ -8,5 +8,5 @@ spec:
|
|||||||
accessModes:
|
accessModes:
|
||||||
- ReadWriteOnce
|
- ReadWriteOnce
|
||||||
nfs:
|
nfs:
|
||||||
path: /tmp
|
path: /somepath
|
||||||
server: 172.17.0.2
|
server: 172.17.0.2
|
||||||
|
@ -105,7 +105,7 @@ const (
|
|||||||
"finished_tasks": 0,
|
"finished_tasks": 0,
|
||||||
"flags": {
|
"flags": {
|
||||||
"zk_session_timeout": "10secs",
|
"zk_session_timeout": "10secs",
|
||||||
"work_dir": "/tmp/mesos/local/Lc9arz",
|
"work_dir": "/somepath/mesos/local/Lc9arz",
|
||||||
"webui_dir": "/usr/local/share/mesos/webui",
|
"webui_dir": "/usr/local/share/mesos/webui",
|
||||||
"version": "false",
|
"version": "false",
|
||||||
"user_sorter": "drf",
|
"user_sorter": "drf",
|
||||||
|
@ -17,6 +17,8 @@ limitations under the License.
|
|||||||
package persistentvolume
|
package persistentvolume
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -27,6 +29,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/api/testapi"
|
"k8s.io/kubernetes/pkg/api/testapi"
|
||||||
"k8s.io/kubernetes/pkg/client/cache"
|
"k8s.io/kubernetes/pkg/client/cache"
|
||||||
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
||||||
|
utiltesting "k8s.io/kubernetes/pkg/util/testing"
|
||||||
"k8s.io/kubernetes/pkg/volume"
|
"k8s.io/kubernetes/pkg/volume"
|
||||||
"k8s.io/kubernetes/pkg/volume/host_path"
|
"k8s.io/kubernetes/pkg/volume/host_path"
|
||||||
)
|
)
|
||||||
@ -53,6 +56,11 @@ func TestRunStop(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestClaimRace(t *testing.T) {
|
func TestClaimRace(t *testing.T) {
|
||||||
|
tmpDir, err := utiltesting.MkTmpdir("claimbinder-test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error creating temp dir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
c1 := &api.PersistentVolumeClaim{
|
c1 := &api.PersistentVolumeClaim{
|
||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
Name: "c1",
|
Name: "c1",
|
||||||
@ -100,7 +108,7 @@ func TestClaimRace(t *testing.T) {
|
|||||||
},
|
},
|
||||||
PersistentVolumeSource: api.PersistentVolumeSource{
|
PersistentVolumeSource: api.PersistentVolumeSource{
|
||||||
HostPath: &api.HostPathVolumeSource{
|
HostPath: &api.HostPathVolumeSource{
|
||||||
Path: "/tmp/data01",
|
Path: fmt.Sprintf("%s/data01", tmpDir),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -113,7 +121,7 @@ func TestClaimRace(t *testing.T) {
|
|||||||
mockClient := &mockBinderClient{}
|
mockClient := &mockBinderClient{}
|
||||||
|
|
||||||
plugMgr := volume.VolumePluginMgr{}
|
plugMgr := volume.VolumePluginMgr{}
|
||||||
plugMgr.InitPlugins(host_path.ProbeRecyclableVolumePlugins(newMockRecycler, volume.VolumeConfig{}), volume.NewFakeVolumeHost("/tmp/fake", nil, nil))
|
plugMgr.InitPlugins(host_path.ProbeRecyclableVolumePlugins(newMockRecycler, volume.VolumeConfig{}), volume.NewFakeVolumeHost(tmpDir, nil, nil))
|
||||||
|
|
||||||
// adds the volume to the index, making the volume available
|
// adds the volume to the index, making the volume available
|
||||||
syncVolume(volumeIndex, mockClient, v)
|
syncVolume(volumeIndex, mockClient, v)
|
||||||
@ -125,7 +133,7 @@ func TestClaimRace(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// an initial sync for a claim matches the volume
|
// an initial sync for a claim matches the volume
|
||||||
err := syncClaim(volumeIndex, mockClient, c1)
|
err = syncClaim(volumeIndex, mockClient, c1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unexpected error: %v", err)
|
t.Errorf("Unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
@ -144,6 +152,12 @@ func TestClaimRace(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestClaimSyncAfterVolumeProvisioning(t *testing.T) {
|
func TestClaimSyncAfterVolumeProvisioning(t *testing.T) {
|
||||||
|
tmpDir, err := utiltesting.MkTmpdir("claimbinder-test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error creating temp dir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
// Tests that binder.syncVolume will also syncClaim if the PV has completed
|
// Tests that binder.syncVolume will also syncClaim if the PV has completed
|
||||||
// provisioning but the claim is still Pending. We want to advance to Bound
|
// provisioning but the claim is still Pending. We want to advance to Bound
|
||||||
// without having to wait until the binder's next sync period.
|
// without having to wait until the binder's next sync period.
|
||||||
@ -184,7 +198,7 @@ func TestClaimSyncAfterVolumeProvisioning(t *testing.T) {
|
|||||||
},
|
},
|
||||||
PersistentVolumeSource: api.PersistentVolumeSource{
|
PersistentVolumeSource: api.PersistentVolumeSource{
|
||||||
HostPath: &api.HostPathVolumeSource{
|
HostPath: &api.HostPathVolumeSource{
|
||||||
Path: "/tmp/data01",
|
Path: fmt.Sprintf("%s/data01", tmpDir),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
ClaimRef: claimRef,
|
ClaimRef: claimRef,
|
||||||
@ -200,7 +214,7 @@ func TestClaimSyncAfterVolumeProvisioning(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
plugMgr := volume.VolumePluginMgr{}
|
plugMgr := volume.VolumePluginMgr{}
|
||||||
plugMgr.InitPlugins(host_path.ProbeRecyclableVolumePlugins(newMockRecycler, volume.VolumeConfig{}), volume.NewFakeVolumeHost("/tmp/fake", nil, nil))
|
plugMgr.InitPlugins(host_path.ProbeRecyclableVolumePlugins(newMockRecycler, volume.VolumeConfig{}), volume.NewFakeVolumeHost(tmpDir, nil, nil))
|
||||||
|
|
||||||
// adds the volume to the index, making the volume available.
|
// adds the volume to the index, making the volume available.
|
||||||
// pv also completed provisioning, so syncClaim should cause claim's phase to advance to Bound
|
// pv also completed provisioning, so syncClaim should cause claim's phase to advance to Bound
|
||||||
@ -250,7 +264,7 @@ func TestExampleObjects(t *testing.T) {
|
|||||||
},
|
},
|
||||||
PersistentVolumeSource: api.PersistentVolumeSource{
|
PersistentVolumeSource: api.PersistentVolumeSource{
|
||||||
HostPath: &api.HostPathVolumeSource{
|
HostPath: &api.HostPathVolumeSource{
|
||||||
Path: "/tmp/data01",
|
Path: "/somepath/data01",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -265,7 +279,7 @@ func TestExampleObjects(t *testing.T) {
|
|||||||
},
|
},
|
||||||
PersistentVolumeSource: api.PersistentVolumeSource{
|
PersistentVolumeSource: api.PersistentVolumeSource{
|
||||||
HostPath: &api.HostPathVolumeSource{
|
HostPath: &api.HostPathVolumeSource{
|
||||||
Path: "/tmp/data02",
|
Path: "/somepath/data02",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
PersistentVolumeReclaimPolicy: api.PersistentVolumeReclaimRecycle,
|
PersistentVolumeReclaimPolicy: api.PersistentVolumeReclaimRecycle,
|
||||||
@ -333,6 +347,12 @@ func TestExampleObjects(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestBindingWithExamples(t *testing.T) {
|
func TestBindingWithExamples(t *testing.T) {
|
||||||
|
tmpDir, err := utiltesting.MkTmpdir("claimbinder-test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error creating temp dir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
codec := api.Codecs.UniversalDecoder()
|
codec := api.Codecs.UniversalDecoder()
|
||||||
o := testclient.NewObjects(api.Scheme, codec)
|
o := testclient.NewObjects(api.Scheme, codec)
|
||||||
if err := testclient.AddObjectsFromPath("../../../docs/user-guide/persistent-volumes/claims/claim-01.yaml", o, codec); err != nil {
|
if err := testclient.AddObjectsFromPath("../../../docs/user-guide/persistent-volumes/claims/claim-01.yaml", o, codec); err != nil {
|
||||||
@ -370,7 +390,7 @@ func TestBindingWithExamples(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
plugMgr := volume.VolumePluginMgr{}
|
plugMgr := volume.VolumePluginMgr{}
|
||||||
plugMgr.InitPlugins(host_path.ProbeRecyclableVolumePlugins(newMockRecycler, volume.VolumeConfig{}), volume.NewFakeVolumeHost("/tmp/fake", nil, nil))
|
plugMgr.InitPlugins(host_path.ProbeRecyclableVolumePlugins(newMockRecycler, volume.VolumeConfig{}), volume.NewFakeVolumeHost(tmpDir, nil, nil))
|
||||||
|
|
||||||
recycler := &PersistentVolumeRecycler{
|
recycler := &PersistentVolumeRecycler{
|
||||||
kubeClient: client,
|
kubeClient: client,
|
||||||
|
@ -66,7 +66,7 @@ func makeTestVolume() *api.PersistentVolume {
|
|||||||
},
|
},
|
||||||
PersistentVolumeSource: api.PersistentVolumeSource{
|
PersistentVolumeSource: api.PersistentVolumeSource{
|
||||||
HostPath: &api.HostPathVolumeSource{
|
HostPath: &api.HostPathVolumeSource{
|
||||||
Path: "/tmp/data01",
|
Path: "/somepath/data01",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -34,7 +34,7 @@ func TestFailedRecycling(t *testing.T) {
|
|||||||
},
|
},
|
||||||
PersistentVolumeSource: api.PersistentVolumeSource{
|
PersistentVolumeSource: api.PersistentVolumeSource{
|
||||||
HostPath: &api.HostPathVolumeSource{
|
HostPath: &api.HostPathVolumeSource{
|
||||||
Path: "/tmp/data02",
|
Path: "/somepath/data02",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
PersistentVolumeReclaimPolicy: api.PersistentVolumeReclaimRecycle,
|
PersistentVolumeReclaimPolicy: api.PersistentVolumeReclaimRecycle,
|
||||||
|
@ -30,6 +30,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/runtime"
|
"k8s.io/kubernetes/pkg/runtime"
|
||||||
"k8s.io/kubernetes/pkg/securitycontext"
|
"k8s.io/kubernetes/pkg/securitycontext"
|
||||||
"k8s.io/kubernetes/pkg/util"
|
"k8s.io/kubernetes/pkg/util"
|
||||||
|
utiltesting "k8s.io/kubernetes/pkg/util/testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestExtractFromNonExistentFile(t *testing.T) {
|
func TestExtractFromNonExistentFile(t *testing.T) {
|
||||||
@ -174,7 +175,7 @@ func TestExtractFromBadDataFile(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestExtractFromEmptyDir(t *testing.T) {
|
func TestExtractFromEmptyDir(t *testing.T) {
|
||||||
dirName, err := ioutil.TempDir("", "foo")
|
dirName, err := utiltesting.MkTmpdir("file-test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unexpected error: %v", err)
|
t.Fatalf("Unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ func TestLabels(t *testing.T) {
|
|||||||
}
|
}
|
||||||
container := &api.Container{
|
container := &api.Container{
|
||||||
Name: "test_container",
|
Name: "test_container",
|
||||||
TerminationMessagePath: "/tmp",
|
TerminationMessagePath: "/somepath",
|
||||||
Lifecycle: lifecycle,
|
Lifecycle: lifecycle,
|
||||||
}
|
}
|
||||||
pod := &api.Pod{
|
pod := &api.Pod{
|
||||||
|
@ -39,17 +39,9 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/kubelet/network"
|
"k8s.io/kubernetes/pkg/kubelet/network"
|
||||||
proberesults "k8s.io/kubernetes/pkg/kubelet/prober/results"
|
proberesults "k8s.io/kubernetes/pkg/kubelet/prober/results"
|
||||||
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
|
kubetypes "k8s.io/kubernetes/pkg/kubelet/types"
|
||||||
|
utiltesting "k8s.io/kubernetes/pkg/util/testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
// The temp dir where test plugins will be stored.
|
|
||||||
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, testVendorCNIDirPrefix, testNetworkConfigPath, vendorName string, plugName string) {
|
func installPluginUnderTest(t *testing.T, testVendorCNIDirPrefix, testNetworkConfigPath, vendorName string, plugName string) {
|
||||||
pluginDir := path.Join(testNetworkConfigPath, plugName)
|
pluginDir := path.Join(testNetworkConfigPath, plugName)
|
||||||
err := os.MkdirAll(pluginDir, 0777)
|
err := os.MkdirAll(pluginDir, 0777)
|
||||||
@ -173,7 +165,7 @@ func TestCNIPlugin(t *testing.T) {
|
|||||||
pluginName := fmt.Sprintf("test%d", rand.Intn(1000))
|
pluginName := fmt.Sprintf("test%d", rand.Intn(1000))
|
||||||
vendorName := fmt.Sprintf("test_vendor%d", rand.Intn(1000))
|
vendorName := fmt.Sprintf("test_vendor%d", rand.Intn(1000))
|
||||||
|
|
||||||
tmpDir := tmpDirOrDie()
|
tmpDir := utiltesting.MkTmpdirOrDie("cni-test")
|
||||||
testNetworkConfigPath := path.Join(tmpDir, "plugins", "net", "cni")
|
testNetworkConfigPath := path.Join(tmpDir, "plugins", "net", "cni")
|
||||||
testVendorCNIDirPrefix := tmpDir
|
testVendorCNIDirPrefix := tmpDir
|
||||||
defer tearDownPlugin(tmpDir)
|
defer tearDownPlugin(tmpDir)
|
||||||
|
@ -31,10 +31,11 @@ import (
|
|||||||
|
|
||||||
"k8s.io/kubernetes/pkg/kubelet/network"
|
"k8s.io/kubernetes/pkg/kubelet/network"
|
||||||
"k8s.io/kubernetes/pkg/util/sets"
|
"k8s.io/kubernetes/pkg/util/sets"
|
||||||
|
utiltesting "k8s.io/kubernetes/pkg/util/testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func tmpDirOrDie() string {
|
func tmpDirOrDie() string {
|
||||||
dir, err := ioutil.TempDir(os.TempDir(), "exec-test")
|
dir, err := utiltesting.MkTmpdir("exec-test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("error creating tmp dir: %v", err))
|
panic(fmt.Sprintf("error creating tmp dir: %v", err))
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ package rkt
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -30,6 +31,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"k8s.io/kubernetes/pkg/api/resource"
|
"k8s.io/kubernetes/pkg/api/resource"
|
||||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||||
|
utiltesting "k8s.io/kubernetes/pkg/util/testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func mustMarshalPodManifest(man *appcschema.PodManifest) []byte {
|
func mustMarshalPodManifest(man *appcschema.PodManifest) []byte {
|
||||||
@ -755,6 +757,12 @@ func sortAppFields(app *appctypes.App) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSetApp(t *testing.T) {
|
func TestSetApp(t *testing.T) {
|
||||||
|
tmpDir, err := utiltesting.MkTmpdir("rkt_test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error creating temp dir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
rootUser := int64(0)
|
rootUser := int64(0)
|
||||||
nonRootUser := int64(42)
|
nonRootUser := int64(42)
|
||||||
runAsNonRootTrue := true
|
runAsNonRootTrue := true
|
||||||
@ -796,7 +804,7 @@ func TestSetApp(t *testing.T) {
|
|||||||
container: &api.Container{
|
container: &api.Container{
|
||||||
Command: []string{"/bin/bar"},
|
Command: []string{"/bin/bar"},
|
||||||
Args: []string{"hello", "world"},
|
Args: []string{"hello", "world"},
|
||||||
WorkingDir: "/tmp",
|
WorkingDir: tmpDir,
|
||||||
Resources: api.ResourceRequirements{
|
Resources: api.ResourceRequirements{
|
||||||
Limits: api.ResourceList{"cpu": resource.MustParse("50m"), "memory": resource.MustParse("50M")},
|
Limits: api.ResourceList{"cpu": resource.MustParse("50m"), "memory": resource.MustParse("50M")},
|
||||||
Requests: api.ResourceList{"cpu": resource.MustParse("5m"), "memory": resource.MustParse("5M")},
|
Requests: api.ResourceList{"cpu": resource.MustParse("5m"), "memory": resource.MustParse("5M")},
|
||||||
@ -830,7 +838,7 @@ func TestSetApp(t *testing.T) {
|
|||||||
User: "42",
|
User: "42",
|
||||||
Group: "22",
|
Group: "22",
|
||||||
SupplementaryGIDs: []int{1, 2, 3},
|
SupplementaryGIDs: []int{1, 2, 3},
|
||||||
WorkingDirectory: "/tmp",
|
WorkingDirectory: tmpDir,
|
||||||
Environment: []appctypes.EnvironmentVariable{
|
Environment: []appctypes.EnvironmentVariable{
|
||||||
{"env-foo", "bar"},
|
{"env-foo", "bar"},
|
||||||
{"env-bar", "foo"},
|
{"env-bar", "foo"},
|
||||||
@ -857,7 +865,7 @@ func TestSetApp(t *testing.T) {
|
|||||||
container: &api.Container{
|
container: &api.Container{
|
||||||
Command: []string{"/bin/bar"},
|
Command: []string{"/bin/bar"},
|
||||||
Args: []string{"hello", "world"},
|
Args: []string{"hello", "world"},
|
||||||
WorkingDir: "/tmp",
|
WorkingDir: tmpDir,
|
||||||
Resources: api.ResourceRequirements{
|
Resources: api.ResourceRequirements{
|
||||||
Limits: api.ResourceList{"cpu": resource.MustParse("50m"), "memory": resource.MustParse("50M")},
|
Limits: api.ResourceList{"cpu": resource.MustParse("50m"), "memory": resource.MustParse("50M")},
|
||||||
Requests: api.ResourceList{"cpu": resource.MustParse("5m"), "memory": resource.MustParse("5M")},
|
Requests: api.ResourceList{"cpu": resource.MustParse("5m"), "memory": resource.MustParse("5M")},
|
||||||
@ -891,7 +899,7 @@ func TestSetApp(t *testing.T) {
|
|||||||
User: "42",
|
User: "42",
|
||||||
Group: "22",
|
Group: "22",
|
||||||
SupplementaryGIDs: []int{1, 2, 3},
|
SupplementaryGIDs: []int{1, 2, 3},
|
||||||
WorkingDirectory: "/tmp",
|
WorkingDirectory: tmpDir,
|
||||||
Environment: []appctypes.EnvironmentVariable{
|
Environment: []appctypes.EnvironmentVariable{
|
||||||
{"env-foo", "foo"},
|
{"env-foo", "foo"},
|
||||||
},
|
},
|
||||||
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
package kubelet
|
package kubelet
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -32,6 +31,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/kubelet/network"
|
"k8s.io/kubernetes/pkg/kubelet/network"
|
||||||
kubepod "k8s.io/kubernetes/pkg/kubelet/pod"
|
kubepod "k8s.io/kubernetes/pkg/kubelet/pod"
|
||||||
"k8s.io/kubernetes/pkg/kubelet/status"
|
"k8s.io/kubernetes/pkg/kubelet/status"
|
||||||
|
utiltesting "k8s.io/kubernetes/pkg/util/testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRunOnce(t *testing.T) {
|
func TestRunOnce(t *testing.T) {
|
||||||
@ -49,7 +49,7 @@ func TestRunOnce(t *testing.T) {
|
|||||||
podManager := kubepod.NewBasicPodManager(kubepod.NewFakeMirrorClient())
|
podManager := kubepod.NewBasicPodManager(kubepod.NewFakeMirrorClient())
|
||||||
diskSpaceManager, _ := newDiskSpaceManager(cadvisor, DiskSpacePolicy{})
|
diskSpaceManager, _ := newDiskSpaceManager(cadvisor, DiskSpacePolicy{})
|
||||||
fakeRuntime := &kubecontainer.FakeRuntime{}
|
fakeRuntime := &kubecontainer.FakeRuntime{}
|
||||||
basePath, err := ioutil.TempDir(os.TempDir(), "kubelet")
|
basePath, err := utiltesting.MkTmpdir("kubelet")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("can't make a temp rootdir %v", err)
|
t.Fatalf("can't make a temp rootdir %v", err)
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ func TestRefreshTunnels(t *testing.T) {
|
|||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
// Fail case (no addresses associated with nodes)
|
// Fail case (no addresses associated with nodes)
|
||||||
assert.Error(tunneler.refreshTunnels("test", "/tmp/undefined"))
|
assert.Error(tunneler.refreshTunnels("test", "/somepath/undefined"))
|
||||||
|
|
||||||
// TODO: pass case without needing actual connections?
|
// TODO: pass case without needing actual connections?
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/apimachinery/registered"
|
"k8s.io/kubernetes/pkg/apimachinery/registered"
|
||||||
"k8s.io/kubernetes/pkg/runtime"
|
"k8s.io/kubernetes/pkg/runtime"
|
||||||
"k8s.io/kubernetes/pkg/util/io"
|
"k8s.io/kubernetes/pkg/util/io"
|
||||||
|
utiltesting "k8s.io/kubernetes/pkg/util/testing"
|
||||||
"k8s.io/kubernetes/pkg/volume"
|
"k8s.io/kubernetes/pkg/volume"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -37,8 +38,9 @@ func TestSavePodToFile(t *testing.T) {
|
|||||||
encoded, err := runtime.Encode(codec, pod)
|
encoded, err := runtime.Encode(codec, pod)
|
||||||
runtime.DecodeInto(codec, encoded, pod)
|
runtime.DecodeInto(codec, encoded, pod)
|
||||||
|
|
||||||
path := fmt.Sprintf("/tmp/kube-io-test-%s", uuid.New())
|
tmpDir := utiltesting.MkTmpdirOrDie("kube-io-test")
|
||||||
defer os.Remove(path)
|
defer os.RemoveAll(tmpDir)
|
||||||
|
path := fmt.Sprintf("/%s/kube-io-test-%s", tmpDir, uuid.New())
|
||||||
|
|
||||||
if err := io.SavePodToFile(pod, path, 777); err != nil {
|
if err := io.SavePodToFile(pod, path, 777); err != nil {
|
||||||
t.Fatalf("failed to save pod to file: %v", err)
|
t.Fatalf("failed to save pod to file: %v", err)
|
||||||
|
44
pkg/util/testing/tmpdir.go
Normal file
44
pkg/util/testing/tmpdir.go
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2016 The Kubernetes Authors All rights reserved.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package testing
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MkTmpdir creates a temporary directory based upon the prefix passed in.
|
||||||
|
// If successful, it returns the temporary directory path. The directory can be
|
||||||
|
// deleted with a call to "os.RemoveAll(...)".
|
||||||
|
// In case of error, it'll return an empty string and the error.
|
||||||
|
func MkTmpdir(prefix string) (string, error) {
|
||||||
|
tmpDir, err := ioutil.TempDir(os.TempDir(), prefix)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return tmpDir, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// MkTmpdir does the same work as "MkTmpdir", except in case of
|
||||||
|
// errors, it'll trigger a panic.
|
||||||
|
func MkTmpdirOrDie(prefix string) string {
|
||||||
|
tmpDir, err := MkTmpdir(prefix)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return tmpDir
|
||||||
|
}
|
@ -18,7 +18,6 @@ package aws_ebs
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"testing"
|
"testing"
|
||||||
@ -28,11 +27,12 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
||||||
"k8s.io/kubernetes/pkg/types"
|
"k8s.io/kubernetes/pkg/types"
|
||||||
"k8s.io/kubernetes/pkg/util/mount"
|
"k8s.io/kubernetes/pkg/util/mount"
|
||||||
|
utiltesting "k8s.io/kubernetes/pkg/util/testing"
|
||||||
"k8s.io/kubernetes/pkg/volume"
|
"k8s.io/kubernetes/pkg/volume"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCanSupport(t *testing.T) {
|
func TestCanSupport(t *testing.T) {
|
||||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "awsebsTest")
|
tmpDir, err := utiltesting.MkTmpdir("awsebsTest")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("can't make a temp dir: %v", err)
|
t.Fatalf("can't make a temp dir: %v", err)
|
||||||
}
|
}
|
||||||
@ -56,7 +56,7 @@ func TestCanSupport(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGetAccessModes(t *testing.T) {
|
func TestGetAccessModes(t *testing.T) {
|
||||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "awsebsTest")
|
tmpDir, err := utiltesting.MkTmpdir("awsebsTest")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("can't make a temp dir: %v", err)
|
t.Fatalf("can't make a temp dir: %v", err)
|
||||||
}
|
}
|
||||||
@ -119,7 +119,7 @@ func (fake *fakePDManager) DeleteVolume(cd *awsElasticBlockStoreDeleter) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPlugin(t *testing.T) {
|
func TestPlugin(t *testing.T) {
|
||||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "awsebsTest")
|
tmpDir, err := utiltesting.MkTmpdir("awsebsTest")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("can't make a temp dir: %v")
|
t.Fatalf("can't make a temp dir: %v")
|
||||||
}
|
}
|
||||||
@ -260,7 +260,7 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
|
|||||||
|
|
||||||
client := testclient.NewSimpleFake(pv, claim)
|
client := testclient.NewSimpleFake(pv, claim)
|
||||||
|
|
||||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "awsebsTest")
|
tmpDir, err := utiltesting.MkTmpdir("awsebsTest")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("can't make a temp dir: %v", err)
|
t.Fatalf("can't make a temp dir: %v", err)
|
||||||
}
|
}
|
||||||
@ -280,7 +280,7 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestBuilderAndCleanerTypeAssert(t *testing.T) {
|
func TestBuilderAndCleanerTypeAssert(t *testing.T) {
|
||||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "awsebsTest")
|
tmpDir, err := utiltesting.MkTmpdir("awsebsTest")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("can't make a temp dir: %v", err)
|
t.Fatalf("can't make a temp dir: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
package cephfs
|
package cephfs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"testing"
|
"testing"
|
||||||
@ -25,11 +24,12 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"k8s.io/kubernetes/pkg/types"
|
"k8s.io/kubernetes/pkg/types"
|
||||||
"k8s.io/kubernetes/pkg/util/mount"
|
"k8s.io/kubernetes/pkg/util/mount"
|
||||||
|
utiltesting "k8s.io/kubernetes/pkg/util/testing"
|
||||||
"k8s.io/kubernetes/pkg/volume"
|
"k8s.io/kubernetes/pkg/volume"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCanSupport(t *testing.T) {
|
func TestCanSupport(t *testing.T) {
|
||||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "cephTest")
|
tmpDir, err := utiltesting.MkTmpdir("cephTest")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("can't make a temp dir: %v", err)
|
t.Fatalf("can't make a temp dir: %v", err)
|
||||||
}
|
}
|
||||||
@ -52,7 +52,7 @@ func TestCanSupport(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPlugin(t *testing.T) {
|
func TestPlugin(t *testing.T) {
|
||||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "cephTest")
|
tmpDir, err := utiltesting.MkTmpdir("cephTest")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("can't make a temp dir: %v", err)
|
t.Fatalf("can't make a temp dir: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ package cinder
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"testing"
|
"testing"
|
||||||
@ -27,11 +26,12 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/api/resource"
|
"k8s.io/kubernetes/pkg/api/resource"
|
||||||
"k8s.io/kubernetes/pkg/types"
|
"k8s.io/kubernetes/pkg/types"
|
||||||
"k8s.io/kubernetes/pkg/util/mount"
|
"k8s.io/kubernetes/pkg/util/mount"
|
||||||
|
utiltesting "k8s.io/kubernetes/pkg/util/testing"
|
||||||
"k8s.io/kubernetes/pkg/volume"
|
"k8s.io/kubernetes/pkg/volume"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCanSupport(t *testing.T) {
|
func TestCanSupport(t *testing.T) {
|
||||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "cinderTest")
|
tmpDir, err := utiltesting.MkTmpdir("cinderTest")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("can't make a temp dir: %v", err)
|
t.Fatalf("can't make a temp dir: %v", err)
|
||||||
}
|
}
|
||||||
@ -87,7 +87,7 @@ func (fake *fakePDManager) DeleteVolume(cd *cinderVolumeDeleter) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPlugin(t *testing.T) {
|
func TestPlugin(t *testing.T) {
|
||||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "cinderTest")
|
tmpDir, err := utiltesting.MkTmpdir("cinderTest")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("can't make a temp dir: %v", err)
|
t.Fatalf("can't make a temp dir: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ import (
|
|||||||
client "k8s.io/kubernetes/pkg/client/unversioned"
|
client "k8s.io/kubernetes/pkg/client/unversioned"
|
||||||
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
||||||
"k8s.io/kubernetes/pkg/types"
|
"k8s.io/kubernetes/pkg/types"
|
||||||
|
utiltesting "k8s.io/kubernetes/pkg/util/testing"
|
||||||
"k8s.io/kubernetes/pkg/volume"
|
"k8s.io/kubernetes/pkg/volume"
|
||||||
"k8s.io/kubernetes/pkg/volume/empty_dir"
|
"k8s.io/kubernetes/pkg/volume/empty_dir"
|
||||||
)
|
)
|
||||||
@ -39,8 +40,8 @@ func formatMap(m map[string]string) (fmtstr string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTestHost(t *testing.T, client client.Interface, basePath string) (string, volume.VolumeHost) {
|
func newTestHost(t *testing.T, client client.Interface) (string, volume.VolumeHost) {
|
||||||
tempDir, err := ioutil.TempDir(basePath, "downwardApi_volume_test.")
|
tempDir, err := utiltesting.MkTmpdir("downwardApi_volume_test.")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("can't make a temp rootdir: %v", err)
|
t.Fatalf("can't make a temp rootdir: %v", err)
|
||||||
}
|
}
|
||||||
@ -48,13 +49,9 @@ func newTestHost(t *testing.T, client client.Interface, basePath string) (string
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCanSupport(t *testing.T) {
|
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 := volume.VolumePluginMgr{}
|
||||||
_, host := newTestHost(t, nil, tmpDir)
|
tmpDir, host := newTestHost(t, nil)
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
pluginMgr.InitPlugins(ProbeVolumePlugins(), host)
|
pluginMgr.InitPlugins(ProbeVolumePlugins(), host)
|
||||||
|
|
||||||
plugin, err := pluginMgr.FindPluginByName(downwardAPIPluginName)
|
plugin, err := pluginMgr.FindPluginByName(downwardAPIPluginName)
|
||||||
@ -105,13 +102,9 @@ func TestLabels(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 := volume.VolumePluginMgr{}
|
||||||
rootDir, host := newTestHost(t, fake, tmpDir)
|
rootDir, host := newTestHost(t, fake)
|
||||||
|
defer os.RemoveAll(rootDir)
|
||||||
pluginMgr.InitPlugins(ProbeVolumePlugins(), host)
|
pluginMgr.InitPlugins(ProbeVolumePlugins(), host)
|
||||||
plugin, err := pluginMgr.FindPluginByName(downwardAPIPluginName)
|
plugin, err := pluginMgr.FindPluginByName(downwardAPIPluginName)
|
||||||
volumeSpec := &api.Volume{
|
volumeSpec := &api.Volume{
|
||||||
@ -196,13 +189,9 @@ 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 := volume.VolumePluginMgr{}
|
||||||
_, host := newTestHost(t, fake, tmpDir)
|
tmpDir, host := newTestHost(t, fake)
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
pluginMgr.InitPlugins(ProbeVolumePlugins(), host)
|
pluginMgr.InitPlugins(ProbeVolumePlugins(), host)
|
||||||
plugin, err := pluginMgr.FindPluginByName(downwardAPIPluginName)
|
plugin, err := pluginMgr.FindPluginByName(downwardAPIPluginName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -262,13 +251,9 @@ 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 := volume.VolumePluginMgr{}
|
||||||
_, host := newTestHost(t, fake, tmpDir)
|
tmpDir, host := newTestHost(t, fake)
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
pluginMgr.InitPlugins(ProbeVolumePlugins(), host)
|
pluginMgr.InitPlugins(ProbeVolumePlugins(), host)
|
||||||
plugin, err := pluginMgr.FindPluginByName(downwardAPIPluginName)
|
plugin, err := pluginMgr.FindPluginByName(downwardAPIPluginName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -329,13 +314,9 @@ 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 := volume.VolumePluginMgr{}
|
||||||
_, host := newTestHost(t, fake, tmpDir)
|
tmpDir, host := newTestHost(t, fake)
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
pluginMgr.InitPlugins(ProbeVolumePlugins(), host)
|
pluginMgr.InitPlugins(ProbeVolumePlugins(), host)
|
||||||
plugin, err := pluginMgr.FindPluginByName(downwardAPIPluginName)
|
plugin, err := pluginMgr.FindPluginByName(downwardAPIPluginName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -389,13 +370,9 @@ func TestWriteTwiceNoUpdate(t *testing.T) {
|
|||||||
Labels: labels,
|
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 := volume.VolumePluginMgr{}
|
||||||
_, host := newTestHost(t, fake, tmpDir)
|
tmpDir, host := newTestHost(t, fake)
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
pluginMgr.InitPlugins(ProbeVolumePlugins(), host)
|
pluginMgr.InitPlugins(ProbeVolumePlugins(), host)
|
||||||
plugin, err := pluginMgr.FindPluginByName(downwardAPIPluginName)
|
plugin, err := pluginMgr.FindPluginByName(downwardAPIPluginName)
|
||||||
volumeSpec := &api.Volume{
|
volumeSpec := &api.Volume{
|
||||||
@ -479,13 +456,9 @@ func TestWriteTwiceWithUpdate(t *testing.T) {
|
|||||||
Labels: labels,
|
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 := volume.VolumePluginMgr{}
|
||||||
_, host := newTestHost(t, fake, tmpDir)
|
tmpDir, host := newTestHost(t, fake)
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
pluginMgr.InitPlugins(ProbeVolumePlugins(), host)
|
pluginMgr.InitPlugins(ProbeVolumePlugins(), host)
|
||||||
plugin, err := pluginMgr.FindPluginByName(downwardAPIPluginName)
|
plugin, err := pluginMgr.FindPluginByName(downwardAPIPluginName)
|
||||||
volumeSpec := &api.Volume{
|
volumeSpec := &api.Volume{
|
||||||
@ -589,13 +562,9 @@ 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 := volume.VolumePluginMgr{}
|
||||||
_, host := newTestHost(t, fake, tmpDir)
|
tmpDir, host := newTestHost(t, fake)
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
pluginMgr.InitPlugins(ProbeVolumePlugins(), host)
|
pluginMgr.InitPlugins(ProbeVolumePlugins(), host)
|
||||||
plugin, err := pluginMgr.FindPluginByName(downwardAPIPluginName)
|
plugin, err := pluginMgr.FindPluginByName(downwardAPIPluginName)
|
||||||
volumeSpec := &api.Volume{
|
volumeSpec := &api.Volume{
|
||||||
@ -669,13 +638,9 @@ 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 := volume.VolumePluginMgr{}
|
||||||
_, host := newTestHost(t, fake, tmpDir)
|
tmpDir, host := newTestHost(t, fake)
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
pluginMgr.InitPlugins(ProbeVolumePlugins(), host)
|
pluginMgr.InitPlugins(ProbeVolumePlugins(), host)
|
||||||
plugin, err := pluginMgr.FindPluginByName(downwardAPIPluginName)
|
plugin, err := pluginMgr.FindPluginByName(downwardAPIPluginName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -19,7 +19,6 @@ limitations under the License.
|
|||||||
package empty_dir
|
package empty_dir
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"testing"
|
"testing"
|
||||||
@ -27,6 +26,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"k8s.io/kubernetes/pkg/types"
|
"k8s.io/kubernetes/pkg/types"
|
||||||
"k8s.io/kubernetes/pkg/util/mount"
|
"k8s.io/kubernetes/pkg/util/mount"
|
||||||
|
utiltesting "k8s.io/kubernetes/pkg/util/testing"
|
||||||
"k8s.io/kubernetes/pkg/volume"
|
"k8s.io/kubernetes/pkg/volume"
|
||||||
"k8s.io/kubernetes/pkg/volume/util"
|
"k8s.io/kubernetes/pkg/volume/util"
|
||||||
)
|
)
|
||||||
@ -44,7 +44,7 @@ func makePluginUnderTest(t *testing.T, plugName, basePath string) volume.VolumeP
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCanSupport(t *testing.T) {
|
func TestCanSupport(t *testing.T) {
|
||||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "emptydirTest")
|
tmpDir, err := utiltesting.MkTmpdir("emptydirTest")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("can't make a temp dir: %v", err)
|
t.Fatalf("can't make a temp dir: %v", err)
|
||||||
}
|
}
|
||||||
@ -119,7 +119,7 @@ type pluginTestConfig struct {
|
|||||||
|
|
||||||
// doTestPlugin sets up a volume and tears it back down.
|
// doTestPlugin sets up a volume and tears it back down.
|
||||||
func doTestPlugin(t *testing.T, config pluginTestConfig) {
|
func doTestPlugin(t *testing.T, config pluginTestConfig) {
|
||||||
basePath, err := ioutil.TempDir(os.TempDir(), "emptydir_volume_test")
|
basePath, err := utiltesting.MkTmpdir("emptydir_volume_test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("can't make a temp rootdir: %v", err)
|
t.Fatalf("can't make a temp rootdir: %v", err)
|
||||||
}
|
}
|
||||||
@ -251,7 +251,7 @@ func doTestPlugin(t *testing.T, config pluginTestConfig) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPluginBackCompat(t *testing.T) {
|
func TestPluginBackCompat(t *testing.T) {
|
||||||
basePath, err := ioutil.TempDir(os.TempDir(), "emptydirTest")
|
basePath, err := utiltesting.MkTmpdir("emptydirTest")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("can't make a temp dir: %v", err)
|
t.Fatalf("can't make a temp dir: %v", err)
|
||||||
}
|
}
|
||||||
@ -280,7 +280,7 @@ func TestPluginBackCompat(t *testing.T) {
|
|||||||
// TestMetrics tests that MetricProvider methods return sane values.
|
// TestMetrics tests that MetricProvider methods return sane values.
|
||||||
func TestMetrics(t *testing.T) {
|
func TestMetrics(t *testing.T) {
|
||||||
// Create an empty temp directory for the volume
|
// Create an empty temp directory for the volume
|
||||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "empty_dir_test")
|
tmpDir, err := utiltesting.MkTmpdir("empty_dir_test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Can't make a tmp dir: %v", err)
|
t.Fatalf("Can't make a tmp dir: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
package fc
|
package fc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -24,12 +25,19 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
||||||
"k8s.io/kubernetes/pkg/types"
|
"k8s.io/kubernetes/pkg/types"
|
||||||
"k8s.io/kubernetes/pkg/util/mount"
|
"k8s.io/kubernetes/pkg/util/mount"
|
||||||
|
utiltesting "k8s.io/kubernetes/pkg/util/testing"
|
||||||
"k8s.io/kubernetes/pkg/volume"
|
"k8s.io/kubernetes/pkg/volume"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCanSupport(t *testing.T) {
|
func TestCanSupport(t *testing.T) {
|
||||||
|
tmpDir, err := utiltesting.MkTmpdir("fc_test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error creating temp dir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
plugMgr := volume.VolumePluginMgr{}
|
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/fc")
|
plug, err := plugMgr.FindPluginByName("kubernetes.io/fc")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -44,8 +52,14 @@ func TestCanSupport(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGetAccessModes(t *testing.T) {
|
func TestGetAccessModes(t *testing.T) {
|
||||||
|
tmpDir, err := utiltesting.MkTmpdir("fc_test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error creating temp dir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
plugMgr := volume.VolumePluginMgr{}
|
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/fc")
|
plug, err := plugMgr.FindPersistentPluginByName("kubernetes.io/fc")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -66,12 +80,23 @@ func contains(modes []api.PersistentVolumeAccessMode, mode api.PersistentVolumeA
|
|||||||
}
|
}
|
||||||
|
|
||||||
type fakeDiskManager struct {
|
type fakeDiskManager struct {
|
||||||
|
tmpDir string
|
||||||
attachCalled bool
|
attachCalled bool
|
||||||
detachCalled bool
|
detachCalled bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewFakeDiskManager() *fakeDiskManager {
|
||||||
|
return &fakeDiskManager{
|
||||||
|
tmpDir: utiltesting.MkTmpdirOrDie("fc_test"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *fakeDiskManager) Cleanup() {
|
||||||
|
os.RemoveAll(fake.tmpDir)
|
||||||
|
}
|
||||||
|
|
||||||
func (fake *fakeDiskManager) MakeGlobalPDName(disk fcDisk) string {
|
func (fake *fakeDiskManager) MakeGlobalPDName(disk fcDisk) string {
|
||||||
return "/tmp/fake_fc_path"
|
return fake.tmpDir
|
||||||
}
|
}
|
||||||
func (fake *fakeDiskManager) AttachDisk(b fcDiskBuilder) error {
|
func (fake *fakeDiskManager) AttachDisk(b fcDiskBuilder) error {
|
||||||
globalPath := b.manager.MakeGlobalPDName(*b.fcDisk)
|
globalPath := b.manager.MakeGlobalPDName(*b.fcDisk)
|
||||||
@ -98,14 +123,21 @@ func (fake *fakeDiskManager) DetachDisk(c fcDiskCleaner, mntPath string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func doTestPlugin(t *testing.T, spec *volume.Spec) {
|
func doTestPlugin(t *testing.T, spec *volume.Spec) {
|
||||||
|
tmpDir, err := utiltesting.MkTmpdir("fc_test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error creating temp dir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
plugMgr := volume.VolumePluginMgr{}
|
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/fc")
|
plug, err := plugMgr.FindPluginByName("kubernetes.io/fc")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Can't find the plugin by name")
|
t.Errorf("Can't find the plugin by name")
|
||||||
}
|
}
|
||||||
fakeManager := &fakeDiskManager{}
|
fakeManager := NewFakeDiskManager()
|
||||||
|
defer fakeManager.Cleanup()
|
||||||
fakeMounter := &mount.FakeMounter{}
|
fakeMounter := &mount.FakeMounter{}
|
||||||
builder, err := plug.(*fcPlugin).newBuilderInternal(spec, types.UID("poduid"), fakeManager, fakeMounter)
|
builder, err := plug.(*fcPlugin).newBuilderInternal(spec, types.UID("poduid"), fakeManager, fakeMounter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -116,8 +148,9 @@ func doTestPlugin(t *testing.T, spec *volume.Spec) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
path := builder.GetPath()
|
path := builder.GetPath()
|
||||||
if path != "/tmp/fake/pods/poduid/volumes/kubernetes.io~fc/vol1" {
|
expectedPath := fmt.Sprintf("%s/pods/poduid/volumes/kubernetes.io~fc/vol1", tmpDir)
|
||||||
t.Errorf("Got unexpected path: %s", path)
|
if path != expectedPath {
|
||||||
|
t.Errorf("Unexpected path, expected %q, got: %q", expectedPath, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := builder.SetUp(nil); err != nil {
|
if err := builder.SetUp(nil); err != nil {
|
||||||
@ -141,8 +174,9 @@ func doTestPlugin(t *testing.T, spec *volume.Spec) {
|
|||||||
t.Errorf("Attach was not called")
|
t.Errorf("Attach was not called")
|
||||||
}
|
}
|
||||||
|
|
||||||
fakeManager = &fakeDiskManager{}
|
fakeManager2 := NewFakeDiskManager()
|
||||||
cleaner, err := plug.(*fcPlugin).newCleanerInternal("vol1", types.UID("poduid"), fakeManager, fakeMounter)
|
defer fakeManager2.Cleanup()
|
||||||
|
cleaner, err := plug.(*fcPlugin).newCleanerInternal("vol1", types.UID("poduid"), fakeManager2, fakeMounter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Failed to make a new Cleaner: %v", err)
|
t.Errorf("Failed to make a new Cleaner: %v", err)
|
||||||
}
|
}
|
||||||
@ -158,7 +192,7 @@ func doTestPlugin(t *testing.T, spec *volume.Spec) {
|
|||||||
} else if !os.IsNotExist(err) {
|
} else if !os.IsNotExist(err) {
|
||||||
t.Errorf("SetUp() failed: %v", err)
|
t.Errorf("SetUp() failed: %v", err)
|
||||||
}
|
}
|
||||||
if !fakeManager.detachCalled {
|
if !fakeManager2.detachCalled {
|
||||||
t.Errorf("Detach was not called")
|
t.Errorf("Detach was not called")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -198,6 +232,12 @@ func TestPluginPersistentVolume(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPersistentClaimReadOnlyFlag(t *testing.T) {
|
func TestPersistentClaimReadOnlyFlag(t *testing.T) {
|
||||||
|
tmpDir, err := utiltesting.MkTmpdir("fc_test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error creating temp dir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
lun := 0
|
lun := 0
|
||||||
pv := &api.PersistentVolume{
|
pv := &api.PersistentVolume{
|
||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
@ -233,7 +273,7 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
|
|||||||
client := testclient.NewSimpleFake(pv, claim)
|
client := testclient.NewSimpleFake(pv, claim)
|
||||||
|
|
||||||
plugMgr := volume.VolumePluginMgr{}
|
plugMgr := volume.VolumePluginMgr{}
|
||||||
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", client, nil))
|
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost(tmpDir, client, nil))
|
||||||
plug, _ := plugMgr.FindPluginByName(fcPluginName)
|
plug, _ := plugMgr.FindPluginByName(fcPluginName)
|
||||||
|
|
||||||
// readOnly bool is supplied by persistent-claim volume source when its builder creates other volumes
|
// readOnly bool is supplied by persistent-claim volume source when its builder creates other volumes
|
||||||
|
@ -28,12 +28,10 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/types"
|
"k8s.io/kubernetes/pkg/types"
|
||||||
"k8s.io/kubernetes/pkg/util/exec"
|
"k8s.io/kubernetes/pkg/util/exec"
|
||||||
"k8s.io/kubernetes/pkg/util/mount"
|
"k8s.io/kubernetes/pkg/util/mount"
|
||||||
|
utiltesting "k8s.io/kubernetes/pkg/util/testing"
|
||||||
"k8s.io/kubernetes/pkg/volume"
|
"k8s.io/kubernetes/pkg/volume"
|
||||||
)
|
)
|
||||||
|
|
||||||
// The temp dir where test plugins will be stored.
|
|
||||||
const testPluginPath = "/tmp/fake/plugins/volume"
|
|
||||||
|
|
||||||
const execScriptTempl1 = `#!/bin/bash
|
const execScriptTempl1 = `#!/bin/bash
|
||||||
if [ "$1" == "init" -a $# -eq 1 ]; then
|
if [ "$1" == "init" -a $# -eq 1 ]; then
|
||||||
echo -n '{
|
echo -n '{
|
||||||
@ -134,12 +132,12 @@ exit 1
|
|||||||
echo -n $@ &> {{.OutputFile}}
|
echo -n $@ &> {{.OutputFile}}
|
||||||
`
|
`
|
||||||
|
|
||||||
func installPluginUnderTest(t *testing.T, vendorName string, plugName string, execScriptTempl string, execTemplateData *map[string]interface{}) {
|
func installPluginUnderTest(t *testing.T, vendorName, plugName, tmpDir string, execScriptTempl string, execTemplateData *map[string]interface{}) {
|
||||||
vendoredName := plugName
|
vendoredName := plugName
|
||||||
if vendorName != "" {
|
if vendorName != "" {
|
||||||
vendoredName = fmt.Sprintf("%s~%s", vendorName, plugName)
|
vendoredName = fmt.Sprintf("%s~%s", vendorName, plugName)
|
||||||
}
|
}
|
||||||
pluginDir := path.Join(testPluginPath, vendoredName)
|
pluginDir := path.Join(tmpDir, vendoredName)
|
||||||
err := os.MkdirAll(pluginDir, 0777)
|
err := os.MkdirAll(pluginDir, 0777)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Failed to create plugin: %v", err)
|
t.Errorf("Failed to create plugin: %v", err)
|
||||||
@ -174,9 +172,15 @@ func installPluginUnderTest(t *testing.T, vendorName string, plugName string, ex
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCanSupport(t *testing.T) {
|
func TestCanSupport(t *testing.T) {
|
||||||
|
tmpDir, err := utiltesting.MkTmpdir("flexvolume_test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error creating temp dir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
plugMgr := volume.VolumePluginMgr{}
|
plugMgr := volume.VolumePluginMgr{}
|
||||||
installPluginUnderTest(t, "kubernetes.io", "fakeAttacher", execScriptTempl1, nil)
|
installPluginUnderTest(t, "kubernetes.io", "fakeAttacher", tmpDir, execScriptTempl1, nil)
|
||||||
plugMgr.InitPlugins(ProbeVolumePlugins(testPluginPath), volume.NewFakeVolumeHost("fake", nil, nil))
|
plugMgr.InitPlugins(ProbeVolumePlugins(tmpDir), volume.NewFakeVolumeHost("fake", nil, nil))
|
||||||
plugin, err := plugMgr.FindPluginByName("kubernetes.io/fakeAttacher")
|
plugin, err := plugMgr.FindPluginByName("kubernetes.io/fakeAttacher")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Can't find the plugin by name")
|
t.Errorf("Can't find the plugin by name")
|
||||||
@ -196,12 +200,19 @@ func TestCanSupport(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGetAccessModes(t *testing.T) {
|
func TestGetAccessModes(t *testing.T) {
|
||||||
|
tmpDir, err := utiltesting.MkTmpdir("flexvolume_test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error creating temp dir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
plugMgr := volume.VolumePluginMgr{}
|
plugMgr := volume.VolumePluginMgr{}
|
||||||
plugMgr.InitPlugins(ProbeVolumePlugins(testPluginPath), volume.NewFakeVolumeHost("fake", nil, nil))
|
installPluginUnderTest(t, "kubernetes.io", "fakeAttacher", tmpDir, execScriptTempl1, nil)
|
||||||
|
plugMgr.InitPlugins(ProbeVolumePlugins(tmpDir), volume.NewFakeVolumeHost(tmpDir, nil, nil))
|
||||||
|
|
||||||
plugin, err := plugMgr.FindPersistentPluginByName("kubernetes.io/fakeAttacher")
|
plugin, err := plugMgr.FindPersistentPluginByName("kubernetes.io/fakeAttacher")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Can't find the plugin by name")
|
t.Fatalf("Can't find the plugin by name")
|
||||||
}
|
}
|
||||||
if !contains(plugin.GetAccessModes(), api.ReadWriteOnce) || !contains(plugin.GetAccessModes(), api.ReadOnlyMany) {
|
if !contains(plugin.GetAccessModes(), api.ReadWriteOnce) || !contains(plugin.GetAccessModes(), api.ReadOnlyMany) {
|
||||||
t.Errorf("Expected two AccessModeTypes: %s and %s", api.ReadWriteOnce, api.ReadOnlyMany)
|
t.Errorf("Expected two AccessModeTypes: %s and %s", api.ReadWriteOnce, api.ReadOnlyMany)
|
||||||
@ -217,9 +228,10 @@ func contains(modes []api.PersistentVolumeAccessMode, mode api.PersistentVolumeA
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func doTestPluginAttachDetach(t *testing.T, spec *volume.Spec) {
|
func doTestPluginAttachDetach(t *testing.T, spec *volume.Spec, tmpDir string) {
|
||||||
plugMgr := volume.VolumePluginMgr{}
|
plugMgr := volume.VolumePluginMgr{}
|
||||||
plugMgr.InitPlugins(ProbeVolumePlugins(testPluginPath), volume.NewFakeVolumeHost("/tmp/fake", nil, nil))
|
installPluginUnderTest(t, "kubernetes.io", "fakeAttacher", tmpDir, execScriptTempl1, nil)
|
||||||
|
plugMgr.InitPlugins(ProbeVolumePlugins(tmpDir), volume.NewFakeVolumeHost(tmpDir, nil, nil))
|
||||||
plugin, err := plugMgr.FindPluginByName("kubernetes.io/fakeAttacher")
|
plugin, err := plugMgr.FindPluginByName("kubernetes.io/fakeAttacher")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Can't find the plugin by name")
|
t.Errorf("Can't find the plugin by name")
|
||||||
@ -235,8 +247,9 @@ func doTestPluginAttachDetach(t *testing.T, spec *volume.Spec) {
|
|||||||
t.Errorf("Got a nil Builder")
|
t.Errorf("Got a nil Builder")
|
||||||
}
|
}
|
||||||
path := builder.GetPath()
|
path := builder.GetPath()
|
||||||
if path != "/tmp/fake/pods/poduid/volumes/kubernetes.io~fakeAttacher/vol1" {
|
expectedPath := fmt.Sprintf("%s/pods/poduid/volumes/kubernetes.io~fakeAttacher/vol1", tmpDir)
|
||||||
t.Errorf("Got unexpected path: %s", path)
|
if path != expectedPath {
|
||||||
|
t.Errorf("Unexpected path, expected %q, got: %q", expectedPath, path)
|
||||||
}
|
}
|
||||||
if err := builder.SetUp(nil); err != nil {
|
if err := builder.SetUp(nil); err != nil {
|
||||||
t.Errorf("Expected success, got: %v", err)
|
t.Errorf("Expected success, got: %v", err)
|
||||||
@ -288,10 +301,16 @@ func doTestPluginAttachDetach(t *testing.T, spec *volume.Spec) {
|
|||||||
fake.ResetLog()
|
fake.ResetLog()
|
||||||
}
|
}
|
||||||
|
|
||||||
func doTestPluginMountUnmount(t *testing.T, spec *volume.Spec) {
|
func doTestPluginMountUnmount(t *testing.T, spec *volume.Spec, tmpDir string) {
|
||||||
|
tmpDir, err := utiltesting.MkTmpdir("flexvolume_test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error creating temp dir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
plugMgr := volume.VolumePluginMgr{}
|
plugMgr := volume.VolumePluginMgr{}
|
||||||
installPluginUnderTest(t, "kubernetes.io", "fakeMounter", execScriptTempl2, nil)
|
installPluginUnderTest(t, "kubernetes.io", "fakeMounter", tmpDir, execScriptTempl2, nil)
|
||||||
plugMgr.InitPlugins(ProbeVolumePlugins(testPluginPath), volume.NewFakeVolumeHost("/tmp/fake", nil, nil))
|
plugMgr.InitPlugins(ProbeVolumePlugins(tmpDir), volume.NewFakeVolumeHost(tmpDir, nil, nil))
|
||||||
plugin, err := plugMgr.FindPluginByName("kubernetes.io/fakeMounter")
|
plugin, err := plugMgr.FindPluginByName("kubernetes.io/fakeMounter")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Can't find the plugin by name")
|
t.Errorf("Can't find the plugin by name")
|
||||||
@ -307,8 +326,9 @@ func doTestPluginMountUnmount(t *testing.T, spec *volume.Spec) {
|
|||||||
t.Errorf("Got a nil Builder")
|
t.Errorf("Got a nil Builder")
|
||||||
}
|
}
|
||||||
path := builder.GetPath()
|
path := builder.GetPath()
|
||||||
if path != "/tmp/fake/pods/poduid/volumes/kubernetes.io~fakeMounter/vol1" {
|
expectedPath := fmt.Sprintf("%s/pods/poduid/volumes/kubernetes.io~fakeMounter/vol1", tmpDir)
|
||||||
t.Errorf("Got unexpected path: %s", path)
|
if path != expectedPath {
|
||||||
|
t.Errorf("Unexpected path, expected %q, got: %q", expectedPath, path)
|
||||||
}
|
}
|
||||||
if err := builder.SetUp(nil); err != nil {
|
if err := builder.SetUp(nil); err != nil {
|
||||||
t.Errorf("Expected success, got: %v", err)
|
t.Errorf("Expected success, got: %v", err)
|
||||||
@ -343,22 +363,40 @@ func doTestPluginMountUnmount(t *testing.T, spec *volume.Spec) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPluginVolumeAttacher(t *testing.T) {
|
func TestPluginVolumeAttacher(t *testing.T) {
|
||||||
|
tmpDir, err := utiltesting.MkTmpdir("flexvolume_test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error creating temp dir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
vol := &api.Volume{
|
vol := &api.Volume{
|
||||||
Name: "vol1",
|
Name: "vol1",
|
||||||
VolumeSource: api.VolumeSource{FlexVolume: &api.FlexVolumeSource{Driver: "kubernetes.io/fakeAttacher", ReadOnly: false}},
|
VolumeSource: api.VolumeSource{FlexVolume: &api.FlexVolumeSource{Driver: "kubernetes.io/fakeAttacher", ReadOnly: false}},
|
||||||
}
|
}
|
||||||
doTestPluginAttachDetach(t, volume.NewSpecFromVolume(vol))
|
doTestPluginAttachDetach(t, volume.NewSpecFromVolume(vol), tmpDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPluginVolumeMounter(t *testing.T) {
|
func TestPluginVolumeMounter(t *testing.T) {
|
||||||
|
tmpDir, err := utiltesting.MkTmpdir("flexvolume_test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error creating temp dir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
vol := &api.Volume{
|
vol := &api.Volume{
|
||||||
Name: "vol1",
|
Name: "vol1",
|
||||||
VolumeSource: api.VolumeSource{FlexVolume: &api.FlexVolumeSource{Driver: "kubernetes.io/fakeMounter", ReadOnly: false}},
|
VolumeSource: api.VolumeSource{FlexVolume: &api.FlexVolumeSource{Driver: "kubernetes.io/fakeMounter", ReadOnly: false}},
|
||||||
}
|
}
|
||||||
doTestPluginMountUnmount(t, volume.NewSpecFromVolume(vol))
|
doTestPluginMountUnmount(t, volume.NewSpecFromVolume(vol), tmpDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPluginPersistentVolume(t *testing.T) {
|
func TestPluginPersistentVolume(t *testing.T) {
|
||||||
|
tmpDir, err := utiltesting.MkTmpdir("flexvolume_test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error creating temp dir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
vol := &api.PersistentVolume{
|
vol := &api.PersistentVolume{
|
||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
Name: "vol1",
|
Name: "vol1",
|
||||||
@ -370,5 +408,5 @@ func TestPluginPersistentVolume(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
doTestPluginAttachDetach(t, volume.NewSpecFromPersistentVolume(vol, false))
|
doTestPluginAttachDetach(t, volume.NewSpecFromPersistentVolume(vol, false), tmpDir)
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
package flocker
|
package flocker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -25,6 +24,7 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"k8s.io/kubernetes/pkg/types"
|
"k8s.io/kubernetes/pkg/types"
|
||||||
|
utiltesting "k8s.io/kubernetes/pkg/util/testing"
|
||||||
"k8s.io/kubernetes/pkg/volume"
|
"k8s.io/kubernetes/pkg/volume"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ const pluginName = "kubernetes.io/flocker"
|
|||||||
|
|
||||||
func newInitializedVolumePlugMgr(t *testing.T) (volume.VolumePluginMgr, string) {
|
func newInitializedVolumePlugMgr(t *testing.T) (volume.VolumePluginMgr, string) {
|
||||||
plugMgr := volume.VolumePluginMgr{}
|
plugMgr := volume.VolumePluginMgr{}
|
||||||
dir, err := ioutil.TempDir("", "flocker")
|
dir, err := utiltesting.MkTmpdir("flocker")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost(dir, nil, nil))
|
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost(dir, nil, nil))
|
||||||
return plugMgr, dir
|
return plugMgr, dir
|
||||||
|
@ -18,7 +18,6 @@ package gce_pd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"testing"
|
"testing"
|
||||||
@ -28,11 +27,12 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
||||||
"k8s.io/kubernetes/pkg/types"
|
"k8s.io/kubernetes/pkg/types"
|
||||||
"k8s.io/kubernetes/pkg/util/mount"
|
"k8s.io/kubernetes/pkg/util/mount"
|
||||||
|
utiltesting "k8s.io/kubernetes/pkg/util/testing"
|
||||||
"k8s.io/kubernetes/pkg/volume"
|
"k8s.io/kubernetes/pkg/volume"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCanSupport(t *testing.T) {
|
func TestCanSupport(t *testing.T) {
|
||||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "gcepdTest")
|
tmpDir, err := utiltesting.MkTmpdir("gcepdTest")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("can't make a temp dir: %v", err)
|
t.Fatalf("can't make a temp dir: %v", err)
|
||||||
}
|
}
|
||||||
@ -56,7 +56,7 @@ func TestCanSupport(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGetAccessModes(t *testing.T) {
|
func TestGetAccessModes(t *testing.T) {
|
||||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "gcepdTest")
|
tmpDir, err := utiltesting.MkTmpdir("gcepdTest")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("can't make a temp dir: %v", err)
|
t.Fatalf("can't make a temp dir: %v", err)
|
||||||
}
|
}
|
||||||
@ -124,7 +124,7 @@ func (fake *fakePDManager) DeleteVolume(cd *gcePersistentDiskDeleter) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPlugin(t *testing.T) {
|
func TestPlugin(t *testing.T) {
|
||||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "gcepdTest")
|
tmpDir, err := utiltesting.MkTmpdir("gcepdTest")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("can't make a temp dir: %v", err)
|
t.Fatalf("can't make a temp dir: %v", err)
|
||||||
}
|
}
|
||||||
@ -275,7 +275,7 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
|
|||||||
|
|
||||||
client := testclient.NewSimpleFake(pv, claim)
|
client := testclient.NewSimpleFake(pv, claim)
|
||||||
|
|
||||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "gcepdTest")
|
tmpDir, err := utiltesting.MkTmpdir("gcepdTest")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("can't make a temp dir: %v", err)
|
t.Fatalf("can't make a temp dir: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
package glusterfs
|
package glusterfs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -25,12 +26,19 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/types"
|
"k8s.io/kubernetes/pkg/types"
|
||||||
"k8s.io/kubernetes/pkg/util/exec"
|
"k8s.io/kubernetes/pkg/util/exec"
|
||||||
"k8s.io/kubernetes/pkg/util/mount"
|
"k8s.io/kubernetes/pkg/util/mount"
|
||||||
|
utiltesting "k8s.io/kubernetes/pkg/util/testing"
|
||||||
"k8s.io/kubernetes/pkg/volume"
|
"k8s.io/kubernetes/pkg/volume"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCanSupport(t *testing.T) {
|
func TestCanSupport(t *testing.T) {
|
||||||
|
tmpDir, err := utiltesting.MkTmpdir("glusterfs_test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error creating temp dir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
plugMgr := volume.VolumePluginMgr{}
|
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/glusterfs")
|
plug, err := plugMgr.FindPluginByName("kubernetes.io/glusterfs")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Can't find the plugin by name")
|
t.Errorf("Can't find the plugin by name")
|
||||||
@ -47,8 +55,14 @@ func TestCanSupport(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGetAccessModes(t *testing.T) {
|
func TestGetAccessModes(t *testing.T) {
|
||||||
|
tmpDir, err := utiltesting.MkTmpdir("glusterfs_test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error creating temp dir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
plugMgr := volume.VolumePluginMgr{}
|
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/glusterfs")
|
plug, err := plugMgr.FindPersistentPluginByName("kubernetes.io/glusterfs")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -69,8 +83,14 @@ func contains(modes []api.PersistentVolumeAccessMode, mode api.PersistentVolumeA
|
|||||||
}
|
}
|
||||||
|
|
||||||
func doTestPlugin(t *testing.T, spec *volume.Spec) {
|
func doTestPlugin(t *testing.T, spec *volume.Spec) {
|
||||||
|
tmpDir, err := utiltesting.MkTmpdir("glusterfs_test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error creating temp dir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
plugMgr := volume.VolumePluginMgr{}
|
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/glusterfs")
|
plug, err := plugMgr.FindPluginByName("kubernetes.io/glusterfs")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Can't find the plugin by name")
|
t.Errorf("Can't find the plugin by name")
|
||||||
@ -101,8 +121,9 @@ func doTestPlugin(t *testing.T, spec *volume.Spec) {
|
|||||||
t.Error("Got a nil Builder")
|
t.Error("Got a nil Builder")
|
||||||
}
|
}
|
||||||
path := builder.GetPath()
|
path := builder.GetPath()
|
||||||
if path != "/tmp/fake/pods/poduid/volumes/kubernetes.io~glusterfs/vol1" {
|
expectedPath := fmt.Sprintf("%s/pods/poduid/volumes/kubernetes.io~glusterfs/vol1", tmpDir)
|
||||||
t.Errorf("Got unexpected path: %s", path)
|
if path != expectedPath {
|
||||||
|
t.Errorf("Unexpected path, expected %q, got: %q", expectedPath, path)
|
||||||
}
|
}
|
||||||
if err := builder.SetUp(nil); err != nil {
|
if err := builder.SetUp(nil); err != nil {
|
||||||
t.Errorf("Expected success, got: %v", err)
|
t.Errorf("Expected success, got: %v", err)
|
||||||
@ -155,6 +176,12 @@ func TestPluginPersistentVolume(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPersistentClaimReadOnlyFlag(t *testing.T) {
|
func TestPersistentClaimReadOnlyFlag(t *testing.T) {
|
||||||
|
tmpDir, err := utiltesting.MkTmpdir("glusterfs_test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error creating temp dir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
pv := &api.PersistentVolume{
|
pv := &api.PersistentVolume{
|
||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
Name: "pvA",
|
Name: "pvA",
|
||||||
@ -195,7 +222,7 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
|
|||||||
client := testclient.NewSimpleFake(pv, claim, ep)
|
client := testclient.NewSimpleFake(pv, claim, ep)
|
||||||
|
|
||||||
plugMgr := volume.VolumePluginMgr{}
|
plugMgr := volume.VolumePluginMgr{}
|
||||||
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", client, nil))
|
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost(tmpDir, client, nil))
|
||||||
plug, _ := plugMgr.FindPluginByName(glusterfsPluginName)
|
plug, _ := plugMgr.FindPluginByName(glusterfsPluginName)
|
||||||
|
|
||||||
// readOnly bool is supplied by persistent-claim volume source when its builder creates other volumes
|
// readOnly bool is supplied by persistent-claim volume source when its builder creates other volumes
|
||||||
|
@ -90,6 +90,7 @@ func TestRecycler(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDeleter(t *testing.T) {
|
func TestDeleter(t *testing.T) {
|
||||||
|
// Deleter has a hard-coded regex for "/tmp".
|
||||||
tempPath := fmt.Sprintf("/tmp/hostpath/%s", util.NewUUID())
|
tempPath := fmt.Sprintf("/tmp/hostpath/%s", util.NewUUID())
|
||||||
defer os.RemoveAll(tempPath)
|
defer os.RemoveAll(tempPath)
|
||||||
err := os.MkdirAll(tempPath, 0750)
|
err := os.MkdirAll(tempPath, 0750)
|
||||||
@ -147,7 +148,7 @@ func TestDeleterTempDir(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestProvisioner(t *testing.T) {
|
func TestProvisioner(t *testing.T) {
|
||||||
tempPath := "/tmp/hostpath/"
|
tempPath := fmt.Sprintf("/tmp/hostpath/%s", util.NewUUID())
|
||||||
defer os.RemoveAll(tempPath)
|
defer os.RemoveAll(tempPath)
|
||||||
err := os.MkdirAll(tempPath, 0750)
|
err := os.MkdirAll(tempPath, 0750)
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
package iscsi
|
package iscsi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -24,12 +25,19 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
||||||
"k8s.io/kubernetes/pkg/types"
|
"k8s.io/kubernetes/pkg/types"
|
||||||
"k8s.io/kubernetes/pkg/util/mount"
|
"k8s.io/kubernetes/pkg/util/mount"
|
||||||
|
utiltesting "k8s.io/kubernetes/pkg/util/testing"
|
||||||
"k8s.io/kubernetes/pkg/volume"
|
"k8s.io/kubernetes/pkg/volume"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCanSupport(t *testing.T) {
|
func TestCanSupport(t *testing.T) {
|
||||||
|
tmpDir, err := utiltesting.MkTmpdir("iscsi_test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error creating temp dir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
plugMgr := volume.VolumePluginMgr{}
|
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/iscsi")
|
plug, err := plugMgr.FindPluginByName("kubernetes.io/iscsi")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -44,8 +52,14 @@ func TestCanSupport(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGetAccessModes(t *testing.T) {
|
func TestGetAccessModes(t *testing.T) {
|
||||||
|
tmpDir, err := utiltesting.MkTmpdir("iscsi_test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error creating temp dir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
plugMgr := volume.VolumePluginMgr{}
|
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/iscsi")
|
plug, err := plugMgr.FindPersistentPluginByName("kubernetes.io/iscsi")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -66,12 +80,23 @@ func contains(modes []api.PersistentVolumeAccessMode, mode api.PersistentVolumeA
|
|||||||
}
|
}
|
||||||
|
|
||||||
type fakeDiskManager struct {
|
type fakeDiskManager struct {
|
||||||
|
tmpDir string
|
||||||
attachCalled bool
|
attachCalled bool
|
||||||
detachCalled bool
|
detachCalled bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewFakeDiskManager() *fakeDiskManager {
|
||||||
|
return &fakeDiskManager{
|
||||||
|
tmpDir: utiltesting.MkTmpdirOrDie("fc_test"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *fakeDiskManager) Cleanup() {
|
||||||
|
os.RemoveAll(fake.tmpDir)
|
||||||
|
}
|
||||||
|
|
||||||
func (fake *fakeDiskManager) MakeGlobalPDName(disk iscsiDisk) string {
|
func (fake *fakeDiskManager) MakeGlobalPDName(disk iscsiDisk) string {
|
||||||
return "/tmp/fake_iscsi_path"
|
return fake.tmpDir
|
||||||
}
|
}
|
||||||
func (fake *fakeDiskManager) AttachDisk(b iscsiDiskBuilder) error {
|
func (fake *fakeDiskManager) AttachDisk(b iscsiDiskBuilder) error {
|
||||||
globalPath := b.manager.MakeGlobalPDName(*b.iscsiDisk)
|
globalPath := b.manager.MakeGlobalPDName(*b.iscsiDisk)
|
||||||
@ -98,14 +123,21 @@ func (fake *fakeDiskManager) DetachDisk(c iscsiDiskCleaner, mntPath string) erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
func doTestPlugin(t *testing.T, spec *volume.Spec) {
|
func doTestPlugin(t *testing.T, spec *volume.Spec) {
|
||||||
|
tmpDir, err := utiltesting.MkTmpdir("iscsi_test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error creating temp dir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
plugMgr := volume.VolumePluginMgr{}
|
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/iscsi")
|
plug, err := plugMgr.FindPluginByName("kubernetes.io/iscsi")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Can't find the plugin by name")
|
t.Errorf("Can't find the plugin by name")
|
||||||
}
|
}
|
||||||
fakeManager := &fakeDiskManager{}
|
fakeManager := NewFakeDiskManager()
|
||||||
|
defer fakeManager.Cleanup()
|
||||||
fakeMounter := &mount.FakeMounter{}
|
fakeMounter := &mount.FakeMounter{}
|
||||||
builder, err := plug.(*iscsiPlugin).newBuilderInternal(spec, types.UID("poduid"), fakeManager, fakeMounter)
|
builder, err := plug.(*iscsiPlugin).newBuilderInternal(spec, types.UID("poduid"), fakeManager, fakeMounter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -116,8 +148,9 @@ func doTestPlugin(t *testing.T, spec *volume.Spec) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
path := builder.GetPath()
|
path := builder.GetPath()
|
||||||
if path != "/tmp/fake/pods/poduid/volumes/kubernetes.io~iscsi/vol1" {
|
expectedPath := fmt.Sprintf("%s/pods/poduid/volumes/kubernetes.io~iscsi/vol1", tmpDir)
|
||||||
t.Errorf("Got unexpected path: %s", path)
|
if path != expectedPath {
|
||||||
|
t.Errorf("Unexpected path, expected %q, got: %q", expectedPath, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := builder.SetUp(nil); err != nil {
|
if err := builder.SetUp(nil); err != nil {
|
||||||
@ -141,8 +174,9 @@ func doTestPlugin(t *testing.T, spec *volume.Spec) {
|
|||||||
t.Errorf("Attach was not called")
|
t.Errorf("Attach was not called")
|
||||||
}
|
}
|
||||||
|
|
||||||
fakeManager = &fakeDiskManager{}
|
fakeManager2 := NewFakeDiskManager()
|
||||||
cleaner, err := plug.(*iscsiPlugin).newCleanerInternal("vol1", types.UID("poduid"), fakeManager, fakeMounter)
|
defer fakeManager2.Cleanup()
|
||||||
|
cleaner, err := plug.(*iscsiPlugin).newCleanerInternal("vol1", types.UID("poduid"), fakeManager2, fakeMounter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Failed to make a new Cleaner: %v", err)
|
t.Errorf("Failed to make a new Cleaner: %v", err)
|
||||||
}
|
}
|
||||||
@ -158,7 +192,7 @@ func doTestPlugin(t *testing.T, spec *volume.Spec) {
|
|||||||
} else if !os.IsNotExist(err) {
|
} else if !os.IsNotExist(err) {
|
||||||
t.Errorf("SetUp() failed: %v", err)
|
t.Errorf("SetUp() failed: %v", err)
|
||||||
}
|
}
|
||||||
if !fakeManager.detachCalled {
|
if !fakeManager2.detachCalled {
|
||||||
t.Errorf("Detach was not called")
|
t.Errorf("Detach was not called")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -198,6 +232,12 @@ func TestPluginPersistentVolume(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPersistentClaimReadOnlyFlag(t *testing.T) {
|
func TestPersistentClaimReadOnlyFlag(t *testing.T) {
|
||||||
|
tmpDir, err := utiltesting.MkTmpdir("iscsi_test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error creating temp dir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
pv := &api.PersistentVolume{
|
pv := &api.PersistentVolume{
|
||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
Name: "pvA",
|
Name: "pvA",
|
||||||
@ -233,7 +273,7 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
|
|||||||
client := testclient.NewSimpleFake(pv, claim)
|
client := testclient.NewSimpleFake(pv, claim)
|
||||||
|
|
||||||
plugMgr := volume.VolumePluginMgr{}
|
plugMgr := volume.VolumePluginMgr{}
|
||||||
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", client, nil))
|
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost(tmpDir, client, nil))
|
||||||
plug, _ := plugMgr.FindPluginByName(iscsiPluginName)
|
plug, _ := plugMgr.FindPluginByName(iscsiPluginName)
|
||||||
|
|
||||||
// readOnly bool is supplied by persistent-claim volume source when its builder creates other volumes
|
// readOnly bool is supplied by persistent-claim volume source when its builder creates other volumes
|
||||||
|
@ -23,6 +23,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
utiltesting "k8s.io/kubernetes/pkg/util/testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
const expectedBlockSize = 4096
|
const expectedBlockSize = 4096
|
||||||
@ -30,7 +32,7 @@ const expectedBlockSize = 4096
|
|||||||
// TestMetricsDuGetCapacity tests that MetricsDu can read disk usage
|
// TestMetricsDuGetCapacity tests that MetricsDu can read disk usage
|
||||||
// for path
|
// for path
|
||||||
func TestMetricsDuGetCapacity(t *testing.T) {
|
func TestMetricsDuGetCapacity(t *testing.T) {
|
||||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "metrics_du_test")
|
tmpDir, err := utiltesting.MkTmpdir("metrics_du_test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Can't make a tmp dir: %v", err)
|
t.Fatalf("Can't make a tmp dir: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
package nfs
|
package nfs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -24,12 +25,19 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
||||||
"k8s.io/kubernetes/pkg/types"
|
"k8s.io/kubernetes/pkg/types"
|
||||||
"k8s.io/kubernetes/pkg/util/mount"
|
"k8s.io/kubernetes/pkg/util/mount"
|
||||||
|
utiltesting "k8s.io/kubernetes/pkg/util/testing"
|
||||||
"k8s.io/kubernetes/pkg/volume"
|
"k8s.io/kubernetes/pkg/volume"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCanSupport(t *testing.T) {
|
func TestCanSupport(t *testing.T) {
|
||||||
|
tmpDir, err := utiltesting.MkTmpdir("nfs_test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error creating temp dir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
plugMgr := volume.VolumePluginMgr{}
|
plugMgr := volume.VolumePluginMgr{}
|
||||||
plugMgr.InitPlugins(ProbeVolumePlugins(volume.VolumeConfig{}), volume.NewFakeVolumeHost("fake", nil, nil))
|
plugMgr.InitPlugins(ProbeVolumePlugins(volume.VolumeConfig{}), volume.NewFakeVolumeHost(tmpDir, nil, nil))
|
||||||
plug, err := plugMgr.FindPluginByName("kubernetes.io/nfs")
|
plug, err := plugMgr.FindPluginByName("kubernetes.io/nfs")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Can't find the plugin by name")
|
t.Errorf("Can't find the plugin by name")
|
||||||
@ -49,8 +57,14 @@ func TestCanSupport(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGetAccessModes(t *testing.T) {
|
func TestGetAccessModes(t *testing.T) {
|
||||||
|
tmpDir, err := utiltesting.MkTmpdir("nfs_test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error creating temp dir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
plugMgr := volume.VolumePluginMgr{}
|
plugMgr := volume.VolumePluginMgr{}
|
||||||
plugMgr.InitPlugins(ProbeVolumePlugins(volume.VolumeConfig{}), volume.NewFakeVolumeHost("/tmp/fake", nil, nil))
|
plugMgr.InitPlugins(ProbeVolumePlugins(volume.VolumeConfig{}), volume.NewFakeVolumeHost(tmpDir, nil, nil))
|
||||||
|
|
||||||
plug, err := plugMgr.FindPersistentPluginByName("kubernetes.io/nfs")
|
plug, err := plugMgr.FindPersistentPluginByName("kubernetes.io/nfs")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -62,8 +76,14 @@ func TestGetAccessModes(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRecycler(t *testing.T) {
|
func TestRecycler(t *testing.T) {
|
||||||
|
tmpDir, err := utiltesting.MkTmpdir("nfs_test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error creating temp dir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
plugMgr := volume.VolumePluginMgr{}
|
plugMgr := volume.VolumePluginMgr{}
|
||||||
plugMgr.InitPlugins([]volume.VolumePlugin{&nfsPlugin{nil, newMockRecycler, volume.VolumeConfig{}}}, volume.NewFakeVolumeHost("/tmp/fake", nil, nil))
|
plugMgr.InitPlugins([]volume.VolumePlugin{&nfsPlugin{nil, newMockRecycler, volume.VolumeConfig{}}}, volume.NewFakeVolumeHost(tmpDir, nil, nil))
|
||||||
|
|
||||||
spec := &volume.Spec{PersistentVolume: &api.PersistentVolume{Spec: api.PersistentVolumeSpec{PersistentVolumeSource: api.PersistentVolumeSource{NFS: &api.NFSVolumeSource{Path: "/foo"}}}}}
|
spec := &volume.Spec{PersistentVolume: &api.PersistentVolume{Spec: api.PersistentVolumeSpec{PersistentVolumeSource: api.PersistentVolumeSource{NFS: &api.NFSVolumeSource{Path: "/foo"}}}}}
|
||||||
plug, err := plugMgr.FindRecyclablePluginBySpec(spec)
|
plug, err := plugMgr.FindRecyclablePluginBySpec(spec)
|
||||||
@ -113,8 +133,14 @@ func contains(modes []api.PersistentVolumeAccessMode, mode api.PersistentVolumeA
|
|||||||
}
|
}
|
||||||
|
|
||||||
func doTestPlugin(t *testing.T, spec *volume.Spec) {
|
func doTestPlugin(t *testing.T, spec *volume.Spec) {
|
||||||
|
tmpDir, err := utiltesting.MkTmpdir("nfs_test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error creating temp dir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
plugMgr := volume.VolumePluginMgr{}
|
plugMgr := volume.VolumePluginMgr{}
|
||||||
plugMgr.InitPlugins(ProbeVolumePlugins(volume.VolumeConfig{}), volume.NewFakeVolumeHost("/tmp/fake", nil, nil))
|
plugMgr.InitPlugins(ProbeVolumePlugins(volume.VolumeConfig{}), volume.NewFakeVolumeHost(tmpDir, nil, nil))
|
||||||
plug, err := plugMgr.FindPluginByName("kubernetes.io/nfs")
|
plug, err := plugMgr.FindPluginByName("kubernetes.io/nfs")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Can't find the plugin by name")
|
t.Errorf("Can't find the plugin by name")
|
||||||
@ -130,8 +156,9 @@ func doTestPlugin(t *testing.T, spec *volume.Spec) {
|
|||||||
t.Errorf("Got a nil Builder")
|
t.Errorf("Got a nil Builder")
|
||||||
}
|
}
|
||||||
path := builder.GetPath()
|
path := builder.GetPath()
|
||||||
if path != "/tmp/fake/pods/poduid/volumes/kubernetes.io~nfs/vol1" {
|
expectedPath := fmt.Sprintf("%s/pods/poduid/volumes/kubernetes.io~nfs/vol1", tmpDir)
|
||||||
t.Errorf("Got unexpected path: %s", path)
|
if path != expectedPath {
|
||||||
|
t.Errorf("Unexpected path, expected %q, got: %q", expectedPath, path)
|
||||||
}
|
}
|
||||||
if err := builder.SetUp(nil); err != nil {
|
if err := builder.SetUp(nil); err != nil {
|
||||||
t.Errorf("Expected success, got: %v", err)
|
t.Errorf("Expected success, got: %v", err)
|
||||||
@ -184,7 +211,7 @@ func doTestPlugin(t *testing.T, spec *volume.Spec) {
|
|||||||
func TestPluginVolume(t *testing.T) {
|
func TestPluginVolume(t *testing.T) {
|
||||||
vol := &api.Volume{
|
vol := &api.Volume{
|
||||||
Name: "vol1",
|
Name: "vol1",
|
||||||
VolumeSource: api.VolumeSource{NFS: &api.NFSVolumeSource{Server: "localhost", Path: "/tmp", ReadOnly: false}},
|
VolumeSource: api.VolumeSource{NFS: &api.NFSVolumeSource{Server: "localhost", Path: "/somepath", ReadOnly: false}},
|
||||||
}
|
}
|
||||||
doTestPlugin(t, volume.NewSpecFromVolume(vol))
|
doTestPlugin(t, volume.NewSpecFromVolume(vol))
|
||||||
}
|
}
|
||||||
@ -196,7 +223,7 @@ func TestPluginPersistentVolume(t *testing.T) {
|
|||||||
},
|
},
|
||||||
Spec: api.PersistentVolumeSpec{
|
Spec: api.PersistentVolumeSpec{
|
||||||
PersistentVolumeSource: api.PersistentVolumeSource{
|
PersistentVolumeSource: api.PersistentVolumeSource{
|
||||||
NFS: &api.NFSVolumeSource{Server: "localhost", Path: "/tmp", ReadOnly: false},
|
NFS: &api.NFSVolumeSource{Server: "localhost", Path: "/somepath", ReadOnly: false},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -205,6 +232,12 @@ func TestPluginPersistentVolume(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPersistentClaimReadOnlyFlag(t *testing.T) {
|
func TestPersistentClaimReadOnlyFlag(t *testing.T) {
|
||||||
|
tmpDir, err := utiltesting.MkTmpdir("nfs_test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error creating temp dir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
pv := &api.PersistentVolume{
|
pv := &api.PersistentVolume{
|
||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
Name: "pvA",
|
Name: "pvA",
|
||||||
@ -235,7 +268,7 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
|
|||||||
client := testclient.NewSimpleFake(pv, claim)
|
client := testclient.NewSimpleFake(pv, claim)
|
||||||
|
|
||||||
plugMgr := volume.VolumePluginMgr{}
|
plugMgr := volume.VolumePluginMgr{}
|
||||||
plugMgr.InitPlugins(ProbeVolumePlugins(volume.VolumeConfig{}), volume.NewFakeVolumeHost("/tmp/fake", client, nil))
|
plugMgr.InitPlugins(ProbeVolumePlugins(volume.VolumeConfig{}), volume.NewFakeVolumeHost(tmpDir, client, nil))
|
||||||
plug, _ := plugMgr.FindPluginByName(nfsPluginName)
|
plug, _ := plugMgr.FindPluginByName(nfsPluginName)
|
||||||
|
|
||||||
// readOnly bool is supplied by persistent-claim volume source when its builder creates other volumes
|
// readOnly bool is supplied by persistent-claim volume source when its builder creates other volumes
|
||||||
|
@ -18,7 +18,7 @@ package persistent_claim
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -27,22 +27,25 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
||||||
"k8s.io/kubernetes/pkg/types"
|
"k8s.io/kubernetes/pkg/types"
|
||||||
utilstrings "k8s.io/kubernetes/pkg/util/strings"
|
utilstrings "k8s.io/kubernetes/pkg/util/strings"
|
||||||
|
utiltesting "k8s.io/kubernetes/pkg/util/testing"
|
||||||
"k8s.io/kubernetes/pkg/volume"
|
"k8s.io/kubernetes/pkg/volume"
|
||||||
"k8s.io/kubernetes/pkg/volume/gce_pd"
|
"k8s.io/kubernetes/pkg/volume/gce_pd"
|
||||||
"k8s.io/kubernetes/pkg/volume/host_path"
|
"k8s.io/kubernetes/pkg/volume/host_path"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newTestHost(t *testing.T, fakeKubeClient client.Interface) volume.VolumeHost {
|
// newTestHost returns the temp directory and the VolumeHost created.
|
||||||
tempDir, err := ioutil.TempDir("/tmp", "persistent_volume_test.")
|
// Please be sure to cleanup the temp directory once done!
|
||||||
|
func newTestHost(t *testing.T, fakeKubeClient client.Interface) (string, volume.VolumeHost) {
|
||||||
|
tempDir, err := utiltesting.MkTmpdir("persistent_volume_test.")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("can't make a temp rootdir: %v", err)
|
t.Fatalf("can't make a temp rootdir: %v", err)
|
||||||
}
|
}
|
||||||
return volume.NewFakeVolumeHost(tempDir, fakeKubeClient, testProbeVolumePlugins())
|
return tempDir, volume.NewFakeVolumeHost(tempDir, fakeKubeClient, testProbeVolumePlugins())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCanSupport(t *testing.T) {
|
func TestCanSupport(t *testing.T) {
|
||||||
plugMgr := volume.VolumePluginMgr{}
|
plugMgr := volume.VolumePluginMgr{}
|
||||||
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", nil, ProbeVolumePlugins()))
|
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/somepath/fake", nil, ProbeVolumePlugins()))
|
||||||
|
|
||||||
plug, err := plugMgr.FindPluginByName("kubernetes.io/persistent-claim")
|
plug, err := plugMgr.FindPluginByName("kubernetes.io/persistent-claim")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -119,7 +122,7 @@ func TestNewBuilder(t *testing.T) {
|
|||||||
},
|
},
|
||||||
Spec: api.PersistentVolumeSpec{
|
Spec: api.PersistentVolumeSpec{
|
||||||
PersistentVolumeSource: api.PersistentVolumeSource{
|
PersistentVolumeSource: api.PersistentVolumeSource{
|
||||||
HostPath: &api.HostPathVolumeSource{Path: "/tmp"},
|
HostPath: &api.HostPathVolumeSource{Path: "/somepath"},
|
||||||
},
|
},
|
||||||
ClaimRef: &api.ObjectReference{
|
ClaimRef: &api.ObjectReference{
|
||||||
Name: "claimB",
|
Name: "claimB",
|
||||||
@ -143,8 +146,8 @@ func TestNewBuilder(t *testing.T) {
|
|||||||
},
|
},
|
||||||
plugin: host_path.ProbeVolumePlugins(volume.VolumeConfig{})[0],
|
plugin: host_path.ProbeVolumePlugins(volume.VolumeConfig{})[0],
|
||||||
testFunc: func(builder volume.Builder, plugin volume.VolumePlugin) error {
|
testFunc: func(builder volume.Builder, plugin volume.VolumePlugin) error {
|
||||||
if builder.GetPath() != "/tmp" {
|
if builder.GetPath() != "/somepath" {
|
||||||
return fmt.Errorf("Expected HostPath.Path /tmp, got: %s", builder.GetPath())
|
return fmt.Errorf("Expected HostPath.Path /somepath, got: %s", builder.GetPath())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
@ -237,7 +240,9 @@ func TestNewBuilder(t *testing.T) {
|
|||||||
client := testclient.NewSimpleFake(item.pv, item.claim)
|
client := testclient.NewSimpleFake(item.pv, item.claim)
|
||||||
|
|
||||||
plugMgr := volume.VolumePluginMgr{}
|
plugMgr := volume.VolumePluginMgr{}
|
||||||
plugMgr.InitPlugins(testProbeVolumePlugins(), newTestHost(t, client))
|
tempDir, vh := newTestHost(t, client)
|
||||||
|
defer os.RemoveAll(tempDir)
|
||||||
|
plugMgr.InitPlugins(testProbeVolumePlugins(), vh)
|
||||||
|
|
||||||
plug, err := plugMgr.FindPluginByName("kubernetes.io/persistent-claim")
|
plug, err := plugMgr.FindPluginByName("kubernetes.io/persistent-claim")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -288,7 +293,9 @@ func TestNewBuilderClaimNotBound(t *testing.T) {
|
|||||||
client := testclient.NewSimpleFake(pv, claim)
|
client := testclient.NewSimpleFake(pv, claim)
|
||||||
|
|
||||||
plugMgr := volume.VolumePluginMgr{}
|
plugMgr := volume.VolumePluginMgr{}
|
||||||
plugMgr.InitPlugins(testProbeVolumePlugins(), newTestHost(t, client))
|
tempDir, vh := newTestHost(t, client)
|
||||||
|
defer os.RemoveAll(tempDir)
|
||||||
|
plugMgr.InitPlugins(testProbeVolumePlugins(), vh)
|
||||||
|
|
||||||
plug, err := plugMgr.FindPluginByName("kubernetes.io/persistent-claim")
|
plug, err := plugMgr.FindPluginByName("kubernetes.io/persistent-claim")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
package rbd
|
package rbd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -24,12 +25,19 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
|
||||||
"k8s.io/kubernetes/pkg/types"
|
"k8s.io/kubernetes/pkg/types"
|
||||||
"k8s.io/kubernetes/pkg/util/mount"
|
"k8s.io/kubernetes/pkg/util/mount"
|
||||||
|
utiltesting "k8s.io/kubernetes/pkg/util/testing"
|
||||||
"k8s.io/kubernetes/pkg/volume"
|
"k8s.io/kubernetes/pkg/volume"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCanSupport(t *testing.T) {
|
func TestCanSupport(t *testing.T) {
|
||||||
|
tmpDir, err := utiltesting.MkTmpdir("rbd_test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error creating temp dir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
plugMgr := volume.VolumePluginMgr{}
|
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/rbd")
|
plug, err := plugMgr.FindPluginByName("kubernetes.io/rbd")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -43,10 +51,22 @@ func TestCanSupport(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type fakeDiskManager struct{}
|
type fakeDiskManager struct {
|
||||||
|
tmpDir string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFakeDiskManager() *fakeDiskManager {
|
||||||
|
return &fakeDiskManager{
|
||||||
|
tmpDir: utiltesting.MkTmpdirOrDie("rbd_test"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fake *fakeDiskManager) Cleanup() {
|
||||||
|
os.RemoveAll(fake.tmpDir)
|
||||||
|
}
|
||||||
|
|
||||||
func (fake *fakeDiskManager) MakeGlobalPDName(disk rbd) string {
|
func (fake *fakeDiskManager) MakeGlobalPDName(disk rbd) string {
|
||||||
return "/tmp/fake_rbd_path"
|
return fake.tmpDir
|
||||||
}
|
}
|
||||||
func (fake *fakeDiskManager) AttachDisk(b rbdBuilder) error {
|
func (fake *fakeDiskManager) AttachDisk(b rbdBuilder) error {
|
||||||
globalPath := b.manager.MakeGlobalPDName(*b.rbd)
|
globalPath := b.manager.MakeGlobalPDName(*b.rbd)
|
||||||
@ -67,14 +87,22 @@ func (fake *fakeDiskManager) DetachDisk(c rbdCleaner, mntPath string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func doTestPlugin(t *testing.T, spec *volume.Spec) {
|
func doTestPlugin(t *testing.T, spec *volume.Spec) {
|
||||||
|
tmpDir, err := utiltesting.MkTmpdir("rbd_test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error creating temp dir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
plugMgr := volume.VolumePluginMgr{}
|
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/rbd")
|
plug, err := plugMgr.FindPluginByName("kubernetes.io/rbd")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Can't find the plugin by name")
|
t.Errorf("Can't find the plugin by name")
|
||||||
}
|
}
|
||||||
builder, err := plug.(*rbdPlugin).newBuilderInternal(spec, types.UID("poduid"), &fakeDiskManager{}, &mount.FakeMounter{}, "secrets")
|
fdm := NewFakeDiskManager()
|
||||||
|
defer fdm.Cleanup()
|
||||||
|
builder, err := plug.(*rbdPlugin).newBuilderInternal(spec, types.UID("poduid"), fdm, &mount.FakeMounter{}, "secrets")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Failed to make a new Builder: %v", err)
|
t.Errorf("Failed to make a new Builder: %v", err)
|
||||||
}
|
}
|
||||||
@ -83,8 +111,9 @@ func doTestPlugin(t *testing.T, spec *volume.Spec) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
path := builder.GetPath()
|
path := builder.GetPath()
|
||||||
if path != "/tmp/fake/pods/poduid/volumes/kubernetes.io~rbd/vol1" {
|
expectedPath := fmt.Sprintf("%s/pods/poduid/volumes/kubernetes.io~rbd/vol1", tmpDir)
|
||||||
t.Errorf("Got unexpected path: %s", path)
|
if path != expectedPath {
|
||||||
|
t.Errorf("Unexpected path, expected %q, got: %q", expectedPath, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := builder.SetUp(nil); err != nil {
|
if err := builder.SetUp(nil); err != nil {
|
||||||
@ -105,7 +134,7 @@ func doTestPlugin(t *testing.T, spec *volume.Spec) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cleaner, err := plug.(*rbdPlugin).newCleanerInternal("vol1", types.UID("poduid"), &fakeDiskManager{}, &mount.FakeMounter{})
|
cleaner, err := plug.(*rbdPlugin).newCleanerInternal("vol1", types.UID("poduid"), fdm, &mount.FakeMounter{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Failed to make a new Cleaner: %v", err)
|
t.Errorf("Failed to make a new Cleaner: %v", err)
|
||||||
}
|
}
|
||||||
@ -156,6 +185,12 @@ func TestPluginPersistentVolume(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPersistentClaimReadOnlyFlag(t *testing.T) {
|
func TestPersistentClaimReadOnlyFlag(t *testing.T) {
|
||||||
|
tmpDir, err := utiltesting.MkTmpdir("rbd_test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error creating temp dir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
pv := &api.PersistentVolume{
|
pv := &api.PersistentVolume{
|
||||||
ObjectMeta: api.ObjectMeta{
|
ObjectMeta: api.ObjectMeta{
|
||||||
Name: "pvA",
|
Name: "pvA",
|
||||||
@ -190,7 +225,7 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
|
|||||||
client := testclient.NewSimpleFake(pv, claim)
|
client := testclient.NewSimpleFake(pv, claim)
|
||||||
|
|
||||||
plugMgr := volume.VolumePluginMgr{}
|
plugMgr := volume.VolumePluginMgr{}
|
||||||
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", client, nil))
|
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost(tmpDir, client, nil))
|
||||||
plug, _ := plugMgr.FindPluginByName(rbdPluginName)
|
plug, _ := plugMgr.FindPluginByName(rbdPluginName)
|
||||||
|
|
||||||
// readOnly bool is supplied by persistent-claim volume source when its builder creates other volumes
|
// readOnly bool is supplied by persistent-claim volume source when its builder creates other volumes
|
||||||
|
Loading…
Reference in New Issue
Block a user