def test_deployment_group_with_minimal_parameters(self): expected_deployment_group = CodeDeployDeploymentGroup(self.function_logical_id + 'DeploymentGroup') expected_deployment_group.ApplicationName = {'Ref': CODEDEPLOY_APPLICATION_LOGICAL_ID} expected_deployment_group.AutoRollbackConfiguration = {'Enabled': True, 'Events': ['DEPLOYMENT_FAILURE', 'DEPLOYMENT_STOP_ON_ALARM', 'DEPLOYMENT_STOP_ON_REQUEST']} expected_deployment_group.DeploymentConfigName = { 'Fn::Sub': [ 'CodeDeployDefault.Lambda${ConfigName}', { 'ConfigName': self.deployment_type_global } ] } expected_deployment_group.DeploymentStyle = {'DeploymentType': 'BLUE_GREEN', 'DeploymentOption': 'WITH_TRAFFIC_CONTROL'} expected_deployment_group.ServiceRoleArn = {'Fn::GetAtt': [CODE_DEPLOY_SERVICE_ROLE_LOGICAL_ID, 'Arn']} deployment_preference_collection = DeploymentPreferenceCollection() deployment_preference_collection.add(self.function_logical_id, {'Type': self.deployment_type_global}) deployment_group = deployment_preference_collection.deployment_group(self.function_logical_id) self.assertEqual(deployment_group.to_dict(), expected_deployment_group.to_dict())
def test_deployment_group_with_all_parameters(self): expected_deployment_group = CodeDeployDeploymentGroup(self.function_logical_id + "DeploymentGroup") expected_deployment_group.AlarmConfiguration = { "Enabled": True, "Alarms": [{"Name": {"Ref": "alarm1"}}, {"Name": {"Ref": "alarm2"}}], } expected_deployment_group.ApplicationName = {"Ref": CODEDEPLOY_APPLICATION_LOGICAL_ID} expected_deployment_group.AutoRollbackConfiguration = { "Enabled": True, "Events": ["DEPLOYMENT_FAILURE", "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST"], } expected_deployment_group.DeploymentConfigName = { "Fn::Sub": ["CodeDeployDefault.Lambda${ConfigName}", {"ConfigName": self.deployment_type_global}] } expected_deployment_group.DeploymentStyle = { "DeploymentType": "BLUE_GREEN", "DeploymentOption": "WITH_TRAFFIC_CONTROL", } expected_deployment_group.ServiceRoleArn = {"Fn::GetAtt": [CODE_DEPLOY_SERVICE_ROLE_LOGICAL_ID, "Arn"]} deployment_preference_collection = DeploymentPreferenceCollection() deployment_preference_collection.add(self.function_logical_id, self.global_deployment_preference_yaml_dict()) deployment_group = deployment_preference_collection.deployment_group(self.function_logical_id) self.assertEqual(deployment_group.to_dict(), expected_deployment_group.to_dict())
def deployment_group(self, function_logical_id): """ :param function_logical_id: logical_id of the function this deployment group belongs to :return: CodeDeployDeploymentGroup resource """ deployment_preference = self.get(function_logical_id) deployment_group = CodeDeployDeploymentGroup(self.deployment_group_logical_id(function_logical_id)) if deployment_preference.alarms is not None: deployment_group.AlarmConfiguration = {'Enabled': True, 'Alarms': [{'Name': alarm} for alarm in deployment_preference.alarms]} deployment_group.ApplicationName = self.codedeploy_application.get_runtime_attr('name') deployment_group.AutoRollbackConfiguration = {'Enabled': True, 'Events': ['DEPLOYMENT_FAILURE', 'DEPLOYMENT_STOP_ON_ALARM', 'DEPLOYMENT_STOP_ON_REQUEST']} deployment_group.DeploymentConfigName = fnSub("CodeDeployDefault.Lambda${ConfigName}", {"ConfigName": deployment_preference.deployment_type}) deployment_group.DeploymentStyle = {'DeploymentType': 'BLUE_GREEN', 'DeploymentOption': 'WITH_TRAFFIC_CONTROL'} deployment_group.ServiceRoleArn = self.codedeploy_iam_role.get_runtime_attr("arn") if deployment_preference.role: deployment_group.ServiceRoleArn = deployment_preference.role return deployment_group
def deployment_group(self, function_logical_id): """ :param function_logical_id: logical_id of the function this deployment group belongs to :return: CodeDeployDeploymentGroup resource """ deployment_preference = self.get(function_logical_id) deployment_group = CodeDeployDeploymentGroup( self.deployment_group_logical_id(function_logical_id)) if deployment_preference.alarms is not None: deployment_group.AlarmConfiguration = { "Enabled": True, "Alarms": [{ "Name": alarm } for alarm in deployment_preference.alarms], } deployment_group.ApplicationName = self.codedeploy_application.get_runtime_attr( "name") deployment_group.AutoRollbackConfiguration = { "Enabled": True, "Events": [ "DEPLOYMENT_FAILURE", "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ], } deployment_group.DeploymentConfigName = self._replace_deployment_types( copy.deepcopy(deployment_preference.deployment_type)) deployment_group.DeploymentStyle = { "DeploymentType": "BLUE_GREEN", "DeploymentOption": "WITH_TRAFFIC_CONTROL" } deployment_group.ServiceRoleArn = self.codedeploy_iam_role.get_runtime_attr( "arn") if deployment_preference.role: deployment_group.ServiceRoleArn = deployment_preference.role if deployment_preference.trigger_configurations: deployment_group.TriggerConfigurations = deployment_preference.trigger_configurations return deployment_group
def deployment_group(self, function_logical_id): """ :param function_logical_id: logical_id of the function this deployment group belongs to :return: CodeDeployDeploymentGroup resource """ deployment_preference = self.get(function_logical_id) deployment_group = CodeDeployDeploymentGroup( self.deployment_group_logical_id(function_logical_id)) if deployment_preference.alarms is not None: deployment_group.AlarmConfiguration = { 'Enabled': True, 'Alarms': [{ 'Name': alarm } for alarm in deployment_preference.alarms] } deployment_group.ApplicationName = self.codedeploy_application.get_runtime_attr( 'name') deployment_group.AutoRollbackConfiguration = { 'Enabled': True, 'Events': [ 'DEPLOYMENT_FAILURE', 'DEPLOYMENT_STOP_ON_ALARM', 'DEPLOYMENT_STOP_ON_REQUEST' ] } deployment_group.DeploymentConfigName = self._replace_deployment_types( copy.deepcopy(deployment_preference.deployment_type)) deployment_group.DeploymentStyle = { 'DeploymentType': 'BLUE_GREEN', 'DeploymentOption': 'WITH_TRAFFIC_CONTROL' } deployment_group.ServiceRoleArn = self.codedeploy_iam_role.get_runtime_attr( "arn") if deployment_preference.role: deployment_group.ServiceRoleArn = deployment_preference.role return deployment_group