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-297] Clean up kmods functionality #469

Merged
merged 11 commits into from
Nov 3, 2022
Merged

Conversation

r0x0d
Copy link
Member

@r0x0d r0x0d commented Mar 23, 2022

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

Comment on lines 336 to 373
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),
)
)
Copy link
Member Author

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.

Copy link
Member

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

Comment on lines 312 to 349
# TODO:
# if not self.submgr_enabled_repos:
Copy link
Member Author

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?

Copy link
Member

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?

Copy link
Contributor

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

@r0x0d r0x0d self-assigned this Mar 23, 2022
@codecov
Copy link

codecov bot commented Mar 23, 2022

Codecov Report

Base: 93.30% // Head: 93.23% // Decreases project coverage by -0.06% ⚠️

Coverage data is based on head (c9e9636) compared to base (700088a).
Patch coverage: 91.48% of modified lines in pull request are covered.

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              
Flag Coverage Δ
centos-linux-6 89.72% <91.48%> (-0.04%) ⬇️
centos-linux-7 89.19% <61.70%> (-0.49%) ⬇️
centos-linux-8 89.38% <61.70%> (-0.49%) ⬇️

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

Impacted Files Coverage Δ
convert2rhel/systeminfo.py 96.61% <ø> (ø)
convert2rhel/checks.py 94.82% <88.23%> (-1.16%) ⬇️
convert2rhel/main.py 92.35% <100.00%> (ø)
convert2rhel/pkghandler.py 92.93% <100.00%> (+0.19%) ⬆️

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.
📢 Do you have feedback about the report comment? Let us know in this issue.

convert2rhel/checks.py Outdated Show resolved Hide resolved
@abadger
Copy link
Member

abadger commented Apr 7, 2022

I've reviewed this. Other than the questions about get_most_recent_unique_kernel_pkgs() and its helper functions, this looks good.

@r0x0d r0x0d force-pushed the kmods-code-cleanup branch 2 times, most recently from 74b12c5 to 882b47b Compare April 26, 2022 18:45
@r0x0d r0x0d force-pushed the kmods-code-cleanup branch from 882b47b to d511dd2 Compare May 12, 2022 19:26
@@ -1075,3 +1082,45 @@ def _get_packages_to_update_dnf():
packages.append(package.name)

return packages


def package_version_cmp(pkg_1, pkg_2):
Copy link
Member

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)?$
  • 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.
  • 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() and utils.string_to_version().

Discuss?

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

convert2rhel/pkghandler.py Outdated Show resolved Hide resolved
@r0x0d r0x0d force-pushed the kmods-code-cleanup branch from 88effe9 to acc88c6 Compare June 3, 2022 15:02
@kokesak
Copy link
Member

kokesak commented Jun 22, 2022

@r0x0d once you will have a free time, please rebase the PR

@r0x0d r0x0d force-pushed the kmods-code-cleanup branch from 6fa7abc to 5017f8d Compare July 11, 2022 12:37
@r0x0d
Copy link
Member Author

r0x0d commented Jul 11, 2022

@kokesak rebased!

@r0x0d
Copy link
Member Author

r0x0d commented Jul 15, 2022

I will rebase this to resolve the conflict with the checks.py

@r0x0d r0x0d force-pushed the kmods-code-cleanup branch from 5017f8d to a2b8f15 Compare August 2, 2022 14:47
@danmyway
Copy link
Member

danmyway commented Aug 3, 2022

/packit retest-failed

@r0x0d r0x0d changed the title Clean up kmods functionality [RHELC-297] Clean up kmods functionality Aug 3, 2022
@danmyway
Copy link
Member

danmyway commented Aug 3, 2022

/packit build

1 similar comment
@danmyway
Copy link
Member

danmyway commented Aug 4, 2022

/packit build

convert2rhel/checks.py Outdated Show resolved Hide resolved
convert2rhel/checks.py Show resolved Hide resolved
@lgtm-com
Copy link
Contributor

lgtm-com bot commented Aug 5, 2022

This pull request fixes 1 alert when merging 5f52da8 into 121fa76 - view on LGTM.com

fixed alerts:

  • 1 for Unused named argument in formatting call

@danmyway danmyway requested a review from kokesak August 8, 2022 10:01
convert2rhel/utils.py Outdated Show resolved Hide resolved
Copy link
Member

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

r0x0d and others added 7 commits October 28, 2022 16:14
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>
@r0x0d r0x0d force-pushed the kmods-code-cleanup branch from 7b41411 to 82c646c Compare October 28, 2022 19:20
Signed-off-by: Rodolfo Olivieri <rolivier@redhat.com>
@r0x0d r0x0d force-pushed the kmods-code-cleanup branch from 9194cfe to 32faec7 Compare October 28, 2022 19:21
@lgtm-com
Copy link
Contributor

lgtm-com bot commented Oct 28, 2022

This pull request fixes 3 alerts when merging 32faec7 into 700088a - view on LGTM.com

fixed alerts:

  • 2 for Unused import
  • 1 for Unused named argument in formatting call

@danmyway danmyway requested a review from kokesak October 31, 2022 14:09
kokesak
kokesak previously approved these changes Oct 31, 2022
Copy link
Member

@kokesak kokesak left a 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>
@lgtm-com
Copy link
Contributor

lgtm-com bot commented Oct 31, 2022

This pull request fixes 3 alerts when merging c9e9636 into e1dfbdd - view on LGTM.com

fixed alerts:

  • 2 for Unused import
  • 1 for Unused named argument in formatting call

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.

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?

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.

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

@r0x0d
Copy link
Member Author

r0x0d commented Nov 1, 2022

Thanks, @abadger for re-running the tests. Now the only thing that failed is the codecov patch/project checks, but they are fine.

@kokesak could you approve it once again?

Copy link
Member

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

@r0x0d r0x0d merged commit 1e52449 into oamg:main Nov 3, 2022
@r0x0d r0x0d deleted the kmods-code-cleanup branch November 3, 2022 12:49
abadger added a commit to abadger/convert2rhel that referenced this pull request Nov 4, 2022
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
r0x0d pushed a commit that referenced this pull request Nov 7, 2022
…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>
hosekadam pushed a commit to hosekadam/convert2rhel that referenced this pull request Nov 11, 2022
…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>
@Venefilyn Venefilyn mentioned this pull request Nov 30, 2022
abadger added a commit to Andrew-ang9/convert2rhel that referenced this pull request Dec 7, 2022
…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>
Venefilyn pushed a commit that referenced this pull request Jun 19, 2023
* 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>
Venefilyn pushed a commit that referenced this pull request Jun 19, 2023
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants