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

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