Blame SOURCES/bz1845574-azure-events-2-import-urlerror-encode-postdata.patch

bcdf71
From f2bf1d8a07ea810099b03469883cb7f485ab9ac1 Mon Sep 17 00:00:00 2001
bcdf71
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
bcdf71
Date: Mon, 27 Jul 2020 10:09:43 +0200
bcdf71
Subject: [PATCH 1/2] azure-events: import URLError and encode postData when
bcdf71
 necessary
bcdf71
bcdf71
---
bcdf71
 heartbeat/azure-events.in | 6 ++++++
bcdf71
 1 file changed, 6 insertions(+)
bcdf71
bcdf71
diff --git a/heartbeat/azure-events.in b/heartbeat/azure-events.in
bcdf71
index d4a166d9f..a7f359468 100644
bcdf71
--- a/heartbeat/azure-events.in
bcdf71
+++ b/heartbeat/azure-events.in
bcdf71
@@ -13,8 +13,10 @@ import subprocess
bcdf71
 import json
bcdf71
 try:
bcdf71
 		import urllib2
bcdf71
+		from urllib2 import URLError
bcdf71
 except ImportError:
bcdf71
 		import urllib.request as urllib2
bcdf71
+		from urllib.error import URLError
bcdf71
 import socket
bcdf71
 from collections import defaultdict
bcdf71
 
bcdf71
@@ -76,9 +78,13 @@ class azHelper:
bcdf71
 		Send a request to Azure's Azure Metadata Service API
bcdf71
 		"""
bcdf71
 		url = "%s/%s?api-version=%s" % (azHelper.metadata_host, endpoint, azHelper.api_version)
bcdf71
+		data = ""
bcdf71
 		ocf.logger.debug("_sendMetadataRequest: begin; endpoint = %s, postData = %s" % (endpoint, postData))
bcdf71
 		ocf.logger.debug("_sendMetadataRequest: url = %s" % url)
bcdf71
 
bcdf71
+		if postData and type(postData) != bytes:
bcdf71
+			postData = postData.encode()
bcdf71
+
bcdf71
 		req = urllib2.Request(url, postData)
bcdf71
 		req.add_header("Metadata", "true")
bcdf71
 		req.add_header("User-Agent", USER_AGENT)
bcdf71
bcdf71
From 1ab5d71bff95eb271f1e1bbc401961dc313219d9 Mon Sep 17 00:00:00 2001
bcdf71
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
bcdf71
Date: Wed, 29 Jul 2020 21:25:43 +0200
bcdf71
Subject: [PATCH 2/2] azure-events: report error if jsondata not received
bcdf71
bcdf71
---
bcdf71
 heartbeat/azure-events.in | 8 ++++++--
bcdf71
 1 file changed, 6 insertions(+), 2 deletions(-)
bcdf71
bcdf71
diff --git a/heartbeat/azure-events.in b/heartbeat/azure-events.in
bcdf71
index a7f359468..3a24d6358 100644
bcdf71
--- a/heartbeat/azure-events.in
bcdf71
+++ b/heartbeat/azure-events.in
bcdf71
@@ -117,8 +117,12 @@ class azHelper:
bcdf71
 		jsondata = azHelper._sendMetadataRequest(azHelper.instance_api)
bcdf71
 		ocf.logger.debug("getInstanceInfo: json = %s" % jsondata)
bcdf71
 
bcdf71
-		ocf.logger.debug("getInstanceInfo: finished, returning {}".format(jsondata["compute"]))
bcdf71
-		return attrDict(jsondata["compute"])
bcdf71
+		if jsondata:
bcdf71
+			ocf.logger.debug("getInstanceInfo: finished, returning {}".format(jsondata["compute"]))
bcdf71
+			return attrDict(jsondata["compute"])
bcdf71
+		else:
bcdf71
+			ocf.ocf_exit_reason("getInstanceInfo: Unable to get instance info")
bcdf71
+			sys.exit(ocf.OCF_ERR_GENERIC)
bcdf71
 
bcdf71
 	@staticmethod
bcdf71
 	def pullScheduledEvents():