Skip to content

Commit

Permalink
e2e: topomgr: autodetect SRIOV resource to use
Browse files Browse the repository at this point in the history
The SRIOV device plugin can create different resources depending
on both the hardware present on the system and the configuration.
As long as we have at least one SRIOV device, the tests don't actually
care about which specific device is.

Previously, the test hardcoded the most common intel SRIOV device
identifier. This patch lifts the restriction and let the test
autodetect and use what's available.

Signed-off-by: Francesco Romani <[email protected]>
  • Loading branch information
ffromani committed Feb 10, 2020
1 parent fa26fb6 commit 6687fcc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
33 changes: 20 additions & 13 deletions test/e2e_node/topology_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"fmt"
"os/exec"
"regexp"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -206,15 +207,18 @@ func readServiceAccountV1OrDie(objBytes []byte) *v1.ServiceAccount {
return requiredObj.(*v1.ServiceAccount)
}

// numberOfResources returns the number of resources advertised by a node.
func numberOfResources(node *v1.Node, resourceKey string) int64 {
val, ok := node.Status.Capacity[v1.ResourceName(resourceKey)]

if !ok {
return 0
func findSRIOVResource(node *v1.Node) (string, int64) {
re := regexp.MustCompile(`^intel.com/.*sriov.*`)
for key, val := range node.Status.Capacity {
resource := string(key)
if re.MatchString(resource) {
v := val.Value()
if v > 0 {
return resource, v
}
}
}

return val.Value()
return "", 0
}

func deletePodInNamespace(f *framework.Framework, namespace, name string) {
Expand Down Expand Up @@ -464,14 +468,14 @@ func runTopologyManagerPolicySuiteTests(f *framework.Framework) {
waitForContainerRemoval(pod2.Spec.Containers[0].Name, pod2.Name, pod2.Namespace)
}

func runTopologyManagerNodeAlignmentSinglePodTest(f *framework.Framework, numaNodes int) {
func runTopologyManagerNodeAlignmentSinglePodTest(f *framework.Framework, sriovResourceName string, numaNodes int) {
ginkgo.By("allocate aligned resources for a single pod")
ctnAttrs := []tmCtnAttribute{
{
ctnName: "gu-container",
cpuRequest: "1000m",
cpuLimit: "1000m",
devResource: SRIOVResourceName,
devResource: sriovResourceName,
},
}

Expand Down Expand Up @@ -510,15 +514,18 @@ func runTopologyManagerNodeAlignmentSuiteTests(f *framework.Framework, numaNodes
dpPod, err := f.ClientSet.CoreV1().Pods(metav1.NamespaceSystem).Create(context.TODO(), dp, metav1.CreateOptions{})
framework.ExpectNoError(err)

sriovResourceName := ""
var sriovResourceAmount int64
ginkgo.By("Waiting for devices to become available on the local node")
gomega.Eventually(func() bool {
node := getLocalNode(f)
framework.Logf("Node status: %v", node.Status.Capacity)
return numberOfResources(node, SRIOVResourceName) > 0
sriovResourceName, sriovResourceAmount = findSRIOVResource(node)
return sriovResourceAmount > 0
}, 5*time.Minute, framework.Poll).Should(gomega.BeTrue())
framework.Logf("Successfully created device plugin pod")
framework.Logf("Successfully created device plugin pod, detected SRIOV device %q", sriovResourceName)

runTopologyManagerNodeAlignmentSinglePodTest(f, numaNodes)
runTopologyManagerNodeAlignmentSinglePodTest(f, sriovResourceName, numaNodes)

framework.Logf("deleting the SRIOV device plugin pod %s/%s and waiting for container %s removal",
dpPod.Namespace, dpPod.Name, dpPod.Spec.Containers[0].Name)
Expand Down
2 changes: 0 additions & 2 deletions test/e2e_node/util_sriov.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ limitations under the License.
package e2enode

const (
// SRIOVResourceName is the name of the example resource which is used in the e2e test
SRIOVResourceName = "intel.com/intel_sriov_netdevice" // TODO make it configurable
// SRIOVDevicePluginCMYAML is the path of the config map to configure the sriov device plugin.
SRIOVDevicePluginCMYAML = "test/e2e_node/testing-manifests/sriovdp-cm.yaml"
// SRIOVDevicePluginDSYAML is the path of the daemonset template of the sriov device plugin. // TODO: Parametrize it by making it a feature in TestFramework.
Expand Down

0 comments on commit 6687fcc

Please sign in to comment.