From 32d134f45222b053e7c8c583fe268bee6aebb90c Mon Sep 17 00:00:00 2001
From: Guillem Jover <gjover@sipwise.com>
Date: Fri, 18 Oct 2024 21:04:46 +0200
Subject: [PATCH] MT#61304 Handle conflicting Prosody and HAProxy ports

These share the same ports depending on the role of the current node, so
to avoid emitting the same duplicate port entries we should turn these
into cascading if/elif.

This is being detected by new goss versions from Debian trixie as
errors, and causing the entire ngcp-system-tests run to fail.

Change-Id: I2898f623e87867a03ef6cfb728a90631f53ffae7
---
 templates/821_network-ports-ngcp.yaml.tt2 | 57 +++++++++++++++--------
 1 file changed, 37 insertions(+), 20 deletions(-)

diff --git a/templates/821_network-ports-ngcp.yaml.tt2 b/templates/821_network-ports-ngcp.yaml.tt2
index 90bc7cd..0045bc7 100644
--- a/templates/821_network-ports-ngcp.yaml.tt2
+++ b/templates/821_network-ports-ngcp.yaml.tt2
@@ -124,26 +124,6 @@ port:
     listening: {{.Vars.NODE_ACTIVE}}
     ip: ["[% sip_ext_ips.0 %]"]
 
-  # HAProxy: Prosody (xmpp-client)
-  tcp:5222:
-    listening: [% haproxy.enable == 'yes' ? 'true' : 'false' %]
-    ip: ["[% sip_ext_ips.0 %]"]
-
-  # HAProxy: Prosody (xmpp-server)
-  tcp:5269:
-    listening: [% haproxy.enable == 'yes' ? 'true' : 'false' %]
-    ip: ["[% sip_ext_ips.0 %]"]
-
-  # HAProxy: Prosody (http)
-  tcp:5281:
-    listening: [% haproxy.enable == 'yes' ? 'true' : 'false' %]
-    ip: ["[% sip_ext_ips.0 %]"]
-
-  # HAProxy admin
-  tcp:8080:
-    listening: [% haproxy.enable == 'yes' && haproxy.admin == 'yes' ? 'true' : 'false' %]
-    ip: ["[% sip_ext_ips.0 %]"]
-
 [% END -%]
 [% IF is_proxy -%]
   # Kamailio proxy
@@ -151,31 +131,68 @@ port:
     listening: {{.Vars.NODE_ACTIVE}}
     ip: ["[% sip_int_ips.0 %]"]
 
+[% END -%]
+[% IF is_proxy -%]
   # Prosody (xmpp-client)
   tcp:5222:
     listening: {{.Vars.NODE_ACTIVE}}
     ip: ["[% sip_proxy_ip %]"]
 
+[% ELSIF is_lb -%]
+  # HAProxy: Prosody (xmpp-client)
+  tcp:5222:
+    listening: [% haproxy.enable == 'yes' ? 'true' : 'false' %]
+    ip: ["[% sip_ext_ips.0 %]"]
+
+[% END -%]
+[% IF is_proxy -%]
   # Prosody (xmpp-server)
   tcp:5269:
     listening: {{.Vars.NODE_ACTIVE}}
     ip: ["[% sip_proxy_ip %]"]
 
+[% ELSIF is_lb -%]
+  # HAProxy: Prosody (xmpp-server)
+  tcp:5269:
+    listening: [% haproxy.enable == 'yes' ? 'true' : 'false' %]
+    ip: ["[% sip_ext_ips.0 %]"]
+
+[% END -%]
+[% IF is_proxy -%]
   # Prosody (http)
   tcp:5280:
     listening: {{.Vars.NODE_ACTIVE}}
     ip: ["[% sip_int_ips.0 %]"]
 
+[% END -%]
+[% IF is_proxy -%]
   # Prosody (https)
   tcp:5281:
     listening: {{.Vars.NODE_ACTIVE}}
     ip: ["[% sip_int_ips.0 %]"]
 
+[% ELSIF is_lb -%]
+  # HAProxy: Prosody (http)
+  tcp:5281:
+    listening: [% haproxy.enable == 'yes' ? 'true' : 'false' %]
+    ip: ["[% sip_ext_ips.0 %]"]
+
+[% END -%]
+[% IF is_proxy -%]
   # Prosody (ctrl)
   tcp:5582:
     listening: {{.Vars.NODE_ACTIVE}}
     ip: ["[% sip_int_ips.0 %]"]
 
+[% END -%]
+[% IF is_lb -%]
+  # HAProxy admin
+  tcp:8080:
+    listening: [% haproxy.enable == 'yes' && haproxy.admin == 'yes' ? 'true' : 'false' %]
+    ip: ["[% sip_ext_ips.0 %]"]
+
+[% END -%]
+[% IF is_proxy -%]
 [%  IF b2b.enable == "yes" -%]
   # SEMS: XMLRPC server of B2B
   tcp:[% b2b.xmlrpcport %]: