Run black on moto & test directories.

This commit is contained in:
Asher Foa 2019-10-31 08:44:26 -07:00
commit 96e5b1993d
507 changed files with 52541 additions and 47814 deletions

File diff suppressed because it is too large Load diff

View file

@ -2,127 +2,134 @@ from __future__ import unicode_literals
import boto3
import sure # noqa
from moto import mock_autoscaling, mock_ec2, mock_elbv2
from moto import mock_autoscaling, mock_ec2, mock_elbv2
from utils import setup_networking
@mock_elbv2
@mock_autoscaling
def test_attach_detach_target_groups():
mocked_networking = setup_networking()
INSTANCE_COUNT = 2
client = boto3.client('autoscaling', region_name='us-east-1')
elbv2_client = boto3.client('elbv2', region_name='us-east-1')
client = boto3.client("autoscaling", region_name="us-east-1")
elbv2_client = boto3.client("elbv2", region_name="us-east-1")
response = elbv2_client.create_target_group(
Name='a-target',
Protocol='HTTP',
Name="a-target",
Protocol="HTTP",
Port=8080,
VpcId=mocked_networking['vpc'],
HealthCheckProtocol='HTTP',
HealthCheckPort='8080',
HealthCheckPath='/',
VpcId=mocked_networking["vpc"],
HealthCheckProtocol="HTTP",
HealthCheckPort="8080",
HealthCheckPath="/",
HealthCheckIntervalSeconds=5,
HealthCheckTimeoutSeconds=5,
HealthyThresholdCount=5,
UnhealthyThresholdCount=2,
Matcher={'HttpCode': '200'})
target_group_arn = response['TargetGroups'][0]['TargetGroupArn']
Matcher={"HttpCode": "200"},
)
target_group_arn = response["TargetGroups"][0]["TargetGroupArn"]
client.create_launch_configuration(
LaunchConfigurationName='test_launch_configuration')
LaunchConfigurationName="test_launch_configuration"
)
# create asg, attach to target group on create
client.create_auto_scaling_group(
AutoScalingGroupName='test_asg',
LaunchConfigurationName='test_launch_configuration',
AutoScalingGroupName="test_asg",
LaunchConfigurationName="test_launch_configuration",
MinSize=0,
MaxSize=INSTANCE_COUNT,
DesiredCapacity=INSTANCE_COUNT,
TargetGroupARNs=[target_group_arn],
VPCZoneIdentifier=mocked_networking['subnet1'])
VPCZoneIdentifier=mocked_networking["subnet1"],
)
# create asg without attaching to target group
client.create_auto_scaling_group(
AutoScalingGroupName='test_asg2',
LaunchConfigurationName='test_launch_configuration',
AutoScalingGroupName="test_asg2",
LaunchConfigurationName="test_launch_configuration",
MinSize=0,
MaxSize=INSTANCE_COUNT,
DesiredCapacity=INSTANCE_COUNT,
VPCZoneIdentifier=mocked_networking['subnet2'])
VPCZoneIdentifier=mocked_networking["subnet2"],
)
response = client.describe_load_balancer_target_groups(
AutoScalingGroupName='test_asg')
list(response['LoadBalancerTargetGroups']).should.have.length_of(1)
AutoScalingGroupName="test_asg"
)
list(response["LoadBalancerTargetGroups"]).should.have.length_of(1)
response = elbv2_client.describe_target_health(
TargetGroupArn=target_group_arn)
list(response['TargetHealthDescriptions']).should.have.length_of(INSTANCE_COUNT)
response = elbv2_client.describe_target_health(TargetGroupArn=target_group_arn)
list(response["TargetHealthDescriptions"]).should.have.length_of(INSTANCE_COUNT)
client.attach_load_balancer_target_groups(
AutoScalingGroupName='test_asg2',
TargetGroupARNs=[target_group_arn])
AutoScalingGroupName="test_asg2", TargetGroupARNs=[target_group_arn]
)
response = elbv2_client.describe_target_health(
TargetGroupArn=target_group_arn)
list(response['TargetHealthDescriptions']).should.have.length_of(INSTANCE_COUNT * 2)
response = elbv2_client.describe_target_health(TargetGroupArn=target_group_arn)
list(response["TargetHealthDescriptions"]).should.have.length_of(INSTANCE_COUNT * 2)
response = client.detach_load_balancer_target_groups(
AutoScalingGroupName='test_asg2',
TargetGroupARNs=[target_group_arn])
response = elbv2_client.describe_target_health(
TargetGroupArn=target_group_arn)
list(response['TargetHealthDescriptions']).should.have.length_of(INSTANCE_COUNT)
AutoScalingGroupName="test_asg2", TargetGroupARNs=[target_group_arn]
)
response = elbv2_client.describe_target_health(TargetGroupArn=target_group_arn)
list(response["TargetHealthDescriptions"]).should.have.length_of(INSTANCE_COUNT)
@mock_elbv2
@mock_autoscaling
def test_detach_all_target_groups():
mocked_networking = setup_networking()
INSTANCE_COUNT = 2
client = boto3.client('autoscaling', region_name='us-east-1')
elbv2_client = boto3.client('elbv2', region_name='us-east-1')
client = boto3.client("autoscaling", region_name="us-east-1")
elbv2_client = boto3.client("elbv2", region_name="us-east-1")
response = elbv2_client.create_target_group(
Name='a-target',
Protocol='HTTP',
Name="a-target",
Protocol="HTTP",
Port=8080,
VpcId=mocked_networking['vpc'],
HealthCheckProtocol='HTTP',
HealthCheckPort='8080',
HealthCheckPath='/',
VpcId=mocked_networking["vpc"],
HealthCheckProtocol="HTTP",
HealthCheckPort="8080",
HealthCheckPath="/",
HealthCheckIntervalSeconds=5,
HealthCheckTimeoutSeconds=5,
HealthyThresholdCount=5,
UnhealthyThresholdCount=2,
Matcher={'HttpCode': '200'})
target_group_arn = response['TargetGroups'][0]['TargetGroupArn']
Matcher={"HttpCode": "200"},
)
target_group_arn = response["TargetGroups"][0]["TargetGroupArn"]
client.create_launch_configuration(
LaunchConfigurationName='test_launch_configuration')
LaunchConfigurationName="test_launch_configuration"
)
client.create_auto_scaling_group(
AutoScalingGroupName='test_asg',
LaunchConfigurationName='test_launch_configuration',
AutoScalingGroupName="test_asg",
LaunchConfigurationName="test_launch_configuration",
MinSize=0,
MaxSize=INSTANCE_COUNT,
DesiredCapacity=INSTANCE_COUNT,
TargetGroupARNs=[target_group_arn],
VPCZoneIdentifier=mocked_networking['subnet1'])
VPCZoneIdentifier=mocked_networking["subnet1"],
)
response = client.describe_load_balancer_target_groups(
AutoScalingGroupName='test_asg')
list(response['LoadBalancerTargetGroups']).should.have.length_of(1)
AutoScalingGroupName="test_asg"
)
list(response["LoadBalancerTargetGroups"]).should.have.length_of(1)
response = elbv2_client.describe_target_health(
TargetGroupArn=target_group_arn)
list(response['TargetHealthDescriptions']).should.have.length_of(INSTANCE_COUNT)
response = elbv2_client.describe_target_health(TargetGroupArn=target_group_arn)
list(response["TargetHealthDescriptions"]).should.have.length_of(INSTANCE_COUNT)
response = client.detach_load_balancer_target_groups(
AutoScalingGroupName='test_asg',
TargetGroupARNs=[target_group_arn])
AutoScalingGroupName="test_asg", TargetGroupARNs=[target_group_arn]
)
response = elbv2_client.describe_target_health(
TargetGroupArn=target_group_arn)
list(response['TargetHealthDescriptions']).should.have.length_of(0)
response = elbv2_client.describe_target_health(TargetGroupArn=target_group_arn)
list(response["TargetHealthDescriptions"]).should.have.length_of(0)
response = client.describe_load_balancer_target_groups(
AutoScalingGroupName='test_asg')
list(response['LoadBalancerTargetGroups']).should.have.length_of(0)
AutoScalingGroupName="test_asg"
)
list(response["LoadBalancerTargetGroups"]).should.have.length_of(0)

