From 9d17f637e3c72978a9d906e9e7c39d8c927ff8ab Mon Sep 17 00:00:00 2001 From: Kebo Liu Date: Tue, 20 Dec 2022 16:00:11 +0800 Subject: [PATCH] [Mellanox] change the implementation of is_host() to fix a stuck issue on simx platform (#13100) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Why I did it Following code to judge whether a process is running inside a docker could get stuck on the simx platform subprocess.Popen(["docker", "--version"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) When it gets stuck, the config-chassisdb service can not be successfully started, thus the system can not be booted up. root@sonic:/# service config-chassisdb status config-chassisdb.service - Config chassis_db Loaded: loaded (/lib/systemd/system/config-chassisdb.service; enabled; vendor preset: enabled) Active: activating (start) since Thu 2022-12-15 09:23:02 UTC; 29min ago Main PID: 571 (config-chassisd) Tasks: 14 (limit: 9501) Memory: 132.4M CGroup: /system.slice/config-chassisdb.service ├─571 /bin/bash /usr/bin/config-chassisdb ├─575 /usr/bin/python3 /usr/local/bin/sonic-cfggen -H -v DEVICE_METADATA.localhost.platform ├─602 /bin/sh -c sudo decode-syseeprom -m ├─603 sudo decode-syseeprom -m ├─607 /usr/bin/python3 /usr/local/bin/decode-syseeprom -m ├─616 /bin/sh -c docker --version 2>/dev/null └─617 docker --version - How I did it Use an alternative way to implement this function and issue can be avoided: docker_env_file = '/.dockerenv' return os.path.exists(docker_env_file) is False - How to verify it run regression on real hardware and simx platform. --- .../mlnx-platform-api/sonic_platform/utils.py | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/utils.py b/platform/mellanox/mlnx-platform-api/sonic_platform/utils.py index 2bc312cd2234..634078c9a077 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/utils.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/utils.py @@ -186,17 +186,8 @@ def is_host(): Test whether current process is running on the host or an docker return True for host and False for docker """ - try: - proc = subprocess.Popen(["docker", "--version"], - stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, - universal_newlines=True) - stdout = proc.communicate()[0] - proc.wait() - result = stdout.rstrip('\n') - return result != '' - except OSError as e: - return False + docker_env_file = '/.dockerenv' + return os.path.exists(docker_env_file) is False def default_return(return_value, log_func=logger.log_debug):