summaryrefslogtreecommitdiffstats
path: root/ms/command-executor/src/main/python/utils.py
diff options
context:
space:
mode:
authorOleg Mitsura <oleg.mitsura@amdocs.com>2020-07-08 03:07:07 -0400
committerOleg Mitsura <oleg.mitsura@amdocs.com>2020-07-08 09:09:49 -0400
commit4ad951ee4c3ed41ca58a240e8b9193416c304b20 (patch)
treed2812e247957a6d097f2ea2a9d01f8b5a8e71591 /ms/command-executor/src/main/python/utils.py
parentf8cef69cf00a48a5aa352c17210f5befdcaa297d (diff)
cmd-exec server-side timeout.
Issue-ID: CCSDK-2535 Signed-off-by: Oleg Mitsura <oleg.mitsura@amdocs.com> Change-Id: I897678a5a8a23503a878f2d3eb836ba4597a6e6e
Diffstat (limited to 'ms/command-executor/src/main/python/utils.py')
-rw-r--r--ms/command-executor/src/main/python/utils.py33
1 files changed, 32 insertions, 1 deletions
diff --git a/ms/command-executor/src/main/python/utils.py b/ms/command-executor/src/main/python/utils.py
index 180cd8c12..54c5ceafa 100644
--- a/ms/command-executor/src/main/python/utils.py
+++ b/ms/command-executor/src/main/python/utils.py
@@ -17,6 +17,7 @@ from google.protobuf.timestamp_pb2 import Timestamp
import proto.CommandExecutor_pb2 as CommandExecutor_pb2
import json
+import email.parser
CDS_IS_SUCCESSFUL_KEY = "cds_is_successful"
ERR_MSG_KEY = "err_msg"
@@ -29,6 +30,9 @@ def get_blueprint_id(request):
blueprint_version = request.identifiers.blueprintVersion
return blueprint_name + '/' + blueprint_version
+def get_blueprint_timeout(request):
+ return request.timeOut
+
# Create a response for grpc. Fills in the timestamp as well as removes cds_is_successful element
def build_grpc_response(request_id, response):
if response[CDS_IS_SUCCESSFUL_KEY]:
@@ -71,4 +75,31 @@ def truncate_execution_output(execution_output):
removed_item = execution_output.response.pop()
sum_truncated_chars += len(removed_item)
execution_output.response.append("[...] TRUNCATED CHARS : {}".format(sum_truncated_chars))
- return execution_output \ No newline at end of file
+ return execution_output
+
+
+# Read temp file 'outputfile' into results_log and split out the returned payload into payload_result
+def parse_cmd_exec_output(outputfile, logger, payload_result, results_log):
+ payload_section = []
+ is_payload_section = False
+ outputfile.seek(0)
+ while True:
+ output = outputfile.readline()
+ if output == '':
+ break
+ if output.startswith('BEGIN_EXTRA_PAYLOAD'):
+ is_payload_section = True
+ output = outputfile.readline()
+ if output.startswith('END_EXTRA_PAYLOAD'):
+ is_payload_section = False
+ output = ''
+ payload = '\n'.join(payload_section)
+ msg = email.parser.Parser().parsestr(payload)
+ for part in msg.get_payload():
+ payload_result.update(json.loads(part.get_payload()))
+ if output and not is_payload_section:
+ logger.info(output.strip())
+ results_log.append(output.strip())
+ else:
+ payload_section.append(output.strip())
+