2015-03-26 18:53:21 +00:00
|
|
|
/*
|
2016-06-03 00:25:58 +00:00
|
|
|
Copyright 2014 The Kubernetes Authors.
|
2015-03-26 18:53:21 +00:00
|
|
|
|
|
|
|
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 glusterfs
|
|
|
|
|
|
|
|
import (
|
2016-01-25 21:57:42 +00:00
|
|
|
"fmt"
|
2015-03-26 18:53:21 +00:00
|
|
|
"os"
|
2016-10-18 07:54:35 +00:00
|
|
|
"reflect"
|
2015-03-26 18:53:21 +00:00
|
|
|
"testing"
|
|
|
|
|
2017-01-06 07:03:25 +00:00
|
|
|
gapi "github.com/heketi/heketi/pkg/glusterfs/api"
|
2017-06-22 18:24:23 +00:00
|
|
|
"k8s.io/api/core/v1"
|
2017-01-17 03:38:19 +00:00
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
2017-01-11 14:09:48 +00:00
|
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
|
|
"k8s.io/apimachinery/pkg/types"
|
2017-06-23 20:56:37 +00:00
|
|
|
"k8s.io/client-go/kubernetes/fake"
|
2017-01-25 20:07:10 +00:00
|
|
|
core "k8s.io/client-go/testing"
|
2017-01-23 18:37:22 +00:00
|
|
|
utiltesting "k8s.io/client-go/util/testing"
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/util/mount"
|
|
|
|
"k8s.io/kubernetes/pkg/volume"
|
2016-02-29 21:31:42 +00:00
|
|
|
volumetest "k8s.io/kubernetes/pkg/volume/testing"
|
2015-03-26 18:53:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCanSupport(t *testing.T) {
|
2016-01-25 21:57:42 +00:00
|
|
|
tmpDir, err := utiltesting.MkTmpdir("glusterfs_test")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error creating temp dir: %v", err)
|
|
|
|
}
|
|
|
|
defer os.RemoveAll(tmpDir)
|
|
|
|
|
2015-03-26 18:53:21 +00:00
|
|
|
plugMgr := volume.VolumePluginMgr{}
|
2017-07-26 00:48:26 +00:00
|
|
|
plugMgr.InitPlugins(ProbeVolumePlugins(), nil /* prober */, volumetest.NewFakeVolumeHost(tmpDir, nil, nil))
|
2015-03-26 18:53:21 +00:00
|
|
|
plug, err := plugMgr.FindPluginByName("kubernetes.io/glusterfs")
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Can't find the plugin by name")
|
|
|
|
}
|
2016-05-30 02:22:22 +00:00
|
|
|
if plug.GetPluginName() != "kubernetes.io/glusterfs" {
|
|
|
|
t.Errorf("Wrong name: %s", plug.GetPluginName())
|
2015-03-26 18:53:21 +00:00
|
|
|
}
|
2018-02-08 08:24:54 +00:00
|
|
|
if plug.CanSupport(&volume.Spec{}) {
|
2015-10-07 16:47:11 +00:00
|
|
|
t.Errorf("Expected false")
|
2015-05-23 13:53:33 +00:00
|
|
|
}
|
2016-11-18 20:58:56 +00:00
|
|
|
if plug.CanSupport(&volume.Spec{Volume: &v1.Volume{VolumeSource: v1.VolumeSource{}}}) {
|
2015-03-26 18:53:21 +00:00
|
|
|
t.Errorf("Expected false")
|
|
|
|
}
|
2018-02-08 08:24:54 +00:00
|
|
|
if !plug.CanSupport(&volume.Spec{Volume: &v1.Volume{VolumeSource: v1.VolumeSource{Glusterfs: &v1.GlusterfsVolumeSource{}}}}) {
|
|
|
|
t.Errorf("Expected true")
|
|
|
|
}
|
|
|
|
if plug.CanSupport(&volume.Spec{PersistentVolume: &v1.PersistentVolume{Spec: v1.PersistentVolumeSpec{}}}) {
|
|
|
|
t.Errorf("Expected false")
|
|
|
|
}
|
|
|
|
if plug.CanSupport(&volume.Spec{PersistentVolume: &v1.PersistentVolume{Spec: v1.PersistentVolumeSpec{PersistentVolumeSource: v1.PersistentVolumeSource{}}}}) {
|
|
|
|
t.Errorf("Expected false")
|
|
|
|
}
|
|
|
|
if !plug.CanSupport(&volume.Spec{PersistentVolume: &v1.PersistentVolume{Spec: v1.PersistentVolumeSpec{PersistentVolumeSource: v1.PersistentVolumeSource{Glusterfs: &v1.GlusterfsVolumeSource{}}}}}) {
|
|
|
|
t.Errorf("Expected true")
|
|
|
|
}
|
2015-03-26 18:53:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetAccessModes(t *testing.T) {
|
2016-01-25 21:57:42 +00:00
|
|
|
tmpDir, err := utiltesting.MkTmpdir("glusterfs_test")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error creating temp dir: %v", err)
|
|
|
|
}
|
|
|
|
defer os.RemoveAll(tmpDir)
|
|
|
|
|
2015-03-26 18:53:21 +00:00
|
|
|
plugMgr := volume.VolumePluginMgr{}
|
2017-07-26 00:48:26 +00:00
|
|
|
plugMgr.InitPlugins(ProbeVolumePlugins(), nil /* prober */, volumetest.NewFakeVolumeHost(tmpDir, nil, nil))
|
2015-03-26 18:53:21 +00:00
|
|
|
|
|
|
|
plug, err := plugMgr.FindPersistentPluginByName("kubernetes.io/glusterfs")
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Can't find the plugin by name")
|
|
|
|
}
|
2017-10-20 16:35:47 +00:00
|
|
|
if !volumetest.ContainsAccessMode(plug.GetAccessModes(), v1.ReadWriteOnce) || !volumetest.ContainsAccessMode(plug.GetAccessModes(), v1.ReadOnlyMany) || !volumetest.ContainsAccessMode(plug.GetAccessModes(), v1.ReadWriteMany) {
|
2016-11-18 20:58:56 +00:00
|
|
|
t.Errorf("Expected three AccessModeTypes: %s, %s, and %s", v1.ReadWriteOnce, v1.ReadOnlyMany, v1.ReadWriteMany)
|
2015-03-26 18:53:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-01 14:34:40 +00:00
|
|
|
func doTestPlugin(t *testing.T, spec *volume.Spec) {
|
2016-01-25 21:57:42 +00:00
|
|
|
tmpDir, err := utiltesting.MkTmpdir("glusterfs_test")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error creating temp dir: %v", err)
|
|
|
|
}
|
|
|
|
defer os.RemoveAll(tmpDir)
|
|
|
|
|
2015-03-26 18:53:21 +00:00
|
|
|
plugMgr := volume.VolumePluginMgr{}
|
2017-07-26 00:48:26 +00:00
|
|
|
plugMgr.InitPlugins(ProbeVolumePlugins(), nil /* prober */, volumetest.NewFakeVolumeHost(tmpDir, nil, nil))
|
2015-03-26 18:53:21 +00:00
|
|
|
plug, err := plugMgr.FindPluginByName("kubernetes.io/glusterfs")
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Can't find the plugin by name")
|
|
|
|
}
|
2017-01-17 03:38:19 +00:00
|
|
|
ep := &v1.Endpoints{ObjectMeta: metav1.ObjectMeta{Name: "foo"}, Subsets: []v1.EndpointSubset{{
|
2016-11-18 20:58:56 +00:00
|
|
|
Addresses: []v1.EndpointAddress{{IP: "127.0.0.1"}}}}}
|
2017-01-17 03:38:19 +00:00
|
|
|
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{UID: types.UID("poduid")}}
|
2017-08-22 12:53:25 +00:00
|
|
|
mounter, err := plug.(*glusterfsPlugin).newMounterInternal(spec, ep, pod, &mount.FakeMounter{})
|
2016-03-23 05:12:21 +00:00
|
|
|
volumePath := mounter.GetPath()
|
2015-03-26 18:53:21 +00:00
|
|
|
if err != nil {
|
2016-03-23 05:12:21 +00:00
|
|
|
t.Errorf("Failed to make a new Mounter: %v", err)
|
2015-03-26 18:53:21 +00:00
|
|
|
}
|
2016-03-23 05:12:21 +00:00
|
|
|
if mounter == nil {
|
|
|
|
t.Error("Got a nil Mounter")
|
2015-03-26 18:53:21 +00:00
|
|
|
}
|
2016-01-25 21:57:42 +00:00
|
|
|
expectedPath := fmt.Sprintf("%s/pods/poduid/volumes/kubernetes.io~glusterfs/vol1", tmpDir)
|
2017-03-26 14:44:16 +00:00
|
|
|
if volumePath != expectedPath {
|
|
|
|
t.Errorf("Unexpected path, expected %q, got: %q", expectedPath, volumePath)
|
2015-03-26 18:53:21 +00:00
|
|
|
}
|
2016-03-23 05:12:21 +00:00
|
|
|
if err := mounter.SetUp(nil); err != nil {
|
2015-03-26 18:53:21 +00:00
|
|
|
t.Errorf("Expected success, got: %v", err)
|
|
|
|
}
|
|
|
|
if _, err := os.Stat(volumePath); err != nil {
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
t.Errorf("SetUp() failed, volume path not created: %s", volumePath)
|
|
|
|
} else {
|
|
|
|
t.Errorf("SetUp() failed: %v", err)
|
|
|
|
}
|
|
|
|
}
|
2016-03-23 05:12:21 +00:00
|
|
|
unmounter, err := plug.(*glusterfsPlugin).newUnmounterInternal("vol1", types.UID("poduid"), &mount.FakeMounter{})
|
2015-03-26 18:53:21 +00:00
|
|
|
if err != nil {
|
2016-03-23 05:12:21 +00:00
|
|
|
t.Errorf("Failed to make a new Unmounter: %v", err)
|
2015-03-26 18:53:21 +00:00
|
|
|
}
|
2016-03-23 05:12:21 +00:00
|
|
|
if unmounter == nil {
|
|
|
|
t.Error("Got a nil Unmounter")
|
2015-03-26 18:53:21 +00:00
|
|
|
}
|
2016-03-23 05:12:21 +00:00
|
|
|
if err := unmounter.TearDown(); err != nil {
|
2015-03-26 18:53:21 +00:00
|
|
|
t.Errorf("Expected success, got: %v", err)
|
|
|
|
}
|
|
|
|
if _, err := os.Stat(volumePath); err == nil {
|
|
|
|
t.Errorf("TearDown() failed, volume path still exists: %s", volumePath)
|
|
|
|
} else if !os.IsNotExist(err) {
|
2017-10-25 17:30:33 +00:00
|
|
|
t.Errorf("TearDown() failed: %v", err)
|
2015-03-26 18:53:21 +00:00
|
|
|
}
|
|
|
|
}
|
2015-06-01 14:34:40 +00:00
|
|
|
|
|
|
|
func TestPluginVolume(t *testing.T) {
|
2016-11-18 20:58:56 +00:00
|
|
|
vol := &v1.Volume{
|
2015-06-01 14:34:40 +00:00
|
|
|
Name: "vol1",
|
2016-11-18 20:58:56 +00:00
|
|
|
VolumeSource: v1.VolumeSource{Glusterfs: &v1.GlusterfsVolumeSource{EndpointsName: "ep", Path: "vol", ReadOnly: false}},
|
2015-06-01 14:34:40 +00:00
|
|
|
}
|
|
|
|
doTestPlugin(t, volume.NewSpecFromVolume(vol))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPluginPersistentVolume(t *testing.T) {
|
2016-11-18 20:58:56 +00:00
|
|
|
vol := &v1.PersistentVolume{
|
2017-01-17 03:38:19 +00:00
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
2015-06-01 14:34:40 +00:00
|
|
|
Name: "vol1",
|
|
|
|
},
|
2016-11-18 20:58:56 +00:00
|
|
|
Spec: v1.PersistentVolumeSpec{
|
|
|
|
PersistentVolumeSource: v1.PersistentVolumeSource{
|
|
|
|
Glusterfs: &v1.GlusterfsVolumeSource{EndpointsName: "ep", Path: "vol", ReadOnly: false},
|
2015-06-01 14:34:40 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2015-07-01 14:50:39 +00:00
|
|
|
doTestPlugin(t, volume.NewSpecFromPersistentVolume(vol, false))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPersistentClaimReadOnlyFlag(t *testing.T) {
|
2016-01-25 21:57:42 +00:00
|
|
|
tmpDir, err := utiltesting.MkTmpdir("glusterfs_test")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error creating temp dir: %v", err)
|
|
|
|
}
|
|
|
|
defer os.RemoveAll(tmpDir)
|
|
|
|
|
2016-11-18 20:58:56 +00:00
|
|
|
pv := &v1.PersistentVolume{
|
2017-01-17 03:38:19 +00:00
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
2015-07-01 14:50:39 +00:00
|
|
|
Name: "pvA",
|
|
|
|
},
|
2016-11-18 20:58:56 +00:00
|
|
|
Spec: v1.PersistentVolumeSpec{
|
|
|
|
PersistentVolumeSource: v1.PersistentVolumeSource{
|
|
|
|
Glusterfs: &v1.GlusterfsVolumeSource{EndpointsName: "ep", Path: "vol", ReadOnly: false},
|
2015-07-01 14:50:39 +00:00
|
|
|
},
|
2016-11-18 20:58:56 +00:00
|
|
|
ClaimRef: &v1.ObjectReference{
|
2015-07-01 14:50:39 +00:00
|
|
|
Name: "claimA",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2016-11-18 20:58:56 +00:00
|
|
|
claim := &v1.PersistentVolumeClaim{
|
2017-01-17 03:38:19 +00:00
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
2015-07-01 14:50:39 +00:00
|
|
|
Name: "claimA",
|
|
|
|
Namespace: "nsA",
|
|
|
|
},
|
2016-11-18 20:58:56 +00:00
|
|
|
Spec: v1.PersistentVolumeClaimSpec{
|
2015-07-01 14:50:39 +00:00
|
|
|
VolumeName: "pvA",
|
|
|
|
},
|
2016-11-18 20:58:56 +00:00
|
|
|
Status: v1.PersistentVolumeClaimStatus{
|
|
|
|
Phase: v1.ClaimBound,
|
2015-07-01 14:50:39 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2016-11-18 20:58:56 +00:00
|
|
|
ep := &v1.Endpoints{
|
2017-01-17 03:38:19 +00:00
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
2016-06-02 01:47:36 +00:00
|
|
|
Namespace: "nsA",
|
|
|
|
Name: "ep",
|
2015-07-01 14:50:39 +00:00
|
|
|
},
|
2016-11-18 20:58:56 +00:00
|
|
|
Subsets: []v1.EndpointSubset{{
|
|
|
|
Addresses: []v1.EndpointAddress{{IP: "127.0.0.1"}},
|
|
|
|
Ports: []v1.EndpointPort{{Name: "foo", Port: 80, Protocol: v1.ProtocolTCP}},
|
2015-07-01 14:50:39 +00:00
|
|
|
}},
|
|
|
|
}
|
|
|
|
|
2016-01-15 05:00:58 +00:00
|
|
|
client := fake.NewSimpleClientset(pv, claim, ep)
|
2015-07-01 14:50:39 +00:00
|
|
|
|
|
|
|
plugMgr := volume.VolumePluginMgr{}
|
2017-07-26 00:48:26 +00:00
|
|
|
plugMgr.InitPlugins(ProbeVolumePlugins(), nil /* prober */, volumetest.NewFakeVolumeHost(tmpDir, client, nil))
|
2015-07-01 14:50:39 +00:00
|
|
|
plug, _ := plugMgr.FindPluginByName(glusterfsPluginName)
|
|
|
|
|
2016-03-23 05:12:21 +00:00
|
|
|
// readOnly bool is supplied by persistent-claim volume source when its mounter creates other volumes
|
2015-07-01 14:50:39 +00:00
|
|
|
spec := volume.NewSpecFromPersistentVolume(pv, true)
|
2017-01-17 03:38:19 +00:00
|
|
|
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Namespace: "nsA", UID: types.UID("poduid")}}
|
2016-03-23 05:12:21 +00:00
|
|
|
mounter, _ := plug.NewMounter(spec, pod, volume.VolumeOptions{})
|
2015-07-01 14:50:39 +00:00
|
|
|
|
2016-03-23 05:12:21 +00:00
|
|
|
if !mounter.GetAttributes().ReadOnly {
|
|
|
|
t.Errorf("Expected true for mounter.IsReadOnly")
|
2015-07-01 14:50:39 +00:00
|
|
|
}
|
2015-06-01 14:34:40 +00:00
|
|
|
}
|
2016-09-20 14:24:30 +00:00
|
|
|
|
2016-10-18 07:54:35 +00:00
|
|
|
func TestParseClassParameters(t *testing.T) {
|
2016-11-18 20:58:56 +00:00
|
|
|
secret := v1.Secret{
|
2016-10-27 06:21:36 +00:00
|
|
|
Type: "kubernetes.io/glusterfs",
|
2016-10-18 07:54:35 +00:00
|
|
|
Data: map[string][]byte{
|
|
|
|
"data": []byte("mypassword"),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
parameters map[string]string
|
2016-11-18 20:58:56 +00:00
|
|
|
secret *v1.Secret
|
2016-10-18 07:54:35 +00:00
|
|
|
expectError bool
|
2017-01-31 09:01:55 +00:00
|
|
|
expectConfig *provisionerConfig
|
2016-10-18 07:54:35 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
"password",
|
|
|
|
map[string]string{
|
|
|
|
"resturl": "https://localhost:8080",
|
|
|
|
"restuser": "admin",
|
|
|
|
"restuserkey": "password",
|
|
|
|
},
|
|
|
|
nil, // secret
|
|
|
|
false, // expect error
|
2017-01-31 09:01:55 +00:00
|
|
|
&provisionerConfig{
|
2016-10-18 07:54:35 +00:00
|
|
|
url: "https://localhost:8080",
|
|
|
|
user: "admin",
|
|
|
|
userKey: "password",
|
|
|
|
secretValue: "password",
|
2016-12-02 01:16:23 +00:00
|
|
|
gidMin: 2000,
|
2016-12-05 21:33:35 +00:00
|
|
|
gidMax: 2147483647,
|
2017-01-06 07:03:25 +00:00
|
|
|
volumeType: gapi.VolumeDurabilityInfo{Type: "replicate", Replicate: gapi.ReplicaDurability{Replica: 3}, Disperse: gapi.DisperseDurability{Data: 0, Redundancy: 0}},
|
2016-10-18 07:54:35 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"secret",
|
|
|
|
map[string]string{
|
|
|
|
"resturl": "https://localhost:8080",
|
|
|
|
"restuser": "admin",
|
|
|
|
"secretname": "mysecret",
|
|
|
|
"secretnamespace": "default",
|
|
|
|
},
|
|
|
|
&secret,
|
|
|
|
false, // expect error
|
2017-01-31 09:01:55 +00:00
|
|
|
&provisionerConfig{
|
2016-10-18 07:54:35 +00:00
|
|
|
url: "https://localhost:8080",
|
|
|
|
user: "admin",
|
|
|
|
secretName: "mysecret",
|
|
|
|
secretNamespace: "default",
|
|
|
|
secretValue: "mypassword",
|
2016-12-02 01:16:23 +00:00
|
|
|
gidMin: 2000,
|
2016-12-05 21:33:35 +00:00
|
|
|
gidMax: 2147483647,
|
2017-01-06 07:03:25 +00:00
|
|
|
volumeType: gapi.VolumeDurabilityInfo{Type: "replicate", Replicate: gapi.ReplicaDurability{Replica: 3}, Disperse: gapi.DisperseDurability{Data: 0, Redundancy: 0}},
|
2016-10-18 07:54:35 +00:00
|
|
|
},
|
|
|
|
},
|
2016-09-20 14:24:30 +00:00
|
|
|
{
|
2016-10-18 07:54:35 +00:00
|
|
|
"no authentication",
|
|
|
|
map[string]string{
|
|
|
|
"resturl": "https://localhost:8080",
|
|
|
|
"restauthenabled": "false",
|
|
|
|
},
|
|
|
|
&secret,
|
|
|
|
false, // expect error
|
2017-01-31 09:01:55 +00:00
|
|
|
&provisionerConfig{
|
2017-01-06 07:03:25 +00:00
|
|
|
url: "https://localhost:8080",
|
|
|
|
gidMin: 2000,
|
|
|
|
gidMax: 2147483647,
|
|
|
|
volumeType: gapi.VolumeDurabilityInfo{Type: "replicate", Replicate: gapi.ReplicaDurability{Replica: 3}, Disperse: gapi.DisperseDurability{Data: 0, Redundancy: 0}},
|
2016-10-18 07:54:35 +00:00
|
|
|
},
|
2016-09-20 14:24:30 +00:00
|
|
|
},
|
|
|
|
{
|
2016-10-18 07:54:35 +00:00
|
|
|
"missing secret",
|
|
|
|
map[string]string{
|
|
|
|
"resturl": "https://localhost:8080",
|
|
|
|
"secretname": "mysecret",
|
|
|
|
"secretnamespace": "default",
|
|
|
|
},
|
|
|
|
nil, // secret
|
|
|
|
true, // expect error
|
|
|
|
nil,
|
2016-09-20 14:24:30 +00:00
|
|
|
},
|
|
|
|
{
|
2016-10-18 07:54:35 +00:00
|
|
|
"secret with no namespace",
|
|
|
|
map[string]string{
|
|
|
|
"resturl": "https://localhost:8080",
|
|
|
|
"secretname": "mysecret",
|
|
|
|
},
|
|
|
|
&secret,
|
|
|
|
true, // expect error
|
|
|
|
nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"missing url",
|
|
|
|
map[string]string{
|
|
|
|
"restuser": "admin",
|
|
|
|
"restuserkey": "password",
|
|
|
|
},
|
|
|
|
nil, // secret
|
|
|
|
true, // expect error
|
|
|
|
nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"unknown parameter",
|
|
|
|
map[string]string{
|
|
|
|
"unknown": "yes",
|
|
|
|
"resturl": "https://localhost:8080",
|
|
|
|
"restuser": "admin",
|
|
|
|
"restuserkey": "password",
|
|
|
|
},
|
|
|
|
nil, // secret
|
|
|
|
true, // expect error
|
|
|
|
nil,
|
2016-09-20 14:24:30 +00:00
|
|
|
},
|
2016-12-08 22:41:31 +00:00
|
|
|
{
|
|
|
|
"invalid gidMin #1",
|
|
|
|
map[string]string{
|
|
|
|
"resturl": "https://localhost:8080",
|
|
|
|
"restauthenabled": "false",
|
|
|
|
"gidMin": "0",
|
|
|
|
},
|
|
|
|
&secret,
|
|
|
|
true, // expect error
|
|
|
|
nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"invalid gidMin #2",
|
|
|
|
map[string]string{
|
|
|
|
"resturl": "https://localhost:8080",
|
|
|
|
"restauthenabled": "false",
|
|
|
|
"gidMin": "1999",
|
|
|
|
},
|
|
|
|
&secret,
|
|
|
|
true, // expect error
|
|
|
|
nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"invalid gidMin #3",
|
|
|
|
map[string]string{
|
|
|
|
"resturl": "https://localhost:8080",
|
|
|
|
"restauthenabled": "false",
|
|
|
|
"gidMin": "1999",
|
|
|
|
},
|
|
|
|
&secret,
|
|
|
|
true, // expect error
|
|
|
|
nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"invalid gidMax #1",
|
|
|
|
map[string]string{
|
|
|
|
"resturl": "https://localhost:8080",
|
|
|
|
"restauthenabled": "false",
|
|
|
|
"gidMax": "0",
|
|
|
|
},
|
|
|
|
&secret,
|
|
|
|
true, // expect error
|
|
|
|
nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"invalid gidMax #2",
|
|
|
|
map[string]string{
|
|
|
|
"resturl": "https://localhost:8080",
|
|
|
|
"restauthenabled": "false",
|
|
|
|
"gidMax": "1999",
|
|
|
|
},
|
|
|
|
&secret,
|
|
|
|
true, // expect error
|
|
|
|
nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"invalid gidMax #3",
|
|
|
|
map[string]string{
|
|
|
|
"resturl": "https://localhost:8080",
|
|
|
|
"restauthenabled": "false",
|
|
|
|
"gidMax": "1999",
|
|
|
|
},
|
|
|
|
&secret,
|
|
|
|
true, // expect error
|
|
|
|
nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"invalid gidMin:gidMax",
|
|
|
|
map[string]string{
|
|
|
|
"resturl": "https://localhost:8080",
|
|
|
|
"restauthenabled": "false",
|
|
|
|
"gidMin": "5001",
|
|
|
|
"gidMax": "5000",
|
|
|
|
},
|
|
|
|
&secret,
|
|
|
|
true, // expect error
|
|
|
|
nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"valid gidMin",
|
|
|
|
map[string]string{
|
|
|
|
"resturl": "https://localhost:8080",
|
|
|
|
"restauthenabled": "false",
|
|
|
|
"gidMin": "4000",
|
|
|
|
},
|
|
|
|
&secret,
|
|
|
|
false, // expect error
|
2017-01-31 09:01:55 +00:00
|
|
|
&provisionerConfig{
|
2017-01-06 07:03:25 +00:00
|
|
|
url: "https://localhost:8080",
|
|
|
|
gidMin: 4000,
|
|
|
|
gidMax: 2147483647,
|
|
|
|
volumeType: gapi.VolumeDurabilityInfo{Type: "replicate", Replicate: gapi.ReplicaDurability{Replica: 3}, Disperse: gapi.DisperseDurability{Data: 0, Redundancy: 0}},
|
2016-12-08 22:41:31 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"valid gidMax",
|
|
|
|
map[string]string{
|
|
|
|
"resturl": "https://localhost:8080",
|
|
|
|
"restauthenabled": "false",
|
|
|
|
"gidMax": "5000",
|
|
|
|
},
|
|
|
|
&secret,
|
|
|
|
false, // expect error
|
2017-01-31 09:01:55 +00:00
|
|
|
&provisionerConfig{
|
2017-01-06 07:03:25 +00:00
|
|
|
url: "https://localhost:8080",
|
|
|
|
gidMin: 2000,
|
|
|
|
gidMax: 5000,
|
|
|
|
volumeType: gapi.VolumeDurabilityInfo{Type: "replicate", Replicate: gapi.ReplicaDurability{Replica: 3}, Disperse: gapi.DisperseDurability{Data: 0, Redundancy: 0}},
|
2016-12-08 22:41:31 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"valid gidMin:gidMax",
|
|
|
|
map[string]string{
|
|
|
|
"resturl": "https://localhost:8080",
|
|
|
|
"restauthenabled": "false",
|
|
|
|
"gidMin": "4000",
|
|
|
|
"gidMax": "5000",
|
|
|
|
},
|
|
|
|
&secret,
|
|
|
|
false, // expect error
|
2017-01-31 09:01:55 +00:00
|
|
|
&provisionerConfig{
|
2017-01-06 07:03:25 +00:00
|
|
|
url: "https://localhost:8080",
|
|
|
|
gidMin: 4000,
|
|
|
|
gidMax: 5000,
|
|
|
|
volumeType: gapi.VolumeDurabilityInfo{Type: "replicate", Replicate: gapi.ReplicaDurability{Replica: 3}, Disperse: gapi.DisperseDurability{Data: 0, Redundancy: 0}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
"valid volumetype: replicate",
|
|
|
|
map[string]string{
|
|
|
|
"resturl": "https://localhost:8080",
|
|
|
|
"restauthenabled": "false",
|
|
|
|
"gidMin": "4000",
|
|
|
|
"gidMax": "5000",
|
|
|
|
"volumetype": "replicate:4",
|
|
|
|
},
|
|
|
|
&secret,
|
|
|
|
false, // expect error
|
2017-01-31 09:01:55 +00:00
|
|
|
&provisionerConfig{
|
2017-01-06 07:03:25 +00:00
|
|
|
url: "https://localhost:8080",
|
|
|
|
gidMin: 4000,
|
|
|
|
gidMax: 5000,
|
|
|
|
volumeType: gapi.VolumeDurabilityInfo{Type: "replicate", Replicate: gapi.ReplicaDurability{Replica: 4}, Disperse: gapi.DisperseDurability{Data: 0, Redundancy: 0}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
"valid volumetype: disperse",
|
|
|
|
map[string]string{
|
|
|
|
"resturl": "https://localhost:8080",
|
|
|
|
"restauthenabled": "false",
|
|
|
|
"gidMin": "4000",
|
|
|
|
"gidMax": "5000",
|
|
|
|
"volumetype": "disperse:4:2",
|
|
|
|
},
|
|
|
|
&secret,
|
|
|
|
false, // expect error
|
2017-01-31 09:01:55 +00:00
|
|
|
&provisionerConfig{
|
2017-01-06 07:03:25 +00:00
|
|
|
url: "https://localhost:8080",
|
|
|
|
gidMin: 4000,
|
|
|
|
gidMax: 5000,
|
|
|
|
volumeType: gapi.VolumeDurabilityInfo{Type: "disperse", Replicate: gapi.ReplicaDurability{Replica: 0}, Disperse: gapi.DisperseDurability{Data: 4, Redundancy: 2}},
|
2016-12-08 22:41:31 +00:00
|
|
|
},
|
|
|
|
},
|
2017-01-06 07:03:25 +00:00
|
|
|
{
|
|
|
|
"invalid volumetype (disperse) parameter",
|
|
|
|
map[string]string{
|
|
|
|
"resturl": "https://localhost:8080",
|
|
|
|
"restauthenabled": "false",
|
|
|
|
"volumetype": "disperse:4:asd",
|
|
|
|
},
|
|
|
|
&secret,
|
|
|
|
true, // expect error
|
|
|
|
nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"invalid volumetype (replicate) parameter",
|
|
|
|
map[string]string{
|
|
|
|
"resturl": "https://localhost:8080",
|
|
|
|
"restauthenabled": "false",
|
|
|
|
"volumetype": "replicate:asd",
|
|
|
|
},
|
|
|
|
&secret,
|
|
|
|
true, // expect error
|
|
|
|
nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"invalid volumetype: unknown volumetype",
|
|
|
|
map[string]string{
|
|
|
|
"resturl": "https://localhost:8080",
|
|
|
|
"restauthenabled": "false",
|
|
|
|
"volumetype": "dispersereplicate:4:2",
|
|
|
|
},
|
|
|
|
&secret,
|
|
|
|
true, // expect error
|
|
|
|
nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"invalid volumetype : negative value",
|
|
|
|
map[string]string{
|
|
|
|
"resturl": "https://localhost:8080",
|
|
|
|
"restauthenabled": "false",
|
|
|
|
"volumetype": "replicate:-1000",
|
|
|
|
},
|
|
|
|
&secret,
|
|
|
|
true, // expect error
|
|
|
|
nil,
|
|
|
|
},
|
2016-09-20 14:24:30 +00:00
|
|
|
}
|
|
|
|
|
2016-10-18 07:54:35 +00:00
|
|
|
for _, test := range tests {
|
2016-09-20 14:24:30 +00:00
|
|
|
|
2016-10-18 07:54:35 +00:00
|
|
|
client := &fake.Clientset{}
|
|
|
|
client.AddReactor("get", "secrets", func(action core.Action) (handled bool, ret runtime.Object, err error) {
|
|
|
|
if test.secret != nil {
|
|
|
|
return true, test.secret, nil
|
|
|
|
}
|
|
|
|
return true, nil, fmt.Errorf("Test %s did not set a secret", test.name)
|
|
|
|
})
|
2016-09-20 14:24:30 +00:00
|
|
|
|
2016-10-18 07:54:35 +00:00
|
|
|
cfg, err := parseClassParameters(test.parameters, client)
|
|
|
|
|
|
|
|
if err != nil && !test.expectError {
|
|
|
|
t.Errorf("Test %s got unexpected error %v", test.name, err)
|
2016-09-20 14:24:30 +00:00
|
|
|
}
|
2016-10-18 07:54:35 +00:00
|
|
|
if err == nil && test.expectError {
|
|
|
|
t.Errorf("test %s expected error and got none", test.name)
|
2016-09-20 14:24:30 +00:00
|
|
|
}
|
2016-10-18 07:54:35 +00:00
|
|
|
if test.expectConfig != nil {
|
|
|
|
if !reflect.DeepEqual(cfg, test.expectConfig) {
|
|
|
|
t.Errorf("Test %s returned unexpected data, expected: %+v, got: %+v", test.name, test.expectConfig, cfg)
|
|
|
|
}
|
2016-09-20 14:24:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|