View file

@ -15,29 +15,29 @@ from tests.helpers import requires_boto_gte
def test_create_launch_configuration():
conn = boto.connect_autoscale()
config = LaunchConfiguration(
name='tester',
image_id='ami-abcd1234',
instance_type='t1.micro',
key_name='the_keys',
name="tester",
image_id="ami-abcd1234",
instance_type="t1.micro",
key_name="the_keys",
security_groups=["default", "default2"],
user_data=b"This is some user_data",
instance_monitoring=True,
instance_profile_name='arn:aws:iam::123456789012:instance-profile/testing',
instance_profile_name="arn:aws:iam::123456789012:instance-profile/testing",
spot_price=0.1,
)
conn.create_launch_configuration(config)
launch_config = conn.get_all_launch_configurations()[0]
launch_config.name.should.equal('tester')
launch_config.image_id.should.equal('ami-abcd1234')
launch_config.instance_type.should.equal('t1.micro')
launch_config.key_name.should.equal('the_keys')
set(launch_config.security_groups).should.equal(
set(['default', 'default2']))
launch_config.name.should.equal("tester")
launch_config.image_id.should.equal("ami-abcd1234")
launch_config.instance_type.should.equal("t1.micro")
launch_config.key_name.should.equal("the_keys")
set(launch_config.security_groups).should.equal(set(["default", "default2"]))
launch_config.user_data.should.equal(b"This is some user_data")
launch_config.instance_monitoring.enabled.should.equal('true')
launch_config.instance_monitoring.enabled.should.equal("true")
launch_config.instance_profile_name.should.equal(
'arn:aws:iam::123456789012:instance-profile/testing')
"arn:aws:iam::123456789012:instance-profile/testing"
)
launch_config.spot_price.should.equal(0.1)
@ -47,64 +47,65 @@ def test_create_launch_configuration_with_block_device_mappings():
block_device_mapping = BlockDeviceMapping()
ephemeral_drive = BlockDeviceType()
ephemeral_drive.ephemeral_name = 'ephemeral0'
block_device_mapping['/dev/xvdb'] = ephemeral_drive
ephemeral_drive.ephemeral_name = "ephemeral0"
block_device_mapping["/dev/xvdb"] = ephemeral_drive
snapshot_drive = BlockDeviceType()
snapshot_drive.snapshot_id = "snap-1234abcd"
snapshot_drive.volume_type = "standard"
block_device_mapping['/dev/xvdp'] = snapshot_drive
block_device_mapping["/dev/xvdp"] = snapshot_drive
ebs_drive = BlockDeviceType()
ebs_drive.volume_type = "io1"
ebs_drive.size = 100
ebs_drive.iops = 1000
ebs_drive.delete_on_termination = False
block_device_mapping['/dev/xvdh'] = ebs_drive
block_device_mapping["/dev/xvdh"] = ebs_drive
conn = boto.connect_autoscale(use_block_device_types=True)
config = LaunchConfiguration(
name='tester',
image_id='ami-abcd1234',
instance_type='m1.small',
key_name='the_keys',
name="tester",
image_id="ami-abcd1234",
instance_type="m1.small",
key_name="the_keys",
security_groups=["default", "default2"],
user_data=b"This is some user_data",
instance_monitoring=True,
instance_profile_name='arn:aws:iam::123456789012:instance-profile/testing',
instance_profile_name="arn:aws:iam::123456789012:instance-profile/testing",
spot_price=0.1,
block_device_mappings=[block_device_mapping]
block_device_mappings=[block_device_mapping],
)
conn.create_launch_configuration(config)
launch_config = conn.get_all_launch_configurations()[0]
launch_config.name.should.equal('tester')
launch_config.image_id.should.equal('ami-abcd1234')
launch_config.instance_type.should.equal('m1.small')
launch_config.key_name.should.equal('the_keys')
set(launch_config.security_groups).should.equal(
set(['default', 'default2']))
launch_config.name.should.equal("tester")
launch_config.image_id.should.equal("ami-abcd1234")
launch_config.instance_type.should.equal("m1.small")
launch_config.key_name.should.equal("the_keys")
set(launch_config.security_groups).should.equal(set(["default", "default2"]))
launch_config.user_data.should.equal(b"This is some user_data")
launch_config.instance_monitoring.enabled.should.equal('true')
launch_config.instance_monitoring.enabled.should.equal("true")
launch_config.instance_profile_name.should.equal(
'arn:aws:iam::123456789012:instance-profile/testing')
"arn:aws:iam::123456789012:instance-profile/testing"
)
launch_config.spot_price.should.equal(0.1)
len(launch_config.block_device_mappings).should.equal(3)
returned_mapping = launch_config.block_device_mappings
set(returned_mapping.keys()).should.equal(
set(['/dev/xvdb', '/dev/xvdp', '/dev/xvdh']))
set(["/dev/xvdb", "/dev/xvdp", "/dev/xvdh"])
)
returned_mapping['/dev/xvdh'].iops.should.equal(1000)
returned_mapping['/dev/xvdh'].size.should.equal(100)
returned_mapping['/dev/xvdh'].volume_type.should.equal("io1")
returned_mapping['/dev/xvdh'].delete_on_termination.should.be.false
returned_mapping["/dev/xvdh"].iops.should.equal(1000)
returned_mapping["/dev/xvdh"].size.should.equal(100)
returned_mapping["/dev/xvdh"].volume_type.should.equal("io1")
returned_mapping["/dev/xvdh"].delete_on_termination.should.be.false
returned_mapping['/dev/xvdp'].snapshot_id.should.equal("snap-1234abcd")
returned_mapping['/dev/xvdp'].volume_type.should.equal("standard")
returned_mapping["/dev/xvdp"].snapshot_id.should.equal("snap-1234abcd")
returned_mapping["/dev/xvdp"].volume_type.should.equal("standard")
returned_mapping['/dev/xvdb'].ephemeral_name.should.equal('ephemeral0')
returned_mapping["/dev/xvdb"].ephemeral_name.should.equal("ephemeral0")
@requires_boto_gte("2.12")
@ -112,9 +113,7 @@ def test_create_launch_configuration_with_block_device_mappings():
def test_create_launch_configuration_for_2_12():
conn = boto.connect_autoscale()
config = LaunchConfiguration(
name='tester',
image_id='ami-abcd1234',
ebs_optimized=True,
name="tester", image_id="ami-abcd1234", ebs_optimized=True
)
conn.create_launch_configuration(config)
@ -127,9 +126,7 @@ def test_create_launch_configuration_for_2_12():
def test_create_launch_configuration_using_ip_association():
conn = boto.connect_autoscale()
config = LaunchConfiguration(
name='tester',
image_id='ami-abcd1234',
associate_public_ip_address=True,
name="tester", image_id="ami-abcd1234", associate_public_ip_address=True
)
conn.create_launch_configuration(config)
@ -141,10 +138,7 @@ def test_create_launch_configuration_using_ip_association():
@mock_autoscaling_deprecated
def test_create_launch_configuration_using_ip_association_should_default_to_false():
conn = boto.connect_autoscale()
config = LaunchConfiguration(
name='tester',
image_id='ami-abcd1234',
)
config = LaunchConfiguration(name="tester", image_id="ami-abcd1234")
conn.create_launch_configuration(config)
launch_config = conn.get_all_launch_configurations()[0]
@ -157,22 +151,20 @@ def test_create_launch_configuration_defaults():
are assigned for the other attributes """
conn = boto.connect_autoscale()
config = LaunchConfiguration(
name='tester',
image_id='ami-abcd1234',
instance_type='m1.small',
name="tester", image_id="ami-abcd1234", instance_type="m1.small"
)
conn.create_launch_configuration(config)
launch_config = conn.get_all_launch_configurations()[0]
launch_config.name.should.equal('tester')
launch_config.image_id.should.equal('ami-abcd1234')
launch_config.instance_type.should.equal('m1.small')
launch_config.name.should.equal("tester")
launch_config.image_id.should.equal("ami-abcd1234")
launch_config.instance_type.should.equal("m1.small")
# Defaults
launch_config.key_name.should.equal('')
launch_config.key_name.should.equal("")
list(launch_config.security_groups).should.equal([])
launch_config.user_data.should.equal(b"")
launch_config.instance_monitoring.enabled.should.equal('false')
launch_config.instance_monitoring.enabled.should.equal("false")
launch_config.instance_profile_name.should.equal(None)
launch_config.spot_price.should.equal(None)
@ -181,10 +173,7 @@ def test_create_launch_configuration_defaults():
@mock_autoscaling_deprecated
def test_create_launch_configuration_defaults_for_2_12():
conn = boto.connect_autoscale()
config = LaunchConfiguration(
name='tester',
image_id='ami-abcd1234',
)
config = LaunchConfiguration(name="tester", image_id="ami-abcd1234")
conn.create_launch_configuration(config)
launch_config = conn.get_all_launch_configurations()[0]
@ -195,51 +184,48 @@ def test_create_launch_configuration_defaults_for_2_12():
def test_launch_configuration_describe_filter():
conn = boto.connect_autoscale()
config = LaunchConfiguration(
name='tester',
image_id='ami-abcd1234',
instance_type='m1.small',
name="tester", image_id="ami-abcd1234", instance_type="m1.small"
)
conn.create_launch_configuration(config)
config.name = 'tester2'
config.name = "tester2"
conn.create_launch_configuration(config)
config.name = 'tester3'
config.name = "tester3"
conn.create_launch_configuration(config)
conn.get_all_launch_configurations(
names=['tester', 'tester2']).should.have.length_of(2)
names=["tester", "tester2"]
).should.have.length_of(2)
conn.get_all_launch_configurations().should.have.length_of(3)
@mock_autoscaling
def test_launch_configuration_describe_paginated():
conn = boto3.client('autoscaling', region_name='us-east-1')
conn = boto3.client("autoscaling", region_name="us-east-1")
for i in range(51):
conn.create_launch_configuration(LaunchConfigurationName='TestLC%d' % i)
conn.create_launch_configuration(LaunchConfigurationName="TestLC%d" % i)
response = conn.describe_launch_configurations()
lcs = response["LaunchConfigurations"]
marker = response["NextToken"]
lcs.should.have.length_of(50)
marker.should.equal(lcs[-1]['LaunchConfigurationName'])
marker.should.equal(lcs[-1]["LaunchConfigurationName"])
response2 = conn.describe_launch_configurations(NextToken=marker)
lcs.extend(response2["LaunchConfigurations"])
lcs.should.have.length_of(51)
assert 'NextToken' not in response2.keys()
assert "NextToken" not in response2.keys()
@mock_autoscaling_deprecated
def test_launch_configuration_delete():
conn = boto.connect_autoscale()
config = LaunchConfiguration(
name='tester',
image_id='ami-abcd1234',
instance_type='m1.small',
name="tester", image_id="ami-abcd1234", instance_type="m1.small"
)
conn.create_launch_configuration(config)
conn.get_all_launch_configurations().should.have.length_of(1)
conn.delete_launch_configuration('tester')
conn.delete_launch_configuration("tester")
conn.get_all_launch_configurations().should.have.length_of(0)

View file

@ -14,18 +14,16 @@ def setup_autoscale_group():
mocked_networking = setup_networking_deprecated()
conn = boto.connect_autoscale()
config = LaunchConfiguration(
name='tester',
image_id='ami-abcd1234',
instance_type='m1.small',
name="tester", image_id="ami-abcd1234", instance_type="m1.small"
)
conn.create_launch_configuration(config)
group = AutoScalingGroup(
name='tester_group',
name="tester_group",
max_size=2,
min_size=2,
launch_config=config,
vpc_zone_identifier=mocked_networking['subnet1'],
vpc_zone_identifier=mocked_networking["subnet1"],
)
conn.create_auto_scaling_group(group)
return group
@ -36,18 +34,18 @@ def test_create_policy():
setup_autoscale_group()
conn = boto.connect_autoscale()
policy = ScalingPolicy(
name='ScaleUp',
adjustment_type='ExactCapacity',
as_name='tester_group',
name="ScaleUp",
adjustment_type="ExactCapacity",
as_name="tester_group",
scaling_adjustment=3,
cooldown=60,
)
conn.create_scaling_policy(policy)
policy = conn.get_all_policies()[0]
policy.name.should.equal('ScaleUp')
policy.adjustment_type.should.equal('ExactCapacity')
policy.as_name.should.equal('tester_group')
policy.name.should.equal("ScaleUp")
policy.adjustment_type.should.equal("ExactCapacity")
policy.as_name.should.equal("tester_group")
policy.scaling_adjustment.should.equal(3)
policy.cooldown.should.equal(60)
@ -57,15 +55,15 @@ def test_create_policy_default_values():
setup_autoscale_group()
conn = boto.connect_autoscale()
policy = ScalingPolicy(
name='ScaleUp',
adjustment_type='ExactCapacity',
as_name='tester_group',
name="ScaleUp",
adjustment_type="ExactCapacity",
as_name="tester_group",
scaling_adjustment=3,
)
conn.create_scaling_policy(policy)
policy = conn.get_all_policies()[0]
policy.name.should.equal('ScaleUp')
policy.name.should.equal("ScaleUp")
# Defaults
policy.cooldown.should.equal(300)
@ -76,9 +74,9 @@ def test_update_policy():
setup_autoscale_group()
conn = boto.connect_autoscale()
policy = ScalingPolicy(
name='ScaleUp',
adjustment_type='ExactCapacity',
as_name='tester_group',
name="ScaleUp",
adjustment_type="ExactCapacity",
as_name="tester_group",
scaling_adjustment=3,
)
conn.create_scaling_policy(policy)
@ -88,9 +86,9 @@ def test_update_policy():
# Now update it by creating another with the same name
policy = ScalingPolicy(
name='ScaleUp',
adjustment_type='ExactCapacity',
as_name='tester_group',
name="ScaleUp",
adjustment_type="ExactCapacity",
as_name="tester_group",
scaling_adjustment=2,
)
conn.create_scaling_policy(policy)
@ -103,16 +101,16 @@ def test_delete_policy():
setup_autoscale_group()
conn = boto.connect_autoscale()
policy = ScalingPolicy(
name='ScaleUp',
adjustment_type='ExactCapacity',
as_name='tester_group',
name="ScaleUp",
adjustment_type="ExactCapacity",
as_name="tester_group",
scaling_adjustment=3,
)
conn.create_scaling_policy(policy)
conn.get_all_policies().should.have.length_of(1)
conn.delete_policy('ScaleUp')
conn.delete_policy("ScaleUp")
conn.get_all_policies().should.have.length_of(0)
@ -121,9 +119,9 @@ def test_execute_policy_exact_capacity():
setup_autoscale_group()
conn = boto.connect_autoscale()
policy = ScalingPolicy(
name='ScaleUp',
adjustment_type='ExactCapacity',
as_name='tester_group',
name="ScaleUp",
adjustment_type="ExactCapacity",
as_name="tester_group",
scaling_adjustment=3,
)
conn.create_scaling_policy(policy)
@ -139,9 +137,9 @@ def test_execute_policy_positive_change_in_capacity():
setup_autoscale_group()
conn = boto.connect_autoscale()
policy = ScalingPolicy(
name='ScaleUp',
adjustment_type='ChangeInCapacity',
as_name='tester_group',
name="ScaleUp",
adjustment_type="ChangeInCapacity",
as_name="tester_group",
scaling_adjustment=3,
)
conn.create_scaling_policy(policy)
@ -157,9 +155,9 @@ def test_execute_policy_percent_change_in_capacity():
setup_autoscale_group()
conn = boto.connect_autoscale()
policy = ScalingPolicy(
name='ScaleUp',
adjustment_type='PercentChangeInCapacity',
as_name='tester_group',
name="ScaleUp",
adjustment_type="PercentChangeInCapacity",
as_name="tester_group",
scaling_adjustment=50,
)
conn.create_scaling_policy(policy)
@ -178,9 +176,9 @@ def test_execute_policy_small_percent_change_in_capacity():
setup_autoscale_group()
conn = boto.connect_autoscale()
policy = ScalingPolicy(
name='ScaleUp',
adjustment_type='PercentChangeInCapacity',
as_name='tester_group',
name="ScaleUp",
adjustment_type="PercentChangeInCapacity",
as_name="tester_group",
scaling_adjustment=1,
)
conn.create_scaling_policy(policy)

View file

@ -3,16 +3,16 @@ import sure # noqa
import moto.server as server
'''
"""
Test the different server responses
'''
"""
def test_describe_autoscaling_groups():
backend = server.create_backend_app("autoscaling")
test_client = backend.test_client()
res = test_client.get('/?Action=DescribeLaunchConfigurations')
res = test_client.get("/?Action=DescribeLaunchConfigurations")
res.data.should.contain(b'<DescribeLaunchConfigurationsResponse')
res.data.should.contain(b'<LaunchConfigurations>')
res.data.should.contain(b"<DescribeLaunchConfigurationsResponse")
res.data.should.contain(b"<LaunchConfigurations>")

View file

@ -6,43 +6,36 @@ from moto import mock_ec2, mock_ec2_deprecated
@mock_ec2
def setup_networking():
ec2 = boto3.resource('ec2', region_name='us-east-1')
vpc = ec2.create_vpc(CidrBlock='10.11.0.0/16')
ec2 = boto3.resource("ec2", region_name="us-east-1")
vpc = ec2.create_vpc(CidrBlock="10.11.0.0/16")
subnet1 = ec2.create_subnet(
VpcId=vpc.id,
CidrBlock='10.11.1.0/24',
AvailabilityZone='us-east-1a')
VpcId=vpc.id, CidrBlock="10.11.1.0/24", AvailabilityZone="us-east-1a"
)
subnet2 = ec2.create_subnet(
VpcId=vpc.id,
CidrBlock='10.11.2.0/24',
AvailabilityZone='us-east-1b')
return {'vpc': vpc.id, 'subnet1': subnet1.id, 'subnet2': subnet2.id}
VpcId=vpc.id, CidrBlock="10.11.2.0/24", AvailabilityZone="us-east-1b"
)
return {"vpc": vpc.id, "subnet1": subnet1.id, "subnet2": subnet2.id}
@mock_ec2_deprecated
def setup_networking_deprecated():
conn = boto_vpc.connect_to_region('us-east-1')
conn = boto_vpc.connect_to_region("us-east-1")
vpc = conn.create_vpc("10.11.0.0/16")
subnet1 = conn.create_subnet(
vpc.id,
"10.11.1.0/24",
availability_zone='us-east-1a')
subnet2 = conn.create_subnet(
vpc.id,
"10.11.2.0/24",
availability_zone='us-east-1b')
return {'vpc': vpc.id, 'subnet1': subnet1.id, 'subnet2': subnet2.id}
subnet1 = conn.create_subnet(vpc.id, "10.11.1.0/24", availability_zone="us-east-1a")
subnet2 = conn.create_subnet(vpc.id, "10.11.2.0/24", availability_zone="us-east-1b")
return {"vpc": vpc.id, "subnet1": subnet1.id, "subnet2": subnet2.id}
@mock_ec2
def setup_instance_with_networking(image_id, instance_type):
mock_data = setup_networking()
ec2 = boto3.resource('ec2', region_name='us-east-1')
ec2 = boto3.resource("ec2", region_name="us-east-1")
instances = ec2.create_instances(
ImageId=image_id,
InstanceType=instance_type,
MaxCount=1,
MinCount=1,
SubnetId=mock_data['subnet1']
SubnetId=mock_data["subnet1"],
)
mock_data['instance'] = instances[0].id
mock_data["instance"] = instances[0].id
return mock_data