Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/unit/customizations/ecs/test_codedeployvalidator.py
1569 views
1
# Copyright 2018 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
14
from awscli.testutils import unittest
15
from awscli.customizations.ecs.deploy import (CodeDeployValidator,
16
TIMEOUT_BUFFER_MIN)
17
from awscli.customizations.ecs.exceptions import (InvalidPlatformError,
18
InvalidProperyError)
19
20
21
class TestCodeDeployValidator(unittest.TestCase):
22
TEST_RESOURCES = {
23
'service': 'test-service',
24
'service_arn': 'arn:aws:ecs:::service/test-service',
25
'cluster': 'test-cluster',
26
'cluster_arn': 'arn:aws:ecs:::cluster/test-cluster',
27
'app_name': 'test-application',
28
'deployment_group_name': 'test-deployment-group'
29
}
30
31
TEST_APP_DETAILS = {
32
'application': {
33
'applicationId': '876uyh6-45tdfg',
34
'applicationName': 'test-application',
35
'computePlatform': 'ECS'
36
}
37
}
38
39
TEST_DEPLOYMENT_GROUP_DETAILS = {
40
'deploymentGroupInfo': {
41
'applicationName': 'test-application',
42
'deploymentGroupName': 'test-deployment-group',
43
'computePlatform': 'ECS',
44
'blueGreenDeploymentConfiguration': {
45
'deploymentReadyOption': {
46
'waitTimeInMinutes': 5
47
},
48
'terminateBlueInstancesOnDeploymentSuccess': {
49
'terminationWaitTimeInMinutes': 10
50
}
51
},
52
'ecsServices': [{
53
'serviceName': 'test-service',
54
'clusterName': 'test-cluster'
55
}]
56
}
57
}
58
59
def setUp(self):
60
self.validator = CodeDeployValidator(None, self.TEST_RESOURCES)
61
self.validator.app_details = self.TEST_APP_DETAILS
62
self.validator.deployment_group_details = \
63
self.TEST_DEPLOYMENT_GROUP_DETAILS
64
65
def test_get_deployment_wait_time(self):
66
expected_wait = 5 + 10 + TIMEOUT_BUFFER_MIN
67
actual_wait = self.validator.get_deployment_wait_time()
68
self.assertEqual(expected_wait, actual_wait)
69
70
def test_get_deployment_wait_time_no_dgp(self):
71
empty_validator = CodeDeployValidator(None, self.TEST_RESOURCES)
72
actual_wait = empty_validator.get_deployment_wait_time()
73
self.assertEqual(None, actual_wait)
74
75
def test_validations(self):
76
self.validator.validate_application()
77
self.validator.validate_deployment_group()
78
self.validator.validate_all()
79
80
def test_validate_application_error_compute_platform(self):
81
invalid_app = {
82
'application': {
83
'applicationName': 'test-application',
84
'computePlatform': 'Server'
85
}
86
}
87
88
bad_validator = CodeDeployValidator(None, self.TEST_RESOURCES)
89
bad_validator.app_details = invalid_app
90
91
with self.assertRaises(InvalidPlatformError):
92
bad_validator.validate_application()
93
94
def test_validate_deployment_group_error_compute_platform(self):
95
invalid_dgp = {
96
'deploymentGroupInfo': {
97
'computePlatform': 'Lambda'
98
}
99
}
100
bad_validator = CodeDeployValidator(None, self.TEST_RESOURCES)
101
bad_validator.deployment_group_details = invalid_dgp
102
103
with self.assertRaises(InvalidPlatformError):
104
bad_validator.validate_deployment_group()
105
106
def test_validate_deployment_group_error_service(self):
107
invalid_dgp = {
108
'deploymentGroupInfo': {
109
'computePlatform': 'ECS',
110
'ecsServices': [{
111
'serviceName': 'the-wrong-test-service',
112
'clusterName': 'test-cluster'
113
}]
114
}
115
}
116
bad_validator = CodeDeployValidator(None, self.TEST_RESOURCES)
117
bad_validator.deployment_group_details = invalid_dgp
118
119
with self.assertRaises(InvalidProperyError):
120
bad_validator.validate_deployment_group()
121
122
def test_validate_deployment_group_error_cluster(self):
123
invalid_dgp = {
124
'deploymentGroupInfo': {
125
'computePlatform': 'ECS',
126
'ecsServices': [{
127
'serviceName': 'test-service',
128
'clusterName': 'the-wrong-test-cluster'
129
}]
130
}
131
}
132
bad_validator = CodeDeployValidator(None, self.TEST_RESOURCES)
133
bad_validator.deployment_group_details = invalid_dgp
134
135
with self.assertRaises(InvalidProperyError):
136
bad_validator.validate_deployment_group()
137
138