Changeset - 278ffa0d6f71
[Not reviewed]
0 2 0
Branko Majic (branko) - 10 months ago 2025-01-22 14:39:46
branko@majic.rs
MAR-233: Switch from hping3 to nmap for connectivity tests in the web_server role.
2 files changed with 3 insertions and 7 deletions:
0 comments (0 inline, 0 general)
roles/web_server/molecule/default/prepare.yml
Show inline comments
 
@@ -76,29 +76,24 @@
 
        192.168.56.22: "parameters-optional-bookworm"
 

	
 
    - name: Install curl for testing redirects and webpage content
 
      ansible.builtin.apt:
 
        name: curl
 
        state: present
 

	
 
- name: Prepare, helpers
 
  hosts: client
 
  become: true
 
  tasks:
 

	
 
    - name: Install tool for testing TCP connectivity
 
      ansible.builtin.apt:
 
        name: hping3
 
        state: present
 

	
 
    - name: Install console-based web browser for interactive testing
 
      ansible.builtin.apt:
 
        name: lynx
 
        state: present
 

	
 
    - name: Deploy CA certificate
 
      ansible.builtin.copy:
 
        src: tests/data/x509/ca/level1.cert.pem
 
        dest: /usr/local/share/ca-certificates/testca.crt
 
        owner: root
 
        group: root
 
        mode: "0644"
roles/web_server/molecule/default/tests/test_client.py
Show inline comments
 
@@ -11,14 +11,15 @@ testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 

	
 
@pytest.mark.parametrize('server', testinfra.utils.ansible_runner.AnsibleRunner(
 
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('parameters-*')
 
)
 
@pytest.mark.parametrize('port', [80, 443])
 
def test_connectivity(host, server, port):
 
    """
 
    Tests connectivity to the web server (ports that should be reachable).
 
    """
 

	
 
    with host.sudo():
 

	
 
        ping = host.run('hping3 -S -p %s -c 1 %s', str(port), server)
 
        assert ping.rc == 0
 
        scan = host.run('nmap -4 -p %s -oG - %s', str(port), server)
 
        assert scan.rc == 0
 
        assert "Ports: %d/open/tcp//" % port in scan.stdout
0 comments (0 inline, 0 general)