vsphere_volume_vpxd_restart.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. Copyright 2018 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. "strconv"
  17. "time"
  18. "github.com/onsi/ginkgo"
  19. "github.com/onsi/gomega"
  20. v1 "k8s.io/api/core/v1"
  21. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  22. "k8s.io/apimachinery/pkg/util/uuid"
  23. clientset "k8s.io/client-go/kubernetes"
  24. "k8s.io/kubernetes/test/e2e/framework"
  25. e2elog "k8s.io/kubernetes/test/e2e/framework/log"
  26. "k8s.io/kubernetes/test/e2e/storage/utils"
  27. )
  28. /*
  29. Test to verify that a volume remains attached through vpxd restart.
  30. For the number of schedulable nodes:
  31. 1. Create a Volume with default options.
  32. 2. Create a Pod with the created Volume.
  33. 3. Verify that the Volume is attached.
  34. 4. Create a file with random contents under the Volume's mount point on the Pod.
  35. 5. Stop the vpxd service on the vCenter host.
  36. 6. Verify that the file is accessible on the Pod and that it's contents match.
  37. 7. Start the vpxd service on the vCenter host.
  38. 8. Verify that the Volume remains attached, the file is accessible on the Pod, and that it's contents match.
  39. 9. Delete the Pod and wait for the Volume to be detached.
  40. 10. Delete the Volume.
  41. */
  42. var _ = utils.SIGDescribe("Verify Volume Attach Through vpxd Restart [Feature:vsphere][Serial][Disruptive]", func() {
  43. f := framework.NewDefaultFramework("restart-vpxd")
  44. type node struct {
  45. name string
  46. kvLabels map[string]string
  47. nodeInfo *NodeInfo
  48. }
  49. const (
  50. labelKey = "vsphere_e2e_label_vpxd_restart"
  51. vpxdServiceName = "vmware-vpxd"
  52. )
  53. var (
  54. client clientset.Interface
  55. namespace string
  56. vcNodesMap map[string][]node
  57. )
  58. ginkgo.BeforeEach(func() {
  59. // Requires SSH access to vCenter.
  60. framework.SkipUnlessProviderIs("vsphere")
  61. Bootstrap(f)
  62. client = f.ClientSet
  63. namespace = f.Namespace.Name
  64. framework.ExpectNoError(framework.WaitForAllNodesSchedulable(client, framework.TestContext.NodeSchedulableTimeout))
  65. nodes := framework.GetReadySchedulableNodesOrDie(client)
  66. numNodes := len(nodes.Items)
  67. gomega.Expect(numNodes).NotTo(gomega.BeZero(), "No nodes are available for testing volume access through vpxd restart")
  68. vcNodesMap = make(map[string][]node)
  69. for i := 0; i < numNodes; i++ {
  70. nodeInfo := TestContext.NodeMapper.GetNodeInfo(nodes.Items[i].Name)
  71. nodeName := nodes.Items[i].Name
  72. nodeLabel := "vsphere_e2e_" + string(uuid.NewUUID())
  73. framework.AddOrUpdateLabelOnNode(client, nodeName, labelKey, nodeLabel)
  74. vcHost := nodeInfo.VSphere.Config.Hostname
  75. vcNodesMap[vcHost] = append(vcNodesMap[vcHost], node{
  76. name: nodeName,
  77. kvLabels: map[string]string{labelKey: nodeLabel},
  78. nodeInfo: nodeInfo,
  79. })
  80. }
  81. })
  82. ginkgo.It("verify volume remains attached through vpxd restart", func() {
  83. for vcHost, nodes := range vcNodesMap {
  84. var (
  85. volumePaths []string
  86. filePaths []string
  87. fileContents []string
  88. pods []*v1.Pod
  89. )
  90. e2elog.Logf("Testing for nodes on vCenter host: %s", vcHost)
  91. for i, node := range nodes {
  92. ginkgo.By(fmt.Sprintf("Creating test vsphere volume %d", i))
  93. volumePath, err := node.nodeInfo.VSphere.CreateVolume(&VolumeOptions{}, node.nodeInfo.DataCenterRef)
  94. framework.ExpectNoError(err)
  95. volumePaths = append(volumePaths, volumePath)
  96. ginkgo.By(fmt.Sprintf("Creating pod %d on node %v", i, node.name))
  97. podspec := getVSpherePodSpecWithVolumePaths([]string{volumePath}, node.kvLabels, nil)
  98. pod, err := client.CoreV1().Pods(namespace).Create(podspec)
  99. framework.ExpectNoError(err)
  100. ginkgo.By(fmt.Sprintf("Waiting for pod %d to be ready", i))
  101. gomega.Expect(framework.WaitForPodNameRunningInNamespace(client, pod.Name, namespace)).To(gomega.Succeed())
  102. pod, err = client.CoreV1().Pods(namespace).Get(pod.Name, metav1.GetOptions{})
  103. framework.ExpectNoError(err)
  104. pods = append(pods, pod)
  105. nodeName := pod.Spec.NodeName
  106. ginkgo.By(fmt.Sprintf("Verifying that volume %v is attached to node %v", volumePath, nodeName))
  107. expectVolumeToBeAttached(nodeName, volumePath)
  108. ginkgo.By(fmt.Sprintf("Creating a file with random content on the volume mounted on pod %d", i))
  109. filePath := fmt.Sprintf("/mnt/volume1/%v_vpxd_restart_test_%v.txt", namespace, strconv.FormatInt(time.Now().UnixNano(), 10))
  110. randomContent := fmt.Sprintf("Random Content -- %v", strconv.FormatInt(time.Now().UnixNano(), 10))
  111. err = writeContentToPodFile(namespace, pod.Name, filePath, randomContent)
  112. framework.ExpectNoError(err)
  113. filePaths = append(filePaths, filePath)
  114. fileContents = append(fileContents, randomContent)
  115. }
  116. ginkgo.By("Stopping vpxd on the vCenter host")
  117. vcAddress := vcHost + ":22"
  118. err := invokeVCenterServiceControl("stop", vpxdServiceName, vcAddress)
  119. framework.ExpectNoError(err, "Unable to stop vpxd on the vCenter host")
  120. expectFilesToBeAccessible(namespace, pods, filePaths)
  121. expectFileContentsToMatch(namespace, pods, filePaths, fileContents)
  122. ginkgo.By("Starting vpxd on the vCenter host")
  123. err = invokeVCenterServiceControl("start", vpxdServiceName, vcAddress)
  124. framework.ExpectNoError(err, "Unable to start vpxd on the vCenter host")
  125. expectVolumesToBeAttached(pods, volumePaths)
  126. expectFilesToBeAccessible(namespace, pods, filePaths)
  127. expectFileContentsToMatch(namespace, pods, filePaths, fileContents)
  128. for i, node := range nodes {
  129. pod := pods[i]
  130. nodeName := pod.Spec.NodeName
  131. volumePath := volumePaths[i]
  132. ginkgo.By(fmt.Sprintf("Deleting pod on node %s", nodeName))
  133. err = framework.DeletePodWithWait(f, client, pod)
  134. framework.ExpectNoError(err)
  135. ginkgo.By(fmt.Sprintf("Waiting for volume %s to be detached from node %s", volumePath, nodeName))
  136. err = waitForVSphereDiskToDetach(volumePath, nodeName)
  137. framework.ExpectNoError(err)
  138. ginkgo.By(fmt.Sprintf("Deleting volume %s", volumePath))
  139. err = node.nodeInfo.VSphere.DeleteVolume(volumePath, node.nodeInfo.DataCenterRef)
  140. framework.ExpectNoError(err)
  141. }
  142. }
  143. })
  144. })