Skip to content

Commit

Permalink
Merge pull request #529 from zeeke/e2e-tests
Browse files Browse the repository at this point in the history
Increase end-to-end test coverage
  • Loading branch information
SchSeba authored Nov 11, 2023
2 parents 2988e1d + 28d4726 commit 2468eb8
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions test/conformance/tests/test_sriov_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ var _ = Describe("[sriov] operator", func() {
Skip("Test unsuitable to be run in discovery mode")
}

testStartingTime := time.Now()

By("Checking that a daemon is scheduled on each worker node")
Eventually(func() bool {
return daemonsScheduledOnNodes("node-role.kubernetes.io/worker=")
Expand Down Expand Up @@ -168,6 +170,21 @@ var _ = Describe("[sriov] operator", func() {
Eventually(func() bool {
return daemonsScheduledOnNodes("node-role.kubernetes.io/worker")
}, 1*time.Minute, 1*time.Second).Should(Equal(true))

By("Checking that a daemon is able to publish events")
Eventually(func() bool {
events, err := clients.Events(operatorNamespace).List(
context.Background(), metav1.ListOptions{TypeMeta: sriovv1.SriovNetworkNodeState{}.TypeMeta})
Expect(err).ToNot(HaveOccurred())

for _, e := range events.Items {
if e.Reason == "ConfigDaemonStart" &&
e.CreationTimestamp.Time.After(testStartingTime) {
return true
}
}
return false
}, 30*time.Second, 5*time.Second).Should(BeTrue(), "Config Daemon should record an event when starting")
})
})

Expand Down Expand Up @@ -913,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="function called"`),
ContainSubstring(`func="cmdAdd"`),
ContainSubstring(`cniName="sriov-cni"`),
ContainSubstring(`ifname="net1"`),
),
))
})
})
})

Describe("Custom SriovNetworkNodePolicy", func() {
Expand Down Expand Up @@ -2410,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 2468eb8

Please sign in to comment.