From 007e761e4357f0f89a81f0f087e37f6fc3d61551 Mon Sep 17 00:00:00 2001
From: Fabian Herschel <fabian.herschel@suse.com>
Date: Fri, 5 Jul 2024 13:09:45 +0200
Subject: [PATCH] angi: ra - improved handling for timeout-return-codes (>=124,
 <124)

---
 ra/saphana-controller-common-lib |  8 ++++----
 ra/saphana-controller-lib        |  2 +-
 ra/saphana-topology-lib          | 10 +++++-----
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/ra/saphana-controller-common-lib b/ra/saphana-controller-common-lib
index 11055fdd..5482e04e 100755
--- a/ra/saphana-controller-common-lib
+++ b/ra/saphana-controller-common-lib
@@ -559,15 +559,15 @@ function get_hana_landscape_status() {
     else
         super_ocf_log info "RUNTIME do NOT use cached value for lss return code (cache_mode=$cache_mode, g_cache_lss=$g_cache_lss)"
         hana_LSS_Out=$(HANA_CALL --timeout "$HANA_CALL_TIMEOUT" --cmd "python landscapeHostConfiguration.py --sapcontrol=1" 2>/dev/null); rc=$?
-        if [[ "$rc" == 124 ]]; then
+        if [[ "$rc" -ge 124 ]]; then
             # TODO: PRIO 1: Check, if we should loop here like 'for i in 1 2 3 ...' ?
             # landscape timeout
-            super_ocf_log warn "RA: landscapeHostConfiguration.py TIMEOUT after $HANA_CALL_TIMEOUT seconds"
+            super_ocf_log warn "RA: landscapeHostConfiguration.py TIMEOUT after $HANA_CALL_TIMEOUT seconds (rc=$rc)"
             sleep 20
             # shellcheck disable=SC2034
             hana_LSS_Out=$(HANA_CALL --timeout "$HANA_CALL_TIMEOUT" --cmd "python landscapeHostConfiguration.py --sapcontrol=1" 2>/dev/null); rc=$?
-            if [ "$rc" == 124 ]; then
-               super_ocf_log warn "RA: landscapeHostConfiguration.py second TIMEOUT after $HANA_CALL_TIMEOUT seconds"
+            if [ "$rc" -ge 124 ]; then
+               super_ocf_log warn "RA: landscapeHostConfiguration.py second TIMEOUT after $HANA_CALL_TIMEOUT seconds (rc=$rc)"
                # TODO PRIO2: How to handle still hanging lss - current solution is to say "FATAL" - Maybe we should return the stored attribute value?
                rc=0
             fi
diff --git a/ra/saphana-controller-lib b/ra/saphana-controller-lib
index 34db1a92..dac3ce5c 100755
--- a/ra/saphana-controller-lib
+++ b/ra/saphana-controller-lib
@@ -161,7 +161,7 @@ function saphana_print_parameters() {
         <shortdesc lang="en">Define timeout how long a call to HANA to receive information can take.</shortdesc>
         <longdesc lang="en">Define timeout how long a call to HANA to receive information can take. This could be eg landscapeHostConfiguration.py.
           There are some specific calls to HANA which have their own timeout values. For example the takeover command does not timeout (inf).
-          If the timeout is reached, the return code will be 124. If you increase the timeouts for HANA calls you should also adjust the operation timeouts
+          If the timeout is reached, the return code will be 124 or 137 (for kill -9). If you increase the timeouts for HANA calls you should also adjust the operation timeouts
           of your cluster resources.
         </longdesc>
         <content type="string" default="120" />
diff --git a/ra/saphana-topology-lib b/ra/saphana-topology-lib
index 9915c418..60916c7a 100755
--- a/ra/saphana-topology-lib
+++ b/ra/saphana-topology-lib
@@ -113,7 +113,7 @@ SAPHanaTopology scans the output table of landscapeHostConfiguration.py to ident
         <shortdesc lang="en">Define timeout how long a call to HANA to receive information can take.</shortdesc>
         <longdesc lang="en">Define timeout how long a call to HANA to receive information can take. This could be eg landscapeHostConfiguration.py.
           There are some specific calls to HANA which have their own timeout values. For example the takeover command does not timeout (inf).
-          If the timeout is reached, the return code will be 124. If you increase the timeouts for HANA calls you should also adjust the operation timeouts
+          If the timeout is reached, the return code will be 124 or 137 (for kill -9). If you increase the timeouts for HANA calls you should also adjust the operation timeouts
           of your cluster resources.
         </longdesc>
         <content type="string" default="120" />
@@ -283,7 +283,7 @@ function sht_start() {
         start_saphostagent
     fi
     gNodeRole="$( get_role_by_landscape "$gVirtName")"; hanalrc="$?"
-    if [[ "$hanalrc" != 124 ]]; then
+    if [[ "$hanalrc" -lt 124 ]]; then
         set_hana_attribute "${NODENAME}" "$gNodeRole" "${ATTR_NAME_HANA_ROLES[@]}"
     fi
     # TODO PRIO 1: scale-out used side-effect via RC_hdbnsutil to give back different return codes; scale-up rc was always OCF_SUCCESS
@@ -451,7 +451,7 @@ function sht_stop_clone() {
     fi
     get_local_virtual_name
     gNodeRole="$( get_role_by_landscape "$gVirtName" --timeout="$timeout")"; hanalrc="$?"
-    if [[ "$hanalrc" != "124" ]]; then
+    if [[ "$hanalrc" -lt "124" ]]; then
         # normal exit, use gNodeRole
         tout=0
         set_hana_attribute "${NODENAME}" "$gNodeRole" "${ATTR_NAME_HANA_ROLES[@]}"
@@ -519,7 +519,7 @@ function sht_monitor_clone() {
         done
         g_cache_lss="$hanalrc"
         super_ocf_log info "DEC: gNodeRole=$gNodeRole gTopology=$gTopology hanalrc=$g_cache_lss"
-        if [[ "$hanalrc" != "124" ]]; then
+        if [[ "$hanalrc" -lt "124" ]]; then
             # normal exit, use gNodeRole
             super_ocf_log info "DEC: gNodeRole=$gNodeRole"
             set_hana_attribute "${NODENAME}" "$gNodeRole" "${ATTR_NAME_HANA_ROLES[@]}"
@@ -536,7 +536,7 @@ function sht_monitor_clone() {
             super_ocf_log info "DEC: set_hana_attribute ${NODENAME} $gSite ${ATTR_NAME_HANA_SITE[0]}"
         fi
         # TODO PRIO2: NG - COULD/SHOULD WE LIMIT THE SET OF THE LSS/SRR ATTRIBUTE TO ONLY THE_MASTER nodes?
-        # ignore timeout (124) and "ignore" (5) as return code from the landscapeHostConfiguration call
+        # ignore timeout (124, 137) and "ignore" (5) as return code from the landscapeHostConfiguration call
         case "$hanaPrim" in
             P ) ;;
             S ) # only secondary may propagate its sync status
