From 07ea4bec19958563e82bd8e863f64ba4f36850c0 Mon Sep 17 00:00:00 2001
From: Ivan Devat <idevat@redhat.com>
Date: Mon, 29 Aug 2016 18:16:41 +0200
Subject: [PATCH] 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 be3e7ad..cab72c8 100644
--- a/pcs/lib/pacemaker/state.py
+++ b/pcs/lib/pacemaker/state.py
@@ -145,10 +145,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 5de9426..70bd886 100644
--- a/pcs/lib/pacemaker/test/test_state.py
+++ b/pcs/lib/pacemaker/test/test_state.py
@@ -5,6 +5,14 @@ from __future__ import (
unicode_literals,
)
+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
@@ -87,16 +95,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):
--
1.8.3.1