Skip to content

Commit

Permalink
Parallel 4.14 (#170)
Browse files Browse the repository at this point in the history
* goinfra bumped to v0.0.0-20240819130344-f80d1970ca76

* cnf network: backport parallel draining tests
  • Loading branch information
evgenLevin authored Aug 21, 2024
1 parent 28ccc39 commit 299957d
Show file tree
Hide file tree
Showing 10 changed files with 919 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.13.0
github.com/onsi/gomega v1.28.0
github.com/openshift-kni/eco-goinfra v0.0.0-20240715131405-c1d20ad6ec42
github.com/openshift-kni/eco-goinfra v0.0.0-20240819130344-f80d1970ca76
github.com/openshift-kni/k8sreporter v1.0.5
github.com/openshift/api v3.9.1-0.20190916204813-cdbe64fb0c91+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 @@ -530,8 +530,8 @@ github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8
github.com/opencontainers/image-spec v1.1.0-rc4 h1:oOxKUJWnFC4YGHCCMNql1x4YaDfYBTS5Y4x/Cgeo1E0=
github.com/openshift-kni/cluster-group-upgrades-operator v0.0.0-20230810161322-3ef5efb0de85 h1:j1yPV4NOpTXhn/C0faq7Lu4mHmbngbyVaO5JDE4SmUU=
github.com/openshift-kni/cluster-group-upgrades-operator v0.0.0-20230810161322-3ef5efb0de85/go.mod h1:56E+O17XBxULAIOtc2qAtILRfICfzUEaqlE9yUia/Eg=
github.com/openshift-kni/eco-goinfra v0.0.0-20240715131405-c1d20ad6ec42 h1:FtdI0Vvalipf5OqyRtwWPa2mewG3Kshu9W1BCI/07QE=
github.com/openshift-kni/eco-goinfra v0.0.0-20240715131405-c1d20ad6ec42/go.mod h1:ElIow5w4NIAqqF0Zm1NzQHWVzznv9dfyYEuYkqaiymc=
github.com/openshift-kni/eco-goinfra v0.0.0-20240819130344-f80d1970ca76 h1:Tv5K43/VC3qFnnRakRUf5ZJyTn0DsSIVYZikkgbU8g8=
github.com/openshift-kni/eco-goinfra v0.0.0-20240819130344-f80d1970ca76/go.mod h1:ElIow5w4NIAqqF0Zm1NzQHWVzznv9dfyYEuYkqaiymc=
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/api v0.0.0-20231117205818-971e4ba78c9a h1:p/TXj7qipRh0/CMN4dfBvJ3FePanXQ9Lfv/L17IxUaU=
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 @@ -78,3 +78,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"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
Expand Down Expand Up @@ -195,6 +197,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 299957d

Please sign in to comment.