Skip to content

Commit

Permalink
[sonic_platform.platform] improve the logic of determining whether it…
Browse files Browse the repository at this point in the history
… is running on host or docker
  • Loading branch information
Stephen Sun committed Aug 10, 2019
1 parent 5f7cbec commit 3f48f05
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions platform/mellanox/mlnx-platform-api/sonic_platform/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,16 @@ def _is_host(self):
Test whether current process is running on the host or an docker
return True for host and False for docker
"""
is_host = False
try:
subprocess.Popen("docker")
proc = subprocess.Popen("docker --version 2>/dev/null", stdout=subprocess.PIPE, shell=True, stderr=subprocess.STDOUT)
stdout = proc.communicate()[0]
proc.wait()
result = stdout.rstrip('\n')
if result != '':
is_host = True

except OSError, e:
return False
pass

return True
return is_host

0 comments on commit 3f48f05

Please sign in to comment.