Blame SOURCES/bz1235022-02-fix-crash-when-missing-nagios-metadata.patch

71541a
From 2c269bd74344dab5b55f398c90ab0077b3d31e21 Mon Sep 17 00:00:00 2001
71541a
From: Tomas Jelinek <tojeline@redhat.com>
71541a
Date: Fri, 4 Sep 2015 12:59:41 +0200
71541a
Subject: [PATCH] fix crash when missing nagios-metadata
71541a
71541a
---
71541a
 pcs/resource.py | 36 ++++++++++++++++++++----------------
71541a
 1 file changed, 20 insertions(+), 16 deletions(-)
71541a
71541a
diff --git a/pcs/resource.py b/pcs/resource.py
71541a
index 8e05aeb..2dcddc3 100644
71541a
--- a/pcs/resource.py
71541a
+++ b/pcs/resource.py
71541a
@@ -261,22 +261,26 @@ def resource_list_available(argv):
71541a
 
71541a
     # nagios metadata
71541a
     nagios_metadata_path = "/usr/share/pacemaker/nagios/plugins-metadata"
71541a
-    for metadata_file in sorted(os.listdir(nagios_metadata_path)):
71541a
-        if metadata_file.startswith("."):
71541a
-            continue
71541a
-        full_res_name = "nagios:" + metadata_file
71541a
-        if full_res_name.lower().endswith(".xml"):
71541a
-            full_res_name = full_res_name[:-len(".xml")]
71541a
-        if "--nodesc" in utils.pcs_options:
71541a
-            ret += full_res_name + "\n"
71541a
-            continue
71541a
-        try:
71541a
-            ret += get_name_and_desc(
71541a
-                full_res_name,
71541a
-                open(os.path.join(nagios_metadata_path, metadata_file), "r").read()
71541a
-            )
71541a
-        except EnvironmentError as e:
71541a
-            pass
71541a
+    if os.path.isdir(nagios_metadata_path):
71541a
+        for metadata_file in sorted(os.listdir(nagios_metadata_path)):
71541a
+            if metadata_file.startswith("."):
71541a
+                continue
71541a
+            full_res_name = "nagios:" + metadata_file
71541a
+            if full_res_name.lower().endswith(".xml"):
71541a
+                full_res_name = full_res_name[:-len(".xml")]
71541a
+            if "--nodesc" in utils.pcs_options:
71541a
+                ret += full_res_name + "\n"
71541a
+                continue
71541a
+            try:
71541a
+                ret += get_name_and_desc(
71541a
+                    full_res_name,
71541a
+                    open(
71541a
+                        os.path.join(nagios_metadata_path, metadata_file),
71541a
+                        "r"
71541a
+                    ).read()
71541a
+                )
71541a
+            except EnvironmentError as e:
71541a
+                pass
71541a
 
71541a
     # output
71541a
     if not ret:
71541a
-- 
71541a
1.9.1
71541a