Skip to content

Commit

Permalink
Merge pull request #155 from nicolasbock/failure
Browse files Browse the repository at this point in the history
Allow for failures in script
  • Loading branch information
nicolasbock authored May 30, 2024
2 parents 196841e + 68affe4 commit c5a1682
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
10 changes: 4 additions & 6 deletions athena-processor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@ processor:
set -e -u
pipx install hotsos &>/dev/null
pipx upgrade hotsos &>/dev/null
tar -xf {{filepath}} -C {{basedir}} &>/dev/null
~/.local/bin/hotsos --save --output-path hotsos-out --all-logs {{basedir}}/$(basename {{filepath}} .tar.xz)/ &>/dev/null
tar -xf {{filepath}} -C {{basedir}} &>/dev/null || true
~/.local/bin/hotsos --save --output-path hotsos-out --all-logs {{basedir}}/$(basename {{filepath}} .tar.xz)/ &>/dev/null || true
if [ -s hotsos-out/*/summary/full/yaml/hotsos-summary.all.yaml ]; then
cat hotsos-out/*/summary/full/yaml/hotsos-summary.all.yaml
else
echo "No full sosreport generated."
fi
rm -rf hotsos-out
exit 0
hotsos-short:
exit-codes: 0 2 127 126
Expand All @@ -53,12 +52,11 @@ processor:
set -e -u
pipx install hotsos &>/dev/null
pipx upgrade hotsos &>/dev/null
tar -xf {{filepath}} -C {{basedir}} &>/dev/null
~/.local/bin/hotsos --short --save --output-path hotsos-out --all-logs {{basedir}}/$(basename {{filepath}} .tar.xz)/ &>/dev/null
tar -xf {{filepath}} -C {{basedir}} &>/dev/null || true
~/.local/bin/hotsos --short --save --output-path hotsos-out --all-logs {{basedir}}/$(basename {{filepath}} .tar.xz)/ &>/dev/null || true
if [ -s hotsos-out/*/summary/short/yaml/hotsos-summary.all.yaml ]; then
cat hotsos-out/*/summary/short/yaml/hotsos-summary.all.yaml
else
echo "No known bugs or issues found on sosreport."
fi
rm -rf hotsos-out
exit 0
6 changes: 3 additions & 3 deletions pkg/processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,11 @@ type ReportRunner struct {
}

func RunWithTimeout(baseDir string, timeout time.Duration, command string) ([]byte, error) {
log.Debugf("Running script with %s timeout", timeout)
log.Debugf("Running script with %s timeout in %s", timeout, baseDir)
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
cmd := exec.CommandContext(ctx, "bash", "-c", command)
cmd.Dir = baseDir

output, err := cmd.CombinedOutput()
if ctx.Err() == context.DeadlineExceeded {
return nil, nil
Expand All @@ -77,7 +76,7 @@ func RunWithTimeout(baseDir string, timeout time.Duration, command string) ([]by
}

func RunWithoutTimeout(baseDir string, command string) ([]byte, error) {
log.Debug("Running script without timeout")
log.Debugf("Running script without timeout in %s", baseDir)
cmd := exec.Command("bash", "-c", command)
cmd.Dir = baseDir
return cmd.CombinedOutput()
Expand All @@ -95,6 +94,7 @@ func RunReport(report *ReportToExecute) (map[string][]byte, error) {
} else {
ret, err = RunWithoutTimeout(report.BaseDir, script)
}
log.Debugf("Script '%s' on '%s' completed", scriptName, filepath.Base(report.FileName))
if err != nil {
log.Errorf("Error occurred (test) while running script: %s", err)
for _, line := range strings.Split(string(ret), "\n") {
Expand Down

0 comments on commit c5a1682

Please sign in to comment.