From 8d67cca58871b70712e5e931969d6cc0a3fef9ee 2025-01-21 23:13:11
From: Branko Majic <branko@majic.rs>
Date: 2025-01-21 23:13:11
Subject: [PATCH] MAR-233: Replace hping3 with nmap and add IPv6 connectivity tests in the ldap_server role.

---

diff --git a/roles/ldap_server/molecule/default/molecule.yml b/roles/ldap_server/molecule/default/molecule.yml
index ff43d52803a0286b796af858fa6d39342f445c6a..4e5204a0ae43627a7158b1b5fbf0be09d203d4db 100644
--- a/roles/ldap_server/molecule/default/molecule.yml
+++ b/roles/ldap_server/molecule/default/molecule.yml
@@ -20,6 +20,11 @@ platforms:
         ip: 192.168.56.11
         network_name: private_network
         type: static
+      - auto_config: true
+        ip: fd00::192:168:56:11
+        network_name: private_network
+        netmask: 116
+        type: static
 
   - name: parameters-mandatory-bookworm
     groups:
@@ -32,6 +37,11 @@ platforms:
         ip: 192.168.56.21
         network_name: private_network
         type: static
+      - auto_config: true
+        ip: fd00::192:168:56:21
+        network_name: private_network
+        netmask: 116
+        type: static
 
   - name: parameters-optional-bookworm
     groups:
@@ -45,6 +55,11 @@ platforms:
         ip: 192.168.56.22
         network_name: private_network
         type: static
+      - auto_config: true
+        ip: fd00::192:168:56:22
+        network_name: private_network
+        netmask: 116
+        type: static
 
 provisioner:
   name: ansible
diff --git a/roles/ldap_server/molecule/default/prepare.yml b/roles/ldap_server/molecule/default/prepare.yml
index 8da9fd860a43f6f760d0a390404e9c21a3683038..3725210fda5d862f2dc102025a41ba36d4392350 100644
--- a/roles/ldap_server/molecule/default/prepare.yml
+++ b/roles/ldap_server/molecule/default/prepare.yml
@@ -70,11 +70,6 @@
   become: true
   tasks:
 
-    - name: Install tool for teting TCP connectivity
-      ansible.builtin.apt:
-        name: hping3
-        state: present
-
     - name: Set-up /etc/hosts with entries for all servers
       ansible.builtin.lineinfile:
         path: /etc/hosts
@@ -87,6 +82,9 @@
       with_dict:
         192.168.56.21: parameters-mandatory-bookworm
         192.168.56.22: parameters-optional-bookworm
+        fd00::192:168:56:21: parameters-mandatory-bookworm
+        fd00::192:168:56:22: parameters-optional-bookworm
+
 
 - name: Prepare, test fixtures
   hosts: parameters-optional
diff --git a/roles/ldap_server/molecule/default/tests/test_client.py b/roles/ldap_server/molecule/default/tests/test_client.py
index 040da79b11e8de364bca351d13f5471ebe9b41e0..41119069a21e2a64669a26502eb6f7311bec414b 100644
--- a/roles/ldap_server/molecule/default/tests/test_client.py
+++ b/roles/ldap_server/molecule/default/tests/test_client.py
@@ -12,12 +12,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-*')
 )
-def test_connectivity(host, server):
+@pytest.mark.parametrize('ip_protocol', [4, 6])
+def test_connectivity(host, server, ip_protocol):
 
     with host.sudo():
 
-        ping = host.run('hping3 -S -p 389 -c 1 %s', server)
+        ping = host.run('nmap -%s -p 389 -oG - %s', str(ip_protocol), server)
         assert ping.rc == 0
+        assert "Ports: 389/open/tcp//ldap/" in ping.stdout
 
-        ping = host.run('hping3 -S -p 636 -c 1 %s', server)
+        ping = host.run('nmap -%s -p 636 -oG - %s', str(ip_protocol), server)
         assert ping.rc == 0
+        assert "Ports: 636/open/tcp//ldapssl/" in ping.stdout