Skip to content

Commit 8cd52ac

Browse files
committed
Add test helpers to check if cluster capabilities are enabled and skip accordingly
1 parent 65422c8 commit 8cd52ac

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/extended/util/framework.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2404,6 +2404,27 @@ func IsCapabilityEnabled(oc *CLI, cap configv1.ClusterVersionCapability) (bool,
24042404
return false, nil
24052405
}
24062406

2407+
// AllCapabilitiesEnabled returns true if all of the given capabilities are enabled on the cluster.
2408+
func AllCapabilitiesEnabled(oc *CLI, caps ...configv1.ClusterVersionCapability) (bool, error) {
2409+
cv, err := oc.AdminConfigClient().ConfigV1().ClusterVersions().Get(context.Background(), "version", metav1.GetOptions{})
2410+
if err != nil {
2411+
return false, err
2412+
}
2413+
2414+
enabledCaps := make(map[configv1.ClusterVersionCapability]struct{}, len(cv.Status.Capabilities.EnabledCapabilities))
2415+
for _, c := range cv.Status.Capabilities.EnabledCapabilities {
2416+
enabledCaps[c] = struct{}{}
2417+
}
2418+
2419+
for _, c := range caps {
2420+
if _, found := enabledCaps[c]; !found {
2421+
return false, nil
2422+
}
2423+
}
2424+
2425+
return true, nil
2426+
}
2427+
24072428
// SkipIfNotPlatform skip the test if supported platforms are not matched
24082429
func SkipIfNotPlatform(oc *CLI, platforms ...configv1.PlatformType) {
24092430
var match bool
@@ -2420,6 +2441,15 @@ func SkipIfNotPlatform(oc *CLI, platforms ...configv1.PlatformType) {
24202441
}
24212442
}
24222443

2444+
// SkipIfMissingCapabilities skips the test if any of the given cluster capabilities is not enabled.
2445+
func SkipIfMissingCapabilities(oc *CLI, caps ...configv1.ClusterVersionCapability) {
2446+
enabled, err := AllCapabilitiesEnabled(oc, caps...)
2447+
o.Expect(err).NotTo(o.HaveOccurred())
2448+
if !enabled {
2449+
g.Skip(fmt.Sprintf("Skip this test scenario because not all of the following capabilities are enabled: %v", caps))
2450+
}
2451+
}
2452+
24232453
// GetClusterRegion get the cluster's region
24242454
func GetClusterRegion(oc *CLI) string {
24252455
region, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("node", `-ojsonpath={.items[].metadata.labels.topology\.kubernetes\.io/region}`).Output()

0 commit comments

Comments
 (0)