Bumping k8s dependencies to 1.13
This commit is contained in:
128
vendor/k8s.io/kubernetes/pkg/volume/local/local_test.go
generated
vendored
128
vendor/k8s.io/kubernetes/pkg/volume/local/local_test.go
generated
vendored
@@ -31,16 +31,18 @@ import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
utiltesting "k8s.io/client-go/util/testing"
|
||||
"k8s.io/kubernetes/pkg/util/mount"
|
||||
"k8s.io/kubernetes/pkg/volume"
|
||||
volumetest "k8s.io/kubernetes/pkg/volume/testing"
|
||||
)
|
||||
|
||||
const (
|
||||
testPVName = "pvA"
|
||||
testMountPath = "pods/poduid/volumes/kubernetes.io~local-volume/pvA"
|
||||
testGlobalPath = "plugins/kubernetes.io~local-volume/volumeDevices/pvA"
|
||||
testPodPath = "pods/poduid/volumeDevices/kubernetes.io~local-volume"
|
||||
testNodeName = "fakeNodeName"
|
||||
testPVName = "pvA"
|
||||
testMountPath = "pods/poduid/volumes/kubernetes.io~local-volume/pvA"
|
||||
testGlobalPath = "plugins/kubernetes.io~local-volume/volumeDevices/pvA"
|
||||
testPodPath = "pods/poduid/volumeDevices/kubernetes.io~local-volume"
|
||||
testNodeName = "fakeNodeName"
|
||||
testBlockFormattingToFSGlobalPath = "plugins/kubernetes.io/local-volume/mounts/pvA"
|
||||
)
|
||||
|
||||
func getPlugin(t *testing.T) (string, volume.VolumePlugin) {
|
||||
@@ -102,6 +104,33 @@ func getPersistentPlugin(t *testing.T) (string, volume.PersistentVolumePlugin) {
|
||||
return tmpDir, plug
|
||||
}
|
||||
|
||||
func getDeviceMountablePluginWithBlockPath(t *testing.T, isBlockDevice bool) (string, volume.DeviceMountableVolumePlugin) {
|
||||
tmpDir, err := utiltesting.MkTmpdir("localVolumeTest")
|
||||
if err != nil {
|
||||
t.Fatalf("can't make a temp dir: %v", err)
|
||||
}
|
||||
|
||||
plugMgr := volume.VolumePluginMgr{}
|
||||
var pathToFSType map[string]mount.FileType
|
||||
if isBlockDevice {
|
||||
pathToFSType = map[string]mount.FileType{
|
||||
tmpDir: mount.FileTypeBlockDev,
|
||||
}
|
||||
}
|
||||
|
||||
plugMgr.InitPlugins(ProbeVolumePlugins(), nil /* prober */, volumetest.NewFakeVolumeHostWithMounterFSType(tmpDir, nil, nil, pathToFSType))
|
||||
|
||||
plug, err := plugMgr.FindDeviceMountablePluginByName(localVolumePluginName)
|
||||
if err != nil {
|
||||
os.RemoveAll(tmpDir)
|
||||
t.Fatalf("Can't find the plugin by name")
|
||||
}
|
||||
if plug.GetPluginName() != localVolumePluginName {
|
||||
t.Errorf("Wrong name: %s", plug.GetPluginName())
|
||||
}
|
||||
return tmpDir, plug
|
||||
}
|
||||
|
||||
func getTestVolume(readOnly bool, path string, isBlock bool) *volume.Spec {
|
||||
pv := &v1.PersistentVolume{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
@@ -179,6 +208,87 @@ func TestInvalidLocalPath(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBlockDeviceGlobalPathAndMountDevice(t *testing.T) {
|
||||
// Block device global mount path testing
|
||||
tmpBlockDir, plug := getDeviceMountablePluginWithBlockPath(t, true)
|
||||
defer os.RemoveAll(tmpBlockDir)
|
||||
|
||||
dm, err := plug.NewDeviceMounter()
|
||||
if err != nil {
|
||||
t.Errorf("Failed to make a new device mounter: %v", err)
|
||||
}
|
||||
|
||||
pvSpec := getTestVolume(false, tmpBlockDir, false)
|
||||
|
||||
expectedGlobalPath := filepath.Join(tmpBlockDir, testBlockFormattingToFSGlobalPath)
|
||||
actualPath, err := dm.GetDeviceMountPath(pvSpec)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to get device mount path: %v", err)
|
||||
}
|
||||
if expectedGlobalPath != actualPath {
|
||||
t.Fatalf("Expected device mount global path:%s, got: %s", expectedGlobalPath, actualPath)
|
||||
}
|
||||
|
||||
fmt.Println("expected global path is:", expectedGlobalPath)
|
||||
|
||||
err = dm.MountDevice(pvSpec, tmpBlockDir, expectedGlobalPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := os.Stat(actualPath); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
t.Errorf("DeviceMounter.MountDevice() failed, device mount path not created: %s", actualPath)
|
||||
} else {
|
||||
t.Errorf("DeviceMounter.MountDevice() failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
du, err := plug.NewDeviceUnmounter()
|
||||
if err != nil {
|
||||
t.Fatalf("Create device unmounter error: %v", err)
|
||||
}
|
||||
|
||||
err = du.UnmountDevice(actualPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Unmount device error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFSGlobalPathAndMountDevice(t *testing.T) {
|
||||
// FS global path testing
|
||||
tmpFSDir, plug := getDeviceMountablePluginWithBlockPath(t, false)
|
||||
defer os.RemoveAll(tmpFSDir)
|
||||
|
||||
dm, err := plug.NewDeviceMounter()
|
||||
if err != nil {
|
||||
t.Errorf("Failed to make a new device mounter: %v", err)
|
||||
}
|
||||
|
||||
pvSpec := getTestVolume(false, tmpFSDir, false)
|
||||
|
||||
expectedGlobalPath := tmpFSDir
|
||||
actualPath, err := dm.GetDeviceMountPath(pvSpec)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to get device mount path: %v", err)
|
||||
}
|
||||
if expectedGlobalPath != actualPath {
|
||||
t.Fatalf("Expected device mount global path:%s, got: %s", expectedGlobalPath, actualPath)
|
||||
}
|
||||
|
||||
// Actually, we will do nothing if the local path is FS type
|
||||
err = dm.MountDevice(pvSpec, tmpFSDir, expectedGlobalPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := os.Stat(expectedGlobalPath); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
t.Errorf("DeviceMounter.MountDevice() failed, device mount path not created: %s", expectedGlobalPath)
|
||||
} else {
|
||||
t.Errorf("DeviceMounter.MountDevice() failed: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMountUnmount(t *testing.T) {
|
||||
tmpDir, plug := getPlugin(t)
|
||||
defer os.RemoveAll(tmpDir)
|
||||
@@ -336,6 +446,14 @@ func TestConstructVolumeSpec(t *testing.T) {
|
||||
t.Fatalf("PersistentVolume object nil")
|
||||
}
|
||||
|
||||
if spec.PersistentVolume.Spec.VolumeMode == nil {
|
||||
t.Fatalf("Volume mode has not been set.")
|
||||
}
|
||||
|
||||
if *spec.PersistentVolume.Spec.VolumeMode != v1.PersistentVolumeFilesystem {
|
||||
t.Errorf("Unexpected volume mode %q", *spec.PersistentVolume.Spec.VolumeMode)
|
||||
}
|
||||
|
||||
ls := pv.Spec.PersistentVolumeSource.Local
|
||||
if ls == nil {
|
||||
t.Fatalf("LocalVolumeSource object nil")
|
||||
|
Reference in New Issue
Block a user