)
import rift.mano.dts as mano_dts
import rwlogger
-
+import xmltodict, json
class MonitoringParamError(Exception):
"""Monitoring Parameter error"""
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)
import tornado.web
import unittest
import xmlrunner
+import xmltodict, json
import rift.tasklets.rwmonparam.vnfr_core as mon_params
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