Blame SOURCES/bz1115537-Improve-error-messages-for-scoped-cib-operations.patch

337c54
From 03b38736eef95a430e74298642cec3701cabc8d7 Mon Sep 17 00:00:00 2001
337c54
From: Tomas Jelinek <tojeline@redhat.com>
337c54
Date: Tue, 2 Dec 2014 14:58:44 +0100
337c54
Subject: [PATCH] Improve error messages for scoped cib operations
337c54
337c54
---
337c54
 pcs/cluster.py | 11 +++++++++++
337c54
 pcs/utils.py   |  5 ++++-
337c54
 2 files changed, 15 insertions(+), 1 deletion(-)
337c54
337c54
diff --git a/pcs/cluster.py b/pcs/cluster.py
337c54
index 8879316..9730e55 100644
337c54
--- a/pcs/cluster.py
337c54
+++ b/pcs/cluster.py
337c54
@@ -17,6 +17,7 @@ import tempfile
337c54
 import datetime
337c54
 import commands
337c54
 import json
337c54
+import xml.dom.minidom
337c54
 
337c54
 pcs_dir = os.path.dirname(os.path.realpath(__file__))
337c54
 COROSYNC_CONFIG_TEMPLATE = pcs_dir + "/corosync.conf.template"
337c54
@@ -667,6 +668,16 @@ def cluster_push(argv):
337c54
         usage.cluster(["cib-push"])
337c54
         sys.exit(1)
337c54
 
337c54
+    try:
337c54
+        new_cib_dom = xml.dom.minidom.parse(filename)
337c54
+        if scope and not new_cib_dom.getElementsByTagName(scope):
337c54
+            utils.err(
337c54
+                "unable to push cib, scope '%s' not present in new cib"
337c54
+                % scope
337c54
+            )
337c54
+    except (EnvironmentError, xml.parsers.expat.ExpatError) as e:
337c54
+        utils.err("unable to parse new cib: %s" % e)
337c54
+
337c54
     command = ["cibadmin", "--replace", "--xml-file", filename]
337c54
     if scope:
337c54
         command.append("--scope=%s" % scope)
337c54
diff --git a/pcs/utils.py b/pcs/utils.py
337c54
index 531b837..0e6c70c 100644
337c54
--- a/pcs/utils.py
337c54
+++ b/pcs/utils.py
337c54
@@ -1520,7 +1520,10 @@ def get_cib(scope=None):
337c54
         command.append("--scope=%s" % scope)
337c54
     output, retval = run(command)
337c54
     if retval != 0:
337c54
-        err("unable to get cib")
337c54
+        if retval == 6 and scope:
337c54
+            err("unable to get cib, scope '%s' not present in cib" % scope)
337c54
+        else:
337c54
+            err("unable to get cib")
337c54
     return output
337c54
 
337c54
 def get_cib_dom():
337c54
-- 
337c54
1.9.1
337c54