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

15f218
From 7e4c0a0ea1cadf2c887994afa1e0f728ce64c1aa 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
---
15f218
 pcs/lib/pacemaker_state.py           | 13 ++++++++++---
15f218
 pcs/test/test_lib_pacemaker_state.py | 24 ++++++++++++++++++++----
15f218
 2 files changed, 30 insertions(+), 7 deletions(-)
15f218
15f218
diff --git a/pcs/lib/pacemaker_state.py b/pcs/lib/pacemaker_state.py
15f218
index b413b90..e300da7 100644
15f218
--- a/pcs/lib/pacemaker_state.py
15f218
+++ b/pcs/lib/pacemaker_state.py
15f218
@@ -136,10 +136,17 @@ class _NodeSection(_Element):
15f218
 def _get_valid_cluster_state_dom(xml):
15f218
     try:
15f218
         dom = etree.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):
15f218
diff --git a/pcs/test/test_lib_pacemaker_state.py b/pcs/test/test_lib_pacemaker_state.py
15f218
index 13f6eb0..83b30a3 100644
15f218
--- a/pcs/test/test_lib_pacemaker_state.py
15f218
+++ b/pcs/test/test_lib_pacemaker_state.py
15f218
@@ -5,6 +5,14 @@ from __future__ import (
15f218
     unicode_literals,
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
+
15f218
 from pcs.test.tools.pcs_unittest import TestCase
15f218
 from lxml import etree
15f218
 
15f218
@@ -84,16 +92,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
15f218
         self.covered_status.append_to_first_tag_name(
15f218
             'nodes',
15f218
             '<node without="required attributes" />'
15f218
         )
15f218
-
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
         )
15f218
 
15f218
+        sys.stdout = tmp_stdout
15f218
+
15f218
 
15f218
 class WorkWithClusterStatusNodesTest(TestBase):
15f218
     def fixture_node_string(self, **kwargs):
15f218
-- 
15f218
1.8.3.1
15f218