Bonjour,
Some of the testinfra tests are redundant with Ansible, in the sense that they verify something that is exactly what Ansible does, only written differently and therefore not DRY. Here is an example:
The testinfra test
@pytest.mark.parametrize('setting', [
'VERBOSE=yes',
'MAILDIR=/var/mail/',
'DEFAULT=$MAILDIR',
'LOGFILE=/var/log/procmail.log',
'SUBJECT=`formail -xSubject:`',
':0 c',
'*^To:.*root.*',
'|/var/ossec/send_encrypted_alarm.sh',
])
def test_procmail_settings(File, Sudo, setting):
"""
Ensure procmail settings are correct. These config lines determine
how the OSSEC email alerts are encrypted and then passed off for sending.
"""
# Sudo is required to traverse the /var/ossec directory.
with Sudo():
f = File("/var/ossec/.procmailrc")
assert f.contains('^{}$'.format(setting))
and the corresponding ansible code
- name: Copy procmail config file.
copy:
src: procmailrc
dest: /var/ossec/.procmailrc
owner: root
group: ossec
tags:
- procmail
which includes this file
VERBOSE=yes
MAILDIR=/var/mail/
DEFAULT=$MAILDIR
LOGFILE=/var/log/procmail.log
SUBJECT=`formail -xSubject:`
:0 c
*^To:.*root.*
|/var/ossec/send_encrypted_alarm.sh
In this case and many others, testinfra duplicates what Asnible does and running the corresponding ansible code twice to verify it does not change would do exactly the same thing.
Some testinfra tests are actually useful and do not have their equivalent in Ansible such as OSSEC rule tests.
I’m not proposing we cleanup all duplicates, that would not help much. But I propose that whenever we are modifying testinfra code for some reason, we should feel free to trim the tests that are duplicate of an ansible task.
What do you think ?