Skip to content

Commit

Permalink
fix: Detect insights-client status in non-legacy mode
Browse files Browse the repository at this point in the history
* Card ID: CCT-525

With `legacy_upload=True` mode, `insights-client --status` returns code
0 if the system is registered and 1 otherwise.

In non-legacy mode, 0 is always returned. For this reason, we should
rely on the message emitted to standard output.
  • Loading branch information
m-horky committed Jul 12, 2024
1 parent 888aac9 commit 69fe879
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion insights.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ func unregisterInsights() error {
}

func insightsIsRegistered() (bool, error) {
var outBuffer bytes.Buffer
var errBuffer bytes.Buffer
cmd := exec.Command("/usr/bin/insights-client", "--status")
cmd.Stdout = &outBuffer
cmd.Stderr = &errBuffer

err := cmd.Run()
Expand All @@ -45,5 +47,20 @@ func insightsIsRegistered() (bool, error) {
}
}

return cmd.ProcessState.Success(), err
if cmd.ProcessState.Success() == false {

Check failure on line 50 in insights.go

View workflow job for this annotation

GitHub Actions / Lint code

S1002: should omit comparison to bool constant, can be simplified to `!cmd.ProcessState.Success()` (gosimple)
return false, nil
}

// We can't rely only on return codes; non-legacy mode always returns 0,
// no matter the status.
for _, line := range []string{
"This host is registered.",
"System is registered locally via .registered file.", // legacy upload mode
} {
if strings.Contains(outBuffer.String(), line) {
return true, nil
}
}

return false, nil
}

0 comments on commit 69fe879

Please sign in to comment.