From 6687fcc78c103cb7c6df4153fadfee191472d26b Mon Sep 17 00:00:00 2001 From: Francesco Romani Date: Thu, 30 Jan 2020 16:52:55 +0100 Subject: [PATCH] e2e: topomgr: autodetect SRIOV resource to use 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 --- test/e2e_node/topology_manager_test.go | 33 ++++++++++++++++---------- test/e2e_node/util_sriov.go | 2 -- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/test/e2e_node/topology_manager_test.go b/test/e2e_node/topology_manager_test.go index 833002fe460..944156b61b6 100644 --- a/test/e2e_node/topology_manager_test.go +++ b/test/e2e_node/topology_manager_test.go @@ -20,6 +20,7 @@ import ( "context" "fmt" "os/exec" + "regexp" "strconv" "strings" "time" @@ -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) { @@ -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, }, } @@ -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) diff --git a/test/e2e_node/util_sriov.go b/test/e2e_node/util_sriov.go index f985b11d94a..4b404332157 100644 --- a/test/e2e_node/util_sriov.go +++ b/test/e2e_node/util_sriov.go @@ -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.