1
1
package run
2
2
3
3
import (
4
+ "encoding/json"
5
+ "fmt"
4
6
"os"
5
7
6
8
"github.com/openshift-eng/openshift-tests-extension/pkg/extension"
@@ -28,9 +30,6 @@ type RunSuiteFlags struct {
28
30
ToImage string
29
31
TestOptions []string
30
32
31
- // Shared by initialization code
32
- config * clusterdiscovery.ClusterConfiguration
33
-
34
33
genericclioptions.IOStreams
35
34
}
36
35
@@ -84,7 +83,7 @@ func (f *RunSuiteFlags) ToOptions(args []string, availableSuites []*testginkgo.T
84
83
// shallow copy to mutate
85
84
ginkgoOptions := f .GinkgoRunSuiteOptions
86
85
87
- providerConfig , err := f .SuiteWithKubeTestInitializationPreSuite ()
86
+ clusterConfig , err := f .SuiteWithKubeTestInitializationPreSuite ()
88
87
if err != nil {
89
88
return nil , err
90
89
}
@@ -95,13 +94,39 @@ func (f *RunSuiteFlags) ToOptions(args []string, availableSuites []*testginkgo.T
95
94
return nil , err
96
95
}
97
96
97
+ // Parse hypervisor configuration if provided and set it in environment for test context
98
+ if f .GinkgoRunSuiteOptions .WithHypervisorConfigJSON != "" {
99
+ // Validate the JSON format
100
+ var hypervisorConfig clusterdiscovery.HypervisorConfig
101
+ if err := json .Unmarshal ([]byte (f .GinkgoRunSuiteOptions .WithHypervisorConfigJSON ), & hypervisorConfig ); err != nil {
102
+ return nil , fmt .Errorf ("failed to parse hypervisor configuration JSON: %v" , err )
103
+ }
104
+
105
+ // Validate required fields
106
+ if hypervisorConfig .HypervisorIP == "" {
107
+ return nil , fmt .Errorf ("hypervisorIP is required in hypervisor configuration" )
108
+ }
109
+ if hypervisorConfig .SSHUser == "" {
110
+ return nil , fmt .Errorf ("sshUser is required in hypervisor configuration" )
111
+ }
112
+ if hypervisorConfig .PrivateKey == "" {
113
+ return nil , fmt .Errorf ("privateKey is required in hypervisor configuration" )
114
+ }
115
+
116
+ // Set the hypervisor configuration in the cluster config
117
+ clusterConfig .HypervisorConfig = & hypervisorConfig
118
+
119
+ // Also set it in environment for test context access
120
+ os .Setenv ("HYPERVISOR_CONFIG" , f .GinkgoRunSuiteOptions .WithHypervisorConfigJSON )
121
+ }
122
+
98
123
o := & RunSuiteOptions {
99
124
GinkgoRunSuiteOptions : ginkgoOptions ,
100
125
Suite : suite ,
101
126
Extension : internalExtension ,
102
- ClusterConfig : providerConfig ,
127
+ ClusterConfig : clusterConfig ,
103
128
FromRepository : f .FromRepository ,
104
- CloudProviderJSON : providerConfig .ToJSONString (),
129
+ CloudProviderJSON : clusterConfig .ToJSONString (),
105
130
CloseFn : closeFn ,
106
131
IOStreams : f .IOStreams ,
107
132
}
0 commit comments