Blame SOURCES/bz1908146-bz1908147-bz1908148-bz1949114-openstack-agents-warn-when-openstackcli-slow.patch

e1b3f1
From ebea4c3620261c529cad908c0e52064df84b0c61 Mon Sep 17 00:00:00 2001
e1b3f1
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
e1b3f1
Date: Mon, 11 Jul 2022 10:28:11 +0200
e1b3f1
Subject: [PATCH] openstack-agents: warn when openstackcli is slow
e1b3f1
e1b3f1
---
e1b3f1
 heartbeat/openstack-cinder-volume | 19 +++++++++++--------
e1b3f1
 heartbeat/openstack-common.sh     | 22 ++++++++++++++++++++++
e1b3f1
 heartbeat/openstack-floating-ip   | 17 ++++++++++-------
e1b3f1
 heartbeat/openstack-info.in       | 20 ++++++++++----------
e1b3f1
 heartbeat/openstack-virtual-ip    | 20 ++++++++++----------
e1b3f1
 5 files changed, 63 insertions(+), 35 deletions(-)
e1b3f1
e1b3f1
diff --git a/heartbeat/openstack-cinder-volume b/heartbeat/openstack-cinder-volume
e1b3f1
index 19bf04faf..116442c41 100755
e1b3f1
--- a/heartbeat/openstack-cinder-volume
e1b3f1
+++ b/heartbeat/openstack-cinder-volume
e1b3f1
@@ -113,11 +113,14 @@ _get_node_id() {
e1b3f1
 }
e1b3f1
 
