Skip to content

Commit

Permalink
cnf-network: backport parallel draining test to 4.15 (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
evgenLevin committed Aug 8, 2024
1 parent ac862cd commit e634242
Show file tree
Hide file tree
Showing 10 changed files with 877 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/nmstate/kubernetes-nmstate/api v0.0.0-20231116153922-80c6e01df02e
github.com/onsi/ginkgo/v2 v2.15.0
github.com/onsi/gomega v1.31.1
github.com/openshift-kni/eco-goinfra v0.0.0-20240806183830-e3d1d55fa491 // release-4.15
github.com/openshift-kni/eco-goinfra v0.0.0-20240806191402-9800847af598 // release-4.15
github.com/openshift-kni/k8sreporter v1.0.5
github.com/openshift/api v3.9.1-0.20191111211345-a27ff30ebf09+incompatible
github.com/openshift/assisted-service/api v0.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,8 @@ github.com/opencontainers/runc v1.1.12 h1:BOIssBaW1La0/qbNZHXOOa71dZfZEQOzW7dqQf
github.com/opencontainers/runtime-spec v1.1.0 h1:HHUyrt9mwHUjtasSbXSMvs4cyFxh+Bll4AjJ9odEGpg=
github.com/openshift-kni/cluster-group-upgrades-operator v0.0.0-20240227195723-b6e045729e4d h1:JsYQI7mtdh+x+Z/J3zfkLcK4eGtcWivikdxyYMWrjos=
github.com/openshift-kni/cluster-group-upgrades-operator v0.0.0-20240227195723-b6e045729e4d/go.mod h1:zs70lcNtrMh1On3+e48IDg/bvoJER/IygEgo0bSnUuo=
github.com/openshift-kni/eco-goinfra v0.0.0-20240806183830-e3d1d55fa491 h1:YuoKfNHfh0MzFLadozclVaYyVCJw5OEfimJk7otpALk=
github.com/openshift-kni/eco-goinfra v0.0.0-20240806183830-e3d1d55fa491/go.mod h1:msival6kW06SsMcB5eWX5FcCFYG0ZQ36GNPz9pdKf3s=
github.com/openshift-kni/eco-goinfra v0.0.0-20240806191402-9800847af598 h1:KOi+i2hw9Nb8R/PzM5J5eMLrNHHW8MY5SkAlg4SnPWI=
github.com/openshift-kni/eco-goinfra v0.0.0-20240806191402-9800847af598/go.mod h1:msival6kW06SsMcB5eWX5FcCFYG0ZQ36GNPz9pdKf3s=
github.com/openshift-kni/k8sreporter v1.0.5 h1:1GYBc/BTZyVoXilHef43v9A8BSzw700zAPZ6zsZvo6Y=
github.com/openshift-kni/k8sreporter v1.0.5/go.mod h1:fg8HI9yxiKAi6UzR6NTtrmQmA2WKzUqmkRUHwQ1+Bj8=
github.com/openshift-kni/lifecycle-agent v0.0.0-20240309022641-e2b836e0f2d3 h1:8xBtqDIor4vR8uczH6KHNJCJv359WW/+pw6xH7emHFc=
Expand Down
10 changes: 10 additions & 0 deletions tests/cnf/core/network/internal/netenv/netenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,13 @@ func IsSriovDeployed(apiClient *clients.Settings, netConfig *netconfig.NetworkCo

return nil
}

// MapFirstKeyValue returns the first key-value pair found in the input map.
// If the input map is empty, it returns empty strings.
func MapFirstKeyValue(inputMap map[string]string) (string, string) {
for key, value := range inputMap {
return key, value
}

return "", ""
}
149 changes: 149 additions & 0 deletions tests/cnf/core/network/sriov/internal/sriovenv/sriovenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import (
"github.com/openshift-kni/eco-goinfra/pkg/sriov"

sriovV1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1"
"github.com/openshift-kni/eco-gotests/tests/cnf/core/network/internal/cmd"
"github.com/openshift-kni/eco-gotests/tests/cnf/core/network/internal/netenv"
. "github.com/openshift-kni/eco-gotests/tests/cnf/core/network/internal/netinittools"
"github.com/openshift-kni/eco-gotests/tests/cnf/core/network/internal/netparam"
"github.com/openshift-kni/eco-gotests/tests/cnf/core/network/sriov/internal/tsparams"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
Expand Down Expand Up @@ -197,6 +199,153 @@ func ConfigureSriovMlnxFirmwareOnWorkers(
return nil
}

// CreatePodsAndRunTraffic creates test pods and verifies connectivity between them.
func CreatePodsAndRunTraffic(
clientNodeName string,
serverNodeName string,
sriovResNameClient string,
sriovResNameServer string,
clientMac string,
serverMac string,
clientIPs []string,
serverIPs []string) error {
glog.V(90).Infof("Creating test pods and checking ICMP connectivity between them")

clientPod, _, err := createAndWaitTestPods(
clientNodeName,
serverNodeName,
sriovResNameClient,
sriovResNameServer,
clientMac,
serverMac,
clientIPs,
serverIPs)

if err != nil {
glog.V(90).Infof("Failed to create test pods")

return err
}

return cmd.ICMPConnectivityCheck(clientPod, serverIPs)
}

// RemoveSriovConfigurationAndWaitForSriovAndMCPStable removes all SR-IOV networks
// and policies in SR-IOV operator namespace.
func RemoveSriovConfigurationAndWaitForSriovAndMCPStable() error {
glog.V(90).Infof("Removing all SR-IOV networks and policies")

err := RemoveAllSriovNetworks()
if err != nil {
glog.V(90).Infof("Failed to remove all SR-IOV networks")

return err
}

err = removeAllPoliciesAndWaitForSriovAndMCPStable()
if err != nil {
glog.V(90).Infof("Failed to remove all SR-IOV policies")

return err
}

return nil
}

// RemoveAllSriovNetworks removes all SR-IOV networks.
func RemoveAllSriovNetworks() error {
glog.V(90).Infof("Removing all SR-IOV networks")

sriovNs, err := namespace.Pull(APIClient, NetConfig.SriovOperatorNamespace)
if err != nil {
glog.V(90).Infof("Failed to pull SR-IOV operator namespace")

return err
}

err = sriovNs.CleanObjects(
netparam.DefaultTimeout,
sriov.GetSriovNetworksGVR())
if err != nil {
glog.V(90).Infof("Failed to remove SR-IOV networks from SR-IOV operator namespace")

return err
}

return nil
}

// removeAllPoliciesAndWaitForSriovAndMCPStable removes all SriovNetworkNodePolicies and waits until
// SR-IOV and MCP become stable.
func removeAllPoliciesAndWaitForSriovAndMCPStable() error {
glog.V(90).Infof("Deleting all SriovNetworkNodePolicies and waiting for SR-IOV and MCP become stable.")

err := sriov.CleanAllNetworkNodePolicies(APIClient, NetConfig.SriovOperatorNamespace)
if err != nil {
return err
}

return netenv.WaitForSriovAndMCPStable(
APIClient, tsparams.MCOWaitTimeout, time.Minute, NetConfig.CnfMcpLabel, NetConfig.SriovOperatorNamespace)
}

// createAndWaitTestPods creates test pods and waits until they are in the ready state.
func createAndWaitTestPods(
clientNodeName string,
serverNodeName string,
sriovResNameClient string,
sriovResNameServer string,
clientMac string,
serverMac string,
clientIPs []string,
serverIPs []string) (client *pod.Builder, server *pod.Builder, err error) {
glog.V(90).Infof("Creating client pod with IPs %v, mac %s, SR-IOV resourceName %s"+
" and server pod with IPs %v, mac %s, SR-IOV resourceName %s.",
clientIPs, clientMac, sriovResNameClient, serverIPs, serverMac, sriovResNameServer)

clientPod, err := createAndWaitTestPodWithSecondaryNetwork("client", clientNodeName,
sriovResNameClient, clientMac, clientIPs)
if err != nil {
glog.V(90).Infof("Failed to create clientPod")

return nil, nil, err
}

serverPod, err := createAndWaitTestPodWithSecondaryNetwork("server", serverNodeName,
sriovResNameServer, serverMac, serverIPs)
if err != nil {
glog.V(90).Infof("Failed to create serverPod")

return nil, nil, err
}

return clientPod, serverPod, nil
}

// createAndWaitTestPodWithSecondaryNetwork creates test pod with secondary network
// and waits until it is in the ready state.
func createAndWaitTestPodWithSecondaryNetwork(
podName string,
testNodeName string,
sriovResNameTest string,
testMac string,
testIPs []string) (*pod.Builder, error) {
glog.V(90).Infof("Creating a test pod name %s", podName)

secNetwork := pod.StaticIPAnnotationWithMacAddress(sriovResNameTest, testIPs, testMac)
testPod, err := pod.NewBuilder(APIClient, podName, tsparams.TestNamespaceName, NetConfig.CnfNetTestContainer).
DefineOnNode(testNodeName).WithPrivilegedFlag().
WithSecondaryNetwork(secNetwork).CreateAndWaitUntilRunning(netparam.DefaultTimeout)

if err != nil {
glog.V(90).Infof("Failed to create pod %s with secondary network", podName)

return nil, err
}

return testPod, nil
}

func isVfCreated(sriovNodeState *sriov.NetworkNodeStateBuilder, vfNumber int, sriovInterfaceName string) error {
sriovNumVfs, err := sriovNodeState.GetNumVFs(sriovInterfaceName)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions tests/cnf/core/network/sriov/internal/tsparams/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ const (
TestNamespaceName = "sriov-tests"
// LabelExternallyManagedTestCases represents ExternallyManaged label that can be used for test cases selection.
LabelExternallyManagedTestCases = "externallymanaged"
// LabelParallelDrainingTestCases represents parallel draining label that can be used for test cases selection.
LabelParallelDrainingTestCases = "paralleldraining"
)
Loading

0 comments on commit e634242

Please sign in to comment.