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