zypper_repository: fix usage of removed method ConfigParser.readfp() (#10223)
Some checks failed
EOL CI / EOL Sanity (Ⓐ2.16) (push) Has been cancelled
EOL CI / EOL Units (Ⓐ2.16+py2.7) (push) Has been cancelled
EOL CI / EOL Units (Ⓐ2.16+py3.11) (push) Has been cancelled
EOL CI / EOL Units (Ⓐ2.16+py3.6) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.16+alpine3+py:azp/posix/1/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.16+alpine3+py:azp/posix/2/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.16+alpine3+py:azp/posix/3/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.16+fedora38+py:azp/posix/1/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.16+fedora38+py:azp/posix/2/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.16+fedora38+py:azp/posix/3/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.16+opensuse15+py:azp/posix/1/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.16+opensuse15+py:azp/posix/2/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.16+opensuse15+py:azp/posix/3/) (push) Has been cancelled
nox / Run extra sanity tests (push) Has been cancelled

* zypper_repository: fix usage of removed method ConfigParser.readfp()

ConfigParser.readfp() has been removed in python 3.12.
See similar fix e.g. in https://github.com/ansible/ansible/pull/81657

This fixes the error message:
AttributeError: 'ConfigParser' object has no attribute 'readfp'. Did you mean: 'read'?

* Update changelogs/fragments/10222-zypper_repository-readfp.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Martin Wilck 2025-06-12 22:13:12 +02:00 committed by GitHub
parent 2428c0dc6f
commit bc99432f89
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- zypper_repository - make compatible with Python 3.12+ (https://github.com/ansible-collections/community.general/issues/10222, https://github.com/ansible-collections/community.general/pull/10223).

View file

@ -142,6 +142,7 @@ from ansible.module_utils.basic import AnsibleModule, missing_required_lib
from ansible.module_utils.urls import fetch_url
from ansible.module_utils.common.text.converters import to_text
from ansible.module_utils.six import PY3
from ansible.module_utils.six.moves import configparser, StringIO
from io import open
@ -407,7 +408,10 @@ def main():
repofile = configparser.ConfigParser()
try:
repofile.readfp(StringIO(repofile_text))
if PY3:
repofile.read_file(StringIO(repofile_text))
else:
repofile.readfp(StringIO(repofile_text))
except configparser.Error:
module.fail_json(msg='Invalid format, .repo file could not be parsed')