Copy container logs for easier debugging

Signed-off-by: Davanum Srinivas <davanum@gmail.com>
This commit is contained in:
Davanum Srinivas 2023-06-29 10:40:18 -04:00
parent 9516a25ce4
commit f96d83af66
No known key found for this signature in database
GPG Key ID: 80D83A796103BF59

View File

@ -207,9 +207,11 @@ func getTestArtifacts(host, testDir string) error {
if err := os.MkdirAll(logPath, 0755); err != nil {
return fmt.Errorf("failed to create log directory %q: %w", logPath, err)
}
// Copy logs to artifacts/hostname
if _, err := runSSHCommand(host, "scp", "-r", fmt.Sprintf("%s:%s/results/*.log", GetHostnameOrIP(host), testDir), logPath); err != nil {
return err
// Copy logs (if any) to artifacts/hostname
if _, err := SSH(host, "ls", fmt.Sprintf("%s:%s/results/*.log", GetHostnameOrIP(host), testDir)); err == nil {
if _, err := runSSHCommand(host, "scp", "-r", fmt.Sprintf("%s:%s/results/*.log", GetHostnameOrIP(host), testDir), logPath); err != nil {
return err
}
}
// Copy json files (if any) to artifacts.
if _, err := SSH(host, "ls", fmt.Sprintf("%s/results/*.json", testDir)); err == nil {
@ -217,12 +219,19 @@ func getTestArtifacts(host, testDir string) error {
return err
}
}
// Copy junit results (if any) to artifacts
if _, err := SSH(host, "ls", fmt.Sprintf("%s/results/junit*", testDir)); err == nil {
// Copy junit (if any) to the top of artifacts
if _, err = runSSHCommand(host, "scp", fmt.Sprintf("%s:%s/results/junit*", GetHostnameOrIP(host), testDir), *resultsDir); err != nil {
return err
}
}
// Copy container logs to artifacts/hostname
if _, err := SSH(host, "chmod", "-R", "a+r", "/var/log/pods"); err == nil {
if _, err = runSSHCommand(host, "scp", "-r", fmt.Sprintf("%s:/var/log/pods/", GetHostnameOrIP(host)), logPath); err != nil {
return err
}
}
return nil
}