Path: blob/develop/tests/functional/ecs/test_execute_command.py
1567 views
# Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.1#2# Licensed under the Apache License, Version 2.0 (the "License"). You3# may not use this file except in compliance with the License. A copy of4# the License is located at5#6# http://aws.amazon.com/apache2.0/7#8# or in the "license" file accompanying this file. This file is9# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF10# ANY KIND, either express or implied. See the License for the specific11# language governing permissions and limitations under the License.12import errno13import json1415from awscli.testutils import BaseAWSCommandParamsTest16from awscli.testutils import BaseAWSHelpOutputTest17from awscli.testutils import mock1819class TestExecuteCommand(BaseAWSCommandParamsTest):2021@mock.patch('awscli.customizations.ecs.executecommand.check_call')22def test_execute_command_success(self, mock_check_call):23cmdline = 'ecs execute-command --cluster someCluster ' \24'--task someTaskId ' \25'--interactive --command ls ' \26'--region us-west-2'27mock_check_call.return_value = 028self.parsed_responses = [{29"containerName": "someContainerName",30"containerArn": "someContainerArn",31"taskArn": "someTaskArn",32"session": {"sessionId": "session-id",33"tokenValue": "token-value",34"streamUrl": "stream-url"},35"clusterArn": "someCluster",36"interactive": "true"37}, {38"failures": [],39"tasks": [40{41"clusterArn": "ecs/someCLuster",42"desiredStatus": "RUNNING",43"createdAt": "1611619514.46",44"taskArn": "someTaskArn",45"containers": [46{47"containerArn": "ecs/someContainerArn",48"taskArn": "ecs/someTaskArn",49"name": "someContainerName",50"managedAgents": [51{52"reason": "Execute Command Agent started",53"lastStatus": "RUNNING",54"lastStartedAt": "1611619528.272",55"name": "ExecuteCommandAgent"56}57],58"runtimeId": "someRuntimeId"59},60{61"containerArn": "ecs/dummyContainerArn",62"taskArn": "ecs/someTaskArn",63"name": "dummyContainerName",64"managedAgents": [65{66"reason": "Execute Command Agent started",67"lastStatus": "RUNNING",68"lastStartedAt": "1611619528.272",69"name": "ExecuteCommandAgent"70}71],72"runtimeId": "dummyRuntimeId"73}74],75"lastStatus": "RUNNING",76"enableExecuteCommand": "true"77}78]79}]80self.run_cmd(cmdline, expected_rc=0)81self.assertEqual(self.operations_called[0][0].name,82'ExecuteCommand'83)84actual_response = json.loads(mock_check_call.call_args[0][0][1])85self.assertEqual(86{"sessionId": "session-id",87"tokenValue": "token-value",88"streamUrl": "stream-url"},89actual_response90)9192@mock.patch('awscli.customizations.ecs.executecommand.check_call')93def test_execute_command_fails(self, mock_check_call):94cmdline = 'ecs execute-command --cluster someCluster ' \95'--task someTaskId ' \96'--interactive --command ls ' \97'--region us-west-2'98mock_check_call.side_effect = OSError(errno.ENOENT, 'some error')99self.run_cmd(cmdline, expected_rc=255)100101102class TestHelpOutput(BaseAWSHelpOutputTest):103104def test_execute_command_output(self):105self.driver.main(['ecs', 'execute-command', 'help'])106self.assert_contains('Output\n======\n\nNone')107108109