def test_find_required_key_error_missing_key(self): invalid_properties_dict = {'name': 'some-lambda-function'} test_key = 'taskDefinition' with self.assertRaises(MissingPropertyError): find_required_key('task definition', invalid_properties_dict, test_key)
def test_find_required_key_error_missing_key(self): invalid_properties_dict = { 'name': 'some-lambda-function' } test_key = 'taskDefinition' with self.assertRaises(MissingPropertyError): find_required_key('task definition', invalid_properties_dict, test_key)
def update_task_def_arn(self, new_arn): """ Inserts the ARN of the previously created ECS task definition into the provided appspec. Expected format of ECS appspec (YAML) is: version: 0.0 resources: - <service-name>: type: AWS::ECS::Service properties: taskDefinition: <value> # replace this loadBalancerInfo: containerName: <value> containerPort: <value> """ appspec_obj = self._appspec_dict resources_key = filehelpers.find_required_key('codedeploy-appspec', appspec_obj, 'resources') updated_resources = [] # 'resources' is a list of string:obj dictionaries for resource in appspec_obj[resources_key]: for name in resource: # get content of resource resource_content = resource[name] # get resource properties properties_key = filehelpers.find_required_key( name, resource_content, 'properties') properties_content = resource_content[properties_key] # find task definition property task_def_key = filehelpers.find_required_key( properties_key, properties_content, 'taskDefinition') # insert new task def ARN into resource properties_content[task_def_key] = new_arn updated_resources.append(resource) appspec_obj[resources_key] = updated_resources self._appspec_dict = appspec_obj
def update_task_def_arn(self, new_arn): """ Inserts the ARN of the previously created ECS task definition into the provided appspec. Expected format of ECS appspec (YAML) is: version: 0.0 resources: - <service-name>: type: AWS::ECS::Service properties: taskDefinition: <value> # replace this loadBalancerInfo: containerName: <value> containerPort: <value> """ appspec_obj = self._appspec_dict resources_key = filehelpers.find_required_key( 'codedeploy-appspec', appspec_obj, 'resources') updated_resources = [] # 'resources' is a list of string:obj dictionaries for resource in appspec_obj[resources_key]: for name in resource: # get content of resource resource_content = resource[name] # get resource properties properties_key = filehelpers.find_required_key( name, resource_content, 'properties') properties_content = resource_content[properties_key] # find task definition property task_def_key = filehelpers.find_required_key( properties_key, properties_content, 'taskDefinition') # insert new task def ARN into resource properties_content[task_def_key] = new_arn updated_resources.append(resource) appspec_obj[resources_key] = updated_resources self._appspec_dict = appspec_obj
def test_find_required_key(self): test_properties_dict = { "TaskDefinition": "arn:aws:ecs:::task-definition/test:1", "loadbalancerInfo": { "containerName": "web", "containerPort": 80 } } test_key = 'taskDefinition' expected_result = 'TaskDefinition' result = find_required_key( 'task definition', test_properties_dict, test_key) self.assertEqual(result, expected_result)
def test_find_required_key(self): test_properties_dict = { "TaskDefinition": "arn:aws:ecs:::task-definition/test:1", "loadbalancerInfo": { "containerName": "web", "containerPort": 80 } } test_key = 'taskDefinition' expected_result = 'TaskDefinition' result = find_required_key('task definition', test_properties_dict, test_key) self.assertEqual(result, expected_result)
def test_find_required_key_error_empty_object(self): test_key = 'taskDefinition' with self.assertRaises(MissingPropertyError): find_required_key('task definition', dict(), test_key)