Skip to content

Commit 8d6db36

Browse files
committed
Add sosreport tools e2e test
Signed-off-by: Meina-rh <meinli@redhat.com>
1 parent f3d2e80 commit 8d6db36

File tree

1 file changed

+282
-0
lines changed

1 file changed

+282
-0
lines changed

test/e2e/sosreport_test.go

Lines changed: 282 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,282 @@
1+
package e2e
2+
3+
import (
4+
"os"
5+
"path/filepath"
6+
"strings"
7+
8+
. "github.com/onsi/ginkgo/v2"
9+
. "github.com/onsi/gomega"
10+
11+
sostypes "github.com/ovn-kubernetes/ovn-kubernetes-mcp/pkg/sosreport/types"
12+
"github.com/ovn-kubernetes/ovn-kubernetes-mcp/test/e2e/inspector"
13+
"github.com/ovn-kubernetes/ovn-kubernetes-mcp/test/e2e/utils"
14+
)
15+
16+
var _ = Describe("Sosreport Tools", func() {
17+
var sosreportInspector *inspector.MCPInspector
18+
var testdataSosreportPath string
19+
20+
BeforeEach(func() {
21+
mcpServerPath := os.Getenv(mcpServerPathEnvVar)
22+
Expect(mcpServerPath).NotTo(BeEmpty())
23+
24+
sosreportInspector = inspector.NewMCPInspector().
25+
Command(mcpServerPath).
26+
CommandFlags(map[string]string{
27+
"mode": "offline",
28+
})
29+
30+
var err error
31+
testdataSosreportPath, err = filepath.Abs("../../pkg/sosreport/mcp/testdata/sosreport")
32+
Expect(err).NotTo(HaveOccurred())
33+
})
34+
const (
35+
sosListPluginsToolName = "sos-list-plugins"
36+
sosListCommandsToolName = "sos-list-commands"
37+
sosSearchCommandsToolName = "sos-search-commands"
38+
sosGetCommandToolName = "sos-get-command"
39+
sosSearchPodLogsToolName = "sos-search-pod-logs"
40+
)
41+
42+
Context("List Plugins", func() {
43+
It("should list all enabled plugins with command counts", func() {
44+
By("Calling sos-list-plugins")
45+
output, err := sosreportInspector.
46+
MethodCall(sosListPluginsToolName, map[string]string{
47+
"sosreport_path": testdataSosreportPath,
48+
}).Execute()
49+
Expect(err).NotTo(HaveOccurred())
50+
Expect(output).NotTo(BeEmpty())
51+
52+
By("Checking the result")
53+
result := utils.UnmarshalCallToolResult[sostypes.ListPluginsResult](output)
54+
55+
// Should have 3 plugins
56+
Expect(result.Plugins).To(HaveLen(3))
57+
Expect(result.TotalCommands).To(Equal(3))
58+
59+
// Verify plugin names and command counts
60+
pluginMap := make(map[string]int)
61+
for _, plugin := range result.Plugins {
62+
pluginMap[plugin.Name] = plugin.CommandCount
63+
}
64+
Expect(pluginMap["openvswitch"]).To(Equal(2))
65+
Expect(pluginMap["networking"]).To(Equal(1))
66+
Expect(pluginMap["container_log"]).To(Equal(0))
67+
})
68+
})
69+
70+
Context("List Commands", func() {
71+
It("should list all commands for openvswitch plugin", func() {
72+
By("Calling sos-list-commands for openvswitch")
73+
output, err := sosreportInspector.
74+
MethodCall(sosListCommandsToolName, map[string]string{
75+
"sosreport_path": testdataSosreportPath,
76+
"plugin": "openvswitch",
77+
}).Execute()
78+
Expect(err).NotTo(HaveOccurred())
79+
Expect(output).NotTo(BeEmpty())
80+
81+
By("Checking the result")
82+
result := utils.UnmarshalCallToolResult[sostypes.ListCommandsResult](output)
83+
84+
Expect(result.Plugin).To(Equal("openvswitch"))
85+
Expect(result.CommandCount).To(Equal(2))
86+
Expect(result.Commands).To(HaveLen(2))
87+
88+
// Verify command details
89+
commandMap := make(map[string]string)
90+
for _, cmd := range result.Commands {
91+
commandMap[cmd.Exec] = cmd.Filepath
92+
}
93+
Expect(commandMap["ovs-vsctl -t 5 show"]).To(Equal("sos_commands/openvswitch/ovs-vsctl_-t_5_show"))
94+
Expect(commandMap["ovs-ofctl dump-flows br-int"]).To(Equal("sos_commands/openvswitch/ovs-ofctl_dump-flows_br-int"))
95+
})
96+
97+
It("should list all commands for networking plugin", func() {
98+
By("Calling sos-list-commands for networking")
99+
output, err := sosreportInspector.
100+
MethodCall(sosListCommandsToolName, map[string]string{
101+
"sosreport_path": testdataSosreportPath,
102+
"plugin": "networking",
103+
}).Execute()
104+
Expect(err).NotTo(HaveOccurred())
105+
Expect(output).NotTo(BeEmpty())
106+
107+
By("Checking the result")
108+
result := utils.UnmarshalCallToolResult[sostypes.ListCommandsResult](output)
109+
110+
Expect(result.Plugin).To(Equal("networking"))
111+
Expect(result.CommandCount).To(Equal(1))
112+
Expect(result.Commands).To(HaveLen(1))
113+
Expect(result.Commands[0].Exec).To(Equal("ip addr show"))
114+
})
115+
})
116+
117+
Context("Search Commands", func() {
118+
It("should find commands matching ovs pattern", func() {
119+
By("Calling sos-search-commands with pattern 'ovs'")
120+
output, err := sosreportInspector.
121+
MethodCall(sosSearchCommandsToolName, map[string]string{
122+
"sosreport_path": testdataSosreportPath,
123+
"pattern": "ovs",
124+
}).Execute()
125+
Expect(err).NotTo(HaveOccurred())
126+
Expect(output).NotTo(BeEmpty())
127+
128+
By("Checking the result")
129+
result := utils.UnmarshalCallToolResult[sostypes.SearchCommandsResult](output)
130+
131+
Expect(result.Total).To(Equal(2))
132+
Expect(result.Matches).To(HaveLen(2))
133+
134+
// Verify all matches are from openvswitch plugin
135+
for _, match := range result.Matches {
136+
Expect(match.Plugin).To(Equal("openvswitch"))
137+
Expect(match.Exec).To(ContainSubstring("ovs"))
138+
}
139+
})
140+
141+
It("should find commands matching ip pattern", func() {
142+
By("Calling sos-search-commands with pattern 'ip'")
143+
output, err := sosreportInspector.
144+
MethodCall(sosSearchCommandsToolName, map[string]string{
145+
"sosreport_path": testdataSosreportPath,
146+
"pattern": "ip",
147+
}).Execute()
148+
Expect(err).NotTo(HaveOccurred())
149+
Expect(output).NotTo(BeEmpty())
150+
151+
By("Checking the result")
152+
result := utils.UnmarshalCallToolResult[sostypes.SearchCommandsResult](output)
153+
154+
Expect(result.Total).To(Equal(1))
155+
Expect(result.Matches).To(HaveLen(1))
156+
Expect(result.Matches[0].Plugin).To(Equal("networking"))
157+
Expect(result.Matches[0].Exec).To(Equal("ip addr show"))
158+
})
159+
})
160+
161+
Context("Get Command", func() {
162+
It("should get command output by filepath", func() {
163+
By("Calling sos-get-command for ovs-vsctl show")
164+
output, err := sosreportInspector.
165+
MethodCall(sosGetCommandToolName, map[string]string{
166+
"sosreport_path": testdataSosreportPath,
167+
"filepath": "sos_commands/openvswitch/ovs-vsctl_-t_5_show",
168+
}).Execute()
169+
Expect(err).NotTo(HaveOccurred())
170+
Expect(output).NotTo(BeEmpty())
171+
172+
By("Checking the result")
173+
result := utils.UnmarshalCallToolResult[sostypes.GetCommandResult](output)
174+
175+
// Verify output contains expected content
176+
Expect(result.Output).To(ContainSubstring("Bridge br-int"))
177+
Expect(result.Output).To(ContainSubstring("ovn-k8s-mp0"))
178+
Expect(result.Output).To(ContainSubstring("ovs_version: \"2.17.0\""))
179+
})
180+
181+
It("should get command output with pattern filter", func() {
182+
By("Calling sos-get-command with pattern filter")
183+
output, err := sosreportInspector.
184+
MethodCall(sosGetCommandToolName, map[string]string{
185+
"sosreport_path": testdataSosreportPath,
186+
"filepath": "sos_commands/networking/ip_addr_show",
187+
"pattern": "eth0",
188+
}).Execute()
189+
Expect(err).NotTo(HaveOccurred())
190+
Expect(output).NotTo(BeEmpty())
191+
192+
By("Checking the result")
193+
result := utils.UnmarshalCallToolResult[sostypes.GetCommandResult](output)
194+
195+
// Should only contain lines matching the pattern
196+
Expect(result.Output).To(ContainSubstring("eth0"))
197+
// Verify lo interface is not in filtered output
198+
lines := strings.Split(strings.TrimSpace(result.Output), "\n")
199+
for _, line := range lines {
200+
if !strings.Contains(line, "eth0") {
201+
Expect(line).To(BeEmpty())
202+
}
203+
}
204+
})
205+
206+
It("should get full ip addr show output without filter", func() {
207+
By("Calling sos-get-command without pattern")
208+
output, err := sosreportInspector.
209+
MethodCall(sosGetCommandToolName, map[string]string{
210+
"sosreport_path": testdataSosreportPath,
211+
"filepath": "sos_commands/networking/ip_addr_show",
212+
}).Execute()
213+
Expect(err).NotTo(HaveOccurred())
214+
Expect(output).NotTo(BeEmpty())
215+
216+
By("Checking the result")
217+
result := utils.UnmarshalCallToolResult[sostypes.GetCommandResult](output)
218+
219+
// Should contain both interfaces
220+
Expect(result.Output).To(ContainSubstring("lo"))
221+
Expect(result.Output).To(ContainSubstring("eth0"))
222+
Expect(result.Output).To(ContainSubstring("127.0.0.1"))
223+
Expect(result.Output).To(ContainSubstring("192.168.1.100"))
224+
})
225+
})
226+
227+
Context("Search Pod Logs", func() {
228+
It("should search for ERROR pattern in pod logs", func() {
229+
By("Calling sos-search-pod-logs with ERROR pattern")
230+
output, err := sosreportInspector.
231+
MethodCall(sosSearchPodLogsToolName, map[string]string{
232+
"sosreport_path": testdataSosreportPath,
233+
"pattern": "ERROR",
234+
}).Execute()
235+
Expect(err).NotTo(HaveOccurred())
236+
Expect(output).NotTo(BeEmpty())
237+
238+
By("Checking the result")
239+
result := utils.UnmarshalCallToolResult[sostypes.SearchPodLogsResult](output)
240+
241+
// Should find the error line
242+
Expect(result.Output).To(ContainSubstring("ERROR"))
243+
Expect(result.Output).To(ContainSubstring("Failed to connect to ovn-controller"))
244+
Expect(result.Output).To(ContainSubstring("ovnkube-node"))
245+
})
246+
247+
It("should search pod logs with pod filter", func() {
248+
By("Calling sos-search-pod-logs with pod filter")
249+
output, err := sosreportInspector.
250+
MethodCall(sosSearchPodLogsToolName, map[string]string{
251+
"sosreport_path": testdataSosreportPath,
252+
"pattern": "ovnkube",
253+
"pod_filter": "ovnkube-node",
254+
}).Execute()
255+
Expect(err).NotTo(HaveOccurred())
256+
Expect(output).NotTo(BeEmpty())
257+
258+
By("Checking the result")
259+
result := utils.UnmarshalCallToolResult[sostypes.SearchPodLogsResult](output)
260+
261+
// Should find matching lines from the ovnkube-node pod
262+
Expect(result.Output).To(ContainSubstring("ovnkube-node"))
263+
Expect(result.Output).To(ContainSubstring("Starting ovnkube-node"))
264+
})
265+
266+
It("should search for successful connection in pod logs", func() {
267+
By("Calling sos-search-pod-logs for successful connection")
268+
output, err := sosreportInspector.
269+
MethodCall(sosSearchPodLogsToolName, map[string]string{
270+
"sosreport_path": testdataSosreportPath,
271+
"pattern": "Successfully connected",
272+
}).Execute()
273+
Expect(err).NotTo(HaveOccurred())
274+
Expect(output).NotTo(BeEmpty())
275+
276+
By("Checking the result")
277+
result := utils.UnmarshalCallToolResult[sostypes.SearchPodLogsResult](output)
278+
279+
Expect(result.Output).To(ContainSubstring("Successfully connected to ovn-controller"))
280+
})
281+
})
282+
})

0 commit comments

Comments
 (0)