Blob Blame History Raw
From f2bf1d8a07ea810099b03469883cb7f485ab9ac1 Mon Sep 17 00:00:00 2001
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
Date: Mon, 27 Jul 2020 10:09:43 +0200
Subject: [PATCH 1/2] azure-events: import URLError and encode postData when
 necessary

---
 heartbeat/azure-events.in | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/heartbeat/azure-events.in b/heartbeat/azure-events.in
index d4a166d9f..a7f359468 100644
--- a/heartbeat/azure-events.in
+++ b/heartbeat/azure-events.in
@@ -13,8 +13,10 @@ import subprocess
 import json
 try:
 		import urllib2
+		from urllib2 import URLError
 except ImportError:
 		import urllib.request as urllib2
+		from urllib.error import URLError
 import socket
 from collections import defaultdict
 
@@ -76,9 +78,13 @@ class azHelper:
 		Send a request to Azure's Azure Metadata Service API
 		"""
 		url = "%s/%s?api-version=%s" % (azHelper.metadata_host, endpoint, azHelper.api_version)
+		data = ""
 		ocf.logger.debug("_sendMetadataRequest: begin; endpoint = %s, postData = %s" % (endpoint, postData))
 		ocf.logger.debug("_sendMetadataRequest: url = %s" % url)
 
+		if postData and type(postData) != bytes:
+			postData = postData.encode()
+
 		req = urllib2.Request(url, postData)
 		req.add_header("Metadata", "true")
 		req.add_header("User-Agent", USER_AGENT)

From 1ab5d71bff95eb271f1e1bbc401961dc313219d9 Mon Sep 17 00:00:00 2001
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
Date: Wed, 29 Jul 2020 21:25:43 +0200
Subject: [PATCH 2/2] azure-events: report error if jsondata not received

---
 heartbeat/azure-events.in | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/heartbeat/azure-events.in b/heartbeat/azure-events.in
index a7f359468..3a24d6358 100644
--- a/heartbeat/azure-events.in
+++ b/heartbeat/azure-events.in
@@ -117,8 +117,12 @@ class azHelper:
 		jsondata = azHelper._sendMetadataRequest(azHelper.instance_api)
 		ocf.logger.debug("getInstanceInfo: json = %s" % jsondata)
 
-		ocf.logger.debug("getInstanceInfo: finished, returning {}".format(jsondata["compute"]))
-		return attrDict(jsondata["compute"])
+		if jsondata:
+			ocf.logger.debug("getInstanceInfo: finished, returning {}".format(jsondata["compute"]))
+			return attrDict(jsondata["compute"])
+		else:
+			ocf.ocf_exit_reason("getInstanceInfo: Unable to get instance info")
+			sys.exit(ocf.OCF_ERR_GENERIC)
 
 	@staticmethod
 	def pullScheduledEvents():