diff --git a/internal/factsengine/gatherers/gatherer.go b/internal/factsengine/gatherers/gatherer.go index 2e899ff2..4c0e1f27 100644 --- a/internal/factsengine/gatherers/gatherer.go +++ b/internal/factsengine/gatherers/gatherer.go @@ -43,8 +43,8 @@ func StandardGatherers() FactGatherersTree { SapHostCtrlGathererName: map[string]FactGatherer{ "v1": NewDefaultSapHostCtrlGatherer(), }, - SapLocalhostResolverGathererName: map[string]FactGatherer{ - "v1": NewDefaultSapLocalhostResolverGatherer(), + SapInstanceHostnameResolverGathererName: map[string]FactGatherer{ + "v1": NewDefaultSapInstanceHostnameResolverGatherer(), }, SapProfilesGathererName: map[string]FactGatherer{ "v1": NewDefaultSapProfilesGatherer(), diff --git a/internal/factsengine/gatherers/saplocalhostresolver.go b/internal/factsengine/gatherers/sapinstancehostnameresolver.go similarity index 71% rename from internal/factsengine/gatherers/saplocalhostresolver.go rename to internal/factsengine/gatherers/sapinstancehostnameresolver.go index 1f5783a3..44013f61 100644 --- a/internal/factsengine/gatherers/saplocalhostresolver.go +++ b/internal/factsengine/gatherers/sapinstancehostnameresolver.go @@ -14,19 +14,19 @@ import ( ) const ( - SapLocalhostResolverGathererName = "saplocalhost_resolver" + SapInstanceHostnameResolverGathererName = "sapinstance_hostname_resolver" ) // nolint:gochecknoglobals var ( - hostnameRegexCompiled = regexp.MustCompile(`(.+)_(.+)_(.+)`) // __ - regexSubgroupsCount = 4 - SapLocalhostResolverDetailsError = entities.FactGatheringError{ - Type: "saplocalhost_resolver-details-error", + hostnameRegexCompiled = regexp.MustCompile(`(.+)_(.+)_(.+)`) // __ + regexSubgroupsCount = 4 + SapInstanceHostnameResolverDetailsError = entities.FactGatheringError{ + Type: "sapinstance_hostname_resolver-details-error", Message: "error gathering details", } - SapLocalhostResolverGathererDecodingError = entities.FactGatheringError{ - Type: "saplocalhost_resolver-decoding-error", + SapInstanceHostnameResolverGathererDecodingError = entities.FactGatheringError{ + Type: "sapinstance_hostname_resolver-decoding-error", Message: "error decoding output to FactValue", } ) @@ -41,7 +41,7 @@ type HostPinger interface { Ping(host string) bool } -type SapLocalhostResolverGatherer struct { +type SapInstanceHostnameResolverGatherer struct { fs afero.Fs hr HostnameResolver hp HostPinger @@ -72,28 +72,32 @@ func (p *Pinger) Ping(host string) bool { return err == nil } -func NewDefaultSapLocalhostResolverGatherer() *SapLocalhostResolverGatherer { - return NewSapLocalhostResolver(afero.NewOsFs(), &Resolver{}, &Pinger{}) +func NewDefaultSapInstanceHostnameResolverGatherer() *SapInstanceHostnameResolverGatherer { + return NewSapInstanceHostnameResolverGatherer(afero.NewOsFs(), &Resolver{}, &Pinger{}) } -func NewSapLocalhostResolver(fs afero.Fs, hr HostnameResolver, hp HostPinger) *SapLocalhostResolverGatherer { - return &SapLocalhostResolverGatherer{fs: fs, hr: hr, hp: hp} +func NewSapInstanceHostnameResolverGatherer( + fs afero.Fs, + hr HostnameResolver, + hp HostPinger) *SapInstanceHostnameResolverGatherer { + + return &SapInstanceHostnameResolverGatherer{fs: fs, hr: hr, hp: hp} } -func (r *SapLocalhostResolverGatherer) Gather(factsRequests []entities.FactRequest) ([]entities.Fact, error) { +func (r *SapInstanceHostnameResolverGatherer) Gather(factsRequests []entities.FactRequest) ([]entities.Fact, error) { facts := []entities.Fact{} details, err := r.getInstanceHostnameDetails() if err != nil { log.Error(err) - return nil, SapLocalhostResolverDetailsError.Wrap(err.Error()) + return nil, SapInstanceHostnameResolverDetailsError.Wrap(err.Error()) } var fact entities.Fact factValue, err := mapReachabilityDetailsToFactValue(details) if err != nil { log.Error(err) - return facts, &SapLocalhostResolverGathererDecodingError + return facts, &SapInstanceHostnameResolverGathererDecodingError } for _, factReq := range factsRequests { @@ -104,7 +108,7 @@ func (r *SapLocalhostResolverGatherer) Gather(factsRequests []entities.FactReque return facts, nil } -func (r *SapLocalhostResolverGatherer) getInstanceHostnameDetails() (map[string][]ResolvabilityDetails, error) { +func (r *SapInstanceHostnameResolverGatherer) getInstanceHostnameDetails() (map[string][]ResolvabilityDetails, error) { systems, err := sapsystem.FindSystems(r.fs) if err != nil { return nil, err diff --git a/internal/factsengine/gatherers/saplocalhostresolver_test.go b/internal/factsengine/gatherers/sapinstancehostnameresolver_test.go similarity index 78% rename from internal/factsengine/gatherers/saplocalhostresolver_test.go rename to internal/factsengine/gatherers/sapinstancehostnameresolver_test.go index 3c7630c5..471775be 100644 --- a/internal/factsengine/gatherers/saplocalhostresolver_test.go +++ b/internal/factsengine/gatherers/sapinstancehostnameresolver_test.go @@ -11,22 +11,22 @@ import ( "github.com/trento-project/agent/pkg/factsengine/entities" ) -type SapLocalhostResolverTestSuite struct { +type SapInstanceHostnameResolverTestSuite struct { suite.Suite mockResolver *mocks.HostnameResolver mockPinger *mocks.HostPinger } -func TestSapLocalhostResolverTestSuite(t *testing.T) { - suite.Run(t, new(SapLocalhostResolverTestSuite)) +func TestSapInstanceHostnameResolverTestSuite(t *testing.T) { + suite.Run(t, new(SapInstanceHostnameResolverTestSuite)) } -func (suite *SapLocalhostResolverTestSuite) SetupTest() { +func (suite *SapInstanceHostnameResolverTestSuite) SetupTest() { suite.mockResolver = new(mocks.HostnameResolver) suite.mockPinger = new(mocks.HostPinger) } -func (suite *SapLocalhostResolverTestSuite) TestSapLocalhostResolverSuccess() { +func (suite *SapInstanceHostnameResolverTestSuite) TestSapInstanceHostnameResolverSuccess() { appFS := afero.NewMemMapFs() err := appFS.MkdirAll("/usr/sap/QAS", 0644) @@ -48,11 +48,11 @@ func (suite *SapLocalhostResolverTestSuite) TestSapLocalhostResolverSuccess() { suite.mockResolver.On("LookupHost", "sapnwper").Return([]string{"10.1.1.7"}, nil) suite.mockPinger.On("Ping", "sapnwper").Return(false, nil) - g := gatherers.NewSapLocalhostResolver(appFS, suite.mockResolver, suite.mockPinger) + g := gatherers.NewSapInstanceHostnameResolverGatherer(appFS, suite.mockResolver, suite.mockPinger) factRequests := []entities.FactRequest{{ - Name: "sap_localhost_resolver", - Gatherer: "sap_localhost_resolver", + Name: "sapinstance_hostname_resolver", + Gatherer: "sapinstance_hostname_resolver", CheckID: "check1", }} @@ -60,7 +60,7 @@ func (suite *SapLocalhostResolverTestSuite) TestSapLocalhostResolverSuccess() { expectedResults := []entities.Fact{ { - Name: "sap_localhost_resolver", + Name: "sapinstance_hostname_resolver", CheckID: "check1", Value: &entities.FactValueMap{ Value: map[string]entities.FactValue{ @@ -117,26 +117,26 @@ func (suite *SapLocalhostResolverTestSuite) TestSapLocalhostResolverSuccess() { suite.Equal(expectedResults, factResults) } -func (suite *SapLocalhostResolverTestSuite) TestSapLocalhostResolverNoProfiles() { +func (suite *SapInstanceHostnameResolverTestSuite) TestSapInstanceHostnameResolverNoProfiles() { appFS := afero.NewMemMapFs() err := appFS.MkdirAll("/usr/sap/QAS", 0644) suite.NoError(err) - g := gatherers.NewSapLocalhostResolver(appFS, suite.mockResolver, suite.mockPinger) + g := gatherers.NewSapInstanceHostnameResolverGatherer(appFS, suite.mockResolver, suite.mockPinger) factRequests := []entities.FactRequest{{ - Name: "sap_localhost_resolver", - Gatherer: "sap_localhost_resolver", + Name: "sapinstance_hostname_resolver", + Gatherer: "sapinstance_hostname_resolver", CheckID: "check1", }} factResults, err := g.Gather(factRequests) suite.Nil(factResults) - suite.EqualError(err, "fact gathering error: saplocalhost_resolver-details-error - error gathering details: open /sapmnt/QAS/profile: file does not exist") + suite.EqualError(err, "fact gathering error: sapinstance_hostname_resolver-details-error - error gathering details: open /sapmnt/QAS/profile: file does not exist") } -func (suite *SapLocalhostResolverTestSuite) TestSapLocalhostResolverLookupHostError() { +func (suite *SapInstanceHostnameResolverTestSuite) TestSapInstanceHostnameResolverLookupHostError() { appFS := afero.NewMemMapFs() err := appFS.MkdirAll("/usr/sap/QAS", 0644) @@ -148,17 +148,17 @@ func (suite *SapLocalhostResolverTestSuite) TestSapLocalhostResolverLookupHostEr suite.mockResolver.On("LookupHost", "sapqasas").Return([]string{}, errors.New("lookup sapqasas on 169.254.169.254:53: dial udp 169.254.169.254:53: connect: no route to host")) suite.mockPinger.On("Ping", "sapqasas").Return(false, nil) - g := gatherers.NewSapLocalhostResolver(appFS, suite.mockResolver, suite.mockPinger) + g := gatherers.NewSapInstanceHostnameResolverGatherer(appFS, suite.mockResolver, suite.mockPinger) factRequests := []entities.FactRequest{{ - Name: "sap_localhost_resolver", - Gatherer: "sap_localhost_resolver", + Name: "sapinstance_hostname_resolver", + Gatherer: "sapinstance_hostname_resolver", CheckID: "check1", }} expectedResults := []entities.Fact{ { - Name: "sap_localhost_resolver", + Name: "sapinstance_hostname_resolver", CheckID: "check1", Value: &entities.FactValueMap{ Value: map[string]entities.FactValue{