moto/tests/test_batch/__init__.py

46 lines
1.4 KiB
Python
Raw Normal View History

2021-08-04 12:40:10 +00:00
import boto3
2021-10-05 17:11:07 +00:00
from uuid import uuid4
2021-08-04 12:40:10 +00:00
DEFAULT_REGION = "eu-central-1"
def _get_clients():
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),
)
def _setup(ec2_client, iam_client):
"""
Do prerequisite setup
:return: VPC ID, Subnet ID, Security group ID, IAM Role ARN
:rtype: tuple
"""
resp = ec2_client.create_vpc(CidrBlock="172.30.0.0/24")
vpc_id = resp["Vpc"]["VpcId"]
resp = ec2_client.create_subnet(
AvailabilityZone="eu-central-1a", CidrBlock="172.30.0.0/25", VpcId=vpc_id
)
subnet_id = resp["Subnet"]["SubnetId"]
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
2021-08-04 12:40:10 +00:00
)
sg_id = resp["GroupId"]
2021-10-05 17:11:07 +00:00
role_name = f"{str(uuid4())[0:6]}"
2021-08-04 12:40:10 +00:00
resp = iam_client.create_role(
2021-10-05 17:11:07 +00:00
RoleName=role_name, AssumeRolePolicyDocument="some_policy"
2021-08-04 12:40:10 +00:00
)
iam_arn = resp["Role"]["Arn"]
2021-10-05 17:11:07 +00:00
iam_client.create_instance_profile(InstanceProfileName=role_name)
2021-08-04 12:40:10 +00:00
iam_client.add_role_to_instance_profile(
2021-10-05 17:11:07 +00:00
InstanceProfileName=role_name, RoleName=role_name
2021-08-04 12:40:10 +00:00
)
return vpc_id, subnet_id, sg_id, iam_arn