Bug135: monitor parameter response to accept XML data 32/832/1
authorSanil Puthiyandyil <sanil.puthiyandyil@riftio.com>
Thu, 22 Dec 2016 18:46:08 +0000 (18:46 +0000)
committerSanil Puthiyandyil <sanil.puthiyandyil@riftio.com>
Thu, 22 Dec 2016 19:01:56 +0000 (19:01 +0000)
Signed-off-by: Sanil Puthiyandyil <sanil.puthiyandyil@riftio.com>
rwlaunchpad/plugins/rwmonparam/rift/tasklets/rwmonparam/vnfr_core.py
rwlaunchpad/plugins/rwmonparam/test/utest_mon_params.py

index e798376..6dc3a25 100644 (file)
@@ -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)
index a0817d7..fd48952 100755 (executable)
@@ -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 = "<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