-
Notifications
You must be signed in to change notification settings - Fork 177
/
vsphere_shared_datastore.go
103 lines (88 loc) · 4.76 KB
/
vsphere_shared_datastore.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
Copyright 2019 The Kubernetes Authors.
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 e2e
import (
"fmt"
"strings"
"time"
"github.com/onsi/ginkgo"
"github.com/onsi/gomega"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/kubernetes/test/e2e/framework"
)
/*
Test to verify provisioning is dependant on type of datastore (shared/non-shared), when no storage policy is offered
Steps
1. Create StorageClass with shared/non-shared datastore.
2. Create PVC which uses the StorageClass created in step 1.
3. Expect:
3a. Volume provisioning to fail if non-shared datastore
3b. Volume provisioning to pass if shared datastore
This test reads env
1. SHARED_VSPHERE_DATASTORE_URL (set to shared datastore URL)
2. NONSHARED_VSPHERE_DATASTORE_URL (set to non-shared datastor URL)
*/
var _ = ginkgo.Describe("[csi-block-e2e] Datastore Based Volume Provisioning With No Storage Policy", func() {
f := framework.NewDefaultFramework("e2e-vsphere-volume-provisioning-no-storage-policy")
var (
client clientset.Interface
namespace string
scParameters map[string]string
sharedDatastoreURL string
nonSharedDatastoreURL string
)
ginkgo.BeforeEach(func() {
client = f.ClientSet
namespace = f.Namespace.Name
scParameters = make(map[string]string)
nodeList := framework.GetReadySchedulableNodesOrDie(f.ClientSet)
if !(len(nodeList.Items) > 0) {
framework.Failf("Unable to find ready and schedulable Node")
}
})
// Shared datastore should be provisioned successfully
ginkgo.It("Verify dynamic provisioning of PV passes with user specified shared datastore and no storage policy specified in the storage class", func() {
ginkgo.By("Invoking Test for user specified Shared Datastore in Storage class for volume provisioning")
sharedDatastoreURL = GetAndExpectStringEnvVar(envSharedDatastoreURL)
scParameters[scParamDatastoreURL] = sharedDatastoreURL
storageclass, pvclaim, err := createPVCAndStorageClass(client, namespace, nil, scParameters, "", nil, "")
gomega.Expect(err).NotTo(gomega.HaveOccurred())
defer client.StorageV1().StorageClasses().Delete(storageclass.Name, nil)
defer framework.DeletePersistentVolumeClaim(client, pvclaim.Name, namespace)
ginkgo.By("Expect claim to pass provisioning volume as shared datastore")
err = framework.WaitForPersistentVolumeClaimPhase(v1.ClaimBound, client, pvclaim.Namespace, pvclaim.Name, framework.Poll, time.Minute)
gomega.Expect(err).NotTo(gomega.HaveOccurred(), fmt.Sprintf("Failed to provision volume on shared datastore with err: %v", err))
})
// Setting non-shared datastore in the storage class should fail dynamic volume provisioning
ginkgo.It("Verify dynamic provisioning of PV fails with user specified non-shared datastore and no storage policy specified in the storage class", func() {
ginkgo.By("Invoking Test for user specified non-shared Datastore in storage class for volume provisioning")
nonSharedDatastoreURL = GetAndExpectStringEnvVar(envNonSharedStorageClassDatastoreURL)
scParameters[scParamDatastoreURL] = nonSharedDatastoreURL
storageclass, pvclaim, err := createPVCAndStorageClass(client, namespace, nil, scParameters, "", nil, "")
gomega.Expect(err).NotTo(gomega.HaveOccurred())
defer client.StorageV1().StorageClasses().Delete(storageclass.Name, nil)
defer framework.DeletePersistentVolumeClaim(client, pvclaim.Name, namespace)
ginkgo.By("Expect claim to fail provisioning volume on non shared datastore")
err = framework.WaitForPersistentVolumeClaimPhase(v1.ClaimBound, client, pvclaim.Namespace, pvclaim.Name, framework.Poll, time.Minute/2)
gomega.Expect(err).To(gomega.HaveOccurred())
// eventList contains the events related to pvc
eventList, _ := client.CoreV1().Events(pvclaim.Namespace).List(metav1.ListOptions{})
actualErrMsg := eventList.Items[len(eventList.Items)-1].Message
fmt.Println(fmt.Sprintf("Actual failure message: %+q", actualErrMsg))
expectedErrMsg := "failed to provision volume with StorageClass \"" + storageclass.Name + "\""
fmt.Println(fmt.Sprintf("Expected failure message: %+q", expectedErrMsg))
gomega.Expect(strings.Contains(actualErrMsg, expectedErrMsg)).To(gomega.BeTrue(), fmt.Sprintf("actualErrMsg: %q does not contain expectedErrMsg: %q", actualErrMsg, expectedErrMsg))
})
})