-
Notifications
You must be signed in to change notification settings - Fork 84
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
[RHELC-676] Unify parsing of the system release string #897
Conversation
f8a7c85
to
399f16f
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.
Nice restructuring. Much appreciated. Just had a few comments on the Draft.
e7ffce9
to
ae0101a
Compare
5c13c18
to
d0ed5e4
Compare
40e5846
to
44e3c62
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #897 +/- ##
==========================================
- Coverage 95.35% 95.26% -0.09%
==========================================
Files 51 51
Lines 4605 4604 -1
Branches 810 810
==========================================
- Hits 4391 4386 -5
- Misses 137 140 +3
- Partials 77 78 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
44e3c62
to
86dbe7c
Compare
/packit test --labels sanity |
962f276
to
81dd2e5
Compare
if not match: | ||
self.logger.critical("Couldn't get system version from the content string: %s" % content) | ||
version = Version(int(match.group(1)), int(match.group(2))) | ||
self.logger.critical_no_exit("Couldn't parse the system release content string: %s" % content) |
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.
Why do we changed this to no_exit? It seems to me very critical to inform that the system release file is not correct.
Also, I think we will raise an exception while resolving system info, right? Is it fine if we just bubble up the exception?
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.
[2024-04-05T13:49:33+0000] TASK - [Prepare: Gather system information] *******************************
CRITICAL - Couldn't parse the system release content string: CentOS Linux release
Writing breadcrumbs to '/etc/migration-results'.
[2024-04-05T13:49:33+0000] DEBUG - No RHSM facts folder found at '/etc/rhsm/facts'. Creating a new one...
Writing RHSM custom facts to '/etc/rhsm/facts/convert2rhel.facts'.
[2024-04-05T13:49:33+0000] DEBUG - Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/convert2rhel/main.py", line 108, in main_locked
gather_system_info()
File "/usr/lib/python3.6/site-packages/convert2rhel/main.py", line 263, in gather_system_info
systeminfo.system_info.resolve_system_info()
File "/usr/lib/python3.6/site-packages/convert2rhel/systeminfo.py", line 122, in resolve_system_info
self.name = system_release_data["name"]
KeyError: 'name'
No changes were made to the system.
[2024-04-05T13:49:33+0000] DEBUG - /var/run/lock/convert2rhel.pid PID 34285 unlocked.
make: *** [Makefile:25: analyze] Error 1
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.
My intent is that parse_.. function is a simple utility function. It should not make decisions on should we stop the execution or not. If parses what it can find, and then the higher-level structure may decide what to do with this information. In this case it still fails, and that's expected.
It maybe eventually we would be overriding these parameters from a config file or whatever.
I could have raise a custom exception here instead of passing None as a reply. But it seems like an overkill.
This wasn't supposed to be an exit from the start. I just didn't realize at the beginning that logger.critical()
does the exit. And didn't cover that scenario in a unit test. Then while I was adding a unit test for the failure scenario, I saw that the function does exit() and that's not what I wanted.
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.
Alright, got the idea behind... And I agree that parse_*
functions should all have that same intention, but at the same time, I feel that we are making some type of "regression". Right now, when this fails, it will show to the user a red message with the exact error, making it less scary if something goes wrong.
With this change, we are going away from a message that seems informative about the error, and just raising an base exception that, sometimes, may not be useful to the user.
What if we handle this type of exception in a higher level function, just so we can maintain the same UX for the user, without them noticing that we changed how we parse the content string?
There are several places where the system release string is parsed via regular expression. These expressions are different and adjusting them requires refactoring in multiple places. This change introduces one parsing function which does a full match of the system-release string and reads all possible data points from it, and provides the result as a dictionary for later use by other tools. The function replaces three other helper methods: _get_system_name, _get_system_version and _get_system_distribution_id, which are removed. NOTE1: The parsing function could be a static method or even implemented as a utility function outside the class. The only reason why it is in the class is the logger object. NOTE2: the function overlaps with the get_system_release_info function. We should check if this needs to be further unified.
81dd2e5
to
736b7ec
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.
Looks good to me.
Only one comment about critical vs critical_no_exit, but other than that, couldn't find anything that would block the PR for me.
Co-authored-by: Freya Gustavsson <freya@spytec.se>
/packit test --labels sanity |
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.
Integration test failures seem unrelated, merging
Jira Issues: RHELC-676
There are several places where the system release string is parsed via regular expressions. These regexps are different and adjusting them requires refactoring in multiple places.
This change introduces one parsing function which does a full match of the system-release string and reads all possible data points from it, and provides the result as a dictionary for later use by other tools.
The function replaces three other helper methods: _get_system_name, _get_system_version and _get_system_distribution_id, which are removed.
NOTE1: The parsing function could be a static method or even implemented as a utility function outside the class. The only reason why it is in the class is the logger object.
NOTE2: the function overlaps with the get_system_release_info function. We should check if this needs to be further unified.
Checklist
[RHELC-]
is part of the PR titleRelease Pending
if relevant