Skip to content

Commit

Permalink
Enable logging using setup_loggers() API in dnf-4.2.17-6 or later
Browse files Browse the repository at this point in the history
  • Loading branch information
saito-hideki authored and relrod committed May 31, 2020
1 parent b1b79be commit 79ab798
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/dnf_setup_loggers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- dnf - enable logging using setup_loggers() API in dnf-4.2.17-6 or later
6 changes: 6 additions & 0 deletions lib/ansible/modules/dnf.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,12 @@ def _base(self, conf_file, disable_gpg_check, disablerepo, enablerepo, installro
"""Return a fully configured dnf Base object."""
base = dnf.Base()
self._configure_base(base, conf_file, disable_gpg_check, installroot)
try:
# this method has been supported in dnf-4.2.17-6 or later
# https://bugzilla.redhat.com/show_bug.cgi?id=1788212
base.setup_loggers()
except AttributeError:
pass
try:
base.init_plugins(set(self.disable_plugin), set(self.enable_plugin))
base.pre_configure_plugins()
Expand Down
45 changes: 45 additions & 0 deletions test/integration/targets/dnf/tasks/logging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Verify logging function is enabled in the dnf module.
# The following tasks has been supported in dnf-4.2.17-6 or later
# Note: https://bugzilla.redhat.com/show_bug.cgi?id=1788212
- name: Install latest version python3-dnf
dnf:
name: python3-dnf
state: latest
register: dnf_result

- name: Verify python3-dnf installed
assert:
that:
- "dnf_result.rc == 0"

- name: Get python3-dnf version
shell: "dnf info python3-dnf | awk '/^Version/ { print $3 }'"
register: py3_dnf_version

- name: Check logging enabled
block:
- name: remove logfiles if exist
file:
path: "{{ item }}"
state: absent
loop: "{{ dnf_log_files }}"

- name: Install sos package
dnf:
name: sos
state: present
register: dnf_result

- name: Get status of logfiles
stat:
path: "{{ item }}"
loop: "{{ dnf_log_files }}"
register: stats

- name: Verify logfile exists
assert:
that:
- "item.stat.exists"
loop: "{{ stats.results }}"
when:
- 'py3_dnf_version.stdout is version("4.2.17", ">=")'
4 changes: 4 additions & 0 deletions test/integration/targets/dnf/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@
- include_tasks: modularity.yml
when: (ansible_distribution == 'Fedora' and ansible_distribution_major_version is version('29', '>=')) or
(ansible_distribution in ['RedHat', 'CentOS'] and ansible_distribution_major_version is version('8', '>='))

- include_tasks: logging.yml
when: (ansible_distribution == 'Fedora' and ansible_distribution_major_version is version('31', '>=')) or
(ansible_distribution in ['RedHat', 'CentOS'] and ansible_distribution_major_version is version('8', '>='))
4 changes: 4 additions & 0 deletions test/integration/targets/dnf/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dnf_log_files:
- /var/log/dnf.log
- /var/log/dnf.rpm.log
- /var/log/dnf.librepo.log

0 comments on commit 79ab798

Please sign in to comment.