Note: This is a public test instance of Red Hat Bugzilla. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback at bugzilla.redhat.com.
Bug 2162436 - Heads up - upgrading python-packaging will break test_chroot_gpg_hashes
Summary: Heads up - upgrading python-packaging will break test_chroot_gpg_hashes
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Fedora
Classification: Fedora
Component: copr-backend
Version: 38
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Copr Team
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: 2166942
TreeView+ depends on / blocked
 
Reported: 2023-01-19 15:00 UTC by Tomáš Hrnčiar
Modified: 2023-04-03 19:00 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2023-04-03 19:00:04 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Tomáš Hrnčiar 2023-01-19 15:00:20 UTC
Hello,

I am working on upgrading python-packaging to version 23.0 and it will break test_chroot_gpg_hashes. Packaging removed support for LegacyVersion(https://github.com/pypa/packaging/pull/407) and this line is now failing:

copr_backend/sign.py:119: in gpg_hashtype_for_chroot

You can use this COPR https://copr.fedorainfracloud.org/coprs/thrnciar/python-packaging/builds/ for testing. I plan to ship the update next week on Thursday 26.1.2023.

Thank you. 


=================================== FAILURES ===================================
____________________________ test_chroot_gpg_hashes ____________________________

    def test_chroot_gpg_hashes():
        chroots = [
            ("fedora-26-x86_64", "sha1"),
            ("fedora-27-s390x", "sha256"),
            ("fedora-eln-x86_64", "sha256"),
            ("fedora-rawhide-x86_64", "sha256"),
            ("mageia-8-x86_64", "sha256"),
            ("opensuse-tumbleweed-aarch64", "sha256"),
            ("epel-7-ppc64", "sha256"),
            ("centos-7.dev-aarch64", "sha256"),
            ("epel-8-aarch64", "sha256"),
            ("rhel-8.dev-ppc64le", "sha256"),
            ("oraclelinux-9-s390x", "sha256"),
            ("centos-stream-8-s390x", "sha256"),
            ("centos-stream-9-s390x", "sha256"),
            ("rhel-rawhide-s390x", "sha256"),
            # we don't expect stream 7 will ever exist
            ("centos-stream-7-aarch64", "sha256"),
            ("srpm-builds", "sha256"),
            ("epel-4-s390x", "sha1"),
            ("epel-5-s390x", "sha256"),
            ("centos-stream+epel-next-9-aarch64", "sha256"),
        ]
    
        opts = Munch()
        opts.gently_gpg_sha256 = False
    
        for chroot, exp_type in chroots:
            assert (chroot, exp_type) == (chroot, gpg_hashtype_for_chroot(chroot, opts))
    
        opts.gently_gpg_sha256 = True
        chroots = [
            ("fedora-26-x86_64", "sha1"),
            ("fedora-27-s390x", "sha1"),
            ("fedora-eln-x86_64", "sha1"),
            ("fedora-rawhide-x86_64", "sha1"),
            ("mageia-8-x86_64", "sha1"),
            ("opensuse-tumbleweed-aarch64", "sha1"),
            ("epel-7-ppc64", "sha1"),
            ("centos-7.dev-aarch64", "sha1"),
            ("epel-8-aarch64", "sha256"),
            ("rhel-8.dev-ppc64le", "sha256"),
            ("oraclelinux-9-s390x", "sha256"),
            ("centos-stream-8-s390x", "sha256"),
            ("centos-stream-9-s390x", "sha256"),
            ("rhel-rawhide-s390x", "sha1"),
            ("srpm-builds", "sha1"),
        ]
        for chroot, exp_type in chroots:
>           assert (chroot, exp_type) == (chroot, gpg_hashtype_for_chroot(chroot, opts))

tests/test_sign.py:354: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
copr_backend/sign.py:119: in gpg_hashtype_for_chroot
    if version.parse(el_version) > version.parse("7"):
/usr/lib/python3.11/site-packages/packaging/version.py:52: in parse
    return Version(version)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <[AttributeError("'Version' object has no attribute '_version'") raised in repr()] Version object at 0x7f1c7564f490>
version = 'rawhide'

    def __init__(self, version: str) -> None:
        """Initialize a Version object.
    
        :param version:
            The string representation of a version which will be parsed and normalized
            before use.
        :raises InvalidVersion:
            If the ``version`` does not conform to PEP 440 in any way then this
            exception will be raised.
        """
    
        # Validate the version and parse it into pieces
        match = self._regex.search(version)
        if not match:
>           raise InvalidVersion(f"Invalid version: '{version}'")
E           packaging.version.InvalidVersion: Invalid version: 'rawhide'

/usr/lib/python3.11/site-packages/packaging/version.py:197: InvalidVersion

Comment 1 Miro Hrončok 2023-01-20 11:21:59 UTC
This only fails in the test because the chroot name is "rhel-rawhide-s390x".

The code itself is:

    el_chroots = ["rhel", "epel", "centos", "oraclelinux"]

    ...

        if parts[0] in el_chroots:
            ...
            if version.parse(el_version) > version.parse("7"):

And all the actual EL chroots have numeric versions, so this will never attempt to parse "rawhide" in production.


However, to stay safe, the code should really try-version.parse-except now. Something like:

try:
    el_version_ = version.parse(el_version)
except InvalidVersion:
    return return "sha256"  # or whatever action is appropriate
else:
    if el_version_ > version.parse("7"):
        ...

Comment 2 Jakub Kadlčík 2023-01-20 15:03:29 UTC
Thank you very much for letting us know beforehand.
PR: https://github.com/fedora-copr/copr/pull/2492/files

Comment 3 Ben Cotton 2023-02-07 15:13:44 UTC
This bug appears to have been reported against 'rawhide' during the Fedora Linux 38 development cycle.
Changing version to 38.


Note You need to log in before you can comment on or make changes to this bug.