Fix parameter convertion for JSON array or object in LCM API payload 40/102740/1
authorEnbo Wang <wangenbo@huawei.com>
Mon, 2 Mar 2020 12:56:11 +0000 (20:56 +0800)
committerEnbo Wang <wangenbo@huawei.com>
Mon, 2 Mar 2020 12:56:11 +0000 (20:56 +0800)
This patch for Ansible server can dump the JSON array or object in LCM API
payload to a correct format of string, and the string can be reloaded
to array or object.

Change-Id: Ia5a5844ecaa3869acaeabd695afd41c113e63690
Issue-ID: CCSDK-2144
Signed-off-by: Enbo Wang <wangenbo@huawei.com>
ansible-server/src/main/ansible-server/RestServer.py

index 483b832..3f42bfe 100755 (executable)
@@ -329,6 +329,13 @@ def process_pnf_playbook(input_json, Id, EnvParameters, time_now):
     cherrypy.log("Request Decode: EnvParameters    " + json.dumps(EnvParameters))
     cherrypy.log("Request Decode: PlaybookName     " + PlaybookName)
 
+    for key in EnvParameters:
+        value = EnvParameters[key]
+        if isinstance(value, (list, dict)):
+            valueStr = json.dumps(value)
+            # Need to dump two times to keep the backslash and double quotes, add backslash and single quotes for spaces
+            EnvParameters[key] = "\\'" + json.dumps(valueStr)[1:-1] + "\\'"
+
     str_uuid = str(uuid.uuid4())
 
     HomeDir = os.path.dirname(os.path.realpath("~/"))