From 663c02da41b85340fa84b582c13948aa80db0585 2020-05-05 22:55:23 From: Branko Majic Date: 2020-05-05 22:55:23 Subject: [PATCH] Noticket: Improve reliability for mail_server tests, detection of running ClamAV daemon: The fixes mainly help with reliability of tests against the mail_server role due to ClamAV not becoming available before the tests get run. This normally is not a real issue in production (since the daemon will become available farily quickly). Changes made: - Wait for ClamAV socket to become available in mail_server role (otherwise mail delivery failures can happen). - Increase memory used in mail server instances for testing to avoid OOM killer kicking-in during tests. - Introduce slight delay when running local alias tests to avoid race condition. - Formating fix in task that waits for ClamAV database to be available. --- diff --git a/roles/mail_server/molecule/default/molecule.yml b/roles/mail_server/molecule/default/molecule.yml index b962e1bd5265e6e6691e300f09494dbb51c4b624..78a9d16e56bb14c21f86eec41543d0d29943929b 100644 --- a/roles/mail_server/molecule/default/molecule.yml +++ b/roles/mail_server/molecule/default/molecule.yml @@ -85,7 +85,7 @@ platforms: - parameters-mandatory - jessie box: debian/contrib-jessie64 - memory: 512 + memory: 1024 cpus: 1 interfaces: - auto_config: true @@ -98,7 +98,7 @@ platforms: - parameters-optional - jessie box: debian/contrib-jessie64 - memory: 512 + memory: 1024 cpus: 1 interfaces: - auto_config: true @@ -111,7 +111,7 @@ platforms: - parameters-mandatory - stretch box: debian/contrib-stretch64 - memory: 512 + memory: 1024 cpus: 1 interfaces: - auto_config: true @@ -124,7 +124,7 @@ platforms: - parameters-optional - stretch box: debian/contrib-stretch64 - memory: 512 + memory: 1024 cpus: 1 interfaces: - auto_config: true diff --git a/roles/mail_server/molecule/default/tests/test_optional.py b/roles/mail_server/molecule/default/tests/test_optional.py index 96819d675d50d11a663bc6f9c38a0e4af267a765..fdffd059a8ec7d36961d9f4a20f11cb49f1a918b 100644 --- a/roles/mail_server/molecule/default/tests/test_optional.py +++ b/roles/mail_server/molecule/default/tests/test_optional.py @@ -1,5 +1,6 @@ import os import re +import time import uuid import testinfra.utils.ansible_runner @@ -117,6 +118,7 @@ def test_local_aliases(host): message_id = str(uuid.uuid4()) send = host.run('swaks --header %s --suppress-data --to root@localhost', "Message-Id: <%s>" % message_id) + time.sleep(1) assert send.rc == 0 with host.sudo(): diff --git a/roles/mail_server/tasks/main.yml b/roles/mail_server/tasks/main.yml index 035da548c4eb2b85397b8d0b846a8a05b2bb99d2..3d01ef702fd067a5a530ef264146e365bd2ec95f 100644 --- a/roles/mail_server/tasks/main.yml +++ b/roles/mail_server/tasks/main.yml @@ -273,7 +273,9 @@ - name: Wait for ClamAV database to be available (up to 10 minutes) when: not item.stat.exists with_items: "{{ clamav_db_files.results }}" - wait_for: path="{{ item.item | replace('.cld', '.cvd') }}" timeout=600 + wait_for: + path: "{{ item.item | replace('.cld', '.cvd') }}" + timeout: 600 - name: Enable ClamAV daemon and milter services service: @@ -283,6 +285,12 @@ - clamav-daemon - clamav-milter +# It may take ClamAV a while to read all the necessary database files etc. +- name: Wait for ClamAV to become available (up to 5 minutes) + wait_for: + path: "/var/run/clamav/clamd.ctl" + timeout: 300 + - name: Enable Postfix service service: name: postfix