Skip to content

Commit

Permalink
test: fix NodeLogQuery tests to query the correct node for logs
Browse files Browse the repository at this point in the history
Currently, the test queries the local node, which is not correct for most kubernetes environments.
Instead, ssh to the target node and call journalctl there

Signed-off-by: Peter Hunt <pehunt@redhat.com>
  • Loading branch information
haircommander committed Jul 25, 2023
1 parent 86b44a3 commit a248c4d
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions test/e2e/node/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ var _ = SIGDescribe("kubelet", func() {
queryCommand := "\"/api/v1/nodes/" + nodeName + "/proxy/logs/?query=kubelet&tailLines=3\""
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
result := runKubectlCommand(cmd)
logs := journalctlCommand("-u", "kubelet", "-n 3 --utc")
logs := journalctlCommandOnNode(nodeName, "-u kubelet -n 3 --utc")
if result != logs {
framework.Failf("Failed to receive the correct kubelet logs or the correct amount of lines of logs")
}
Expand All @@ -593,7 +593,7 @@ var _ = SIGDescribe("kubelet", func() {
queryCommand := "\"/api/v1/nodes/" + nodeName + "/proxy/logs/?query=kubelet&tailLines=3&boot=0&pattern=kubelet\""
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
result := runKubectlCommand(cmd)
logs := journalctlCommand("-u", "kubelet", "-n 3 --utc")
logs := journalctlCommandOnNode(nodeName, "-u kubelet -n 3 --utc")
if result != logs {
framework.Failf("Failed to receive the correct kubelet logs")
}
Expand All @@ -613,7 +613,7 @@ var _ = SIGDescribe("kubelet", func() {
queryCommand := "\"/api/v1/nodes/" + nodeName + "/proxy/logs/?query=kubelet&tailLines=3&sinceTime=" + start.Format(time.RFC3339) + "\""
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
result := runKubectlCommand(cmd)
logs := journalctlCommand("-u", "kubelet", "-n 3 --utc")
logs := journalctlCommandOnNode(nodeName, "-u kubelet -n 3 --utc")
if result != logs {
framework.Failf("Failed to receive the correct kubelet logs or the correct amount of lines of logs")
}
Expand All @@ -634,7 +634,7 @@ var _ = SIGDescribe("kubelet", func() {
queryCommand := "\"/api/v1/nodes/" + nodeName + "/proxy/logs/?query=kubelet&tailLines=3&sinceTime=" + start.Format(time.RFC3339) + "\""
cmd := tk.KubectlCmd("get", "--raw", queryCommand)
result := runKubectlCommand(cmd)
logs := journalctlCommand("-u", "kubelet", "--utc")
logs := journalctlCommandOnNode(nodeName, "-u kubelet --utc")
assertContains(result, logs)
}
})
Expand Down Expand Up @@ -672,13 +672,9 @@ func assertContains(expectedString string, result string) {
return
}

func journalctlCommand(arg ...string) string {
command := exec.Command("journalctl", arg...)
out, err := command.Output()
if err != nil {
framework.Logf("Command: %v\nError: %v", command, err)
framework.Failf("Error at running journalctl command")
}
framework.Logf("Journalctl output: %s", out)
return string(out)
func journalctlCommandOnNode(nodeName string, args string) string {
result, err := e2essh.NodeExec(context.Background(), nodeName, "journalctl "+args, framework.TestContext.Provider)
framework.ExpectNoError(err)
e2essh.LogResult(result)
return result.Stdout
}

0 comments on commit a248c4d

Please sign in to comment.