Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/integration/test_smoke.py
1566 views
1
# Copyright 2014 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 re
14
import os
15
import random
16
import time
17
18
import pytest
19
20
from awscli.testutils import aws
21
22
23
# These are a list of commands that we should run.
24
# We're just verifying that we can properly send a no-arg request
25
# and that we can parse any response that comes back.
26
COMMANDS = [
27
'autoscaling describe-account-limits',
28
'autoscaling describe-adjustment-types',
29
'cloudformation describe-stacks',
30
'cloudformation list-stacks',
31
'cloudsearch describe-domains',
32
'cloudsearch list-domain-names',
33
'cloudtrail describe-trails',
34
'cloudwatch list-metrics',
35
'cognito-identity list-identity-pools --max-results 1',
36
'datapipeline list-pipelines',
37
'directconnect describe-connections',
38
'dynamodb list-tables',
39
'ec2 describe-instances',
40
'ec2 describe-regions',
41
'elasticache describe-cache-clusters',
42
'elb describe-load-balancers',
43
'emr list-clusters',
44
# Smoke test for timestamp parsing.
45
'emr list-clusters --created-after 2014-11-24T00:00:00',
46
'iam list-users',
47
'kinesis list-streams',
48
'kms generate-random --number-of-bytes 128',
49
'logs describe-log-groups',
50
'rds describe-db-instances',
51
'redshift describe-clusters',
52
'route53 list-hosted-zones',
53
'route53domains list-domains',
54
's3api list-buckets',
55
's3 ls',
56
'ses list-identities',
57
'sns list-topics',
58
'sqs list-queues',
59
'storagegateway list-gateways',
60
'swf list-domains --registration-status REGISTERED',
61
('swf list-open-workflow-executions --domain foo '
62
'--start-time-filter oldestDate=1970-01-01'),
63
64
# Verify waiters as well. We're picking the
65
# "resource does not exist" type waiters so we can
66
# give an identifier that doesn't exist and verify we have
67
# a 0 rc.
68
'rds wait db-instance-deleted --db-instance-identifier foo-123',
69
]
70
71
72
# A list of commands that generate error messages. The idea is to try to have
73
# at least one command for each service.
74
#
75
# This verifies that service errors are properly displayed to the user, as
76
# opposed to either silently failing or inproperly handling the error responses
77
# and not displaying something useful. Each command tries to call an operation
78
# with an identifier that does not exist, and part of the identifier is also
79
# randomly generated to help ensure that is the case.
80
ERROR_COMMANDS = [
81
'autoscaling attach-instances --auto-scaling-group-name %s',
82
'cloudformation cancel-update-stack --stack-name %s',
83
'cloudsearch describe-suggesters --domain-name %s',
84
'cloudtrail get-trail-status --name %s',
85
'cognito-identity delete-identity-pool --identity-pool-id %s',
86
'datapipeline delete-pipeline --pipeline-id %s',
87
'directconnect delete-connection --connection-id %s',
88
'dynamodb delete-table --table-name %s',
89
'ec2 terminate-instances --instance-ids %s',
90
'elasticache delete-cache-cluster --cache-cluster-id %s',
91
'elb describe-load-balancers --load-balancer-names %s',
92
'emr list-instances --cluster-id %s',
93
'iam delete-user --user-name %s',
94
'kinesis delete-stream --stream-name %s',
95
'logs delete-log-group --log-group-name %s',
96
'rds delete-db-instance --db-instance-identifier %s',
97
'redshift delete-cluster --cluster-identifier %s',
98
'route53 delete-hosted-zone --id %s',
99
'route53domains get-domain-detail --domain-name %s',
100
's3api head-bucket --bucket %s',
101
'ses set-identity-dkim-enabled --identity %s --dkim-enabled',
102
'sns delete-endpoint --endpoint-arn %s',
103
'sqs delete-queue --queue-url %s',
104
# --gateway-arn has min length client side validation
105
# so we have to generate an identifier that's long enough.
106
('storagegateway delete-gateway --gateway-arn '
107
'foo-cli-test-foo-cli-test-foo-cli-test-%s'),
108
'swf deprecate-domain --name %s',
109
]
110
111
112
# These services require a particular region to run.
113
REGION_OVERRIDES = {
114
'route53domains': 'us-east-1'
115
}
116
117
118
def _aws(command_string, max_attempts=1, delay=5, target_rc=0):
119
service = command_string.split()[0]
120
env = None
121
if service in REGION_OVERRIDES:
122
env = os.environ.copy()
123
env['AWS_DEFAULT_REGION'] = REGION_OVERRIDES[service]
124
125
for _ in range(max_attempts - 1):
126
result = aws(command_string, env_vars=env)
127
if result.rc == target_rc:
128
return result
129
time.sleep(delay)
130
return aws(command_string, env_vars=env)
131
132
133
@pytest.mark.parametrize(
134
"cmd",
135
COMMANDS
136
)
137
def test_can_make_success_request(cmd):
138
result = _aws(cmd, max_attempts=5, delay=5, target_rc=0)
139
assert result.rc == 0
140
assert result.stderr == ''
141
142
143
ERROR_MESSAGE_RE = re.compile(
144
r'An error occurred \(.+\) when calling the \w+ operation: \w+'
145
)
146
147
148
@pytest.mark.parametrize(
149
"cmd",
150
ERROR_COMMANDS
151
)
152
def test_display_error_message(cmd):
153
identifier = 'foo-awscli-test-%s' % random.randint(1000, 100000)
154
command_string = cmd % identifier
155
result = _aws(command_string, target_rc=255)
156
assert result.rc == 255
157
158
match = ERROR_MESSAGE_RE.search(result.stderr)
159
assert match is not None, (
160
f'Error message was not displayed for command "{command_string}": {result.stderr}'
161
)
162
163