diff --git a/test/e2e/govmomi_test.go b/test/e2e/govmomi_test.go index 10e0e60ac3..2e4fdf5e00 100644 --- a/test/e2e/govmomi_test.go +++ b/test/e2e/govmomi_test.go @@ -50,11 +50,28 @@ func init() { } func initVSphereSession() { + vsphereClient, restClient = createVsphereClient(vsphereServer, vsphereUsername, vspherePassword) + + By("creating vSphere finder") + vsphereFinder = find.NewFinder(vsphereClient.Client) + + By("configuring vSphere datacenter") + datacenter, err := vsphereFinder.DatacenterOrDefault(ctx, vsphereDatacenter) + Expect(err).ShouldNot(HaveOccurred()) + vsphereFinder.SetDatacenter(datacenter) +} + +func terminateVSphereSession() { + Expect(vsphereClient.Logout(ctx)).To(Succeed()) +} + +func createVsphereClient(vsphereServer, vsphereUsername, vspherePassword string) (*govmomi.Client, *rest.Client) { By("parsing vSphere server URL") serverURL, err := soap.ParseURL(vsphereServer) Expect(err).ShouldNot(HaveOccurred()) var vimClient *vim25.Client + var vsphereClient *govmomi.Client By("creating vSphere client", func() { serverURL.User = url.UserPassword(vsphereUsername, vspherePassword) @@ -74,21 +91,13 @@ func initVSphereSession() { Expect(vsphereClient.Login(ctx, url.UserPassword(vsphereUsername, vspherePassword))).To(Succeed()) }) + var restClient *rest.Client + By("creating vSphere Rest Client", func() { restClient = rest.NewClient(vimClient) restClient.Transport = keepalive.NewHandlerREST(restClient, 5*time.Minute, nil) Expect(restClient.Login(ctx, url.UserPassword(vsphereUsername, vspherePassword))).To(Succeed()) }) - By("creating vSphere finder") - vsphereFinder = find.NewFinder(vsphereClient.Client) - - By("configuring vSphere datacenter") - datacenter, err := vsphereFinder.DatacenterOrDefault(ctx, vsphereDatacenter) - Expect(err).ShouldNot(HaveOccurred()) - vsphereFinder.SetDatacenter(datacenter) -} - -func terminateVSphereSession() { - Expect(vsphereClient.Logout(ctx)).To(Succeed()) + return vsphereClient, restClient } diff --git a/test/e2e/ownerrefs_finalizers_test.go b/test/e2e/ownerrefs_finalizers_test.go index cf08549330..0b46feeb0b 100644 --- a/test/e2e/ownerrefs_finalizers_test.go +++ b/test/e2e/ownerrefs_finalizers_test.go @@ -89,8 +89,14 @@ var _ = Describe("Ensure OwnerReferences and Finalizers are resilient [vcsim] [s createVsphereIdentitySecret(ctx, bootstrapClusterProxy, username, password) if testTarget == VCSimTestTarget { + // The global clients are not initialized when using vcsim. + vSphereClient, restClient := createVsphereClient(input.Variables["VSPHERE_SERVER"], username, password) + vsphereFinder := find.NewFinder(vSphereClient.Client) + // Create the necessary k8s-region and k8s-zone tags in VCSim for the failure domain. createGovmomiFailureDomainTags(ctx, restClient, vsphereFinder, e2eConfig.GetVariable("VSPHERE_DATACENTER"), e2eConfig.GetVariable("VSPHERE_COMPUTE_CLUSTER")) + + Expect(vsphereClient.Logout(ctx)).To(Succeed()) } } },