Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(e2e): add local host support bundle test #1680

Merged
merged 5 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions test/e2e/support-bundle/host_local_collector_e2e_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package e2e

import (
"bytes"
"context"
"fmt"
"os"
"os/exec"
"testing"

"golang.org/x/exp/slices"
"sigs.k8s.io/e2e-framework/pkg/envconf"
"sigs.k8s.io/e2e-framework/pkg/features"
)

func TestHostLocalCollector(t *testing.T) {
tests := []struct {
paths []string
notExpectedPaths []string
expectType string
}{
{
paths: []string{
"cpu.json",
"hostos_info.json",
"ipv4Interfaces.json",
"memory.json",
},
notExpectedPaths: []string{
"node_list.json",
},
expectType: "file",
},
}
feature := features.New("Host Local Collector").
Assess("check support bundle catch host local collector", func(ctx context.Context, t *testing.T, c *envconf.Config) context.Context {
var out bytes.Buffer
supportbundleName := "host-local-collector"
tarPath := fmt.Sprintf("%s.tar.gz", supportbundleName)
targetFile := fmt.Sprintf("%s/host-collectors/system/", supportbundleName)
cmd := exec.CommandContext(ctx, sbBinary(), "spec/localHostCollectors.yaml", "--interactive=false", fmt.Sprintf("-o=%s", supportbundleName))
cmd.Stdout = &out
err := cmd.Run()
if err != nil {
t.Fatal(err)
}

defer func() {
err := os.Remove(fmt.Sprintf("%s.tar.gz", supportbundleName))
if err != nil {
t.Fatal("Error remove file:", err)
nvanthao marked this conversation as resolved.
Show resolved Hide resolved
}
}()

files, _, err := readFilesAndFoldersFromTar(tarPath, targetFile)
if err != nil {
t.Fatal(err)
}

for _, test := range tests {
if test.expectType == "file" {
for _, path := range test.notExpectedPaths {
if slices.Contains(files, path) {
t.Fatalf("Unexpected file %s found", path)
}
}
for _, path := range test.paths {
if !slices.Contains(files, path) {
t.Fatalf("Expected file %s not found", path)
}
}
}
}

return ctx
}).Feature()
testenv.Test(t, feature)
}
33 changes: 33 additions & 0 deletions test/e2e/support-bundle/spec/localHostCollectors.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: troubleshoot.sh/v1beta2
kind: SupportBundle
metadata:
name: "remote-host-collectors"
spec:
hostCollectors:
- ipv4Interfaces: {}
- hostServices: {}
- cpu: {}
- hostOS: {}
- memory: {}
- blockDevices: {}
- kernelConfigs: {}
- copy:
collectorName: etc-resolv
path: /etc/resolv.conf
- dns:
collectorName: replicated-app-resolve
hostnames:
- replicated.app
- diskUsage:
collectorName: root-disk-usage
path: /
- diskUsage:
collectorName: tmp
path: /tmp
- http:
collectorName: get-replicated-app
get:
url: https://replicated.app
- run:
collectorName: uptime
command: uptime
Loading