vsphere_volume_node_delete.go 4.0 KB

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