aboutsummaryrefslogtreecommitdiffstats
path: root/ms/command-executor/src/main/python/utils.py
diff options
context:
space:
mode:
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())
+