Blame SOURCES/bz1845574-azure-events-1-handle-exceptions-in-urlopen.patch

5371d1
From 194909ff08cfe75cd5da9f704d8ed4cc9ab40341 Mon Sep 17 00:00:00 2001
5371d1
From: Gustavo Figueira <gfigueira@suse.com>
5371d1
Date: Tue, 19 May 2020 10:58:34 +0200
5371d1
Subject: [PATCH 1/2] azure-events: handle exceptions in urlopen The locking in
5371d1
 azure-events does not correctly handle some failures.
5371d1
5371d1
If the metadata server is not recheable or has an error
5371d1
handling the request, attr_globalPullState will never go
5371d1
back to IDLE unless the administrator manually changes it.
5371d1
5371d1
> azure-events: ERROR: [Errno 104] Connection reset by peer
5371d1
> lrmd[2734]: notice: rsc_azure-events_monitor_10000:113088:stderr [ ocf-exit-reason:[Errno 104] Connection reset by peer ]
5371d1
---
5371d1
 heartbeat/azure-events.in | 16 +++++++++++++---
5371d1
 1 file changed, 13 insertions(+), 3 deletions(-)
5371d1
5371d1
diff --git a/heartbeat/azure-events.in b/heartbeat/azure-events.in
5371d1
index 8709d97e3..bd812f4b2 100644
5371d1
--- a/heartbeat/azure-events.in
5371d1
+++ b/heartbeat/azure-events.in
5371d1
@@ -82,9 +82,19 @@ class azHelper:
5371d1
 		req = urllib2.Request(url, postData)
5371d1
 		req.add_header("Metadata", "true")
5371d1
 		req.add_header("User-Agent", USER_AGENT)
5371d1
-		resp = urllib2.urlopen(req)
5371d1
-		data = resp.read()
5371d1
-		ocf.logger.debug("_sendMetadataRequest: response = %s" % data)
5371d1
+		try:
5371d1
+			resp = urllib2.urlopen(req)
5371d1
+		except URLError as e:
5371d1
+			if hasattr(e, 'reason'):
5371d1
+				print('We failed to reach a server. Reason: '), e.reason
5371d1
+				clusterHelper.setAttr(attr_globalPullState, "IDLE")
5371d1
+			elif hasattr(e, 'code'):
5371d1
+				print('The server couldn\'t fulfill the request. Error code: '), e.code
5371d1
+				clusterHelper.setAttr(attr_globalPullState, "IDLE")
5371d1
+		else:
5371d1
+			data = resp.read()
5371d1
+			ocf.logger.debug("_sendMetadataRequest: response = %s" % data)
5371d1
+
5371d1
 		if data:
5371d1
 			data = json.loads(data)
5371d1
 
5371d1
5371d1
From c4071ec4a82fcb831f170f341e0790633e4b904f Mon Sep 17 00:00:00 2001
5371d1
From: Gustavo Figueira <gfigueira@suse.com>
5371d1
Date: Tue, 19 May 2020 12:53:22 +0200
5371d1
Subject: [PATCH 2/2] azure-events: use ocf.logger.warning instead of print
5371d1
5371d1
---
5371d1
 heartbeat/azure-events.in | 4 ++--
5371d1
 1 file changed, 2 insertions(+), 2 deletions(-)
5371d1
5371d1
diff --git a/heartbeat/azure-events.in b/heartbeat/azure-events.in
5371d1
index bd812f4b2..a48a86309 100644
5371d1
--- a/heartbeat/azure-events.in
5371d1
+++ b/heartbeat/azure-events.in
5371d1
@@ -86,10 +86,10 @@ class azHelper:
5371d1
 			resp = urllib2.urlopen(req)
5371d1
 		except URLError as e:
5371d1
 			if hasattr(e, 'reason'):
5371d1
-				print('We failed to reach a server. Reason: '), e.reason
5371d1
+				ocf.logger.warning("Failed to reach the server: %s" % e.reason)
5371d1
 				clusterHelper.setAttr(attr_globalPullState, "IDLE")
5371d1
 			elif hasattr(e, 'code'):
5371d1
-				print('The server couldn\'t fulfill the request. Error code: '), e.code
5371d1
+				ocf.logger.warning("The server couldn\'t fulfill the request. Error code: %s" % e.code)
5371d1
 				clusterHelper.setAttr(attr_globalPullState, "IDLE")
5371d1
 		else:
5371d1
 			data = resp.read()