[PR #6522/bd6cec21 backport][stable-7] respawn copr module when dnf is missing (#6591)

respawn copr module when dnf is missing (#6522)

* respawn copr module when dnf is missing

Fixes: https://bugzilla.redhat.com/2203513

* don't guard common.respawn module_util import

(cherry picked from commit bd6cec2105)

Co-authored-by: Maxwell G <maxwell@gtmx.me>
This commit is contained in:
patchback[bot] 2023-05-29 21:08:45 +02:00 committed by GitHub
parent 91bfdbd7a0
commit b49aeab5f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 6 deletions

View file

@ -97,6 +97,7 @@ except ImportError:
DNF_IMP_ERR = traceback.format_exc()
HAS_DNF_PACKAGES = False
from ansible.module_utils.common import respawn
from ansible.module_utils.six.moves.urllib.error import HTTPError
from ansible.module_utils.basic import missing_required_lib
from ansible.module_utils import distro # pylint: disable=import-error
@ -104,6 +105,20 @@ from ansible.module_utils.basic import AnsibleModule # pylint: disable=import-e
from ansible.module_utils.urls import open_url # pylint: disable=import-error
def _respawn_dnf():
if respawn.has_respawned():
return
system_interpreters = (
"/usr/libexec/platform-python",
"/usr/bin/python3",
"/usr/bin/python2",
"/usr/bin/python",
)
interpreter = respawn.probe_interpreters_for_module(system_interpreters, "dnf")
if interpreter:
respawn.respawn_module(interpreter)
class CoprModule(object):
"""The class represents a copr module.
@ -460,6 +475,7 @@ def run_module():
params = module.params
if not HAS_DNF_PACKAGES:
_respawn_dnf()
module.fail_json(msg=missing_required_lib("dnf"), exception=DNF_IMP_ERR)
CoprModule.ansible_module = module