vsphere_volume_vpxd_restart.go 6.4 KB

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