From 4ead053031ff6ea186aa5c8876e37507aa6a3577 Mon Sep 17 00:00:00 2001 From: Darren Worrall Date: Tue, 15 Sep 2015 16:40:01 +0100 Subject: [PATCH 1/2] Initialise `stream` variable Fixes `UnboundLocalError: local variable 'stream' referenced before assignment` when the check path doesnt exist --- monitoring/sensu_check.py | 1 + 1 file changed, 1 insertion(+) diff --git a/monitoring/sensu_check.py b/monitoring/sensu_check.py index a1bd36ca665..e1c51463aeb 100644 --- a/monitoring/sensu_check.py +++ b/monitoring/sensu_check.py @@ -182,6 +182,7 @@ def sensu_check(module, path, name, state='present', backup=False): except ImportError: import simplejson as json + stream = None try: try: stream = open(path, 'r') From b0926125c27aae105be2e4c335c43d05b2f560a6 Mon Sep 17 00:00:00 2001 From: Darren Worrall Date: Tue, 15 Sep 2015 16:43:26 +0100 Subject: [PATCH 2/2] Fix json loading in sensu_check Fixes `AttributeError: 'str' object has no attribute 'read'` when the check path exists --- monitoring/sensu_check.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monitoring/sensu_check.py b/monitoring/sensu_check.py index e1c51463aeb..c73fafdcd62 100644 --- a/monitoring/sensu_check.py +++ b/monitoring/sensu_check.py @@ -186,7 +186,7 @@ def sensu_check(module, path, name, state='present', backup=False): try: try: stream = open(path, 'r') - config = json.load(stream.read()) + config = json.load(stream) except IOError, e: if e.errno is 2: # File not found, non-fatal if state == 'absent':