Blob Blame History Raw
From 2b49224c32d08bf4c008333f251c8f4ea1def4ef Mon Sep 17 00:00:00 2001
From: Ivan Devat <idevat@redhat.com>
Date: Mon, 29 Aug 2016 18:16:41 +0200
Subject: [PATCH 5/6] show only warning when crm_mon xml is invalid

---
 pcs/lib/pacemaker/state.py           | 13 ++++++++++---
 pcs/lib/pacemaker/test/test_state.py | 24 ++++++++++++++++++++----
 2 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/pcs/lib/pacemaker/state.py b/pcs/lib/pacemaker/state.py
index 6b87d8b9..6b71612d 100644
--- a/pcs/lib/pacemaker/state.py
+++ b/pcs/lib/pacemaker/state.py
@@ -144,10 +144,17 @@ class _NodeSection(_Element):
 def get_cluster_state_dom(xml):
     try:
         dom = xml_fromstring(xml)
-        if os.path.isfile(settings.crm_mon_schema):
-            etree.RelaxNG(file=settings.crm_mon_schema).assertValid(dom)
+        if(
+            os.path.isfile(settings.crm_mon_schema)
+            and
+            not etree.RelaxNG(file=settings.crm_mon_schema).validate(dom)
+        ):
+            print(
+                "Warning: xml with cluster status does not conform to the"
+                " crm_mon schema"
+            )
         return dom
-    except (etree.XMLSyntaxError, etree.DocumentInvalid):
+    except etree.XMLSyntaxError:
         raise LibraryError(reports.cluster_state_invalid_format())
 
 class ClusterState(_Element):
diff --git a/pcs/lib/pacemaker/test/test_state.py b/pcs/lib/pacemaker/test/test_state.py
index 13628f44..5ea20d98 100644
--- a/pcs/lib/pacemaker/test/test_state.py
+++ b/pcs/lib/pacemaker/test/test_state.py
@@ -4,6 +4,14 @@ from __future__ import (
     print_function,
 )
 
+import sys
+try:
+    from cStringIO import StringIO
+except ImportError:
+    #python 3
+    from io import StringIO
+
+
 from pcs.test.tools.pcs_unittest import TestCase, mock
 from lxml import etree
 
@@ -86,16 +94,24 @@ class ClusterStatusTest(TestBase):
         )
 
     def test_refuse_invalid_document(self):
+        #commands writes to stdout
+        #we want clean test output, so we capture it
+        tmp_stdout = sys.stdout
+        stdout_catpture = StringIO()
+        sys.stdout = stdout_catpture
+
         self.covered_status.append_to_first_tag_name(
             'nodes',
             '<node without="required attributes" />'
         )
 
-        assert_raise_library_error(
-            lambda: ClusterState(str(self.covered_status)),
-            (severities.ERROR, report_codes.BAD_CLUSTER_STATE_FORMAT, {})
+        ClusterState(str(self.covered_status))
+        self.assertEqual(
+            stdout_catpture.getvalue(),
+            "Warning: xml with cluster status does not conform to the crm_mon"
+                " schema\n"
         )
-
+        sys.stdout = tmp_stdout
 
 class WorkWithClusterStatusNodesTest(TestBase):
     def fixture_node_string(self, **kwargs):
-- 
2.21.0