From 9bc79c136d4fae9429d2278bb102b26c07a74889 2025-01-22 15:22:57 From: Branko Majic Date: 2025-01-22 15:22:57 Subject: [PATCH] MAR-233: Replace hping3 with nmap in connectivity tests for the xmpp_server role: - Parametrize the connectivity tests instead of running them in a loop. --- diff --git a/roles/xmpp_server/molecule/default/prepare.yml b/roles/xmpp_server/molecule/default/prepare.yml index 43db75b622315b31829c5d01f54bf28dfda094ef..a568bc57f92616cf45c07fdffb27e1637d01114b 100644 --- a/roles/xmpp_server/molecule/default/prepare.yml +++ b/roles/xmpp_server/molecule/default/prepare.yml @@ -99,11 +99,6 @@ become: true tasks: - - name: Install tool for testing TCP connectivity - ansible.builtin.apt: - name: hping3 - state: present - - name: Deploy CA certificate ansible.builtin.copy: src: tests/data/x509/ca/level1.cert.pem diff --git a/roles/xmpp_server/molecule/default/tests/test_client.py b/roles/xmpp_server/molecule/default/tests/test_client.py index 372d5fd364ce7ba00e0436a7a7dd804f140298d3..506962b96e1b670bae901da54682dd12c0edd230 100644 --- a/roles/xmpp_server/molecule/default/tests/test_client.py +++ b/roles/xmpp_server/molecule/default/tests/test_client.py @@ -9,20 +9,18 @@ testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('clients') -def test_connectivity(host): +@pytest.mark.parametrize('server', ['parameters-mandatory', 'parameters-optional']) +@pytest.mark.parametrize('port', [5222, 5223, 5000, 5269]) +def test_connectivity(host, server, port): """ Tests connectivity to the XMPP server (ports that should be reachable). """ with host.sudo(): - for server in ["parameters-mandatory", - "parameters-optional"]: - # c2s plaintext, c2s TLS, file proxy, s2s. - for port in [5222, 5223, 5000, 5269]: - - ping = host.run('hping3 -S -p %s -c 1 %s', str(port), server) - assert ping.rc == 0 + scan = host.run('nmap -p %s -oG - %s', str(port), server) + assert scan.rc == 0 + assert "Ports: %d/open/tcp//" % port in scan.stdout @pytest.mark.parametrize("username, password, domain", [