Skip to content

Commit

Permalink
initialize clients for vcsim once
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischdi committed Aug 27, 2024
1 parent e5fbbf2 commit fe067af
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
17 changes: 17 additions & 0 deletions test/e2e/e2e_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,23 @@ func addVCSimTestVariables(managementClusterProxy framework.ClusterProxy, specNa

testSpecificVariables[k] = v
}

vsphereClientsInitialized.Do(func() {
for k, v := range envVar.Status.Variables {
switch k {
case "VSPHERE_USERNAME":
vsphereUsername = v
case "VSPHERE_PASSWORD":
vspherePassword = v
case "VSPHERE_SERVER":
vsphereServer = v
case "VSPHERE_DATACENTER":
vsphereDatacenter = v
}
}

By("Initializing the vSphere session to ensure credentials are working", initVSphereSession)
})
}

func setupNamespaceWithVMOperatorDependenciesVCSim(managementClusterProxy framework.ClusterProxy, workloadClusterNamespace string) {
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,7 @@ var _ = SynchronizedBeforeSuite(func() []byte {
if testTarget == VCenterTestTarget {
// Some of the tests targeting VCenter relies on an additional VSphere session to check test progress;
// such session is create once, and shared across many tests.
// Some changes will be requires to get this working with vcsim e.g. about how to get the credentials/vCenter info,
// but we are deferring this to future work (if an and when necessary).
// For vcsim this clients get initialized once in the first run of a postNamespaceCreated function.
By("Initializing the vSphere session to ensure credentials are working", initVSphereSession)
}

Expand Down
3 changes: 3 additions & 0 deletions test/e2e/govmomi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"flag"
"net/url"
"os"
"sync"
"time"

. "github.com/onsi/ginkgo/v2"
Expand All @@ -42,6 +43,8 @@ var (
vsphereClient *govmomi.Client
restClient *rest.Client
vsphereFinder *find.Finder

vsphereClientsInitialized sync.Once
)

func init() {
Expand Down

0 comments on commit fe067af

Please sign in to comment.