vsphere_volume_node_delete.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. "context"
  16. "os"
  17. "github.com/onsi/ginkgo"
  18. "github.com/onsi/gomega"
  19. "github.com/vmware/govmomi/object"
  20. clientset "k8s.io/client-go/kubernetes"
  21. "k8s.io/kubernetes/test/e2e/framework"
  22. "k8s.io/kubernetes/test/e2e/storage/utils"
  23. )
  24. var _ = utils.SIGDescribe("Node Unregister [Feature:vsphere] [Slow] [Disruptive]", func() {
  25. f := framework.NewDefaultFramework("node-unregister")
  26. var (
  27. client clientset.Interface
  28. namespace string
  29. workingDir string
  30. err error
  31. )
  32. ginkgo.BeforeEach(func() {
  33. framework.SkipUnlessProviderIs("vsphere")
  34. Bootstrap(f)
  35. client = f.ClientSet
  36. namespace = f.Namespace.Name
  37. framework.ExpectNoError(framework.WaitForAllNodesSchedulable(client, framework.TestContext.NodeSchedulableTimeout))
  38. framework.ExpectNoError(err)
  39. workingDir = os.Getenv("VSPHERE_WORKING_DIR")
  40. gomega.Expect(workingDir).NotTo(gomega.BeEmpty())
  41. })
  42. ginkgo.It("node unregister", func() {
  43. ginkgo.By("Get total Ready nodes")
  44. nodeList := framework.GetReadySchedulableNodesOrDie(f.ClientSet)
  45. gomega.Expect(len(nodeList.Items) > 1).To(gomega.BeTrue(), "At least 2 nodes are required for this test")
  46. totalNodesCount := len(nodeList.Items)
  47. nodeVM := nodeList.Items[0]
  48. nodeInfo := TestContext.NodeMapper.GetNodeInfo(nodeVM.ObjectMeta.Name)
  49. vmObject := object.NewVirtualMachine(nodeInfo.VSphere.Client.Client, nodeInfo.VirtualMachineRef)
  50. // Find VM .vmx file path, host, resource pool.
  51. // They are required to register a node VM to VC
  52. vmxFilePath := getVMXFilePath(vmObject)
  53. ctx, cancel := context.WithCancel(context.Background())
  54. defer cancel()
  55. vmHost, err := vmObject.HostSystem(ctx)
  56. framework.ExpectNoError(err)
  57. vmPool, err := vmObject.ResourcePool(ctx)
  58. framework.ExpectNoError(err)
  59. // Unregister Node VM
  60. ginkgo.By("Unregister a node VM")
  61. unregisterNodeVM(nodeVM.ObjectMeta.Name, vmObject)
  62. // Ready nodes should be 1 less
  63. ginkgo.By("Verifying the ready node counts")
  64. gomega.Expect(verifyReadyNodeCount(f.ClientSet, totalNodesCount-1)).To(gomega.BeTrue(), "Unable to verify expected ready node count")
  65. nodeList = framework.GetReadySchedulableNodesOrDie(client)
  66. gomega.Expect(nodeList.Items).NotTo(gomega.BeEmpty(), "Unable to find ready and schedulable Node")
  67. var nodeNameList []string
  68. for _, node := range nodeList.Items {
  69. nodeNameList = append(nodeNameList, node.ObjectMeta.Name)
  70. }
  71. gomega.Expect(nodeNameList).NotTo(gomega.ContainElement(nodeVM.ObjectMeta.Name))
  72. // Register Node VM
  73. ginkgo.By("Register back the node VM")
  74. registerNodeVM(nodeVM.ObjectMeta.Name, workingDir, vmxFilePath, vmPool, vmHost)
  75. // Ready nodes should be equal to earlier count
  76. ginkgo.By("Verifying the ready node counts")
  77. gomega.Expect(verifyReadyNodeCount(f.ClientSet, totalNodesCount)).To(gomega.BeTrue(), "Unable to verify expected ready node count")
  78. nodeList = framework.GetReadySchedulableNodesOrDie(client)
  79. gomega.Expect(nodeList.Items).NotTo(gomega.BeEmpty(), "Unable to find ready and schedulable Node")
  80. nodeNameList = nodeNameList[:0]
  81. for _, node := range nodeList.Items {
  82. nodeNameList = append(nodeNameList, node.ObjectMeta.Name)
  83. }
  84. gomega.Expect(nodeNameList).To(gomega.ContainElement(nodeVM.ObjectMeta.Name))
  85. // Sanity test that pod provisioning works
  86. ginkgo.By("Sanity check for volume lifecycle")
  87. scParameters := make(map[string]string)
  88. storagePolicy := os.Getenv("VSPHERE_SPBM_GOLD_POLICY")
  89. gomega.Expect(storagePolicy).NotTo(gomega.BeEmpty(), "Please set VSPHERE_SPBM_GOLD_POLICY system environment")
  90. scParameters[SpbmStoragePolicy] = storagePolicy
  91. invokeValidPolicyTest(f, client, namespace, scParameters)
  92. })
  93. })