Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Container] az container exec: fix exception when stdin is not a tty #30397

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

micromaomao
Copy link
Member

@micromaomao micromaomao commented Nov 21, 2024

Reproduction steps:

az container exec \
  --container-name "container" \
  -g "$RESOURCE_GROUP" \
  -n "$ACI_NAME" \
  --exec-command "echo Hello" > ./stdout < /dev/null 2>./stderr

Expected behavior:

./stdout should contain "Hello"

Actual behavior:

Command crashes without running the command. Error:

 ERROR: The command failed with an unexpected error. Here is the traceback:
 ERROR: (25, 'Inappropriate ioctl for device')
 Traceback (most recent call last):
 File "/opt/az/lib/python3.12/site-packages/knack/cli.py", line 233, in invoke
 cmd_result = self.invocation.execute(args)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "/opt/az/lib/python3.12/site-packages/azure/cli/core/commands/__init__.py", line 666, in execute
 raise ex
 File "/opt/az/lib/python3.12/site-packages/azure/cli/core/commands/__init__.py", line 733, in _run_jobs_serially
 results.append(self._run_job(expanded_arg, cmd_copy))
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "/opt/az/lib/python3.12/site-packages/azure/cli/core/commands/__init__.py", line 703, in _run_job
 result = cmd_copy(params)
           ^^^^^^^^^^^^^^^^
 File "/opt/az/lib/python3.12/site-packages/azure/cli/core/commands/__init__.py", line 336, in __call__
 return self.handler(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "/opt/az/lib/python3.12/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler
 return op(**command_args)
           ^^^^^^^^^^^^^^^^^^
 File "/opt/az/lib/python3.12/site-packages/azure/cli/command_modules/container/custom.py", line 970, in container_exec
 _start_exec_pipe_linux(execContainerResponse.web_socket_uri, execContainerResponse.password)
 File "/opt/az/lib/python3.12/site-packages/azure/cli/command_modules/container/custom.py", line 1006, in _start_exec_pipe_linux
 old_tty = termios.tcgetattr(stdin_fd)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
 termios.error: (25, 'Inappropriate ioctl for device')
 To check existing issues, please visit: https://github.com/Azure/azure-cli/issues

This makes the "exec" command unusable in e.g. CI environments.

Tested that all of the following works:

  • Running az container exec normally, starting bash, starting vi and it takes the correct terminal size.
  • Running az container exec in our CI now works
  • The provided reproduction command now no longer crashes.

This checklist is used to make sure that common guidelines for a pull request are followed.

Reproduction steps:

az container exec \
  --container-name "container" \
  -g "$RESOURCE_GROUP" \
  -n "$ACI_NAME" \
  --exec-command "echo Hello" > ./stdout < /dev/null 2>./stderr

Expected behavior:

./stdout should contain "Hello"

Actual behavior:

Command crashes without running the command. Error:

     ERROR: The command failed with an unexpected error. Here is the traceback:
     ERROR: (25, 'Inappropriate ioctl for device')
     Traceback (most recent call last):
     File "/opt/az/lib/python3.12/site-packages/knack/cli.py", line 233, in invoke
     cmd_result = self.invocation.execute(args)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     File "/opt/az/lib/python3.12/site-packages/azure/cli/core/commands/__init__.py", line 666, in execute
     raise ex
     File "/opt/az/lib/python3.12/site-packages/azure/cli/core/commands/__init__.py", line 733, in _run_jobs_serially
     results.append(self._run_job(expanded_arg, cmd_copy))
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     File "/opt/az/lib/python3.12/site-packages/azure/cli/core/commands/__init__.py", line 703, in _run_job
     result = cmd_copy(params)
               ^^^^^^^^^^^^^^^^
     File "/opt/az/lib/python3.12/site-packages/azure/cli/core/commands/__init__.py", line 336, in __call__
     return self.handler(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     File "/opt/az/lib/python3.12/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler
     return op(**command_args)
               ^^^^^^^^^^^^^^^^^^
     File "/opt/az/lib/python3.12/site-packages/azure/cli/command_modules/container/custom.py", line 970, in container_exec
     _start_exec_pipe_linux(execContainerResponse.web_socket_uri, execContainerResponse.password)
     File "/opt/az/lib/python3.12/site-packages/azure/cli/command_modules/container/custom.py", line 1006, in _start_exec_pipe_linux
     old_tty = termios.tcgetattr(stdin_fd)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
     termios.error: (25, 'Inappropriate ioctl for device')
     To check existing issues, please visit: https://github.com/Azure/azure-cli/issues

This makes the "exec" command unusable in e.g. CI environments.
Copy link

Validation for Azure CLI Full Test Starting...

Thanks for your contribution!

Copy link

Validation for Breaking Change Starting...

Thanks for your contribution!

@yonzhan
Copy link
Collaborator

yonzhan commented Nov 21, 2024

Thank you for your contribution! We will review the pull request and get back to you soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Assign Auto assign by bot
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants