Changeset - 663c02da41b8
[Not reviewed]
0 3 0
Branko Majic (branko) - 4 years ago 2020-05-05 22:55:23
branko@majic.rs
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.
3 files changed with 15 insertions and 5 deletions:
0 comments (0 inline, 0 general)
roles/mail_server/molecule/default/molecule.yml
Show inline comments
 
@@ -82,52 +82,52 @@ platforms:
 

	
 
  - name: parameters-mandatory-jessie64
 
    groups:
 
      - parameters-mandatory
 
      - jessie
 
    box: debian/contrib-jessie64
 
    memory: 512
 
    memory: 1024
 
    cpus: 1
 
    interfaces:
 
      - auto_config: true
 
        ip: 10.31.127.30
 
        network_name: private_network
 
        type: static
 

	
 
  - name: parameters-optional-jessie64
 
    groups:
 
      - parameters-optional
 
      - jessie
 
    box: debian/contrib-jessie64
 
    memory: 512
 
    memory: 1024
 
    cpus: 1
 
    interfaces:
 
      - auto_config: true
 
        ip: 10.31.127.31
 
        network_name: private_network
 
        type: static
 

	
 
  - name: parameters-mandatory-stretch64
 
    groups:
 
      - parameters-mandatory
 
      - stretch
 
    box: debian/contrib-stretch64
 
    memory: 512
 
    memory: 1024
 
    cpus: 1
 
    interfaces:
 
      - auto_config: true
 
        ip: 10.31.127.32
 
        network_name: private_network
 
        type: static
 

	
 
  - name: parameters-optional-stretch64
 
    groups:
 
      - parameters-optional
 
      - stretch
 
    box: debian/contrib-stretch64
 
    memory: 512
 
    memory: 1024
 
    cpus: 1
 
    interfaces:
 
      - auto_config: true
 
        ip: 10.31.127.33
 
        network_name: private_network
 
        type: static
roles/mail_server/molecule/default/tests/test_optional.py
Show inline comments
 
import os
 
import re
 
import time
 
import uuid
 

	
 
import testinfra.utils.ansible_runner
 

	
 

	
 
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 
@@ -114,12 +115,13 @@ def test_local_aliases(host):
 
    Tests if local aliases are configured correctly.
 
    """
 

	
 
    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():
 
        mail_log = host.file('/var/log/mail.log')
 
        pattern = r"dovecot: lda\(john.doe@domain1\): msgid=<%s>: saved mail to INBOX" % message_id
 
        assert re.search(pattern, mail_log.content) is not None
roles/mail_server/tasks/main.yml
Show inline comments
 
@@ -270,22 +270,30 @@
 
    - /var/lib/clamav/main.cld
 
  register: clamav_db_files
 

	
 
- 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:
 
    name: "{{ item }}"
 
    state: started
 
  with_items:
 
    - 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
 
    state: started
 

	
 
- name: Enable Dovecot service
0 comments (0 inline, 0 general)