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

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