Skip to content

Commit

Permalink
Basic verification of SriovNetwork.Spec.LogLevel
Browse files Browse the repository at this point in the history
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 <apanatto@redhat.com>
  • Loading branch information
zeeke committed Oct 26, 2023
1 parent e63bf5a commit 51a197e
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion test/conformance/tests/test_sriov_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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")
}

0 comments on commit 51a197e

Please sign in to comment.