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 25, 2023
1 parent e63bf5a commit 46ce589
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion test/conformance/tests/test_sriov_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
admission "k8s.io/api/admissionregistration/v1"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"

Check failure on line 20 in test/conformance/tests/test_sriov_operator.go

View workflow job for this annotation

GitHub Actions / Golangci-lint

ST1019: package "k8s.io/api/core/v1" is being imported more than once (stylecheck)
v1 "k8s.io/api/core/v1"

Check failure on line 21 in test/conformance/tests/test_sriov_operator.go

View workflow job for this annotation

GitHub Actions / Golangci-lint

ST1019(related information): other import of "k8s.io/api/core/v1" (stylecheck)
rbacv1 "k8s.io/api/rbac/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -108,7 +109,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 +931,35 @@ var _ = Describe("[sriov] operator", func() {
}, 3*time.Minute, time.Second).Should(Equal(corev1.PodRunning))
})
})

Context("CNI Logging level", func() {
// 25874
It("Debug logging should be visible in multus pod", func() {

err := network.CreateSriovNetwork(clients, sriovDevice, "test-log-level-debug-no-file", namespaces.Test, operatorNamespace, resourceName, ipamIpv4, func(sn *sriovv1.SriovNetwork) {
sn.Spec.LogLevel = "debug"
})
Expect(err).ToNot(HaveOccurred())

podDeployTime := time.Now()

testPod := createTestPod(node, []string{"test-log-level-debug-no-file"})

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,25 @@ func assertDevicePluginConfigurationContains(node, configuration string) {
HaveKeyWithValue(node, ContainSubstring(configuration)),
)
}

func getMultusPodLogs(nodeName string, since time.Time) []string {

Check failure on line 2461 in test/conformance/tests/test_sriov_operator.go

View workflow job for this annotation

GitHub Actions / Golangci-lint

unnecessary leading newline (whitespace)

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, &v1.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 46ce589

Please sign in to comment.