Changeset - 65ad7f138939
[Not reviewed]
0 4 0
Branko Majic (branko) - 6 years ago 2018-08-01 11:01:31
branko@majic.rs
MAR-132: Parametrise tests in ldap_server role:

- Dynamically obtain inventory hostnames (don't hard-code them).
- Parametrise connectivity test, switching to using inventory
hostnames along the way (instead of hard-coded IPs in tests.
- Populate /etc/hosts with inventory hostnames in client machine (used
for connectivity tests).
4 files changed with 27 insertions and 15 deletions:
0 comments (0 inline, 0 general)
roles/ldap_server/molecule/default/prepare.yml
Show inline comments
 
@@ -35,6 +35,19 @@
 
        name: hping3
 
        state: present
 

	
 
    - name: Set-up /etc/hosts with entries for all servers
 
      lineinfile:
 
        path: /etc/hosts
 
        regexp: "^{{ item.key }}"
 
        line: "{{ item.key }} {{ item.value }}"
 
        owner: root
 
        group: root
 
        mode: 0644
 
        state: present
 
      with_dict:
 
        10.31.127.20: parameters-mandatory-jessie64.local
 
        10.31.127.21: parameters-optional-jessie64
 

	
 
- hosts: parameters-optional
 
  become: true
 
  tasks:
roles/ldap_server/molecule/default/tests/test_client.py
Show inline comments
 
import os
 

	
 
import pytest
 

	
 
import testinfra.utils.ansible_runner
 

	
 

	
 
@@ -7,18 +9,15 @@ testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts(['client'])
 

	
 

	
 
def test_connectivity(host):
 
@pytest.mark.parametrize('server', testinfra.utils.ansible_runner.AnsibleRunner(
 
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts(['parameters-mandatory', 'parameters-optional'])
 
)
 
def test_connectivity(host, server):
 

	
 
    with host.sudo():
 

	
 
        ping = host.run('hping3 -S -p 389 -c 1 10.31.127.20')
 
        assert ping.rc == 0
 

	
 
        ping = host.run('hping3 -S -p 636 -c 1 10.31.127.20')
 
        assert ping.rc == 0
 

	
 
        ping = host.run('hping3 -S -p 389 -c 1 10.31.127.21')
 
        ping = host.run('hping3 -S -p 389 -c 1 %s', server)
 
        assert ping.rc == 0
 

	
 
        ping = host.run('hping3 -S -p 636 -c 1 10.31.127.21')
 
        ping = host.run('hping3 -S -p 636 -c 1 %s', server)
 
        assert ping.rc == 0
roles/ldap_server/molecule/default/tests/test_mandatory.py
Show inline comments
 
@@ -41,7 +41,7 @@ def test_ldap_tls_private_key_file(host):
 

	
 
    with host.sudo():
 

	
 
        inventory_hostname = "parameters-mandatory-jessie64.local"
 
        inventory_hostname = host.ansible.get_variables()['inventory_hostname']
 

	
 
        key = host.file('/etc/ssl/private/%s_ldap.key' % inventory_hostname)
 

	
 
@@ -59,7 +59,7 @@ def test_ldap_tls_certificate_file(host):
 

	
 
    with host.sudo():
 

	
 
        inventory_hostname = "parameters-mandatory-jessie64.local"
 
        inventory_hostname = host.ansible.get_variables()['inventory_hostname']
 

	
 
        cert = host.file('/etc/ssl/certs/%s_ldap.pem' % inventory_hostname)
 

	
 
@@ -76,7 +76,7 @@ def test_certificate_validity_check_configuration(host):
 
    correctly.
 
    """
 

	
 
    inventory_hostname = "parameters-mandatory-jessie64.local"
 
    inventory_hostname = host.ansible.get_variables()['inventory_hostname']
 

	
 
    config = host.file('/etc/check_certificate/%s_ldap.conf' % inventory_hostname)
 

	
roles/ldap_server/molecule/default/tests/test_optional.py
Show inline comments
 
@@ -41,7 +41,7 @@ def test_ldap_tls_private_key_file(host):
 

	
 
    with host.sudo():
 

	
 
        inventory_hostname = "parameters-optional-jessie64"
 
        inventory_hostname = host.ansible.get_variables()['inventory_hostname']
 

	
 
        key = host.file('/etc/ssl/private/%s_ldap.key' % inventory_hostname)
 

	
 
@@ -59,7 +59,7 @@ def test_ldap_tls_certificate_file(host):
 

	
 
    with host.sudo():
 

	
 
        inventory_hostname = "parameters-optional-jessie64"
 
        inventory_hostname = host.ansible.get_variables()['inventory_hostname']
 

	
 
        cert = host.file('/etc/ssl/certs/%s_ldap.pem' % inventory_hostname)
 

	
 
@@ -76,7 +76,7 @@ def test_certificate_validity_check_configuration(host):
 
    correctly.
 
    """
 

	
 
    inventory_hostname = "parameters-optional-jessie64"
 
    inventory_hostname = host.ansible.get_variables()['inventory_hostname']
 

	
 
    config = host.file('/etc/check_certificate/%s_ldap.conf' % inventory_hostname)
 

	
0 comments (0 inline, 0 general)