Hello Piotr Kliczewski,
I'd like you to do a code review. Please visit
http://gerrit.ovirt.org/21506
to review the following change.
Change subject: xmlrpc: Parsing error logging enhancement - vdsClient
......................................................................
xmlrpc: Parsing error logging enhancement - vdsClient
Logging enhancement which helps understand the issues during
parsing xml response obtained from vdsm. Parsing
issues can occur when bad characters are in xml etc.
In order to get raw response we need to wrap one of transport
classes (plain or provided class for ssl) and present it to
the user when ExpatError is raised.
Change-Id: I0c39ac88e82f2e511f0025f18586e7a251a17321
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=982065
Signed-off-by: pkliczewski <[email protected]>
Signed-off-by: Vinzenz Feenstra <[email protected]>
---
M lib/vdsm/vdscli.py.in
M tests/Makefile.am
A tests/transportWrapperTests.py
3 files changed, 60 insertions(+), 3 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/06/21506/1
diff --git a/lib/vdsm/vdscli.py.in b/lib/vdsm/vdscli.py.in
index b656c87..6b514d1 100644
--- a/lib/vdsm/vdscli.py.in
+++ b/lib/vdsm/vdscli.py.in
@@ -23,12 +23,33 @@
import subprocess
import os
import re
+import sys
+import types
+from xml.parsers.expat import ExpatError
from . import SecureXMLRPCServer
+
d_useSSL = False
d_tsPath = '@TRUSTSTORE@'
d_addr = '0'
d_port = '54321'
+
+
+class TransportWrapper(xmlrpclib.Transport):
+ def __init__(self, transport):
+ TransportWrapper.__init__(self)
+ self._orig_parse_response = transport.parse_response
+ transport.parse_response = types.MethodType(
+ self.wrapped_parse_response,
+ transport)
+
+ def wrapped_parse_response(self, *args, **kwargs):
+ try:
+ return self._orig_parse_response(*args[1:], **kwargs)
+ except ExpatError:
+ sys.stderr.write('Parsing error was thrown during parsing '
+ 'response when provided: {}'.format(args[1]))
+ raise
class SingleRequestTransport(xmlrpclib.Transport):
@@ -143,10 +164,10 @@
transport = TransportClass(key_file=KEYFILE,
cert_file=CERTFILE, ca_certs=CACERT)
server = xmlrpclib.ServerProxy('https://%s' % hostPort,
- transport=transport)
+ TransportWrapper(transport))
else:
- server = xmlrpclib.Server('http://%s' % hostPort,
- transport=SingleRequestTransport())
+ transport = TransportWrapper(SingleRequestTransport())
+ server = xmlrpclib.Server('http://%s' % hostPort, transport)
return server
if __name__ == '__main__':
diff --git a/tests/Makefile.am b/tests/Makefile.am
index de20e8d..435beca 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -63,6 +63,7 @@
sslTests.py \
storageMailboxTests.py \
tcTests.py \
+ transportWrapperTests.py \
utilsTests.py \
vdsClientTests.py \
vmTestsData.py \
diff --git a/tests/transportWrapperTests.py b/tests/transportWrapperTests.py
new file mode 100644
index 0000000..93aa77c
--- /dev/null
+++ b/tests/transportWrapperTests.py
@@ -0,0 +1,35 @@
+#
+# Copyright 2013 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+
+from testrunner import VdsmTestCase as TestCaseBase
+from vdsm.vdscli import TransportWrapper
+
+
+class FakeTransport:
+ def parse_response(self, response):
+ return response
+
+
+class TransportTest(TestCaseBase):
+ def testTransportWrapper(self):
+ transport = FakeTransport()
+ TransportWrapper(transport)
+ response = 'My response'
+ self.assertEquals(response, transport.parse_response(response))
--
To view, visit http://gerrit.ovirt.org/21506
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0c39ac88e82f2e511f0025f18586e7a251a17321
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Vinzenz Feenstra <[email protected]>
Gerrit-Reviewer: Piotr Kliczewski <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches