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

Saptune gatherer #256

Merged
merged 5 commits into from
Sep 27, 2023
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
21 changes: 8 additions & 13 deletions internal/factsengine/gatherers/saptune.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,21 @@ func (s *SaptuneGatherer) Gather(factsRequests []entities.FactRequest) ([]entiti
facts := []entities.Fact{}
log.Infof("Starting %s facts gathering process", SaptuneGathererName)
saptuneRetriever, err := saptune.NewSaptune(s.executor)

if err != nil {
return facts, &SaptuneNotInstalled
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could return nil, &SaptuneNotInstalled as well (the same for the next)
And even SaptuneNotInstalled.Wrap(err.Error()) in this case, as we have the rpm command error

}

if !saptuneRetriever.IsJSONSupported {
return facts, &SaptuneVersionUnsupported
}

for _, factReq := range factsRequests {
var fact entities.Fact

internalArguments, ok := whitelistedArguments[factReq.Argument]
cachedFact, cacheHit := cachedFacts[factReq.Argument]

switch {
case err != nil:
log.Error(err)
fact = entities.NewFactGatheredWithError(factReq, &SaptuneNotInstalled)

case !saptuneRetriever.IsJSONSupported:
log.Error(SaptuneVersionUnsupported.Message)
fact = entities.NewFactGatheredWithError(factReq, &SaptuneVersionUnsupported)

case len(factReq.Argument) == 0:
log.Error(SaptuneMissingArgument.Message)
fact = entities.NewFactGatheredWithError(factReq, &SaptuneMissingArgument)
Expand Down Expand Up @@ -127,14 +126,10 @@ func runCommand(saptuneRetriever *saptune.Saptune, arguments []string) (entities
return nil, commandError
}

log.Error(string(saptuneOutput))

var jsonData interface{}
if err := json.Unmarshal(saptuneOutput, &jsonData); err != nil {
return nil, err
}

log.Error(jsonData)

return entities.NewFactValue(jsonData, entities.WithSnakeCaseKeys())
}
26 changes: 4 additions & 22 deletions internal/factsengine/gatherers/saptune_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,18 +631,9 @@ func (suite *SaptuneTestSuite) TestSaptuneGathererVersionUnsupported() {

factResults, err := c.Gather(factRequests)

expectedResults := []entities.Fact{
{
Name: "saptune_status",
Value: nil,
Error: &entities.FactGatheringError{
Message: "currently installed version of saptune is not supported",
Type: "saptune-version-not-supported",
},
},
}
expectedResults := []entities.Fact{}

suite.NoError(err)
suite.EqualError(err, "fact gathering error: saptune-version-not-supported - currently installed version of saptune is not supported")
suite.ElementsMatch(expectedResults, factResults)
}

Expand All @@ -662,18 +653,9 @@ func (suite *SaptuneTestSuite) TestSaptuneGathererNotInstalled() {

factResults, err := c.Gather(factRequests)

expectedResults := []entities.Fact{
{
Name: "saptune_status",
Value: nil,
Error: &entities.FactGatheringError{
Message: "saptune is not installed",
Type: "saptune-not-installed",
},
},
}
expectedResults := []entities.Fact{}

suite.NoError(err)
suite.EqualError(err, "fact gathering error: saptune-not-installed - saptune is not installed")
suite.ElementsMatch(expectedResults, factResults)
}

Expand Down
Loading