Changeset - f6bd1ff55982
[Not reviewed]
0 2 0
Branko Majic (branko) - 2 months ago 2024-02-10 13:17:27
branko@majic.rs
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.
2 files changed with 35 insertions and 35 deletions:
0 comments (0 inline, 0 general)
roles/common/molecule/default/tests/test_maintenance_from_allowed_client.py
Show inline comments
 
@@ -8,38 +8,32 @@ 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')
 

	
 
@pytest.mark.parametrize("platform", [
 
    "buster",
 
    "bullseye"
 
])
 
def test_ssh_connectivity(host, platform):
 
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', 'parameters-mandatory-%s' % platform)
 
        assert ping.rc == 0
 

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

	
 

	
 
@pytest.mark.parametrize("platform", [
 
    "buster",
 
    "bullseye"
 
])
 
def test_http_connectivity(host, platform):
 
@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', 'parameters-mandatory-%s' % platform)
 
        assert ping.rc == 0
 

	
 
        ping = host.run('hping3 -S -p 80 -c 1 %s', 'parameters-optional-%s' % platform)
 
        ping = host.run('hping3 -S -p 80 -c 1 %s', target_host)
 
        assert ping.rc == 0
roles/common/molecule/default/tests/test_maintenance_from_disallowed_client.py
Show inline comments
 
@@ -8,38 +8,44 @@ import testinfra.utils.ansible_runner
 
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('client-disallowed')
 

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

	
 
@pytest.mark.parametrize("platform", [
 
    "buster",
 
    "bullseye"
 
])
 
def test_ssh_connectivity(host, platform):
 
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', 'parameters-mandatory-%s' % platform)
 
        assert ping.rc == 0
 

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

	
 

	
 
@pytest.mark.parametrize("platform", [
 
    "buster",
 
    "bullseye"
 
])
 
def test_http_connectivity(host, platform):
 
@pytest.mark.parametrize("target_host", parameters_mandatory_hosts)
 
def test_http_connectivity_allowed(host, target_host):
 
    """
 
    Test if HTTP server is reachable.
 
    """
 

	
 
    with host.sudo():
 

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

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

	
 
@pytest.mark.parametrize("target_host", parameters_optional_hosts)
 
def test_http_connectivity_disallowed(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 == 1
0 comments (0 inline, 0 general)