Files @ f6bd1ff55982
Branch filter:

Location: majic-ansible-roles/roles/common/molecule/default/tests/test_maintenance_from_allowed_client.py

branko
MAR-191: Make tests for allowed/disallowed connections more generic:

- Use dynamic inventory to retrive the list of hosts instead of
hard-coding release names in the tests.
import os

import pytest

import testinfra.utils.ansible_runner


testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('client-allowed')

parameters_mandatory_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('parameters-mandatory')

parameters_optional_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('parameters-optional')


@pytest.mark.parametrize("target_host", parameters_mandatory_hosts + parameters_optional_hosts)
def test_ssh_connectivity(host, target_host):
    """
    Test if SSH server is reachable.
    """

    with host.sudo():

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


@pytest.mark.parametrize("target_host", parameters_mandatory_hosts + parameters_optional_hosts)
def test_http_connectivity(host, target_host):
    """
    Test if HTTP server is reachable.
    """

    with host.sudo():

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