Blob Blame History Raw
From 5d47f08c60600708aae354b021da9779a9c8e5e6 Mon Sep 17 00:00:00 2001
From: Michele Baldessari <michele@acksyn.org>
Date: Wed, 3 Jun 2020 14:43:47 +0200
Subject: [PATCH] Make the notify() calls work with IPv6 in the OCF
 resource-agent

When the VIP is an IPv6 address we get the following error in the
resource agent:
ovndb_servers_notify_0:355:stderr [ + ovn-sbctl -- --id=@conn_uuid create Connection 'target=ptcp\:6642\:[fd00:fd00:fd00:2000::a2]' inactivity_probe=180000 -- set SB_Global . connections=@conn_uuid ]
ovndb_servers_notify_0:355:stderr [ ovn-sbctl: ptcp\:6642\:[fd00:fd00:fd00:2000::a2]: unexpected "[" parsing string ]

This is because MASTER_IP is an IPv6 address and is being passed to
ovn-[ns]bctl without being escaped and the command errors out with
unexpected parsing string errors. The rest of the create Connection
command was already escaping the columns, we are just missing the ip
address bits in case of IPv6.

Let's make sure we escape the '[]:' characters and avoid this problem.
Tested this on an OpenStack environment on both IPv6 and IPv4.

Signed-off-by: Michele Baldessari <michele@acksyn.org>
Signed-off-by: Numan Siddique <numans@ovn.org>
---
 utilities/ovndb-servers.ocf | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/utilities/ovndb-servers.ocf b/utilities/ovndb-servers.ocf
index 56c2bc322..7351c7d64 100755
--- a/utilities/ovndb-servers.ocf
+++ b/utilities/ovndb-servers.ocf
@@ -249,7 +249,9 @@ ovsdb_server_notify() {
         if [ "x${LISTEN_ON_MASTER_IP_ONLY}" = xno ]; then
            LISTEN_ON_IP="0.0.0.0"
         else
-           LISTEN_ON_IP=${MASTER_IP}
+           # ovn-[sn]bctl want ':[]' characters to be escaped. We do so in
+           # order to make this work when MASTER_IP is an IPv6 address.
+           LISTEN_ON_IP=$(sed -e 's/\(\[\|\]\|:\)/\\\1/g' <<< ${MASTER_IP})
         fi
         conn=`ovn-nbctl get NB_global . connections`
         if [ "$conn" == "[]" ]
-- 
2.26.2