summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Krizek <martin.krizek@gmail.com>2023-09-26 21:49:14 +0200
committerGitHub <noreply@github.com>2023-09-26 21:49:14 +0200
commit60c96609525f44ac48158b4f7892b5b5eae69be5 (patch)
treedb4caf0bfd8215b1b11395fdfddc0688242b6319
parentTest heuristic_log_sanitize (#81730) (diff)
downloadansible-60c96609525f44ac48158b4f7892b5b5eae69be5.tar.xz
ansible-60c96609525f44ac48158b4f7892b5b5eae69be5.zip
Add intentional tests for dnf install rpm when higher version is installed (#81740)
* Add intentional tests for dnf install rpm when higher version is installed * ci_complete ci_coverage
-rw-r--r--changelogs/fragments/dnf5-from-rpm-allow_downgrade.yml2
-rw-r--r--lib/ansible/modules/dnf5.py8
-rw-r--r--test/integration/targets/dnf/tasks/repo.yml24
3 files changed, 33 insertions, 1 deletions
diff --git a/changelogs/fragments/dnf5-from-rpm-allow_downgrade.yml b/changelogs/fragments/dnf5-from-rpm-allow_downgrade.yml
new file mode 100644
index 0000000000..97716d0469
--- /dev/null
+++ b/changelogs/fragments/dnf5-from-rpm-allow_downgrade.yml
@@ -0,0 +1,2 @@
+bugfixes:
+ - dnf5 - respect ``allow_downgrade`` when installing packages directly from rpm files
diff --git a/lib/ansible/modules/dnf5.py b/lib/ansible/modules/dnf5.py
index 823d3a7fb9..3f54816b99 100644
--- a/lib/ansible/modules/dnf5.py
+++ b/lib/ansible/modules/dnf5.py
@@ -357,9 +357,15 @@ def is_installed(base, spec):
def is_newer_version_installed(base, spec):
+ # FIXME investigate whether this function can be replaced by dnf5's allow_downgrade option
+ if "/" in spec:
+ spec = spec.split("/")[-1]
+ if spec.endswith(".rpm"):
+ spec = spec[:-4]
+
try:
spec_nevra = next(iter(libdnf5.rpm.Nevra.parse(spec)))
- except RuntimeError:
+ except (RuntimeError, StopIteration):
return False
spec_name = spec_nevra.get_name()
v = spec_nevra.get_version()
diff --git a/test/integration/targets/dnf/tasks/repo.yml b/test/integration/targets/dnf/tasks/repo.yml
index 7f785b14e9..6aa268e2b2 100644
--- a/test/integration/targets/dnf/tasks/repo.yml
+++ b/test/integration/targets/dnf/tasks/repo.yml
@@ -101,6 +101,30 @@
that:
- "'results' in dnf_result"
# ============================================================================
+ - name: Install dinginessentail-1.0-1 from a file (higher version is already installed)
+ dnf:
+ name: "{{ repodir }}/dinginessentail-1.0-1.{{ ansible_architecture }}.rpm"
+ state: present
+ disable_gpg_check: True
+ register: dnf_result
+
+ - name: Check dinginessentail with rpm
+ shell: rpm -q dinginessentail
+ register: rpm_result
+
+ - name: Verify installation
+ assert:
+ that:
+ - "not dnf_result.changed"
+ - "rpm_result.stdout.startswith('dinginessentail-1.1-1')"
+
+ - name: Verify dnf module outputs
+ assert:
+ that:
+ - "'msg' in dnf_result"
+ - "'rc' in dnf_result"
+ - "'results' in dnf_result"
+ # ============================================================================
- name: Install dinginessentail-1.0-1 from a file (downgrade)
dnf:
name: "{{ repodir }}/dinginessentail-1.0-1.{{ ansible_architecture }}.rpm"