From ca084889c78230a5e86a3434cb4ccfc5b4d2d120 Mon Sep 17 00:00:00 2001 From: Adam Miller Date: Wed, 2 Jan 2019 16:50:06 -0600 Subject: [PATCH] fix order of dnf api operations so transactions don't fail (#50038) * fix order of dnf api operations so transactions don't fail Previously dnf.base.fill_sack() was called before dnf.base.update_cache() which apparently breaks dnf transaction logic as per https://bugzilla.redhat.com/show_bug.cgi?id=1658694 Fixes #49060 Signed-off-by: Adam Miller * add changelog and test case Signed-off-by: Adam Miller --- .../dnf-update-cache-broken-transaction.yaml | 3 +++ lib/ansible/modules/packaging/os/dnf.py | 18 +++++++++--------- test/integration/targets/dnf/tasks/dnf.yml | 1 + 3 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 changelogs/fragments/dnf-update-cache-broken-transaction.yaml diff --git a/changelogs/fragments/dnf-update-cache-broken-transaction.yaml b/changelogs/fragments/dnf-update-cache-broken-transaction.yaml new file mode 100644 index 00000000000..b6501259295 --- /dev/null +++ b/changelogs/fragments/dnf-update-cache-broken-transaction.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: + - "dnf - fix update_cache combined with install operation to not cause dnf transaction failure" diff --git a/lib/ansible/modules/packaging/os/dnf.py b/lib/ansible/modules/packaging/os/dnf.py index 14d766d90c5..d0dfda7b4c5 100644 --- a/lib/ansible/modules/packaging/os/dnf.py +++ b/lib/ansible/modules/packaging/os/dnf.py @@ -588,6 +588,15 @@ class DnfModule(YumDnf): except AttributeError: pass # older versions of dnf didn't require this and don't have these methods try: + if self.update_cache: + try: + base.update_cache() + except dnf.exceptions.RepoError as e: + self.module.fail_json( + msg="{0}".format(to_text(e)), + results=[], + rc=1 + ) base.fill_sack(load_system_repo='auto') except dnf.exceptions.RepoError as e: self.module.fail_json( @@ -601,15 +610,6 @@ class DnfModule(YumDnf): if self.security: key = {'advisory_type__eq': 'security'} base._update_security_filters = [base.sack.query().filter(**key)] - if self.update_cache: - try: - base.update_cache() - except dnf.exceptions.RepoError as e: - self.module.fail_json( - msg="{0}".format(to_text(e)), - results=[], - rc=1 - ) return base diff --git a/test/integration/targets/dnf/tasks/dnf.yml b/test/integration/targets/dnf/tasks/dnf.yml index 7b9306af277..23bde538dc5 100644 --- a/test/integration/targets/dnf/tasks/dnf.yml +++ b/test/integration/targets/dnf/tasks/dnf.yml @@ -50,6 +50,7 @@ dnf: name: sos state: present + update_cache: True register: dnf_result - name: check sos with rpm