From: Sanil Puthiyandyil Date: Thu, 22 Dec 2016 18:46:08 +0000 (+0000) Subject: Bug135: monitor parameter response to accept XML data X-Git-Tag: v1.1.0~39^2 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=bd419e1f55a4f489a346d47e874c3beb6cbbdd19;p=osm%2FSO.git Bug135: monitor parameter response to accept XML data Signed-off-by: Sanil Puthiyandyil --- diff --git a/rwlaunchpad/plugins/rwmonparam/rift/tasklets/rwmonparam/vnfr_core.py b/rwlaunchpad/plugins/rwmonparam/rift/tasklets/rwmonparam/vnfr_core.py index e7983763..6dc3a25b 100644 --- a/rwlaunchpad/plugins/rwmonparam/rift/tasklets/rwmonparam/vnfr_core.py +++ b/rwlaunchpad/plugins/rwmonparam/rift/tasklets/rwmonparam/vnfr_core.py @@ -36,7 +36,7 @@ from gi.repository import ( ) import rift.mano.dts as mano_dts import rwlogger - +import xmltodict, json class MonitoringParamError(Exception): """Monitoring Parameter error""" @@ -436,6 +436,13 @@ class MonitoringParam(object): self._log.warning("json querier is not created. Cannot extract value form response.") return + try: + xml_data = xmltodict.parse(response_msg) + json_msg=json.dumps(xml_data) + response_msg = json_msg + except Exception as e: + pass + try: value = self._json_querier.query(response_msg) converted_value = self._value_converter.convert(value) diff --git a/rwlaunchpad/plugins/rwmonparam/test/utest_mon_params.py b/rwlaunchpad/plugins/rwmonparam/test/utest_mon_params.py index a0817d7d..fd48952d 100755 --- a/rwlaunchpad/plugins/rwmonparam/test/utest_mon_params.py +++ b/rwlaunchpad/plugins/rwmonparam/test/utest_mon_params.py @@ -28,6 +28,7 @@ import tornado.testing import tornado.web import unittest import xmlrunner +import xmltodict, json import rift.tasklets.rwmonparam.vnfr_core as mon_params @@ -918,6 +919,23 @@ class PortLatencyTest(unittest.TestCase): self.assertEqual(value, 12112) + +class XMLReponseTest(unittest.TestCase): + xml_response = " 2 1 0 0 " + try: + op = xmltodict.parse(xml_response) + x=json.dumps(op) + y=json.loads(x) + system_response = y + except Exception as e: + print("Input is Not XML formatted") + pass + + def test_object_path_value_querier(self): + kv_querier = mon_params.ObjectPathValueQuerier(logger, "$.response.result.entry.current") + value = kv_querier.query(tornado.escape.json_encode(self.system_response)) + self.assertEqual(value, '2') + def main(argv=sys.argv[1:]): # The unittest framework requires a program name, so use the name of this