diff --git a/test/e2e/e2e_setup_test.go b/test/e2e/e2e_setup_test.go index f8674de46a..99d72ef17b 100644 --- a/test/e2e/e2e_setup_test.go +++ b/test/e2e/e2e_setup_test.go @@ -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) { diff --git a/test/e2e/e2e_suite_test.go b/test/e2e/e2e_suite_test.go index 554da15df9..56b29b952b 100644 --- a/test/e2e/e2e_suite_test.go +++ b/test/e2e/e2e_suite_test.go @@ -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) } diff --git a/test/e2e/govmomi_test.go b/test/e2e/govmomi_test.go index 10e0e60ac3..9bc35874b2 100644 --- a/test/e2e/govmomi_test.go +++ b/test/e2e/govmomi_test.go @@ -20,6 +20,7 @@ import ( "flag" "net/url" "os" + "sync" "time" . "github.com/onsi/ginkgo/v2" @@ -42,6 +43,8 @@ var ( vsphereClient *govmomi.Client restClient *rest.Client vsphereFinder *find.Finder + + vsphereClientsInitialized sync.Once ) func init() {