From 51a197e53681f073faf5ca28c19f042e33a6d89b Mon Sep 17 00:00:00 2001 From: Andrea Panattoni Date: Wed, 25 Oct 2023 19:17:28 +0200 Subject: [PATCH] Basic verification of `SriovNetwork.Spec.LogLevel` Add an end-to-end test to verify that configuring the LogLevel field of a SriovNetwork makes sriov cni Add command logging to multus pods Signed-off-by: Andrea Panattoni --- test/conformance/tests/test_sriov_operator.go | 53 ++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/test/conformance/tests/test_sriov_operator.go b/test/conformance/tests/test_sriov_operator.go index bba12fab2..30498507b 100644 --- a/test/conformance/tests/test_sriov_operator.go +++ b/test/conformance/tests/test_sriov_operator.go @@ -108,7 +108,7 @@ var _ = Describe("[sriov] operator", func() { Describe("No SriovNetworkNodePolicy", func() { Context("SR-IOV network config daemon can be set by nodeselector", func() { // 26186 - FIt("Should schedule the config daemon on selected nodes", func() { + It("Should schedule the config daemon on selected nodes", func() { if discovery.Enabled() { Skip("Test unsuitable to be run in discovery mode") } @@ -930,6 +930,36 @@ var _ = Describe("[sriov] operator", func() { }, 3*time.Minute, time.Second).Should(Equal(corev1.PodRunning)) }) }) + + Context("CNI Logging level", func() { + It("Debug logging should be visible in multus pod", func() { + sriovNetworkName := "test-log-level-debug-no-file" + err := network.CreateSriovNetwork(clients, sriovDevice, sriovNetworkName, + namespaces.Test, operatorNamespace, resourceName, ipamIpv4, + func(sn *sriovv1.SriovNetwork) { + sn.Spec.LogLevel = "debug" + }) + Expect(err).ToNot(HaveOccurred()) + + podDeployTime := time.Now() + + testPod := createTestPod(node, []string{sriovNetworkName}) + + recentMultusLogs := getMultusPodLogs(testPod.Spec.NodeName, podDeployTime) + + Expect(recentMultusLogs).To( + ContainElement( + // Assert against multiple ContainSubstring condition because we can't make assumption on the order of the chunks + And( + ContainSubstring(`level="debug"`), + ContainSubstring(`msg="1. Set link down"`), + ContainSubstring(`cniName="sriov-cni"`), + ContainSubstring(`ifname="net1"`), + ContainSubstring(`func="SetupVF"`), + ), + )) + }) + }) }) Describe("Custom SriovNetworkNodePolicy", func() { @@ -2427,3 +2457,24 @@ func assertDevicePluginConfigurationContains(node, configuration string) { HaveKeyWithValue(node, ContainSubstring(configuration)), ) } + +func getMultusPodLogs(nodeName string, since time.Time) []string { + podList, err := clients.Pods("").List(context.Background(), metav1.ListOptions{ + LabelSelector: "app=multus", + FieldSelector: "spec.nodeName=" + nodeName, + }) + ExpectWithOffset(1, err).ToNot(HaveOccurred()) + ExpectWithOffset(1, podList.Items).To(HaveLen(1), "One multus pod expected") + + multusPod := podList.Items[0] + logStart := metav1.NewTime(since) + rawLogs, err := clients.Pods(multusPod.Namespace). + GetLogs(multusPod.Name, &corev1.PodLogOptions{ + Container: multusPod.Spec.Containers[0].Name, + SinceTime: &logStart, + }). + DoRaw(context.Background()) + ExpectWithOffset(1, err).ToNot(HaveOccurred()) + + return strings.Split(string(rawLogs), "\n") +}