From 4947afebcfbee275e2f3a804d0a5648428f69908 Mon Sep 17 00:00:00 2001 From: Oleg Mitsura Date: Thu, 24 Oct 2019 19:22:46 -0400 Subject: Pass requestID/subreqID to python script. Issue-ID: CCSDK-1860 1. initial commit 2. rebased with return value 3. CDS_CORRELATION_ID Signed-off-by: Oleg Mitsura Change-Id: Ia64a0ee9c8eb60e3f39ec00ee17e7ab1b4aa3638 --- .../src/main/python/command_executor_handler.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'ms') diff --git a/ms/command-executor/src/main/python/command_executor_handler.py b/ms/command-executor/src/main/python/command_executor_handler.py index c920dda89..3219a974b 100644 --- a/ms/command-executor/src/main/python/command_executor_handler.py +++ b/ms/command-executor/src/main/python/command_executor_handler.py @@ -31,7 +31,7 @@ import json REQUIREMENTS_TXT = "requirements.txt" -class CommandExecutorHandler(): +class CommandExecutorHandler: def __init__(self, request): self.request = request @@ -81,9 +81,17 @@ class CommandExecutorHandler(): payload_section = [] is_payload_section = False + ### extract the original header request into sys-env variables + ### RequestID + request_id = request.requestId + ### Sub-requestID + subrequest_id = request.correlationId + request_id_map = {'CDS_REQUEST_ID':request_id, 'CDS_CORRELATION_ID':subrequest_id} + updated_env = { **os.environ, **request_id_map } + try: with subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, - shell=True, bufsize=1, universal_newlines=True) as newProcess: + shell=True, bufsize=1, universal_newlines=True, env=updated_env) as newProcess: while True: output = newProcess.stdout.readline() if output == '' and newProcess.poll() is not None: -- cgit 1.2.3-korg