-
Notifications
You must be signed in to change notification settings - Fork 86
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-297] Clean up kmods functionality #469
Conversation
convert2rhel/checks.py
Outdated
def _repos_version_key(pkg_name): | ||
"""Identify the version key in a given package name. | ||
|
||
Consider the following pkg_name that will be passed to this function:: | ||
|
||
pkg_name = 'kernel-core-0:4.18.0-240.10.1.el8_3.x86_64' | ||
|
||
The output of this will be a tuple containing the package version in a tuple:: | ||
|
||
result = _repos_version_key(pkg_name=pkg_name) | ||
print(result) | ||
# (4, 15, 0, 240, 10, 1) | ||
|
||
The function will ignore the package name as it is not an important information here | ||
and will only care about the version that is tied to it's name. | ||
|
||
:param pkg_name: The package to extract the version | ||
:type pkg_name: str | ||
:return: A tuple containing the package version. | ||
:rtype: tuple[int] | ||
:raises: | ||
SystemExit: Raises SytemExit if it can't find the version in the pkg_name. | ||
""" | ||
# TODO(r0x0d): This should be moved to repo.py or utils.py? | ||
try: | ||
rpm_version = KERNEL_REPO_RE.search(pkg_name).group("version") | ||
except AttributeError: | ||
logger.critical( | ||
"Unexpected package:\n%s\n is a source of kernel modules.", | ||
"Unexpected package: %s\n Couldn't find the version of the given package.", | ||
pkg_name, | ||
) | ||
else: | ||
return tuple( | ||
map( | ||
_convert_to_int_or_zero, | ||
convert_to_int_or_zero, | ||
KERNEL_REPO_VER_SPLIT_RE.split(rpm_version), | ||
) | ||
) |
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 was unsure about this... Maybe we should move this function to convert2rhel/repos.py
file? Since it's dealing with "repos" even it is only extracting the version from a string.
Not sure if the convert2rhel/repos.py
or convert2rhel/utils.py
is a better location for this function.
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.
It feels like maybe a function for pkghandler? (Unless we want pkghandler to only deal with packages-in-repositories). It's parsing a version from a single package's NEVR. One possible reason not to move this (or to change it when we do move it), though: right now, this function is very specifically targeted at the NEVR of kernel package's that we think we are going to encounter. All of the following NEVRs would output the same value from this function despite being different packages:
- kernel-2.4.0-1.el8_1
- kernel-2.4-0.1.el8_1
- kernel-2.4.0-1.el9_0
# TODO: | ||
# if not self.submgr_enabled_repos: |
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.
This TODO
here needs any new information? It's not telling much.
If it doesn't make sense, can we remove it?
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 can see the potential problem with repos not being enabled yet but I'm not sure whether that is ever a problem in actuality (especially since customers aren't reporting failures because of it). @zhukovgreen Do you happen to know about this TODO and whether we can either enhance what it says or remove it?
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 don't have any input on this. Seems like some artifact which I forgot to remove
Codecov ReportBase: 93.30% // Head: 93.23% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #469 +/- ##
==========================================
- Coverage 93.30% 93.23% -0.07%
==========================================
Files 22 22
Lines 3107 3135 +28
Branches 552 557 +5
==========================================
+ Hits 2899 2923 +24
- Misses 144 148 +4
Partials 64 64
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
I've reviewed this. Other than the questions about |
74b12c5
to
882b47b
Compare
convert2rhel/pkghandler.py
Outdated
@@ -1075,3 +1082,45 @@ def _get_packages_to_update_dnf(): | |||
packages.append(package.name) | |||
|
|||
return packages | |||
|
|||
|
|||
def package_version_cmp(pkg_1, pkg_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.
Hmmm... A few higher level thoughts on this function:
-
Sometimes yum and dnf return NEVR like this:
NetworkManager-1:1.18.8-2.0.1.el7_9.x86_64
. Other times they return it like this (ENVR form):1:NetworkManager-1.18.8-2.0.1.el7_9.x86_64
. Should we handle both of these cases? In one function or in two? -
There's already a
pkghandler.compare_package_versions
function. That one takes its input as EVR strings:1:1.18.8-2.0.1.el7_9.x86_64
which removes the ambiguity around whether the epoch is before or after name because there is no name. However, we can't use that directly as a key function (since the key will be a NEVR or an ENVR string). -
Should we verify that the name is the same for both strings passed into this function? If I call the function with `package_version_cmp("test-1.0-1", "foobar-2.0-1") I would expect it to error rather than say foobar is later than test.
-
Should we parse arch off the end of the NEVR (arch is
x86_64
,i686
,s390x
, etc) and error if arches do not match?
Here's my strawman to address all of those:
- Separate version parsing and version comparison
- The parsing function will take a version string in either ENVR or NEVR format.
- If epoch or arch does not exist in the input string, it will be set to
None
in the tuple. - Parsing arch will be slightly tricky as I don't think there's a fool-proof way to separate an optional arch from release. Maybe looking for a list of allowed arch patterns is the best we can do. Something like:
.*(x86_64|s390x|i.86)?$
- If epoch or arch does not exist in the input string, it will be set to
- The version comparison function will take two version strings in either ENVR or NEVR format.
- The strings will be passed to the parsing functions to return the information in a normalized form.
- The names and arches will be compared.
- An error will be emitted if names do not match.
- An error will be emitted if arches do not match and both arches are not None.
- The names and arches will be compared.
- rpm.labelCompare() will then be used to compare the EVR for both packages and the results returned.
- Port existing use of
pkghandler.compare_package_versions()
to use the new comparison function. - Remove
pkghandler.compare_package_versions()
andutils.string_to_version()
.
Discuss?
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.
@abadger, I think we can follow up on this in our 1:1 sessions. Probably next week, we can discuss it a bit more on which direction we want to move with this function.
Definitely, there is a lot of room to improve the current function.
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.
We talked about this today and decided that this can be done in a followup PR. For now, we will:
- mark this function as private so we don't have to verify a whole lot of callers work once we refactor this
- Add a comment to the function which list the changes that we want to make.
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 will create a Jira issue as well for specifically this one change.
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.
Issues created: https://issues.redhat.com/browse/RHELC-667
@r0x0d once you will have a free time, please rebase the PR |
6fa7abc
to
5017f8d
Compare
@kokesak rebased! |
I will rebase this to resolve the conflict with the checks.py |
5017f8d
to
a2b8f15
Compare
/packit retest-failed |
/packit build |
1 similar comment
/packit build |
a59c4bd
to
a376984
Compare
This pull request fixes 1 alert when merging 5f52da8 into 121fa76 - view on LGTM.com fixed alerts:
|
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.
@danmyway since we want to improve the tests description, could you please update the summary in tests/integration/tier0/inhibit-if-kmods-is-not-supported/main.fmf
and maybe even in the pytest file as well if you think it's not good enough
Signed-off-by: Rodolfo Olivieri <rolivier@redhat.com>
Signed-off-by: Rodolfo Olivieri <rolivier@redhat.com>
Signed-off-by: Rodolfo Olivieri <rolivier@redhat.com>
As discussed with developers, force loaded kmod should inhibit the c2r run, as it is denoted with (FE) for F = module was force loaded E = unsigned module was loaded. Signed-off-by: Daniel Diblik <ddiblik@redhat.com>
fix typos Signed-off-by: Daniel Diblik <ddiblik@redhat.com>
Signed-off-by: Rodolfo Olivieri <rolivier@redhat.com>
Signed-off-by: Rodolfo Olivieri <rolivier@redhat.com>
7b41411
to
82c646c
Compare
Signed-off-by: Rodolfo Olivieri <rolivier@redhat.com>
9194cfe
to
32faec7
Compare
This pull request fixes 3 alerts when merging 32faec7 into 700088a - view on LGTM.com fixed alerts:
|
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.
The integration test looks nice.
Co-authored-by: Michal Bocek <mbocek@redhat.com>
This pull request fixes 3 alerts when merging c9e9636 into e1dfbdd - view on LGTM.com fixed alerts:
|
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.
Code looks fine but there were two failing integration tests. It looks like those are due to a problem with the yum repository. I've kicked off new runs for both of those.
I also see that Eric had a crequest to change something but I wasn't able to find it in the converaation. Can you check if that was addressed before merging?
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 also see that Eric had a crequest to change something but I wasn't able to find it in the converaation. Can you check if that was addressed before merging?
It was related to py2.6 and been addressed, LGTM 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.
Looks nice, merge it whenever you want.
In oamg#469, one of the cleanups ended up calling `"\n".join()` on a list of kernel modules twice. The first time changes the list into a string with each entry separated by a newline but the second time changes the string into another string with each chatacter separated by a newline. Fixed that by removing the second `str.join()`. This also refactors away a call to `map()` and use of `lambda`. In modern python, any uses of `map()` or `filter()` can be replaced with either a generator expression or list comprehension. Related to oamg#469
…s. (#651) * Fix the format of message about unavailable kernel modules. In #469, one of the cleanups ended up calling `"\n".join()` on a list of kernel modules twice. The first time changes the list into a string with each entry separated by a newline but the second time changes the string into another string with each chatacter separated by a newline. Fixed that by removing the second `str.join()`. This also refactors away a call to `map()` and use of `lambda`. In modern python, any uses of `map()` or `filter()` can be replaced with either a generator expression or list comprehension. Related to #469 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
…s. (oamg#651) * Fix the format of message about unavailable kernel modules. In oamg#469, one of the cleanups ended up calling `"\n".join()` on a list of kernel modules twice. The first time changes the list into a string with each entry separated by a newline but the second time changes the string into another string with each chatacter separated by a newline. Fixed that by removing the second `str.join()`. This also refactors away a call to `map()` and use of `lambda`. In modern python, any uses of `map()` or `filter()` can be replaced with either a generator expression or list comprehension. Related to oamg#469 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
…s. (oamg#651) * Fix the format of message about unavailable kernel modules. In oamg#469, one of the cleanups ended up calling `"\n".join()` on a list of kernel modules twice. The first time changes the list into a string with each entry separated by a newline but the second time changes the string into another string with each chatacter separated by a newline. Fixed that by removing the second `str.join()`. This also refactors away a call to `map()` and use of `lambda`. In modern python, any uses of `map()` or `filter()` can be replaced with either a generator expression or list comprehension. Related to oamg#469 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Clean up kmods functionality These changes are cleanup of most of the things that were left behind from PR#193. Some of the functions were changed to make it easier to read and debug if necessary, some of them were moved around to the files that made sense to place they and some of them just needed a docstring to tell what the function was all about. This PR it is introduced a unit test for the function `get_enabled_rhel_repos` since that was introduced in the past and never had a unit test tied to it. Jira reference (If any): https://issues.redhat.com/browse/OAMG-4668 Bugzilla reference (If any): Signed-off-by: Rodolfo Olivieri <rolivier@redhat.com> * Add unit tests for the code refactored Signed-off-by: Rodolfo Olivieri <rolivier@redhat.com> * Apply integration tests from a59c4bd Signed-off-by: Rodolfo Olivieri <rolivier@redhat.com> * Apply patch from 3b61461 Signed-off-by: Rodolfo Olivieri <rolivier@redhat.com> * Apply suggestions from Michal's review Signed-off-by: Rodolfo Olivieri <rolivier@redhat.com> * Edit force loaded kmod test As discussed with developers, force loaded kmod should inhibit the c2r run, as it is denoted with (FE) for F = module was force loaded E = unsigned module was loaded. Signed-off-by: Daniel Diblik <ddiblik@redhat.com> * Incorporate review suggestions fix typos Signed-off-by: Daniel Diblik <ddiblik@redhat.com> * Fix formatting issue Signed-off-by: Rodolfo Olivieri <rolivier@redhat.com> * Fix unit_tests Signed-off-by: Rodolfo Olivieri <rolivier@redhat.com> * Add cmp_to_key for python 2.6 compatibility Signed-off-by: Rodolfo Olivieri <rolivier@redhat.com> * Update convert2rhel/checks.py Co-authored-by: Michal Bocek <mbocek@redhat.com> Signed-off-by: Rodolfo Olivieri <rolivier@redhat.com> Signed-off-by: Daniel Diblik <ddiblik@redhat.com> Co-authored-by: Daniel Diblik <ddiblik@redhat.com> Co-authored-by: Michal Bocek <mbocek@redhat.com>
…s. (#651) * Fix the format of message about unavailable kernel modules. In #469, one of the cleanups ended up calling `"\n".join()` on a list of kernel modules twice. The first time changes the list into a string with each entry separated by a newline but the second time changes the string into another string with each chatacter separated by a newline. Fixed that by removing the second `str.join()`. This also refactors away a call to `map()` and use of `lambda`. In modern python, any uses of `map()` or `filter()` can be replaced with either a generator expression or list comprehension. Related to #469 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
These changes are cleanup of most of the things that were left behind from
PR #193.
Some of the functions were changed to make it easier to read and debug if
necessary, some of them were moved around to the files that made sense to place
they and some of them just needed a docstring to tell what the function was all
about.
This PR it is introduced a unit test for the function
get_enabled_rhel_repos
since that was introduced in the past and never had a unit test tied to it.
Jira reference (If any): https://issues.redhat.com/browse/OAMG-4668
Bugzilla reference (If any):
Signed-off-by: Rodolfo Olivieri rolivier@redhat.com