Path: blob/develop/tests/unit/customizations/ecs/test_codedeployvalidator.py
1569 views
# Copyright 2018 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.1213from awscli.testutils import unittest14from awscli.customizations.ecs.deploy import (CodeDeployValidator,15TIMEOUT_BUFFER_MIN)16from awscli.customizations.ecs.exceptions import (InvalidPlatformError,17InvalidProperyError)181920class TestCodeDeployValidator(unittest.TestCase):21TEST_RESOURCES = {22'service': 'test-service',23'service_arn': 'arn:aws:ecs:::service/test-service',24'cluster': 'test-cluster',25'cluster_arn': 'arn:aws:ecs:::cluster/test-cluster',26'app_name': 'test-application',27'deployment_group_name': 'test-deployment-group'28}2930TEST_APP_DETAILS = {31'application': {32'applicationId': '876uyh6-45tdfg',33'applicationName': 'test-application',34'computePlatform': 'ECS'35}36}3738TEST_DEPLOYMENT_GROUP_DETAILS = {39'deploymentGroupInfo': {40'applicationName': 'test-application',41'deploymentGroupName': 'test-deployment-group',42'computePlatform': 'ECS',43'blueGreenDeploymentConfiguration': {44'deploymentReadyOption': {45'waitTimeInMinutes': 546},47'terminateBlueInstancesOnDeploymentSuccess': {48'terminationWaitTimeInMinutes': 1049}50},51'ecsServices': [{52'serviceName': 'test-service',53'clusterName': 'test-cluster'54}]55}56}5758def setUp(self):59self.validator = CodeDeployValidator(None, self.TEST_RESOURCES)60self.validator.app_details = self.TEST_APP_DETAILS61self.validator.deployment_group_details = \62self.TEST_DEPLOYMENT_GROUP_DETAILS6364def test_get_deployment_wait_time(self):65expected_wait = 5 + 10 + TIMEOUT_BUFFER_MIN66actual_wait = self.validator.get_deployment_wait_time()67self.assertEqual(expected_wait, actual_wait)6869def test_get_deployment_wait_time_no_dgp(self):70empty_validator = CodeDeployValidator(None, self.TEST_RESOURCES)71actual_wait = empty_validator.get_deployment_wait_time()72self.assertEqual(None, actual_wait)7374def test_validations(self):75self.validator.validate_application()76self.validator.validate_deployment_group()77self.validator.validate_all()7879def test_validate_application_error_compute_platform(self):80invalid_app = {81'application': {82'applicationName': 'test-application',83'computePlatform': 'Server'84}85}8687bad_validator = CodeDeployValidator(None, self.TEST_RESOURCES)88bad_validator.app_details = invalid_app8990with self.assertRaises(InvalidPlatformError):91bad_validator.validate_application()9293def test_validate_deployment_group_error_compute_platform(self):94invalid_dgp = {95'deploymentGroupInfo': {96'computePlatform': 'Lambda'97}98}99bad_validator = CodeDeployValidator(None, self.TEST_RESOURCES)100bad_validator.deployment_group_details = invalid_dgp101102with self.assertRaises(InvalidPlatformError):103bad_validator.validate_deployment_group()104105def test_validate_deployment_group_error_service(self):106invalid_dgp = {107'deploymentGroupInfo': {108'computePlatform': 'ECS',109'ecsServices': [{110'serviceName': 'the-wrong-test-service',111'clusterName': 'test-cluster'112}]113}114}115bad_validator = CodeDeployValidator(None, self.TEST_RESOURCES)116bad_validator.deployment_group_details = invalid_dgp117118with self.assertRaises(InvalidProperyError):119bad_validator.validate_deployment_group()120121def test_validate_deployment_group_error_cluster(self):122invalid_dgp = {123'deploymentGroupInfo': {124'computePlatform': 'ECS',125'ecsServices': [{126'serviceName': 'test-service',127'clusterName': 'the-wrong-test-cluster'128}]129}130}131bad_validator = CodeDeployValidator(None, self.TEST_RESOURCES)132bad_validator.deployment_group_details = invalid_dgp133134with self.assertRaises(InvalidProperyError):135bad_validator.validate_deployment_group()136137138