Skip to content

Commit b9af86f

Browse files
committed
Vibe coding recovery logic
1 parent 2c5f58f commit b9af86f

File tree

7 files changed

+1037
-6
lines changed

7 files changed

+1037
-6
lines changed

pkg/clioptions/clusterdiscovery/cluster.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ import (
3030
"github.com/openshift/origin/test/extended/util/azure"
3131
)
3232

33+
// HypervisorConfig contains configuration for hypervisor-based recovery operations
34+
type HypervisorConfig struct {
35+
HypervisorIP string `json:"hypervisorIP"`
36+
SSHUser string `json:"sshUser"`
37+
PrivateKey string `json:"privateKey"`
38+
}
39+
3340
type ClusterConfiguration struct {
3441
ProviderName string `json:"type"`
3542

@@ -76,6 +83,9 @@ type ClusterConfiguration struct {
7683
// IsNoOptionalCapabilities indicates the cluster has no optional capabilities enabled
7784
HasNoOptionalCapabilities bool
7885

86+
// HypervisorConfig contains SSH configuration for hypervisor-based recovery operations
87+
HypervisorConfig *HypervisorConfig
88+
7989
// APIGroups contains the set of API groups available in the cluster
8090
APIGroups sets.Set[string] `json:"-"`
8191
// EnabledFeatureGates contains the set of enabled feature gates in the cluster

pkg/cmd/openshift-tests/run/flags.go

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package run
22

33
import (
4+
"encoding/json"
5+
"fmt"
46
"os"
57

68
"github.com/openshift-eng/openshift-tests-extension/pkg/extension"
@@ -28,9 +30,6 @@ type RunSuiteFlags struct {
2830
ToImage string
2931
TestOptions []string
3032

31-
// Shared by initialization code
32-
config *clusterdiscovery.ClusterConfiguration
33-
3433
genericclioptions.IOStreams
3534
}
3635

@@ -84,7 +83,7 @@ func (f *RunSuiteFlags) ToOptions(args []string, availableSuites []*testginkgo.T
8483
// shallow copy to mutate
8584
ginkgoOptions := f.GinkgoRunSuiteOptions
8685

87-
providerConfig, err := f.SuiteWithKubeTestInitializationPreSuite()
86+
clusterConfig, err := f.SuiteWithKubeTestInitializationPreSuite()
8887
if err != nil {
8988
return nil, err
9089
}
@@ -95,13 +94,39 @@ func (f *RunSuiteFlags) ToOptions(args []string, availableSuites []*testginkgo.T
9594
return nil, err
9695
}
9796

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+
98123
o := &RunSuiteOptions{
99124
GinkgoRunSuiteOptions: ginkgoOptions,
100125
Suite: suite,
101126
Extension: internalExtension,
102-
ClusterConfig: providerConfig,
127+
ClusterConfig: clusterConfig,
103128
FromRepository: f.FromRepository,
104-
CloudProviderJSON: providerConfig.ToJSONString(),
129+
CloudProviderJSON: clusterConfig.ToJSONString(),
105130
CloseFn: closeFn,
106131
IOStreams: f.IOStreams,
107132
}

pkg/cmd/openshift-tests/run/options.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ type RunSuiteOptions struct {
3131
CloseFn iooptions.CloseFunc
3232
genericclioptions.IOStreams
3333

34+
// HypervisorConfig contains SSH configuration for hypervisor-based recovery operations
35+
// If set, will run recovery tests that require the hypervisor-based recovery, such as
36+
// the node replacement test in the two_node recovery suite.
37+
HypervisorConfig *clusterdiscovery.HypervisorConfig
38+
3439
// ClusterConfig contains cluster-specific configuration for filtering tests
3540
ClusterConfig *clusterdiscovery.ClusterConfiguration
3641

pkg/test/filters/cluster_state.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ func NewClusterStateFilter(config *clusterdiscovery.ClusterConfiguration) *Clust
6767
skips = append(skips, "[Skipped:NoOptionalCapabilities]")
6868
}
6969

70+
if config.HypervisorConfig == nil {
71+
skips = append(skips, "[Requires:HypervisorSSHConfig]")
72+
}
73+
7074
logrus.WithField("skips", skips).Info("Generated skips for cluster state")
7175

7276
return &ClusterStateFilter{

pkg/test/ginkgo/cmd_runsuite.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ type GinkgoRunSuiteOptions struct {
9696

9797
// RetryStrategy controls retry behavior and final outcome decisions
9898
RetryStrategy RetryStrategy
99+
100+
// WithHypervisorConfigJSON contains JSON configuration for hypervisor-based recovery operations
101+
WithHypervisorConfigJSON string
99102
}
100103

101104
func NewGinkgoRunSuiteOptions(streams genericclioptions.IOStreams) *GinkgoRunSuiteOptions {
@@ -133,6 +136,7 @@ func (o *GinkgoRunSuiteOptions) BindFlags(flags *pflag.FlagSet) {
133136
flags.StringVar(&o.ShardStrategy, "shard-strategy", o.ShardStrategy, "Which strategy to use for sharding (hash)")
134137
availableStrategies := getAvailableRetryStrategies()
135138
flags.Var(newRetryStrategyFlag(&o.RetryStrategy), "retry-strategy", fmt.Sprintf("Test retry strategy (available: %s, default: %s)", strings.Join(availableStrategies, ", "), defaultRetryStrategy))
139+
flags.StringVar(&o.WithHypervisorConfigJSON, "with-hypervisor-json", os.Getenv("HYPERVISOR_CONFIG"), "JSON configuration for hypervisor-based recovery operations. Must contain hypervisorIP, sshUser, and privateKey fields.")
136140
}
137141

138142
func (o *GinkgoRunSuiteOptions) Validate() error {

0 commit comments

Comments
 (0)