Skip to content

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.
@azure-client-tools-bot-prd
Copy link

azure-client-tools-bot-prd bot commented Nov 21, 2024

️✔️AzureCLI-FullTest
️✔️acr
️✔️2020-09-01-hybrid
️✔️3.12
️✔️3.9
️✔️latest
️✔️3.12
️✔️3.9
️✔️acs
️✔️2020-09-01-hybrid
️✔️3.12
️✔️3.9
️✔️latest
️✔️3.12
️✔️3.9
️✔️advisor
️✔️latest
️✔️3.12
️✔️3.9
️✔️ams
️✔️latest
️✔️3.12
️✔️3.9
️✔️apim
️✔️latest
️✔️3.12
️✔️3.9
️✔️appconfig
️✔️latest
️✔️3.12
️✔️3.9
️✔️appservice
️✔️latest
️✔️3.12
️✔️3.9
️✔️aro
️✔️latest
️✔️3.12
️✔️3.9
️✔️backup
️✔️latest
️✔️3.12
️✔️3.9
️✔️batch
️✔️latest
️✔️3.12
️✔️3.9
️✔️batchai
️✔️latest
️✔️3.12
️✔️3.9
️✔️billing
️✔️latest
️✔️3.12
️✔️3.9
️✔️botservice
️✔️latest
️✔️3.12
️✔️3.9
️✔️cdn
️✔️latest
️✔️3.12
️✔️3.9
️✔️cloud
️✔️latest
️✔️3.12
️✔️3.9
️✔️cognitiveservices
️✔️latest
️✔️3.12
️✔️3.9
️✔️compute_recommender
️✔️latest
️✔️3.12
️✔️3.9
️✔️computefleet
️✔️latest
️✔️3.12
️✔️3.9
️✔️config
️✔️latest
️✔️3.12
️✔️3.9
️✔️configure
️✔️latest
️✔️3.12
️✔️3.9
️✔️consumption
️✔️latest
️✔️3.12
️✔️3.9
️✔️container
️✔️latest
️✔️3.12
️✔️3.9
️✔️containerapp
️✔️latest
️✔️3.12
️✔️3.9
️✔️core
️✔️2018-03-01-hybrid
️✔️3.12
️✔️3.9
️✔️2019-03-01-hybrid
️✔️3.12
️✔️3.9
️✔️2020-09-01-hybrid
️✔️3.12
️✔️3.9
️✔️latest
️✔️3.12
️✔️3.9
️✔️cosmosdb
️✔️latest
️✔️3.12
️✔️3.9
️✔️databoxedge
️✔️2019-03-01-hybrid
️✔️3.12
️✔️3.9
️✔️2020-09-01-hybrid
️✔️3.12
️✔️3.9
️✔️latest
️✔️3.12
️✔️3.9
️✔️dls
️✔️latest
️✔️3.12
️✔️3.9
️✔️dms
️✔️latest
️✔️3.12
️✔️3.9
️✔️eventgrid
️✔️latest
️✔️3.12
️✔️3.9
️✔️eventhubs
️✔️latest
️✔️3.12
️✔️3.9
️✔️feedback
️✔️latest
️✔️3.12
️✔️3.9
️✔️find
️✔️latest
️✔️3.12
️✔️3.9
️✔️hdinsight
️✔️latest
️✔️3.12
️✔️3.9
️✔️identity
️✔️latest
️✔️3.12
️✔️3.9
️✔️iot
️✔️2019-03-01-hybrid
️✔️3.12
️✔️3.9
️✔️2020-09-01-hybrid
️✔️3.12
️✔️3.9
️✔️latest
️✔️3.12
️✔️3.9
️✔️keyvault
️✔️2018-03-01-hybrid
️✔️3.12
️✔️3.9
️✔️2020-09-01-hybrid
️✔️3.12
️✔️3.9
️✔️latest
️✔️3.12
️✔️3.9
️✔️lab
️✔️latest
️✔️3.12
️✔️3.9
️✔️managedservices
️✔️latest
️✔️3.12
️✔️3.9
️✔️maps
️✔️latest
️✔️3.12
️✔️3.9
️✔️marketplaceordering
️✔️latest
️✔️3.12
️✔️3.9
️✔️monitor
️✔️latest
️✔️3.12
️✔️3.9
️✔️mysql
️✔️latest
️✔️3.12
️✔️3.9
️✔️netappfiles
️✔️latest
️✔️3.12
️✔️3.9
️✔️network
️✔️2018-03-01-hybrid
️✔️3.12
️✔️3.9
️✔️latest
️✔️3.12
️✔️3.9
️✔️policyinsights
️✔️latest
️✔️3.12
️✔️3.9
️✔️privatedns
️✔️latest
️✔️3.12
️✔️3.9
️✔️profile
️✔️latest
️✔️3.12
️✔️3.9
️✔️rdbms
️✔️latest
️✔️3.12
️✔️3.9
️✔️redis
️✔️latest
️✔️3.12
️✔️3.9
️✔️relay
️✔️latest
️✔️3.12
️✔️3.9
️✔️resource
️✔️2018-03-01-hybrid
️✔️3.12
️✔️3.9
️✔️2019-03-01-hybrid
️✔️3.12
️✔️3.9
️✔️latest
️✔️3.12
️✔️3.9
️✔️role
️✔️latest
️✔️3.12
️✔️3.9
️✔️search
️✔️latest
️✔️3.12
️✔️3.9
️✔️security
️✔️latest
️✔️3.12
️✔️3.9
️✔️servicebus
️✔️latest
️✔️3.12
️✔️3.9
️✔️serviceconnector
️✔️latest
️✔️3.12
️✔️3.9
️✔️servicefabric
️✔️latest
️✔️3.12
️✔️3.9
️✔️signalr
️✔️latest
️✔️3.12
️✔️3.9
️✔️sql
️✔️latest
️✔️3.12
️✔️3.9
️✔️sqlvm
️✔️latest
️✔️3.12
️✔️3.9
️✔️storage
️✔️2018-03-01-hybrid
️✔️3.12
️✔️3.9
️✔️2019-03-01-hybrid
️✔️3.12
️✔️3.9
️✔️2020-09-01-hybrid
️✔️3.12
️✔️3.9
️✔️latest
️✔️3.12
️✔️3.9
️✔️synapse
️✔️latest
️✔️3.12
️✔️3.9
️✔️telemetry
️✔️2018-03-01-hybrid
️✔️3.12
️✔️3.9
️✔️2019-03-01-hybrid
️✔️3.12
️✔️3.9
️✔️2020-09-01-hybrid
️✔️3.12
️✔️3.9
️✔️latest
️✔️3.12
️✔️3.9
️✔️util
️✔️latest
️✔️3.12
️✔️3.9
️✔️vm
️✔️2018-03-01-hybrid
️✔️3.12
️✔️3.9
️✔️2019-03-01-hybrid
️✔️3.12
️✔️3.9
️✔️2020-09-01-hybrid
️✔️3.12
️✔️3.9
️✔️latest
️✔️3.12
️✔️3.9

