Skip to content

Commit

Permalink
test: create clients for vcsim when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischdi committed Aug 27, 2024
1 parent e5fbbf2 commit 41f5549
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
31 changes: 20 additions & 11 deletions test/e2e/govmomi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
4 changes: 4 additions & 0 deletions test/e2e/ownerrefs_finalizers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ 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"))
}
Expand Down

0 comments on commit 41f5549

Please sign in to comment.