vsphere_stress.go 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. Copyright 2017 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package vsphere
  14. import (
  15. "fmt"
  16. "sync"
  17. "github.com/onsi/ginkgo"
  18. "github.com/onsi/gomega"
  19. "k8s.io/api/core/v1"
  20. storageV1 "k8s.io/api/storage/v1"
  21. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  22. clientset "k8s.io/client-go/kubernetes"
  23. "k8s.io/kubernetes/test/e2e/framework"
  24. "k8s.io/kubernetes/test/e2e/storage/utils"
  25. )
  26. /*
  27. Induce stress to create volumes in parallel with multiple threads based on user configurable values for number of threads and iterations per thread.
  28. The following actions will be performed as part of this test.
  29. 1. Create Storage Classes of 4 Categories (Default, SC with Non Default Datastore, SC with SPBM Policy, SC with VSAN Storage Capabilities.)
  30. 2. READ VCP_STRESS_INSTANCES, VCP_STRESS_ITERATIONS, VSPHERE_SPBM_POLICY_NAME and VSPHERE_DATASTORE from System Environment.
  31. 3. Launch goroutine for volume lifecycle operations.
  32. 4. Each instance of routine iterates for n times, where n is read from system env - VCP_STRESS_ITERATIONS
  33. 5. Each iteration creates 1 PVC, 1 POD using the provisioned PV, Verify disk is attached to the node, Verify pod can access the volume, delete the pod and finally delete the PVC.
  34. */
  35. var _ = utils.SIGDescribe("vsphere cloud provider stress [Feature:vsphere]", func() {
  36. f := framework.NewDefaultFramework("vcp-stress")
  37. var (
  38. client clientset.Interface
  39. namespace string
  40. instances int
  41. iterations int
  42. policyName string
  43. datastoreName string
  44. err error
  45. scNames = []string{storageclass1, storageclass2, storageclass3, storageclass4}
  46. )
  47. ginkgo.BeforeEach(func() {
  48. framework.SkipUnlessProviderIs("vsphere")
  49. client = f.ClientSet
  50. namespace = f.Namespace.Name
  51. nodeList := framework.GetReadySchedulableNodesOrDie(f.ClientSet)
  52. gomega.Expect(nodeList.Items).NotTo(gomega.BeEmpty(), "Unable to find ready and schedulable Node")
  53. // if VCP_STRESS_INSTANCES = 12 and VCP_STRESS_ITERATIONS is 10. 12 threads will run in parallel for 10 times.
  54. // Resulting 120 Volumes and POD Creation. Volumes will be provisioned with each different types of Storage Class,
  55. // Each iteration creates PVC, verify PV is provisioned, then creates a pod, verify volume is attached to the node, and then delete the pod and delete pvc.
  56. instances = GetAndExpectIntEnvVar(VCPStressInstances)
  57. gomega.Expect(instances <= volumesPerNode*len(nodeList.Items)).To(gomega.BeTrue(), fmt.Sprintf("Number of Instances should be less or equal: %v", volumesPerNode*len(nodeList.Items)))
  58. gomega.Expect(instances > len(scNames)).To(gomega.BeTrue(), "VCP_STRESS_INSTANCES should be greater than 3 to utilize all 4 types of storage classes")
  59. iterations = GetAndExpectIntEnvVar(VCPStressIterations)
  60. framework.ExpectNoError(err, "Error Parsing VCP_STRESS_ITERATIONS")
  61. gomega.Expect(iterations > 0).To(gomega.BeTrue(), "VCP_STRESS_ITERATIONS should be greater than 0")
  62. policyName = GetAndExpectStringEnvVar(SPBMPolicyName)
  63. datastoreName = GetAndExpectStringEnvVar(StorageClassDatastoreName)
  64. })
  65. ginkgo.It("vsphere stress tests", func() {
  66. scArrays := make([]*storageV1.StorageClass, len(scNames))
  67. for index, scname := range scNames {
  68. // Create vSphere Storage Class
  69. ginkgo.By(fmt.Sprintf("Creating Storage Class : %v", scname))
  70. var sc *storageV1.StorageClass
  71. var err error
  72. switch scname {
  73. case storageclass1:
  74. sc, err = client.StorageV1().StorageClasses().Create(getVSphereStorageClassSpec(storageclass1, nil, nil))
  75. case storageclass2:
  76. var scVSanParameters map[string]string
  77. scVSanParameters = make(map[string]string)
  78. scVSanParameters[Policy_HostFailuresToTolerate] = "1"
  79. sc, err = client.StorageV1().StorageClasses().Create(getVSphereStorageClassSpec(storageclass2, scVSanParameters, nil))
  80. case storageclass3:
  81. var scSPBMPolicyParameters map[string]string
  82. scSPBMPolicyParameters = make(map[string]string)
  83. scSPBMPolicyParameters[SpbmStoragePolicy] = policyName
  84. sc, err = client.StorageV1().StorageClasses().Create(getVSphereStorageClassSpec(storageclass3, scSPBMPolicyParameters, nil))
  85. case storageclass4:
  86. var scWithDSParameters map[string]string
  87. scWithDSParameters = make(map[string]string)
  88. scWithDSParameters[Datastore] = datastoreName
  89. scWithDatastoreSpec := getVSphereStorageClassSpec(storageclass4, scWithDSParameters, nil)
  90. sc, err = client.StorageV1().StorageClasses().Create(scWithDatastoreSpec)
  91. }
  92. gomega.Expect(sc).NotTo(gomega.BeNil())
  93. framework.ExpectNoError(err)
  94. defer client.StorageV1().StorageClasses().Delete(scname, nil)
  95. scArrays[index] = sc
  96. }
  97. var wg sync.WaitGroup
  98. wg.Add(instances)
  99. for instanceCount := 0; instanceCount < instances; instanceCount++ {
  100. instanceId := fmt.Sprintf("Thread:%v", instanceCount+1)
  101. go PerformVolumeLifeCycleInParallel(f, client, namespace, instanceId, scArrays[instanceCount%len(scArrays)], iterations, &wg)
  102. }
  103. wg.Wait()
  104. })
  105. })
  106. // goroutine to perform volume lifecycle operations in parallel
  107. func PerformVolumeLifeCycleInParallel(f *framework.Framework, client clientset.Interface, namespace string, instanceId string, sc *storageV1.StorageClass, iterations int, wg *sync.WaitGroup) {
  108. defer wg.Done()
  109. defer ginkgo.GinkgoRecover()
  110. for iterationCount := 0; iterationCount < iterations; iterationCount++ {
  111. logPrefix := fmt.Sprintf("Instance: [%v], Iteration: [%v] :", instanceId, iterationCount+1)
  112. ginkgo.By(fmt.Sprintf("%v Creating PVC using the Storage Class: %v", logPrefix, sc.Name))
  113. pvclaim, err := framework.CreatePVC(client, namespace, getVSphereClaimSpecWithStorageClass(namespace, "1Gi", sc))
  114. framework.ExpectNoError(err)
  115. defer framework.DeletePersistentVolumeClaim(client, pvclaim.Name, namespace)
  116. var pvclaims []*v1.PersistentVolumeClaim
  117. pvclaims = append(pvclaims, pvclaim)
  118. ginkgo.By(fmt.Sprintf("%v Waiting for claim: %v to be in bound phase", logPrefix, pvclaim.Name))
  119. persistentvolumes, err := framework.WaitForPVClaimBoundPhase(client, pvclaims, framework.ClaimProvisionTimeout)
  120. framework.ExpectNoError(err)
  121. ginkgo.By(fmt.Sprintf("%v Creating Pod using the claim: %v", logPrefix, pvclaim.Name))
  122. // Create pod to attach Volume to Node
  123. pod, err := framework.CreatePod(client, namespace, nil, pvclaims, false, "")
  124. framework.ExpectNoError(err)
  125. ginkgo.By(fmt.Sprintf("%v Waiting for the Pod: %v to be in the running state", logPrefix, pod.Name))
  126. err = f.WaitForPodRunningSlow(pod.Name)
  127. framework.ExpectNoError(err)
  128. // Get the copy of the Pod to know the assigned node name.
  129. pod, err = client.CoreV1().Pods(namespace).Get(pod.Name, metav1.GetOptions{})
  130. framework.ExpectNoError(err)
  131. ginkgo.By(fmt.Sprintf("%v Verifing the volume: %v is attached to the node VM: %v", logPrefix, persistentvolumes[0].Spec.VsphereVolume.VolumePath, pod.Spec.NodeName))
  132. isVolumeAttached, verifyDiskAttachedError := diskIsAttached(persistentvolumes[0].Spec.VsphereVolume.VolumePath, pod.Spec.NodeName)
  133. gomega.Expect(isVolumeAttached).To(gomega.BeTrue())
  134. framework.ExpectNoError(verifyDiskAttachedError)
  135. ginkgo.By(fmt.Sprintf("%v Verifing the volume: %v is accessible in the pod: %v", logPrefix, persistentvolumes[0].Spec.VsphereVolume.VolumePath, pod.Name))
  136. verifyVSphereVolumesAccessible(client, pod, persistentvolumes)
  137. ginkgo.By(fmt.Sprintf("%v Deleting pod: %v", logPrefix, pod.Name))
  138. err = framework.DeletePodWithWait(f, client, pod)
  139. framework.ExpectNoError(err)
  140. ginkgo.By(fmt.Sprintf("%v Waiting for volume: %v to be detached from the node: %v", logPrefix, persistentvolumes[0].Spec.VsphereVolume.VolumePath, pod.Spec.NodeName))
  141. err = waitForVSphereDiskToDetach(persistentvolumes[0].Spec.VsphereVolume.VolumePath, pod.Spec.NodeName)
  142. framework.ExpectNoError(err)
  143. ginkgo.By(fmt.Sprintf("%v Deleting the Claim: %v", logPrefix, pvclaim.Name))
  144. err = framework.DeletePersistentVolumeClaim(client, pvclaim.Name, namespace)
  145. framework.ExpectNoError(err)
  146. }
  147. }