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

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