From e93fdd87b96328847bfe31ab9343ccfef4843b93 Mon Sep 17 00:00:00 2001 From: Paul Chaignon Date: Mon, 24 Apr 2023 11:55:19 +0200 Subject: [PATCH] test: Collect sysdump as part of artifacts Once we have a sysdump in the test artifacts a lot of files we collect will become duplicates. This commit however doesn't remove all those duplicate files from the test artifacts. Let's wait a bit and confirm the sysdump collection always work before cleaning things up. The sysdump collection was tested by making a test fail on purpose. Signed-off-by: Paul Chaignon --- test/helpers/kubectl.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/test/helpers/kubectl.go b/test/helpers/kubectl.go index 7a7966c9b8d4..bccb872ff826 100644 --- a/test/helpers/kubectl.go +++ b/test/helpers/kubectl.go @@ -3297,7 +3297,7 @@ func (kub *Kubectl) CiliumReport(commands ...string) { defer cancel() var wg sync.WaitGroup - wg.Add(2) + wg.Add(3) go func() { defer wg.Done() @@ -3309,6 +3309,11 @@ func (kub *Kubectl) CiliumReport(commands ...string) { kub.DumpCiliumCommandOutput(ctx, CiliumNamespace) }() + go func() { + defer wg.Done() + kub.CollectSysdump(ctx) + }() + kub.CiliumCheckReport(ctx) pods, err := kub.GetCiliumPodsContext(ctx, CiliumNamespace) @@ -3335,6 +3340,24 @@ func (kub *Kubectl) CiliumReport(commands ...string) { } } +func (kub *Kubectl) CollectSysdump(ctx context.Context) { + testPath, err := CreateReportDirectory() + if err != nil { + log.WithError(err).Errorf("cannot create test result path '%s'", testPath) + return + } + + logsPath := filepath.Join(kub.BasePath(), testPath) + + // We need to get into the root directory because the CLI doesn't yet + // support absolute path. Once https://github.com/cilium/cilium-cli/pull/1552 + // is installed in test VM images, we can remove this. + res := kub.ExecContext(ctx, fmt.Sprintf("cd / && cilium-cli sysdump --output-filename %s/cilium-sysdump", logsPath)) + if !res.WasSuccessful() { + log.WithError(res.GetError()).Errorf("failed to collect sysdump") + } +} + // CiliumCheckReport prints a few checks on the Junit output to provide more // context to users. The list of checks that prints are the following: // - Number of Kubernetes and Cilium policies installed.