ScaleIO Volume Plugin - volume attribute updates

This commit introduces the following updates and fixes:
- Enable scaleIO volume multip-mapping based on accessMode
- No longer uses "default" as default values for storagepool & protection domain
- validates capacity when capacity is zero
- Better naming for PV and volume
- make mount ro when accessModes contains ROM
This commit is contained in:
Vladimir Vivien
2017-06-26 12:27:31 -04:00
parent 11f8047735
commit fda99bd78e
9 changed files with 202 additions and 58 deletions

View File

@@ -23,6 +23,8 @@ import (
"strings"
"testing"
"github.com/golang/glog"
api "k8s.io/api/core/v1"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
@@ -149,6 +151,7 @@ func TestVolumeMounterUnmounter(t *testing.T) {
VolumeName: testSioVol,
FSType: "ext4",
SecretRef: &api.LocalObjectReference{Name: "sio-secret"},
ReadOnly: false,
},
},
}
@@ -191,6 +194,10 @@ func TestVolumeMounterUnmounter(t *testing.T) {
}
}
if sio.isMultiMap {
t.Errorf("SetUp() - expecting multiple volume disabled by default")
}
// rebuild spec
builtSpec, err := sioPlug.ConstructVolumeSpec(volume.NewSpecFromVolume(vol).Name(), path)
if err != nil {
@@ -235,25 +242,23 @@ func TestVolumeProvisioner(t *testing.T) {
plug, err := plugMgr.FindPluginByName(sioPluginName)
if err != nil {
t.Errorf("Can't find the plugin %v", sioPluginName)
t.Fatalf("Can't find the plugin %v", sioPluginName)
}
sioPlug, ok := plug.(*sioPlugin)
if !ok {
t.Errorf("Cannot assert plugin to be type sioPlugin")
t.Fatal("Cannot assert plugin to be type sioPlugin")
}
options := volume.VolumeOptions{
ClusterName: "testcluster",
PVName: "pvc-sio-dynamic-vol",
PVC: volumetest.CreateTestPVC("100Mi", []api.PersistentVolumeAccessMode{api.ReadWriteOnce}),
PersistentVolumeReclaimPolicy: api.PersistentVolumeReclaimDelete,
}
options.PVC.Name = "testpvc"
options.PVC.Namespace = testns
// incomplete options, test should fail
_, err = sioPlug.NewProvisioner(options)
if err == nil {
t.Fatal("expected failure due to incomplete options")
options.PVC.Spec.AccessModes = []api.PersistentVolumeAccessMode{
api.ReadOnlyMany,
}
options.Parameters = map[string]string{
@@ -288,10 +293,9 @@ func TestVolumeProvisioner(t *testing.T) {
// validate provision
actualSpecName := spec.Name
actualVolName := spec.Spec.PersistentVolumeSource.ScaleIO.VolumeName
if !strings.HasPrefix(actualSpecName, "pvc-") {
t.Errorf("expecting volume name to start with pov-, got %s", actualSpecName)
if !strings.HasPrefix(actualSpecName, "k8svol-") {
t.Errorf("expecting volume name to start with k8svol-, got %s", actualSpecName)
}
vol, err := sio.FindVolume(actualVolName)
if err != nil {
t.Fatalf("failed getting volume %v: %v", actualVolName, err)
@@ -299,6 +303,9 @@ func TestVolumeProvisioner(t *testing.T) {
if vol.Name != actualVolName {
t.Errorf("expected volume name to be %s, got %s", actualVolName, vol.Name)
}
if vol.SizeInKb != 8*1024*1024 {
glog.V(4).Info(log("unexpected volume size"))
}
// mount dynamic vol
sioMounter, err := sioPlug.NewMounter(
@@ -315,8 +322,14 @@ func TestVolumeProvisioner(t *testing.T) {
}
sioVol.sioMgr.client = sio
if err := sioMounter.SetUp(nil); err != nil {
t.Errorf("Expected success, got: %v", err)
t.Fatalf("Expected success, got: %v", err)
}
// isMultiMap applied
if !sio.isMultiMap {
t.Errorf("SetUp() expecting attached volume with multi-mapping")
}
// teardown dynamic vol
sioUnmounter, err := sioPlug.NewUnmounter(spec.Name, podUID)
if err != nil {
@@ -351,3 +364,83 @@ func TestVolumeProvisioner(t *testing.T) {
t.Errorf("Deleter did not delete path %v: %v", path, err)
}
}
func TestVolumeProvisionerWithIncompleteConfig(t *testing.T) {
plugMgr, tmpDir := newPluginMgr(t)
defer os.RemoveAll(tmpDir)
plug, err := plugMgr.FindPluginByName(sioPluginName)
if err != nil {
t.Fatalf("Can't find the plugin %v", sioPluginName)
}
sioPlug, ok := plug.(*sioPlugin)
if !ok {
t.Fatal("Cannot assert plugin to be type sioPlugin")
}
options := volume.VolumeOptions{
ClusterName: "testcluster",
PVName: "pvc-sio-dynamic-vol",
PVC: volumetest.CreateTestPVC("100Mi", []api.PersistentVolumeAccessMode{api.ReadWriteOnce}),
PersistentVolumeReclaimPolicy: api.PersistentVolumeReclaimDelete,
}
options.PVC.Namespace = testns
options.PVC.Spec.AccessModes = []api.PersistentVolumeAccessMode{
api.ReadWriteOnce,
}
// incomplete options, test should fail
_, err = sioPlug.NewProvisioner(options)
if err == nil {
t.Fatal("expected failure due to incomplete options")
}
}
func TestVolumeProvisionerWithZeroCapacity(t *testing.T) {
plugMgr, tmpDir := newPluginMgr(t)
defer os.RemoveAll(tmpDir)
plug, err := plugMgr.FindPluginByName(sioPluginName)
if err != nil {
t.Fatalf("Can't find the plugin %v", sioPluginName)
}
sioPlug, ok := plug.(*sioPlugin)
if !ok {
t.Fatal("Cannot assert plugin to be type sioPlugin")
}
options := volume.VolumeOptions{
ClusterName: "testcluster",
PVName: "pvc-sio-dynamic-vol",
PVC: volumetest.CreateTestPVC("0Mi", []api.PersistentVolumeAccessMode{api.ReadWriteOnce}),
PersistentVolumeReclaimPolicy: api.PersistentVolumeReclaimDelete,
}
options.PVC.Namespace = testns
options.PVC.Spec.AccessModes = []api.PersistentVolumeAccessMode{
api.ReadWriteOnce,
}
options.Parameters = map[string]string{
confKey.gateway: "http://test.scaleio:11111",
confKey.system: "sio",
confKey.protectionDomain: testSioPD,
confKey.storagePool: "default",
confKey.secretRef: "sio-secret",
}
provisioner, _ := sioPlug.NewProvisioner(options)
sio := newFakeSio()
sioVol := provisioner.(*sioVolume)
if err := sioVol.setSioMgrFromConfig(); err != nil {
t.Fatalf("failed to create scaleio mgr from config: %v", err)
}
sioVol.sioMgr.client = sio
_, err = provisioner.Provision()
if err == nil {
t.Fatalf("call to Provision() should fail with invalid capacity")
}
}