Blame SOURCES/show-only-warning-when-crm_mon-xml-is-invalid.patch

a3a2ad
From d290c211b3e4f6b56173a02fb0ef6f93b0192f17 Mon Sep 17 00:00:00 2001
15f218
From: Ivan Devat <idevat@redhat.com>
15f218
Date: Mon, 29 Aug 2016 18:16:41 +0200
15f218
Subject: [PATCH] show only warning when crm_mon xml is invalid
15f218
15f218
---
f778fe
 pcs/lib/pacemaker/state.py           | 13 ++++++++++---
f778fe
 pcs/lib/pacemaker/test/test_state.py | 24 ++++++++++++++++++++----
15f218
 2 files changed, 30 insertions(+), 7 deletions(-)
15f218
f778fe
diff --git a/pcs/lib/pacemaker/state.py b/pcs/lib/pacemaker/state.py
a3a2ad
index 6b87d8b9..6b71612d 100644
f778fe
--- a/pcs/lib/pacemaker/state.py
f778fe
+++ b/pcs/lib/pacemaker/state.py
a3a2ad
@@ -144,10 +144,17 @@ class _NodeSection(_Element):
f778fe
 def get_cluster_state_dom(xml):
15f218
     try:
f778fe
         dom = xml_fromstring(xml)
15f218
-        if os.path.isfile(settings.crm_mon_schema):
15f218
-            etree.RelaxNG(file=settings.crm_mon_schema).assertValid(dom)
15f218
+        if(
15f218
+            os.path.isfile(settings.crm_mon_schema)
15f218
+            and
15f218
+            not etree.RelaxNG(file=settings.crm_mon_schema).validate(dom)
15f218
+        ):
15f218
+            print(
15f218
+                "Warning: xml with cluster status does not conform to the"
15f218
+                " crm_mon schema"
15f218
+            )
15f218
         return dom
15f218
-    except (etree.XMLSyntaxError, etree.DocumentInvalid):
15f218
+    except etree.XMLSyntaxError:
15f218
         raise LibraryError(reports.cluster_state_invalid_format())
15f218
 
15f218
 class ClusterState(_Element):
f778fe
diff --git a/pcs/lib/pacemaker/test/test_state.py b/pcs/lib/pacemaker/test/test_state.py
a3a2ad
index 13628f44..5ea20d98 100644
f778fe
--- a/pcs/lib/pacemaker/test/test_state.py
f778fe
+++ b/pcs/lib/pacemaker/test/test_state.py
a3a2ad
@@ -4,6 +4,14 @@ from __future__ import (
a3a2ad
     print_function,
15f218
 )
15f218
 
15f218
+import sys
15f218
+try:
15f218
+    from cStringIO import StringIO
15f218
+except ImportError:
15f218
+    #python 3
15f218
+    from io import StringIO
15f218
+
15f218
+
f778fe
 from pcs.test.tools.pcs_unittest import TestCase, mock
15f218
 from lxml import etree
15f218
 
a3a2ad
@@ -86,16 +94,24 @@ class ClusterStatusTest(TestBase):
15f218
         )
15f218
 
15f218
     def test_refuse_invalid_document(self):
15f218
+        #commands writes to stdout
15f218
+        #we want clean test output, so we capture it
15f218
+        tmp_stdout = sys.stdout
15f218
+        stdout_catpture = StringIO()
15f218
+        sys.stdout = stdout_catpture
f778fe
+
15f218
         self.covered_status.append_to_first_tag_name(
15f218
             'nodes',
15f218
             '<node without="required attributes" />'
15f218
         )
f778fe
 
15f218
-        assert_raise_library_error(
15f218
-            lambda: ClusterState(str(self.covered_status)),
15f218
-            (severities.ERROR, report_codes.BAD_CLUSTER_STATE_FORMAT, {})
15f218
+        ClusterState(str(self.covered_status))
15f218
+        self.assertEqual(
15f218
+            stdout_catpture.getvalue(),
15f218
+            "Warning: xml with cluster status does not conform to the crm_mon"
15f218
+                " schema\n"
15f218
         )
f778fe
-
15f218
+        sys.stdout = tmp_stdout
15f218
 
15f218
 class WorkWithClusterStatusNodesTest(TestBase):
15f218
     def fixture_node_string(self, **kwargs):
15f218
-- 
a3a2ad
2.13.6
15f218