From cb91b2c5831301ee4f3f6022004fbc98bc992ab0 Mon Sep 17 00:00:00 2001 From: Samuel Anderson <119458760+AWS-Samuel@users.noreply.github.com> Date: Sun, 31 Mar 2024 13:55:33 -0500 Subject: [PATCH] fix: only hookup stdin on windows for dcm login (#271) Signed-off-by: Samuel Anderson <119458760+AWS-Samuel@users.noreply.github.com> --- src/deadline/client/api/_loginout.py | 16 +++++++++----- .../unit/deadline_client/cli/test_cli_auth.py | 22 ++++++++++++++----- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/deadline/client/api/_loginout.py b/src/deadline/client/api/_loginout.py index b3f05bae..4403e1d4 100644 --- a/src/deadline/client/api/_loginout.py +++ b/src/deadline/client/api/_loginout.py @@ -42,12 +42,16 @@ def _login_deadline_cloud_monitor( # Open Deadline Cloud Monitor, non-blocking the user will keep Deadline Cloud Monitor running in the background. try: - # We don't hookup to stdin but do this to avoid issues on windows - # See https://docs.python.org/3/library/subprocess.html#subprocess.STARTUPINFO.lpAttributeList - - p = subprocess.Popen( - args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.PIPE - ) + if sys.platform.startswith("win"): + # We don't hookup to stdin but do this to avoid issues on windows + # See https://docs.python.org/3/library/subprocess.html#subprocess.STARTUPINFO.lpAttributeList + p = subprocess.Popen( + args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.PIPE + ) + else: + p = subprocess.Popen( + args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.DEVNULL + ) # Linux takes time to start DCM binary, which causes the TTY to suspend the process and send it to background job # With wait here, the DCM binary starts and TTY does not suspend the deadline process. if sys.platform == "linux": diff --git a/test/unit/deadline_client/cli/test_cli_auth.py b/test/unit/deadline_client/cli/test_cli_auth.py index c743412b..75fa6729 100644 --- a/test/unit/deadline_client/cli/test_cli_auth.py +++ b/test/unit/deadline_client/cli/test_cli_auth.py @@ -5,6 +5,8 @@ """ import json import subprocess +import sys + from unittest.mock import patch from click.testing import CliRunner @@ -45,12 +47,20 @@ def test_cli_deadline_cloud_monitor_login_and_logout(fresh_deadline_config): assert result.exit_code == 0, result.output - popen_mock.assert_called_once_with( - ["/bin/DeadlineCloudMonitor", "login", "--profile", "sandbox-us-west-2"], - stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, - stdin=subprocess.PIPE, - ) + if sys.platform.startswith("win"): + popen_mock.assert_called_once_with( + ["/bin/DeadlineCloudMonitor", "login", "--profile", "sandbox-us-west-2"], + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + stdin=subprocess.PIPE, + ) + else: + popen_mock.assert_called_once_with( + ["/bin/DeadlineCloudMonitor", "login", "--profile", "sandbox-us-west-2"], + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + stdin=subprocess.DEVNULL, + ) assert result.exit_code == 0