Skip to content

Commit 3de4e48

Browse files
committed
Add sosreport tools e2e test
Signed-off-by: Meina-rh <meinli@redhat.com>
1 parent 988eff5 commit 3de4e48

File tree

1 file changed

+271
-0
lines changed

1 file changed

+271
-0
lines changed

test/e2e/sosreport_test.go

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

0 commit comments

Comments
 (0)