e1b3f1
 osvol_validate() {
e1b3f1
+	local result
e1b3f1
+
e1b3f1
 	check_binary "$OCF_RESKEY_openstackcli"
e1b3f1
 	
e1b3f1
 	get_config
e1b3f1
 
e1b3f1
-	if ! $OCF_RESKEY_openstackcli volume list|grep -q $OCF_RESKEY_volume_id ; then
e1b3f1
+	result=$(run_openstackcli "volume list")
e1b3f1
+	if ! echo "$result" | grep -q $OCF_RESKEY_volume_id; then
e1b3f1
 		ocf_exit_reason "volume-id $OCF_RESKEY_volume_id not found"
e1b3f1
 		return $OCF_ERR_CONFIGURED
e1b3f1
 	fi
e1b3f1
@@ -156,17 +159,17 @@ osvol_monitor() {
e1b3f1
 	# Is the volue attached?
e1b3f1
 	# We use the API
e1b3f1
 	#
e1b3f1
-	result=$($OCF_RESKEY_openstackcli volume show \
e1b3f1
+	result=$(run_openstackcli "volume show \
e1b3f1
 		--column status \
e1b3f1
 		--column attachments \
e1b3f1
 		--format value \
e1b3f1
-		$OCF_RESKEY_volume_id)
e1b3f1
+		$OCF_RESKEY_volume_id")
e1b3f1
 
e1b3f1
-	if echo "$result" | grep -q available ; then
e1b3f1
+	if echo "$result" | grep -q available; then
e1b3f1
 		ocf_log warn "$OCF_RESKEY_volume_id is not attached to any instance"
e1b3f1
 		return $OCF_NOT_RUNNING
e1b3f1
 	else
e1b3f1
-		export attached_server_id=$(echo $result|head -n1|
e1b3f1
+		export attached_server_id=$(echo "$result"|head -n1|
e1b3f1
 			grep -P -o "'server_id': '[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}'"|
e1b3f1
 			grep -P -o "[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}")
e1b3f1
 		ocf_log info "$OCF_RESKEY_volume_id is attached to instance $attached_server_id"
e1b3f1
@@ -199,7 +202,7 @@ osvol_stop() {
e1b3f1
 	#
e1b3f1
 	# Detach the volume
e1b3f1
 	#
e1b3f1
-	if ! $OCF_RESKEY_openstackcli server remove volume $node_id $OCF_RESKEY_volume_id ; then
e1b3f1
+	if ! run_openstackcli "server remove volume $node_id $OCF_RESKEY_volume_id"; then
e1b3f1
 		ocf_log error "Couldn't remove volume $OCF_RESKEY_volume_id from instance $node_id"
e1b3f1
 		return $OCF_ERR_GENERIC
e1b3f1
 	fi
e1b3f1
@@ -225,7 +228,7 @@ osvol_start() {
e1b3f1
 	# TODO: make it optional in case multi-attachment is allowed by Cinder
e1b3f1
 	#
e1b3f1
 	if [ ! -z $attached_server_id ] ; then
e1b3f1
-		if ! $OCF_RESKEY_openstackcli server remove volume $attached_server_id $OCF_RESKEY_volume_id ; then
e1b3f1
+		if ! run_openstackcli "server remove volume $attached_server_id $OCF_RESKEY_volume_id"; then
e1b3f1
 			ocf_log error "Couldn't remove volume $OCF_RESKEY_volume_id from instance $attached_server_id"
e1b3f1
 			return $OCF_ERR_GENERIC
e1b3f1
 		fi
e1b3f1
@@ -238,7 +241,7 @@ osvol_start() {
e1b3f1
 	#
e1b3f1
 	# Attach the volume
e1b3f1
 	#
e1b3f1
-	$OCF_RESKEY_openstackcli server add volume $node_id $OCF_RESKEY_volume_id
e1b3f1
+	run_openstackcli "server add volume $node_id $OCF_RESKEY_volume_id"
e1b3f1
 	if [ $? != $OCF_SUCCESS ]; then
e1b3f1
 		ocf_log error "Couldn't add volume $OCF_RESKEY_volume_id to instance $node_id"
e1b3f1
 		return $OCF_ERR_GENERIC
e1b3f1
diff --git a/heartbeat/openstack-common.sh b/heartbeat/openstack-common.sh
e1b3f1
index 4763c90db..b6eec09c2 100644
e1b3f1
--- a/heartbeat/openstack-common.sh
e1b3f1
+++ b/heartbeat/openstack-common.sh
e1b3f1
@@ -145,3 +145,25 @@ get_config() {
e1b3f1
 		OCF_RESKEY_openstackcli="${OCF_RESKEY_openstackcli} --os-project-domain-name $OCF_RESKEY_project_domain_name"
e1b3f1
 	fi
e1b3f1
 }
e1b3f1
+
e1b3f1
+run_openstackcli() {
e1b3f1
+	local cmd="${OCF_RESKEY_openstackcli} $1"
e1b3f1
+	local result
e1b3f1
+	local rc
e1b3f1
+	local start_time=$(date +%s)
e1b3f1
+	local end_time
e1b3f1
+	local elapsed_time
e1b3f1
+
e1b3f1
+	result=$($cmd)
e1b3f1
+	rc=$?
e1b3f1
+	end_time=$(date +%s)
e1b3f1
+	elapsed_time=$(expr $end_time - $start_time)
e1b3f1
+
e1b3f1
+	if [ $elapsed_time -gt 20 ]; then
e1b3f1
+		ocf_log warn "$cmd took ${elapsed_time}s to complete"
e1b3f1
+	fi
e1b3f1
+
e1b3f1
+	echo "$result"
e1b3f1
+
e1b3f1
+	return $rc
e1b3f1
+}
e1b3f1
diff --git a/heartbeat/openstack-floating-ip b/heartbeat/openstack-floating-ip
e1b3f1
index 6e2895654..7317f19a8 100755
e1b3f1
--- a/heartbeat/openstack-floating-ip
e1b3f1
+++ b/heartbeat/openstack-floating-ip
e1b3f1
@@ -101,11 +101,14 @@ END
e1b3f1
 }
e1b3f1
 
e1b3f1
 osflip_validate() {
e1b3f1
+	local result
e1b3f1
+
e1b3f1
 	check_binary "$OCF_RESKEY_openstackcli"
e1b3f1
 
e1b3f1
 	get_config
e1b3f1
 
e1b3f1
-	if ! $OCF_RESKEY_openstackcli floating ip list|grep -q $OCF_RESKEY_ip_id ; then
e1b3f1
+	result=$(run_openstackcli "floating ip list")
e1b3f1
+	if ! echo "$result" | grep -q $OCF_RESKEY_ip_id; then
e1b3f1
 		ocf_exit_reason "ip-id $OCF_RESKEY_ip_id not found"
e1b3f1
 		return $OCF_ERR_CONFIGURED
e1b3f1
 	fi
e1b3f1
@@ -132,14 +135,14 @@ osflip_monitor() {
e1b3f1
 		| awk '{gsub("[^ ]*:", "");print}')
e1b3f1
 
e1b3f1
 	# Is the IP active and attached?
e1b3f1
-	result=$($OCF_RESKEY_openstackcli floating ip show \
e1b3f1
+	result=$(run_openstackcli "floating ip show \
e1b3f1
 		--column port_id --column floating_ip_address \
e1b3f1
 		--format yaml \
e1b3f1
-		$OCF_RESKEY_ip_id)
e1b3f1
+		$OCF_RESKEY_ip_id")
e1b3f1
 
e1b3f1
 	for port in $node_port_ids ; do
e1b3f1
-		if echo $result | grep -q $port ; then
e1b3f1
-			floating_ip=$(echo $result | awk '/floating_ip_address/ {print $2}')
e1b3f1
+		if echo "$result" | grep -q $port ; then
e1b3f1
+			floating_ip=$(echo "$result" | awk '/floating_ip_address/ {print $2}')
e1b3f1
 			${HA_SBIN_DIR}/attrd_updater ${OCF_RESKEY_delay} -S status -n openstack_floating_ip -v $floating_ip
e1b3f1
 
e1b3f1
 			return $OCF_SUCCESS
e1b3f1
@@ -160,7 +163,7 @@ osflip_stop() {
e1b3f1
 		return $OCF_SUCCESS
e1b3f1
 	fi
e1b3f1
 
e1b3f1
-	if ! $OCF_RESKEY_openstackcli floating ip unset --port $OCF_RESKEY_ip_id ; then
e1b3f1
+	if ! run_openstackcli "floating ip unset --port $OCF_RESKEY_ip_id"; then
e1b3f1
 		return $OCF_ERR_GENERIC
e1b3f1
 	fi
e1b3f1
 
e1b3f1
@@ -194,7 +197,7 @@ osflip_start() {
e1b3f1
 
e1b3f1
 	ocf_log info "Moving IP address $OCF_RESKEY_ip_id to port ID $node_port_id"
e1b3f1
 
e1b3f1
-	$OCF_RESKEY_openstackcli floating ip set --port $node_port_id $OCF_RESKEY_ip_id
e1b3f1
+	run_openstackcli "floating ip set --port $node_port_id $OCF_RESKEY_ip_id"
e1b3f1
 	if [ $? != $OCF_SUCCESS ]; then
e1b3f1
 		ocf_log error "$OCF_RESKEY_ip_id Cannot be set to port $node_port_id"
e1b3f1
 		return $OCF_ERR_GENERIC
e1b3f1
diff --git a/heartbeat/openstack-info.in b/heartbeat/openstack-info.in
e1b3f1
index f3a59fc7a..6502f1df1 100755
e1b3f1
--- a/heartbeat/openstack-info.in
e1b3f1
+++ b/heartbeat/openstack-info.in
e1b3f1
@@ -119,9 +119,7 @@ END
e1b3f1
 #######################################################################
e1b3f1
 
e1b3f1
 OSInfoStats() {
e1b3f1
-	local result
e1b3f1
 	local value
e1b3f1
-	local node
e1b3f1
 	local node_id
e1b3f1
 
e1b3f1
 	get_config
e1b3f1
@@ -141,31 +139,33 @@ OSInfoStats() {
e1b3f1
 	${HA_SBIN_DIR}/attrd_updater ${OCF_RESKEY_delay} -n openstack_id -v "$node_id"
e1b3f1
 
e1b3f1
 	# Nova data: flavor
e1b3f1
-	value=$($OCF_RESKEY_openstackcli server show \
e1b3f1
+	value=$(run_openstackcli "server show \
e1b3f1
 		--format value \
e1b3f1
 		--column flavor \
e1b3f1
-		$node_id)
e1b3f1
+		$node_id")
e1b3f1
 
e1b3f1
 	${HA_SBIN_DIR}/attrd_updater ${OCF_RESKEY_delay} -n openstack_flavor -v "$value"
e1b3f1
 
e1b3f1
 	# Nova data: availability zone
e1b3f1
-	value=$($OCF_RESKEY_openstackcli server show \
e1b3f1
+	value=$(run_openstackcli "server show \
e1b3f1
 		--format value \
e1b3f1
 		--column OS-EXT-AZ:availability_zone \
e1b3f1
-		$node_id)
e1b3f1
+		$node_id")
e1b3f1
 
e1b3f1
 	${HA_SBIN_DIR}/attrd_updater ${OCF_RESKEY_delay} -n openstack_az -v "$value"
e1b3f1
 
e1b3f1
 	# Network data: ports
e1b3f1
 	value=""
e1b3f1
-	for port_id in $($OCF_RESKEY_openstackcli port list \
e1b3f1
+	for port_id in $(run_openstackcli "port list \
e1b3f1
 		--format value \
e1b3f1
 		--column id \
e1b3f1
-		--server $node_id); do
e1b3f1
-		subnet_id=$($OCF_RESKEY_openstackcli port show \
e1b3f1
+		--server $node_id"); do
e1b3f1
+		subnet_result=$(run_openstackcli "port show \
e1b3f1
 			--format json \
e1b3f1
 			--column fixed_ips \
e1b3f1
-			${port_id} | grep -P '\"subnet_id\": \".*\",$' |
e1b3f1
+			${port_id}")
e1b3f1
+		subnet_id=$(echo "$subnet_result" |
e1b3f1
+			grep -P '\"subnet_id\": \".*\",$' |
e1b3f1
 			grep -P -o '[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}')
e1b3f1
 		value="${value}${subnet_id}:${port_id},"
e1b3f1
 	done
e1b3f1
diff --git a/heartbeat/openstack-virtual-ip b/heartbeat/openstack-virtual-ip
e1b3f1
index c654d980a..361357d55 100755
e1b3f1
--- a/heartbeat/openstack-virtual-ip
e1b3f1
+++ b/heartbeat/openstack-virtual-ip
e1b3f1
@@ -132,11 +132,11 @@ osvip_monitor() {
e1b3f1
 
e1b3f1
 	node_port_id=$(osvip_port_id)
e1b3f1
 
e1b3f1
-	result=$($OCF_RESKEY_openstackcli port show \
e1b3f1
+	result=$(run_openstackcli "port show \
e1b3f1
 		--format value \
e1b3f1
 		--column allowed_address_pairs \
e1b3f1
-		${node_port_id})
e1b3f1
-	if echo $result | grep -q "$OCF_RESKEY_ip"; then
e1b3f1
+		${node_port_id}")
e1b3f1
+	if echo "$result" | grep -q "$OCF_RESKEY_ip"; then
e1b3f1
 		${HA_SBIN_DIR}/attrd_updater ${OCF_RESKEY_delay} -S status -n openstack_virtual_ip -v $OCF_RESKEY_ip
e1b3f1
 
e1b3f1
 		return $OCF_SUCCESS
e1b3f1
@@ -158,20 +158,20 @@ osvip_stop() {
e1b3f1
 		return $OCF_SUCCESS
e1b3f1
 	fi
e1b3f1
 
e1b3f1
-	mac_address=$($OCF_RESKEY_openstackcli port show \
e1b3f1
+	mac_address=$(run_openstackcli "port show \
e1b3f1
 		--format value \
e1b3f1
 		--column mac_address \
e1b3f1
-		$node_port_id)
e1b3f1
-	echo ${mac_address} | grep -q -P "^([0-9a-f]{2}:){5}[0-9a-f]{2}$"
e1b3f1
+		$node_port_id")
e1b3f1
+	echo "${mac_address}" | grep -q -P "^([0-9a-f]{2}:){5}[0-9a-f]{2}$"
e1b3f1
 	if [ $? -ne 0 ]; then
e1b3f1
 		ocf_log error "MAC address '${mac_address}' is not valid."
e1b3f1
 		return $OCF_ERR_GENERIC
e1b3f1
 	fi
e1b3f1
 
e1b3f1
-	if ! $OCF_RESKEY_openstackcli port unset \
e1b3f1
+	if ! run_openstackcli "port unset \
e1b3f1
 		--allowed-address \
e1b3f1
 		ip-address=$OCF_RESKEY_ip,mac-address=${mac_address} \
e1b3f1
-		$node_port_id; then
e1b3f1
+		$node_port_id"; then
e1b3f1
 		return $OCF_ERR_GENERIC
e1b3f1
 	fi
e1b3f1
 
e1b3f1
@@ -196,9 +196,9 @@ osvip_start() {
e1b3f1
 
e1b3f1
 	ocf_log info "Moving IP address $OCF_RESKEY_ip to port ID $node_port_id"
e1b3f1
 
e1b3f1
-	$OCF_RESKEY_openstackcli port set \
e1b3f1
+	run_openstackcli "port set \
e1b3f1
 		--allowed-address ip-address=$OCF_RESKEY_ip \
e1b3f1
-		$node_port_id
e1b3f1
+		$node_port_id"
e1b3f1
 	if [ $? != $OCF_SUCCESS ]; then
e1b3f1
 		ocf_log error "$OCF_RESKEY_ip Cannot be set to port $node_port_id"
e1b3f1
 		return $OCF_ERR_GENERIC