@azure-client-tools-bot-prd
Copy link

azure-client-tools-bot-prd bot commented Nov 21, 2024

️✔️AzureCLI-BreakingChangeTest
️✔️Non Breaking Changes

@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.

@zhoxing-ms
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@zhoxing-ms zhoxing-ms changed the title [Container] az container exec: fix exception when stdin is not a tty [Container] az container exec: fix exception when stdin is not a tty Nov 28, 2024
@zhoxing-ms
Copy link
Contributor

Could you add some tests for this code change?

@micromaomao micromaomao changed the title [Container] az container exec: fix exception when stdin is not a tty [Container] az container exec: Fix exception when stdin is not a tty Nov 28, 2024
@wangzelin007
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@micromaomao
Copy link
Member Author

micromaomao commented Jan 6, 2025

Hi @zhoxing-ms - there is already a test for the container exec command (although it is skipped when I tried az test container, and removing the @live_only() annotation does cause it to break due to the fake stdin)

    # test is live only because repo test environment does not have a stdin file pointer
    # ie. "UnsupportedOperation("redirected stdin is pseudofile, has no fileno()")"
    @live_only()
    @ResourceGroupPreparer()
    def test_container_exec(self, resource_group, resource_group_location):

Apologies for the late reply - just didn't manage to find time to look into this and eventually forgot.

@zhoxing-ms zhoxing-ms merged commit e8f875d into Azure:dev Jan 7, 2025
55 checks passed
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.

4 participants