| 
									
										
										
										
											2017-10-20 00:51:04 +01:00
										 |  |  | import boto3 | 
					
						
							| 
									
										
										
										
											2021-10-18 19:44:29 +00:00
										 |  |  | import sure  # noqa # pylint: disable=unused-import | 
					
						
							| 
									
										
										
										
											2022-03-10 13:39:59 -01:00
										 |  |  | from moto import mock_batch, mock_iam, mock_ec2, mock_ecs, mock_cloudformation | 
					
						
							| 
									
										
										
										
											2017-10-20 00:51:04 +01:00
										 |  |  | import json | 
					
						
							| 
									
										
										
										
											2021-10-05 17:11:07 +00:00
										 |  |  | from uuid import uuid4 | 
					
						
							| 
									
										
										
										
											2017-10-20 00:51:04 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  | DEFAULT_REGION = "eu-central-1" | 
					
						
							| 
									
										
										
										
											2017-10-20 00:51:04 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def _get_clients(): | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     return ( | 
					
						
							|  |  |  |         boto3.client("ec2", region_name=DEFAULT_REGION), | 
					
						
							|  |  |  |         boto3.client("iam", region_name=DEFAULT_REGION), | 
					
						
							|  |  |  |         boto3.client("ecs", region_name=DEFAULT_REGION), | 
					
						
							|  |  |  |         boto3.client("logs", region_name=DEFAULT_REGION), | 
					
						
							|  |  |  |         boto3.client("batch", region_name=DEFAULT_REGION), | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-10-20 00:51:04 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def _setup(ec2_client, iam_client): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Do prerequisite setup | 
					
						
							|  |  |  |     :return: VPC ID, Subnet ID, Security group ID, IAM Role ARN | 
					
						
							|  |  |  |     :rtype: tuple | 
					
						
							|  |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     resp = ec2_client.create_vpc(CidrBlock="172.30.0.0/24") | 
					
						
							|  |  |  |     vpc_id = resp["Vpc"]["VpcId"] | 
					
						
							| 
									
										
										
										
											2017-10-20 00:51:04 +01:00
										 |  |  |     resp = ec2_client.create_subnet( | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         AvailabilityZone="eu-central-1a", CidrBlock="172.30.0.0/25", VpcId=vpc_id | 
					
						
							| 
									
										
										
										
											2017-10-20 00:51:04 +01:00
										 |  |  |     ) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     subnet_id = resp["Subnet"]["SubnetId"] | 
					
						
							| 
									
										
										
										
											2017-10-20 00:51:04 +01:00
										 |  |  |     resp = ec2_client.create_security_group( | 
					
						
							| 
									
										
										
										
											2021-10-05 17:11:07 +00:00
										 |  |  |         Description="test_sg_desc", GroupName=str(uuid4())[0:6], VpcId=vpc_id | 
					
						
							| 
									
										
										
										
											2017-10-20 00:51:04 +01:00
										 |  |  |     ) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     sg_id = resp["GroupId"] | 
					
						
							| 
									
										
										
										
											2017-10-20 00:51:04 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-05 17:11:07 +00:00
										 |  |  |     role_name = str(uuid4())[0:6] | 
					
						
							| 
									
										
										
										
											2017-10-20 00:51:04 +01:00
										 |  |  |     resp = iam_client.create_role( | 
					
						
							| 
									
										
										
										
											2021-10-05 17:11:07 +00:00
										 |  |  |         RoleName=role_name, AssumeRolePolicyDocument="some_policy" | 
					
						
							| 
									
										
										
										
											2017-10-20 00:51:04 +01:00
										 |  |  |     ) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     iam_arn = resp["Role"]["Arn"] | 
					
						
							| 
									
										
										
										
											2021-10-05 17:11:07 +00:00
										 |  |  |     iam_client.create_instance_profile(InstanceProfileName=role_name) | 
					
						
							| 
									
										
										
										
											2019-12-13 17:52:37 +00:00
										 |  |  |     iam_client.add_role_to_instance_profile( | 
					
						
							| 
									
										
										
										
											2021-10-05 17:11:07 +00:00
										 |  |  |         InstanceProfileName=role_name, RoleName=role_name | 
					
						
							| 
									
										
										
										
											2019-12-13 17:52:37 +00:00
										 |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-10-20 00:51:04 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return vpc_id, subnet_id, sg_id, iam_arn | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_cloudformation() | 
					
						
							|  |  |  | @mock_ec2 | 
					
						
							|  |  |  | @mock_ecs | 
					
						
							|  |  |  | @mock_iam | 
					
						
							|  |  |  | @mock_batch | 
					
						
							|  |  |  | def test_create_env_cf(): | 
					
						
							| 
									
										
										
										
											2021-10-18 19:44:29 +00:00
										 |  |  |     ec2_client, iam_client, _, _, _ = _get_clients() | 
					
						
							|  |  |  |     _, subnet_id, sg_id, iam_arn = _setup(ec2_client, iam_client) | 
					
						
							| 
									
										
										
										
											2017-10-20 00:51:04 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     create_environment_template = { | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         "Resources": { | 
					
						
							| 
									
										
										
										
											2017-10-20 00:51:04 +01:00
										 |  |  |             "ComputeEnvironment": { | 
					
						
							|  |  |  |                 "Type": "AWS::Batch::ComputeEnvironment", | 
					
						
							|  |  |  |                 "Properties": { | 
					
						
							|  |  |  |                     "Type": "MANAGED", | 
					
						
							|  |  |  |                     "ComputeResources": { | 
					
						
							|  |  |  |                         "Type": "EC2", | 
					
						
							|  |  |  |                         "MinvCpus": 0, | 
					
						
							|  |  |  |                         "DesiredvCpus": 0, | 
					
						
							|  |  |  |                         "MaxvCpus": 64, | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |                         "InstanceTypes": ["optimal"], | 
					
						
							| 
									
										
										
										
											2017-10-20 00:51:04 +01:00
										 |  |  |                         "Subnets": [subnet_id], | 
					
						
							|  |  |  |                         "SecurityGroupIds": [sg_id], | 
					
						
							| 
									
										
										
										
											2019-12-13 17:52:37 +00:00
										 |  |  |                         "InstanceRole": iam_arn.replace("role", "instance-profile"), | 
					
						
							| 
									
										
										
										
											2017-10-20 00:51:04 +01:00
										 |  |  |                     }, | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |                     "ServiceRole": iam_arn, | 
					
						
							|  |  |  |                 }, | 
					
						
							| 
									
										
										
										
											2017-10-20 00:51:04 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     cf_json = json.dumps(create_environment_template) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     cf_conn = boto3.client("cloudformation", DEFAULT_REGION) | 
					
						
							| 
									
										
										
										
											2021-10-05 17:11:07 +00:00
										 |  |  |     stack_name = str(uuid4())[0:6] | 
					
						
							|  |  |  |     stack_id = cf_conn.create_stack(StackName=stack_name, TemplateBody=cf_json)[ | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         "StackId" | 
					
						
							|  |  |  |     ] | 
					
						
							| 
									
										
										
										
											2017-10-20 00:51:04 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     stack_resources = cf_conn.list_stack_resources(StackName=stack_id) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     stack_resources["StackResourceSummaries"][0]["ResourceStatus"].should.equal( | 
					
						
							|  |  |  |         "CREATE_COMPLETE" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-10-20 01:06:30 +01:00
										 |  |  |     # Spot checks on the ARN | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     stack_resources["StackResourceSummaries"][0]["PhysicalResourceId"].startswith( | 
					
						
							|  |  |  |         "arn:aws:batch:" | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     stack_resources["StackResourceSummaries"][0]["PhysicalResourceId"].should.contain( | 
					
						
							| 
									
										
										
										
											2021-10-05 17:11:07 +00:00
										 |  |  |         stack_name | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-10-20 01:06:30 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_cloudformation() | 
					
						
							|  |  |  | @mock_ec2 | 
					
						
							|  |  |  | @mock_ecs | 
					
						
							|  |  |  | @mock_iam | 
					
						
							|  |  |  | @mock_batch | 
					
						
							|  |  |  | def test_create_job_queue_cf(): | 
					
						
							| 
									
										
										
										
											2021-10-18 19:44:29 +00:00
										 |  |  |     ec2_client, iam_client, _, _, _ = _get_clients() | 
					
						
							|  |  |  |     _, subnet_id, sg_id, iam_arn = _setup(ec2_client, iam_client) | 
					
						
							| 
									
										
										
										
											2017-10-20 01:06:30 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     create_environment_template = { | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         "Resources": { | 
					
						
							| 
									
										
										
										
											2017-10-20 01:06:30 +01:00
										 |  |  |             "ComputeEnvironment": { | 
					
						
							|  |  |  |                 "Type": "AWS::Batch::ComputeEnvironment", | 
					
						
							|  |  |  |                 "Properties": { | 
					
						
							|  |  |  |                     "Type": "MANAGED", | 
					
						
							|  |  |  |                     "ComputeResources": { | 
					
						
							|  |  |  |                         "Type": "EC2", | 
					
						
							|  |  |  |                         "MinvCpus": 0, | 
					
						
							|  |  |  |                         "DesiredvCpus": 0, | 
					
						
							|  |  |  |                         "MaxvCpus": 64, | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |                         "InstanceTypes": ["optimal"], | 
					
						
							| 
									
										
										
										
											2017-10-20 01:06:30 +01:00
										 |  |  |                         "Subnets": [subnet_id], | 
					
						
							|  |  |  |                         "SecurityGroupIds": [sg_id], | 
					
						
							| 
									
										
										
										
											2019-12-13 17:52:37 +00:00
										 |  |  |                         "InstanceRole": iam_arn.replace("role", "instance-profile"), | 
					
						
							| 
									
										
										
										
											2017-10-20 01:06:30 +01:00
										 |  |  |                     }, | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |                     "ServiceRole": iam_arn, | 
					
						
							|  |  |  |                 }, | 
					
						
							| 
									
										
										
										
											2017-10-20 01:06:30 +01:00
										 |  |  |             }, | 
					
						
							|  |  |  |             "JobQueue": { | 
					
						
							|  |  |  |                 "Type": "AWS::Batch::JobQueue", | 
					
						
							|  |  |  |                 "Properties": { | 
					
						
							|  |  |  |                     "Priority": 1, | 
					
						
							|  |  |  |                     "ComputeEnvironmentOrder": [ | 
					
						
							|  |  |  |                         { | 
					
						
							|  |  |  |                             "Order": 1, | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |                             "ComputeEnvironment": {"Ref": "ComputeEnvironment"}, | 
					
						
							| 
									
										
										
										
											2017-10-20 01:06:30 +01:00
										 |  |  |                         } | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |                     ], | 
					
						
							|  |  |  |                 }, | 
					
						
							| 
									
										
										
										
											2017-10-20 01:06:30 +01:00
										 |  |  |             }, | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     cf_json = json.dumps(create_environment_template) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     cf_conn = boto3.client("cloudformation", DEFAULT_REGION) | 
					
						
							| 
									
										
										
										
											2021-10-05 17:11:07 +00:00
										 |  |  |     stack_name = str(uuid4())[0:6] | 
					
						
							|  |  |  |     stack_id = cf_conn.create_stack(StackName=stack_name, TemplateBody=cf_json)[ | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         "StackId" | 
					
						
							|  |  |  |     ] | 
					
						
							| 
									
										
										
										
											2017-10-20 01:06:30 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     stack_resources = cf_conn.list_stack_resources(StackName=stack_id) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     len(stack_resources["StackResourceSummaries"]).should.equal(2) | 
					
						
							| 
									
										
										
										
											2017-10-20 01:06:30 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     job_queue_resource = list( | 
					
						
							|  |  |  |         filter( | 
					
						
							|  |  |  |             lambda item: item["ResourceType"] == "AWS::Batch::JobQueue", | 
					
						
							|  |  |  |             stack_resources["StackResourceSummaries"], | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     )[0] | 
					
						
							| 
									
										
										
										
											2017-10-20 01:06:30 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     job_queue_resource["ResourceStatus"].should.equal("CREATE_COMPLETE") | 
					
						
							| 
									
										
										
										
											2017-10-20 01:06:30 +01:00
										 |  |  |     # Spot checks on the ARN | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     job_queue_resource["PhysicalResourceId"].startswith("arn:aws:batch:") | 
					
						
							| 
									
										
										
										
											2021-10-05 17:11:07 +00:00
										 |  |  |     job_queue_resource["PhysicalResourceId"].should.contain(stack_name) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     job_queue_resource["PhysicalResourceId"].should.contain("job-queue/") | 
					
						
							| 
									
										
										
										
											2017-10-20 19:10:31 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_cloudformation() | 
					
						
							|  |  |  | @mock_ec2 | 
					
						
							|  |  |  | @mock_ecs | 
					
						
							|  |  |  | @mock_iam | 
					
						
							|  |  |  | @mock_batch | 
					
						
							|  |  |  | def test_create_job_def_cf(): | 
					
						
							| 
									
										
										
										
											2021-10-18 19:44:29 +00:00
										 |  |  |     ec2_client, iam_client, _, _, _ = _get_clients() | 
					
						
							|  |  |  |     _, subnet_id, sg_id, iam_arn = _setup(ec2_client, iam_client) | 
					
						
							| 
									
										
										
										
											2017-10-20 19:10:31 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     create_environment_template = { | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         "Resources": { | 
					
						
							| 
									
										
										
										
											2017-10-20 19:10:31 +01:00
										 |  |  |             "ComputeEnvironment": { | 
					
						
							|  |  |  |                 "Type": "AWS::Batch::ComputeEnvironment", | 
					
						
							|  |  |  |                 "Properties": { | 
					
						
							|  |  |  |                     "Type": "MANAGED", | 
					
						
							|  |  |  |                     "ComputeResources": { | 
					
						
							|  |  |  |                         "Type": "EC2", | 
					
						
							|  |  |  |                         "MinvCpus": 0, | 
					
						
							|  |  |  |                         "DesiredvCpus": 0, | 
					
						
							|  |  |  |                         "MaxvCpus": 64, | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |                         "InstanceTypes": ["optimal"], | 
					
						
							| 
									
										
										
										
											2017-10-20 19:10:31 +01:00
										 |  |  |                         "Subnets": [subnet_id], | 
					
						
							|  |  |  |                         "SecurityGroupIds": [sg_id], | 
					
						
							| 
									
										
										
										
											2019-12-13 17:52:37 +00:00
										 |  |  |                         "InstanceRole": iam_arn.replace("role", "instance-profile"), | 
					
						
							| 
									
										
										
										
											2017-10-20 19:10:31 +01:00
										 |  |  |                     }, | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |                     "ServiceRole": iam_arn, | 
					
						
							|  |  |  |                 }, | 
					
						
							| 
									
										
										
										
											2017-10-20 19:10:31 +01:00
										 |  |  |             }, | 
					
						
							|  |  |  |             "JobQueue": { | 
					
						
							|  |  |  |                 "Type": "AWS::Batch::JobQueue", | 
					
						
							|  |  |  |                 "Properties": { | 
					
						
							|  |  |  |                     "Priority": 1, | 
					
						
							|  |  |  |                     "ComputeEnvironmentOrder": [ | 
					
						
							|  |  |  |                         { | 
					
						
							|  |  |  |                             "Order": 1, | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |                             "ComputeEnvironment": {"Ref": "ComputeEnvironment"}, | 
					
						
							| 
									
										
										
										
											2017-10-20 19:10:31 +01:00
										 |  |  |                         } | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |                     ], | 
					
						
							|  |  |  |                 }, | 
					
						
							| 
									
										
										
										
											2017-10-20 19:10:31 +01:00
										 |  |  |             }, | 
					
						
							|  |  |  |             "JobDefinition": { | 
					
						
							|  |  |  |                 "Type": "AWS::Batch::JobDefinition", | 
					
						
							|  |  |  |                 "Properties": { | 
					
						
							|  |  |  |                     "Type": "container", | 
					
						
							|  |  |  |                     "ContainerProperties": { | 
					
						
							|  |  |  |                         "Image": { | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |                             "Fn::Join": [ | 
					
						
							|  |  |  |                                 "", | 
					
						
							|  |  |  |                                 [ | 
					
						
							|  |  |  |                                     "137112412989.dkr.ecr.", | 
					
						
							|  |  |  |                                     {"Ref": "AWS::Region"}, | 
					
						
							|  |  |  |                                     ".amazonaws.com/amazonlinux:latest", | 
					
						
							|  |  |  |                                 ], | 
					
						
							|  |  |  |                             ] | 
					
						
							| 
									
										
										
										
											2017-10-20 19:10:31 +01:00
										 |  |  |                         }, | 
					
						
							| 
									
										
										
										
											2021-11-01 03:31:22 -07:00
										 |  |  |                         "ResourceRequirements": [ | 
					
						
							|  |  |  |                             {"Type": "MEMORY", "Value": 2000}, | 
					
						
							|  |  |  |                             {"Type": "VCPU", "Value": 2}, | 
					
						
							|  |  |  |                         ], | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |                         "Command": ["echo", "Hello world"], | 
					
						
							| 
									
										
										
										
											2020-07-14 03:29:49 -07:00
										 |  |  |                         "LinuxParameters": {"Devices": [{"HostPath": "test-path"}]}, | 
					
						
							| 
									
										
										
										
											2017-10-20 19:10:31 +01:00
										 |  |  |                     }, | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |                     "RetryStrategy": {"Attempts": 1}, | 
					
						
							|  |  |  |                 }, | 
					
						
							| 
									
										
										
										
											2017-10-20 19:10:31 +01:00
										 |  |  |             }, | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     cf_json = json.dumps(create_environment_template) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     cf_conn = boto3.client("cloudformation", DEFAULT_REGION) | 
					
						
							| 
									
										
										
										
											2021-10-05 17:11:07 +00:00
										 |  |  |     stack_name = str(uuid4())[0:6] | 
					
						
							|  |  |  |     stack_id = cf_conn.create_stack(StackName=stack_name, TemplateBody=cf_json)[ | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |         "StackId" | 
					
						
							|  |  |  |     ] | 
					
						
							| 
									
										
										
										
											2017-10-20 19:10:31 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     stack_resources = cf_conn.list_stack_resources(StackName=stack_id) | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     len(stack_resources["StackResourceSummaries"]).should.equal(3) | 
					
						
							| 
									
										
										
										
											2017-10-20 19:10:31 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     job_def_resource = list( | 
					
						
							|  |  |  |         filter( | 
					
						
							|  |  |  |             lambda item: item["ResourceType"] == "AWS::Batch::JobDefinition", | 
					
						
							|  |  |  |             stack_resources["StackResourceSummaries"], | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     )[0] | 
					
						
							| 
									
										
										
										
											2017-10-20 19:10:31 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     job_def_resource["ResourceStatus"].should.equal("CREATE_COMPLETE") | 
					
						
							| 
									
										
										
										
											2017-10-20 19:10:31 +01:00
										 |  |  |     # Spot checks on the ARN | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     job_def_resource["PhysicalResourceId"].startswith("arn:aws:batch:") | 
					
						
							| 
									
										
										
										
											2021-10-05 17:11:07 +00:00
										 |  |  |     job_def_resource["PhysicalResourceId"].should.contain(f"{stack_name}-JobDef") | 
					
						
							| 
									
										
										
										
											2019-10-31 08:44:26 -07:00
										 |  |  |     job_def_resource["PhysicalResourceId"].should.contain("job-definition/") | 
					
						
							| 
									
										
										
										
											2020-07-14 03:29:49 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Test the linux parameter device host path | 
					
						
							|  |  |  |     # This ensures that batch is parsing the parameter dictionaries | 
					
						
							|  |  |  |     # correctly by recursively converting the first character of all | 
					
						
							|  |  |  |     # dict keys to lowercase. | 
					
						
							|  |  |  |     batch_conn = boto3.client("batch", DEFAULT_REGION) | 
					
						
							|  |  |  |     response = batch_conn.describe_job_definitions( | 
					
						
							|  |  |  |         jobDefinitions=[job_def_resource["PhysicalResourceId"]] | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     job_def_linux_device_host_path = response.get("jobDefinitions")[0][ | 
					
						
							|  |  |  |         "containerProperties" | 
					
						
							|  |  |  |     ]["linuxParameters"]["devices"][0]["hostPath"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     job_def_linux_device_host_path.should.equal("test-path") |