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