-
Notifications
You must be signed in to change notification settings - Fork 11
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
Implement saphostctrl gatherer #71
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Then, sorry if I bother you with DSL examples 😅 yet I it helps me to keep a connection between the different aspects.
In this case a user would write this piece of yaml
facts:
- name: my_saphostctrl_ping
gatherer: saphostctrl
argument: Ping
LGTM
d7d95c6
to
7f0308f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just the DI thing, than LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a comment, then we can merge
f08bd33
to
7f0308f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For my side, all relevant things have already been addressed or discussed and agreed to be addressed in next PRs (including the DI).
LGTM
7f0308f
to
10b4b15
Compare
@dottorblaster @dottorblaster Finally the requested changes rebased. Could you have a 2nd look? |
10b4b15
to
74f90c7
Compare
@arbulu89 @dottorblaster @CDimonaco @nelsonkopliku I've updated the gatherer to match the latest change in the fact gathering process and improved a bit how the output looks. Take a look at the tests to see if you agree this is usable, and I'll go ahead and write the docs. Basically, the changes in the output are that we now use a map with parsed output fields instead of the whole output as a single string. |
1129bcf
to
7720a66
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @rtorrero ,
Some changes requested.
Besides that, I would say some paths of the code are not tested (some parsing errors, command error, etc)
[]byte("SUCCESS ( 543341 usec)\n"), nil) | ||
suite.mockExecutor.On("Exec", "/usr/sap/hostctrl/exe/saphostctrl", "-function", "ListInstances").Return( | ||
[]byte(" Inst Info : PRD - 00 - myhost-vmhana02 - 753, patch 410, changelist 1908545\n"), nil) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add other scenario when there is not any instance, to see that it returns an empty map
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And we're probably missing a test for a failed ListInstances
as well
2603ee1
to
e9f0e63
Compare
@arbulu89 I've addressed some of your concerns and marked them as "resolved" for others, I've come with slightly different approaches but those should also cover your concerns. Please take a look at let me know 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good Ruben, thanks!
I noted down a few minor things and then for me we're good.
[]byte("SUCCESS ( 543341 usec)\n"), nil) | ||
suite.mockExecutor.On("Exec", "/usr/sap/hostctrl/exe/saphostctrl", "-function", "ListInstances").Return( | ||
[]byte(" Inst Info : PRD - 00 - myhost-vmhana02 - 753, patch 410, changelist 1908545\n"), nil) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And we're probably missing a test for a failed ListInstances
as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @rtorrero ,
I find the code difficult to follow with so many functions that are not meant to be functions (in my opinion), as they are not reused. And this creates the need to duplicate code many times.
I don't know I have the feeling you aimed to an extreme tailoring for functions. To makes reading difficult, as you need to scroll up and down constantly.
instance["system"] = &entities.FactValueString{Value: fields[1]} | ||
instance["instance"] = &entities.FactValueString{Value: fields[2]} | ||
instance["hostname"] = &entities.FactValueString{Value: fields[3]} | ||
instance["revision"] = &entities.FactValueString{Value: fields[4]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't revision
, patch
and changelist
be integers?
} | ||
|
||
pingData["status"] = &entities.FactValueString{Value: matches[1]} | ||
pingData["elapsed"] = &entities.FactValueString{Value: matches[2]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't elapsed
be an integer?
} | ||
SapHostCtrlUnsupportedFunction = entities.FactGatheringError{ | ||
Type: "saphostctrl-webmethod-error", | ||
Message: "requested webmethod not whitelisted", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rephrase this to requested webmethod is not supported
func (suite *SapHostCtrlTestSuite) TestSapHostCtrlGatherError() { | ||
suite.mockExecutor.On("Exec", "/usr/sap/hostctrl/exe/saphostctrl", "-function", "Ping").Return( | ||
[]byte("FAILURE\n"), nil) | ||
suite.mockExecutor.On("Exec", "/usr/sap/hostctrl/exe/saphostctrl", "-function", "Pong").Return( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about an scenario where the command fails.
Here we have a
- parsing error
- unsupported command
So we miss the command error test
393b8d0
to
a8e7b28
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rtorrero
Super perfect from my side! I cannot approve since I opened the PR XD
Old review
saphostctrl gatherer. Simply returns the output of this commands.
Example: