From b8a81973eef15d13def0b88f243cf8e5a0b79bef Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Thu, 18 Jun 2020 03:55:41 +0900 Subject: [PATCH] Backport of dnf module logging (#69480) (#70066) Signed-off-by: Hideki Saito --- changelogs/fragments/dnf_setup_loggers.yml | 2 + lib/ansible/modules/packaging/os/dnf.py | 6 +++ .../integration/targets/dnf/tasks/logging.yml | 45 +++++++++++++++++++ test/integration/targets/dnf/tasks/main.yml | 4 ++ test/integration/targets/dnf/vars/main.yml | 4 ++ 5 files changed, 61 insertions(+) create mode 100644 changelogs/fragments/dnf_setup_loggers.yml create mode 100644 test/integration/targets/dnf/tasks/logging.yml create mode 100644 test/integration/targets/dnf/vars/main.yml diff --git a/changelogs/fragments/dnf_setup_loggers.yml b/changelogs/fragments/dnf_setup_loggers.yml new file mode 100644 index 00000000000..0563fe04380 --- /dev/null +++ b/changelogs/fragments/dnf_setup_loggers.yml @@ -0,0 +1,2 @@ +bugfixes: + - dnf - enable logging using setup_loggers() API in dnf-4.2.17-6 or later diff --git a/lib/ansible/modules/packaging/os/dnf.py b/lib/ansible/modules/packaging/os/dnf.py index f8fa5d96bf2..70a95226885 100644 --- a/lib/ansible/modules/packaging/os/dnf.py +++ b/lib/ansible/modules/packaging/os/dnf.py @@ -631,6 +631,12 @@ class DnfModule(YumDnf): """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() diff --git a/test/integration/targets/dnf/tasks/logging.yml b/test/integration/targets/dnf/tasks/logging.yml new file mode 100644 index 00000000000..ad4df72d6d7 --- /dev/null +++ b/test/integration/targets/dnf/tasks/logging.yml @@ -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", ">=")' diff --git a/test/integration/targets/dnf/tasks/main.yml b/test/integration/targets/dnf/tasks/main.yml index 9369b5b0cd4..05881184039 100644 --- a/test/integration/targets/dnf/tasks/main.yml +++ b/test/integration/targets/dnf/tasks/main.yml @@ -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', '>=')) diff --git a/test/integration/targets/dnf/vars/main.yml b/test/integration/targets/dnf/vars/main.yml new file mode 100644 index 00000000000..86588de335d --- /dev/null +++ b/test/integration/targets/dnf/vars/main.yml @@ -0,0 +1,4 @@ +dnf_log_files: + - /var/log/dnf.log + - /var/log/dnf.rpm.log + - /var/log/dnf.librepo.log