Skip to content

Commit

Permalink
Use testhelper funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
sebrandon1 committed Nov 21, 2023
1 parent 39c44dc commit 9893ba6
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 90 deletions.
101 changes: 11 additions & 90 deletions cnf-certification-test/networking/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,72 +54,6 @@ var (
env = provider.GetTestEnvironment()
return nil
}

skipIfNoContainersFn = func() (bool, string) {
if len(env.Containers) == 0 {
warnStr := "No containers to check."
logrus.Warnf(warnStr)
return true, warnStr
}

return false, ""
}

skipIfNoPodsFn = func() (bool, string) {
if len(env.Pods) == 0 {
warnStr := "No pods to check."
logrus.Warn(warnStr)
return true, warnStr
}

return false, ""
}

skipIfNoServicesFn = func() (bool, string) {
if len(env.Services) == 0 {
warnStr := "No services to check."
logrus.Warn(warnStr)
return true, warnStr
}

return false, ""
}

skipIfDaemonsetFailedToSpawnFn = func() (bool, string) {
warnStr := "Debug Daemonset failed to spawn skipping test."
if env.DaemonsetFailedToSpawn {
logrus.Warn(warnStr)
return true, warnStr
}

return false, ""
}

skipIfCPUPinningPodsFn = func() (bool, string) {
warnStr := "No CPU pinning pods to check."
if len(env.GetCPUPinningPodsWithDpdk()) == 0 {
logrus.Warn(warnStr)
return true, warnStr
}

return false, ""
}

skipIfNoSRIOVPodsFn = func() (bool, string) {
warnStr := "No SRIOV pods to check."
pods, err := env.GetPodsUsingSRIOV()
if err != nil {
logrus.Warnf("Failed to get pods using SRIOV: %v", err)
return true, warnStr
}

if len(pods) == 0 {
logrus.Warn(warnStr)
return true, warnStr
}

return false, ""
}
)

