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

Disp work gatherer #281

Merged
merged 2 commits into from
Oct 23, 2023
Merged

Disp work gatherer #281

merged 2 commits into from
Oct 23, 2023

Conversation

arbulu89
Copy link
Contributor

@arbulu89 arbulu89 commented Oct 19, 2023

disp+work gatherer implementation. It runs the disp+work utility for each sidadm user, and parses the output.
By now, as requested, it only returns the kernel_release, compilation_mode and patch_number.
Everything is parsed using one regexp pattern. Adding new fields should be straightforward.

The fillRegexpGroups function is inspired in the regroup package: https://github.com/oriser/regroup#named-groups-map

I have created the internal dispWorkData struct. It is true that i could've simply use the map, without the json transformation, but I see that having the struct is more "strict" and informative

Output:

#{
  "NWP": #{
    "compilation_mode": "UNICODE",
    "kernel_release": "753",
    "patch_number": "900"
  }
} 

@arbulu89 arbulu89 added the enhancement New feature or request label Oct 19, 2023
Copy link
Member

@CDimonaco CDimonaco left a comment

Choose a reason for hiding this comment

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

For me the code looks good, I really like the named groups expansion

Just some comments to understand better the usecase


result := fillRegexpGroups(string(dispWorkOutput))

dispWorkMap[sid] = dispWorkData{
Copy link
Member

Choose a reason for hiding this comment

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

What happens if we have no matches on the regexp, for example something could be missing or could be empty, we allow that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In that cases the map is filled with empty strings. The FindAllStringSubmatch function returns a value, even an empty one for group, so combined with the SubexpNames you can fill all the groups, at least with empty values.
Actually, I added a test to cover that case XD

if err != nil {
gatheringError := DispWorkCommandError.Wrap(err.Error())
log.Error(gatheringError)
dispWorkMap[sid] = dispWorkData{} // fill with empty data
Copy link
Member

Choose a reason for hiding this comment

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

We don't want to abort on something like that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about that, but the fact that we might have multiple sap installations doesn't make it a good idea in my opinion.
If you have NWP and NWD installed, and one fails, you at least have the result for the other (and the failed one filled with empty strings, that at the end, would make the rhai test fail

Copy link
Contributor

@rtorrero rtorrero left a comment

Choose a reason for hiding this comment

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

@arbulu89 LGTM, only thing I spotted is that you didn't add a test for the command-error case, should we add it?

@arbulu89
Copy link
Contributor Author

@arbulu89 LGTM, only thing I spotted is that you didn't add a test for the command-error case, should we add it?

The Success test should cover this. There are 4 sap systems, and in the DEV one, that command fails, so all the fields are populdated with empty string values

Copy link
Member

@EMaksy EMaksy left a comment

Choose a reason for hiding this comment

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

Hey lgtm :D

@arbulu89 arbulu89 merged commit 995be5e into main Oct 23, 2023
10 checks passed
@arbulu89 arbulu89 deleted the disp-work-gatherer branch October 23, 2023 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging this pull request may close these issues.

4 participants