From ed86907587140daa933d8db08c7dca473757a63a Mon Sep 17 00:00:00 2001 From: Adam Miller Date: Thu, 24 Oct 2019 00:57:31 -0400 Subject: [PATCH] DNF Handle Empty AppStream stream definition (#63819) * DNF Handle Empty AppStream stream definition Fixes #63683 Signed-off-by: Adam Miller * Switch Fedora dnf test target modularity to stratis In Fedora 29, the metadata was not properly set for a default stream for ripgrep even though there is a profile called "default", however that's an arbitrary string and the module maintainer must set the default stream (which it never was for the ripgrep module, thus failing the "empty stream" install test) Signed-off-by: Adam Miller --- ...3683-dnf-handle-empty-appstream-stream.yml | 3 ++ lib/ansible/modules/packaging/os/dnf.py | 11 ++++- .../targets/dnf/tasks/modularity.yml | 48 +++++++++++++++++++ test/integration/targets/dnf/vars/Fedora.yml | 3 +- test/integration/targets/dnf/vars/RedHat.yml | 1 + 5 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/63683-dnf-handle-empty-appstream-stream.yml diff --git a/changelogs/fragments/63683-dnf-handle-empty-appstream-stream.yml b/changelogs/fragments/63683-dnf-handle-empty-appstream-stream.yml new file mode 100644 index 00000000000..e3154957fe4 --- /dev/null +++ b/changelogs/fragments/63683-dnf-handle-empty-appstream-stream.yml @@ -0,0 +1,3 @@ +--- +minor_changes: + - dnf - Properly handle module AppStreams that don't define stream (https://github.com/ansible/ansible/issues/63683) diff --git a/lib/ansible/modules/packaging/os/dnf.py b/lib/ansible/modules/packaging/os/dnf.py index 2a4e2c9080a..cf796bf6886 100644 --- a/lib/ansible/modules/packaging/os/dnf.py +++ b/lib/ansible/modules/packaging/os/dnf.py @@ -886,9 +886,16 @@ class DnfModule(YumDnf): if self.with_modules: module_spec = module_spec.strip() module_list, nsv = self.module_base._get_modules(module_spec) + enabled_streams = self.base._moduleContainer.getEnabledStream(nsv.name) - if nsv.stream in self.base._moduleContainer.getEnabledStream(nsv.name): - return True + if enabled_streams: + if nsv.stream: + if nsv.stream in enabled_streams: + return True # The provided stream was found + else: + return False # The provided stream was not found + else: + return True # No stream provided, but module found return False # seems like a sane default diff --git a/test/integration/targets/dnf/tasks/modularity.yml b/test/integration/targets/dnf/tasks/modularity.yml index 7c848c2dc36..48a0111a266 100644 --- a/test/integration/targets/dnf/tasks/modularity.yml +++ b/test/integration/targets/dnf/tasks/modularity.yml @@ -49,3 +49,51 @@ that: - "not dnf_result.failed" - "not dnf_result.changed" + +- name: install "{{ astream_name_no_stream }}" module without providing stream + dnf: + name: "{{ astream_name_no_stream }}" + state: present + register: dnf_result + +- name: verify installation of "{{ astream_name_no_stream }}" module without providing stream + assert: + that: + - "not dnf_result.failed" + - "dnf_result.changed" + +- name: install "{{ astream_name_no_stream }}" module again without providing stream + dnf: + name: "{{ astream_name_no_stream }}" + state: present + register: dnf_result + +- name: verify installation of "{{ astream_name_no_stream }}" module again without providing stream + assert: + that: + - "not dnf_result.failed" + - "not dnf_result.changed" + +- name: uninstall "{{ astream_name_no_stream }}" module without providing stream + dnf: + name: "{{ astream_name_no_stream }}" + state: absent + register: dnf_result + +- name: verify uninstallation of "{{ astream_name_no_stream }}" module without providing stream + assert: + that: + - "not dnf_result.failed" + - "dnf_result.changed" + +- name: uninstall "{{ astream_name_no_stream }}" module again without providing stream + dnf: + name: "{{ astream_name_no_stream }}" + state: absent + register: dnf_result + +- name: verify uninstallation of "{{ astream_name_no_stream }}" module again without providing stream + assert: + that: + - "not dnf_result.failed" + - "not dnf_result.changed" diff --git a/test/integration/targets/dnf/vars/Fedora.yml b/test/integration/targets/dnf/vars/Fedora.yml index 25a04e74563..af3de4c1ccb 100644 --- a/test/integration/targets/dnf/vars/Fedora.yml +++ b/test/integration/targets/dnf/vars/Fedora.yml @@ -1 +1,2 @@ -astream_name: '@ripgrep:master/default' +astream_name: '@stratis:1/default' +astream_name_no_stream: '@stratis/default' diff --git a/test/integration/targets/dnf/vars/RedHat.yml b/test/integration/targets/dnf/vars/RedHat.yml index 0fd8ee4b01d..c70d8538d81 100644 --- a/test/integration/targets/dnf/vars/RedHat.yml +++ b/test/integration/targets/dnf/vars/RedHat.yml @@ -1 +1,2 @@ astream_name: '@php:7.2/minimal' +astream_name_no_stream: '@php/minimal'