//nolint:funlen
Expand All @@ -132,9 +66,7 @@ func init() {
// Default interface ICMP IPv4 test case
testID, tags := identifiers.GetGinkgoTestIDAndLabels(identifiers.TestICMPv4ConnectivityIdentifier)
checksGroup.Add(checksdb.NewCheck(testID, tags).
WithSkipCheckFn(skipIfNoContainersFn).
WithSkipCheckFn(skipIfDaemonsetFailedToSpawnFn).
WithSkipCheckFn(skipIfNoPodsFn).
WithSkipCheckFn(testhelper.GetNoContainersUnderTestSkipFn(&env), testhelper.GetDaemonSetFailedToSpawnSkipFn(&env), testhelper.GetNoPodsUnderTestSkipFn(&env)).
WithCheckFn(func(c *checksdb.Check) error {
testNetworkConnectivity(&env, netcommons.IPv4, netcommons.DEFAULT, c)
return nil
Expand All @@ -143,9 +75,7 @@ func init() {
// Multus interfaces ICMP IPv4 test case
testID, tags = identifiers.GetGinkgoTestIDAndLabels(identifiers.TestICMPv4ConnectivityMultusIdentifier)
checksGroup.Add(checksdb.NewCheck(testID, tags).
WithSkipCheckFn(skipIfNoContainersFn).
WithSkipCheckFn(skipIfDaemonsetFailedToSpawnFn).
WithSkipCheckFn(skipIfNoPodsFn).
WithSkipCheckFn(testhelper.GetNoContainersUnderTestSkipFn(&env), testhelper.GetDaemonSetFailedToSpawnSkipFn(&env), testhelper.GetNoPodsUnderTestSkipFn(&env)).
WithCheckFn(func(c *checksdb.Check) error {
testNetworkConnectivity(&env, netcommons.IPv4, netcommons.MULTUS, c)
return nil
Expand All @@ -154,9 +84,7 @@ func init() {
// Default interface ICMP IPv6 test case
testID, tags = identifiers.GetGinkgoTestIDAndLabels(identifiers.TestICMPv6ConnectivityIdentifier)
checksGroup.Add(checksdb.NewCheck(testID, tags).
WithSkipCheckFn(skipIfNoContainersFn).
WithSkipCheckFn(skipIfDaemonsetFailedToSpawnFn).
WithSkipCheckFn(skipIfNoPodsFn).
WithSkipCheckFn(testhelper.GetNoContainersUnderTestSkipFn(&env), testhelper.GetDaemonSetFailedToSpawnSkipFn(&env), testhelper.GetNoPodsUnderTestSkipFn(&env)).
WithCheckFn(func(c *checksdb.Check) error {
testNetworkConnectivity(&env, netcommons.IPv6, netcommons.DEFAULT, c)
return nil
Expand All @@ -165,9 +93,7 @@ func init() {
// Multus interfaces ICMP IPv6 test case
testID, tags = identifiers.GetGinkgoTestIDAndLabels(identifiers.TestICMPv6ConnectivityMultusIdentifier)
checksGroup.Add(checksdb.NewCheck(testID, tags).
WithSkipCheckFn(skipIfNoContainersFn).
WithSkipCheckFn(skipIfDaemonsetFailedToSpawnFn).
WithSkipCheckFn(skipIfNoPodsFn).
WithSkipCheckFn(testhelper.GetNoContainersUnderTestSkipFn(&env), testhelper.GetDaemonSetFailedToSpawnSkipFn(&env), testhelper.GetNoPodsUnderTestSkipFn(&env)).
WithCheckFn(func(c *checksdb.Check) error {
testNetworkConnectivity(&env, netcommons.IPv6, netcommons.MULTUS, c)
return nil
Expand All @@ -176,9 +102,7 @@ func init() {
// Undeclared container ports usage test case
testID, tags = identifiers.GetGinkgoTestIDAndLabels(identifiers.TestUndeclaredContainerPortsUsage)
checksGroup.Add(checksdb.NewCheck(testID, tags).
WithSkipCheckFn(skipIfNoContainersFn).
WithSkipCheckFn(skipIfDaemonsetFailedToSpawnFn).
WithSkipCheckFn(skipIfNoPodsFn).
WithSkipCheckFn(testhelper.GetNoContainersUnderTestSkipFn(&env), testhelper.GetDaemonSetFailedToSpawnSkipFn(&env), testhelper.GetNoPodsUnderTestSkipFn(&env)).
WithCheckFn(func(c *checksdb.Check) error {
testUndeclaredContainerPortsUsage(c, &env)
return nil
Expand All @@ -187,9 +111,7 @@ func init() {
// OCP reserved ports usage test case
testID, tags = identifiers.GetGinkgoTestIDAndLabels(identifiers.TestOCPReservedPortsUsage)
checksGroup.Add(checksdb.NewCheck(testID, tags).
WithSkipCheckFn(skipIfNoContainersFn).
WithSkipCheckFn(skipIfDaemonsetFailedToSpawnFn).
WithSkipCheckFn(skipIfNoPodsFn).
WithSkipCheckFn(testhelper.GetNoContainersUnderTestSkipFn(&env), testhelper.GetDaemonSetFailedToSpawnSkipFn(&env), testhelper.GetNoPodsUnderTestSkipFn(&env)).
WithCheckFn(func(c *checksdb.Check) error {
testOCPReservedPortsUsage(c, &env)
return nil
Expand All @@ -198,7 +120,7 @@ func init() {
// Dual stack services test case
testID, tags = identifiers.GetGinkgoTestIDAndLabels(identifiers.TestServiceDualStackIdentifier)
checksGroup.Add(checksdb.NewCheck(testID, tags).
WithSkipCheckFn(skipIfNoServicesFn).
WithSkipCheckFn(testhelper.GetNoServicesUnderTestSkipFn(&env)).
WithCheckFn(func(c *checksdb.Check) error {
testDualStackServices(c, &env)
return nil
Expand All @@ -207,7 +129,7 @@ func init() {
// Network policy deny all test case
testID, tags = identifiers.GetGinkgoTestIDAndLabels(identifiers.TestNetworkPolicyDenyAllIdentifier)
checksGroup.Add(checksdb.NewCheck(testID, tags).
WithSkipCheckFn(skipIfNoPodsFn).
WithSkipCheckFn(testhelper.GetNoPodsUnderTestSkipFn(&env)).
WithCheckFn(func(c *checksdb.Check) error {
testNetworkPolicyDenyAll(c, &env)
return nil
Expand All @@ -216,8 +138,7 @@ func init() {
// Extended partner ports test case
testID, tags = identifiers.GetGinkgoTestIDAndLabels(identifiers.TestReservedExtendedPartnerPorts)
checksGroup.Add(checksdb.NewCheck(testID, tags).
WithSkipCheckFn(skipIfNoPodsFn).
WithSkipCheckFn(skipIfDaemonsetFailedToSpawnFn).
WithSkipCheckFn(testhelper.GetNoPodsUnderTestSkipFn(&env), testhelper.GetDaemonSetFailedToSpawnSkipFn(&env)).
WithCheckFn(func(c *checksdb.Check) error {
testPartnerSpecificTCPPorts(c, &env)
return nil
Expand All @@ -226,7 +147,7 @@ func init() {
// DPDK CPU pinning exec probe test case
testID, tags = identifiers.GetGinkgoTestIDAndLabels(identifiers.TestDpdkCPUPinningExecProbe)
checksGroup.Add(checksdb.NewCheck(testID, tags).
WithSkipCheckFn(skipIfCPUPinningPodsFn).
WithSkipCheckFn(testhelper.GetNoCPUPinningPodsSkipFn(&env)).
WithCheckFn(func(c *checksdb.Check) error {
dpdkPods := env.GetCPUPinningPodsWithDpdk()
testExecProbDenyAtCPUPinning(c, dpdkPods)
Expand All @@ -236,7 +157,7 @@ func init() {
// Restart on reboot label test case
testID, tags = identifiers.GetGinkgoTestIDAndLabels(identifiers.TestRestartOnRebootLabelOnPodsUsingSRIOV)
checksGroup.Add(checksdb.NewCheck(testID, tags).
WithSkipCheckFn(skipIfNoSRIOVPodsFn).
WithSkipCheckFn(testhelper.GetNoSRIOVPodsSkipFn(&env)).
WithCheckFn(func(c *checksdb.Check) error {
sriovPods, err := env.GetPodsUsingSRIOV()
if err != nil {
Expand Down
45 changes: 45 additions & 0 deletions pkg/testhelper/testhelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,51 @@ func ResultToString(result int) (str string) {
return ""
}

func GetNoServicesUnderTestSkipFn(env *provider.TestEnvironment) func() (bool, string) {
return func() (bool, string) {
if len(env.Services) == 0 {
return true, "no services to check found"
}

return false, ""
}
}

func GetDaemonSetFailedToSpawnSkipFn(env *provider.TestEnvironment) func() (bool, string) {

Check failure on line 339 in pkg/testhelper/testhelper.go

View workflow job for this annotation

GitHub Actions / Run Tests

other declaration of GetDaemonSetFailedToSpawnSkipFn
return func() (bool, string) {
if env.DaemonsetFailedToSpawn {
return true, "no daemonSets to check found"
}

return false, ""
}
}

func GetNoCPUPinningPodsSkipFn(env *provider.TestEnvironment) func() (bool, string) {
return func() (bool, string) {
if len(env.GetCPUPinningPodsWithDpdk()) == 0 {
return true, "no CPU pinning pods to check found"
}

return false, ""
}
}

func GetNoSRIOVPodsSkipFn(env *provider.TestEnvironment) func() (bool, string) {
return func() (bool, string) {
pods, err := env.GetPodsUsingSRIOV()
if err != nil {
return true, fmt.Sprintf("failed to get SRIOV pods: %v", err)
}

if len(pods) == 0 {
return true, "no SRIOV pods to check found"
}

return false, ""
}
}

func GetNoContainersUnderTestSkipFn(env *provider.TestEnvironment) func() (bool, string) {
return func() (bool, string) {
if len(env.Containers) == 0 {
Expand Down

0 comments on commit 9893ba6

Please sign in to comment.