From 383f847e97275e59542b0ed54b40cb18cc034d88 Mon Sep 17 00:00:00 2001 From: Oleg Mitsura Date: Tue, 31 Mar 2020 04:19:55 -0400 Subject: cherrypicking to elalto Issue-ID: CCSDK-1860 CDS_REQUEST_ID in cmd-exec env + logging Upstream code: a)revision 4 of patch https://gerrit.onap.org/r/c/ccsdk/cds/+/100922 fixed a bug where boolean was expected instead of return_struct with err msg. b)CDS_REQUEST_ID from this patch https://gerrit.onap.org/r/c/ccsdk/cds/+/97582 Signed-off-by: Oleg Mitsura Change-Id: I7a332f245da9db40745e74356c2267f8566bafec --- .../src/main/python/command_executor_handler.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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 a32be6257..c5469a192 100644 --- a/ms/command-executor/src/main/python/command_executor_handler.py +++ b/ms/command-executor/src/main/python/command_executor_handler.py @@ -108,8 +108,16 @@ 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 } + 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: @@ -181,9 +189,11 @@ class CommandExecutorHandler(): try: results.append(subprocess.run(command, check=True, stdout=PIPE, stderr=PIPE, env=env).stdout.decode()) results.append("\n") + self.logger.info("install_python_packages {} succeeded".format(package)) return True except CalledProcessError as e: results.append(e.stderr.decode()) + self.logger.error("install_python_packages {} failed".format(package)) return False def install_ansible_packages(self, package, results): @@ -215,6 +225,7 @@ class CommandExecutorHandler(): # venv doesn't populate the activate_this.py script, hence we use from virtualenv venv.create(self.venv_home, with_pip=True, system_site_packages=True) virtualenv.writefile(os.path.join(bin_dir, "activate_this.py"), virtualenv.ACTIVATE_THIS) + self.logger.info("{} - Creation of Python Virtual Environment finished.".format(self.blueprint_id)) return utils.build_ret_data(True, "") except Exception as err: err_msg = "{} - Failed to provision Python Virtual Environment. Error: {}".format(self.blueprint_id, err) -- cgit 1.2.3-korg