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

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