Files @ 5eeaa6ef80fd
Branch filter:

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

branko
MAR-194: Configure static IPv6 addresses for testing of common role:

- Requires some additional steps to be done when preparing the
development machine, since VirtualBox prohibits use of network
subnets that are not explicitly configured for use with private
networks.
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():

        scan = host.run('nmap -p 22 -oG - %s', target_host)

        assert scan.rc == 0
        assert "Ports: 22/open/tcp//ssh" in scan.stdout


@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():

        scan = host.run('nmap -p 80 -oG - %s', target_host)

        assert scan.rc == 0
        assert "Ports: 80/open/tcp//http" in scan.stdout