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

[RHELC-676] Unify parsing of the system release string #897

Merged
merged 3 commits into from
Apr 15, 2024

Conversation

bookwar
Copy link
Contributor

@bookwar bookwar commented Aug 31, 2023

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

  • PR has been tested manually in a VM (either author or reviewer)
  • Jira issue has been made public if possible
  • [RHELC-] is part of the PR title
  • GitHub label has been added to help with Release notes
  • PR title explains the change from the user's point of view
  • Code and tests are documented properly
  • The commits are squashed to as few commits as possible (without losing data)
  • When merged: Jira issue has been updated to Release Pending if relevant

@abadger abadger added the tests/tier0 PR ready to run the essential test suit. Equivalent to `/packit test --labels tier0`. label Aug 31, 2023
@has-bot
Copy link
Member

has-bot commented Aug 31, 2023

/packit test --labels tier0


@oamg/conversions-qe please review results and provide ack.

@bookwar bookwar force-pushed the system-release-content branch 3 times, most recently from f8a7c85 to 399f16f Compare August 31, 2023 22:51
Copy link
Member

@abadger abadger left a 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.

convert2rhel/systeminfo.py Show resolved Hide resolved
convert2rhel/systeminfo.py Show resolved Hide resolved
@Venefilyn Venefilyn marked this pull request as draft September 19, 2023 14:59
@Venefilyn Venefilyn changed the title [Draft] Unify parsing of the system release string Unify parsing of the system release string Sep 19, 2023
@bookwar bookwar force-pushed the system-release-content branch 2 times, most recently from e7ffce9 to ae0101a Compare September 26, 2023 11:43
@bookwar bookwar added tests/sanity PR ready to run the sanity test suit. Equivalent to `/packit test --labels sanity`. and removed tests/tier0 PR ready to run the essential test suit. Equivalent to `/packit test --labels tier0`. labels Feb 26, 2024
@has-bot
Copy link
Member

has-bot commented Feb 26, 2024

/packit test --labels sanity


Comment generated by an automation.

@bookwar bookwar force-pushed the system-release-content branch 3 times, most recently from 40e5846 to 44e3c62 Compare March 7, 2024 19:42
Copy link

codecov bot commented Mar 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.26%. Comparing base (28908cd) to head (736b7ec).
Report is 3 commits behind head on main.

❗ Current head 736b7ec differs from pull request most recent head 1cbf6e3. Consider uploading reports for the commit 1cbf6e3 to get more accurate results

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     
Flag Coverage Δ
centos-linux-7 90.33% <100.00%> (-0.09%) ⬇️
centos-linux-8 91.31% <100.00%> (-0.09%) ⬇️
centos-linux-9 91.37% <100.00%> (-0.09%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bookwar bookwar changed the title Unify parsing of the system release string [RHELC-676] Unify parsing of the system release string Mar 13, 2024
@bookwar bookwar added the kind/feature New feature or request label Mar 14, 2024
@bookwar bookwar marked this pull request as ready for review March 14, 2024 18:28
@bookwar
Copy link
Contributor Author

bookwar commented Mar 15, 2024

/packit test --labels sanity

convert2rhel/unit_tests/systeminfo_test.py Outdated Show resolved Hide resolved
convert2rhel/systeminfo.py Outdated Show resolved Hide resolved
@bookwar bookwar force-pushed the system-release-content branch 3 times, most recently from 962f276 to 81dd2e5 Compare March 21, 2024 15:35
convert2rhel/systeminfo.py Show resolved Hide resolved
convert2rhel/systeminfo.py Outdated Show resolved Hide resolved
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)
Copy link
Member

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?

Copy link
Member

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

Copy link
Contributor Author

@bookwar bookwar Apr 9, 2024

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.

Copy link
Member

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.
Copy link
Member

@r0x0d r0x0d left a 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>
@Venefilyn
Copy link
Member

/packit test --labels sanity

Copy link
Member

@Venefilyn Venefilyn left a 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

@Venefilyn Venefilyn merged commit c49cd04 into oamg:main Apr 15, 2024
18 of 25 checks passed
@hosekadam hosekadam mentioned this pull request May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature New feature or request tests/sanity PR ready to run the sanity test suit. Equivalent to `/packit test --labels sanity`.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants