Bug135: monitor parameter response to accept XML data
Signed-off-by: Sanil Puthiyandyil <sanil.puthiyandyil@riftio.com>
diff --git a/rwlaunchpad/plugins/rwmonparam/rift/tasklets/rwmonparam/vnfr_core.py b/rwlaunchpad/plugins/rwmonparam/rift/tasklets/rwmonparam/vnfr_core.py
index e798376..6dc3a25 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 @@
)
import rift.mano.dts as mano_dts
import rwlogger
-
+import xmltodict, json
class MonitoringParamError(Exception):
"""Monitoring Parameter error"""
@@ -437,6 +437,13 @@
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)
except MonitoringParamError as e:
diff --git a/rwlaunchpad/plugins/rwmonparam/test/utest_mon_params.py b/rwlaunchpad/plugins/rwmonparam/test/utest_mon_params.py
index a0817d7..fd48952 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.web
import unittest
import xmlrunner
+import xmltodict, json
import rift.tasklets.rwmonparam.vnfr_core as mon_params
@@ -918,6 +919,23 @@
self.assertEqual(value, 12112)
+
+class XMLReponseTest(unittest.TestCase):
+ xml_response = "<response status='success'><result> <entry> <current>2</current> <vsys>1</vsys> <maximum>0</maximum> <throttled>0</throttled> </entry> </result></response>"
+ 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