Merge branch 'master' into redshift-copy-grants

This commit is contained in:
Steve Pulec 2018-03-06 22:11:34 -05:00 committed by GitHub
commit 8a0cf49b7d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 420 additions and 25 deletions

View file

@ -2156,6 +2156,78 @@ def test_stack_spot_fleet():
launch_spec['WeightedCapacity'].should.equal(2.0)
@mock_cloudformation()
@mock_ec2()
def test_stack_spot_fleet_should_figure_out_default_price():
conn = boto3.client('ec2', 'us-east-1')
vpc = conn.create_vpc(CidrBlock="10.0.0.0/8")['Vpc']
subnet = conn.create_subnet(
VpcId=vpc['VpcId'], CidrBlock='10.0.0.0/16', AvailabilityZone='us-east-1a')['Subnet']
subnet_id = subnet['SubnetId']
spot_fleet_template = {
'Resources': {
"SpotFleet1": {
"Type": "AWS::EC2::SpotFleet",
"Properties": {
"SpotFleetRequestConfigData": {
"IamFleetRole": "arn:aws:iam::123456789012:role/fleet",
"TargetCapacity": 6,
"AllocationStrategy": "diversified",
"LaunchSpecifications": [
{
"EbsOptimized": "false",
"InstanceType": 't2.small',
"ImageId": "ami-1234",
"SubnetId": subnet_id,
"WeightedCapacity": "2",
},
{
"EbsOptimized": "true",
"InstanceType": 't2.large',
"ImageId": "ami-1234",
"Monitoring": {"Enabled": "true"},
"SecurityGroups": [{"GroupId": "sg-123"}],
"SubnetId": subnet_id,
"IamInstanceProfile": {"Arn": "arn:aws:iam::123456789012:role/fleet"},
"WeightedCapacity": "4",
}
]
}
}
}
}
}
spot_fleet_template_json = json.dumps(spot_fleet_template)
cf_conn = boto3.client('cloudformation', 'us-east-1')
stack_id = cf_conn.create_stack(
StackName='test_stack',
TemplateBody=spot_fleet_template_json,
)['StackId']
stack_resources = cf_conn.list_stack_resources(StackName=stack_id)
stack_resources['StackResourceSummaries'].should.have.length_of(1)
spot_fleet_id = stack_resources[
'StackResourceSummaries'][0]['PhysicalResourceId']
spot_fleet_requests = conn.describe_spot_fleet_requests(
SpotFleetRequestIds=[spot_fleet_id])['SpotFleetRequestConfigs']
len(spot_fleet_requests).should.equal(1)
spot_fleet_request = spot_fleet_requests[0]
spot_fleet_request['SpotFleetRequestState'].should.equal("active")
spot_fleet_config = spot_fleet_request['SpotFleetRequestConfig']
assert 'SpotPrice' not in spot_fleet_config
len(spot_fleet_config['LaunchSpecifications']).should.equal(2)
launch_spec1 = spot_fleet_config['LaunchSpecifications'][0]
launch_spec2 = spot_fleet_config['LaunchSpecifications'][1]
assert 'SpotPrice' not in launch_spec1
assert 'SpotPrice' not in launch_spec2
@mock_ec2
@mock_elbv2
@mock_cloudformation

View file

@ -5,10 +5,11 @@ from nose.tools import assert_raises
from moto.ec2 import ec2_backends
import boto
import boto3
from boto.exception import EC2ResponseError
import sure # noqa
from moto import mock_ec2_deprecated
from moto import mock_ec2_deprecated, mock_ec2
@mock_ec2_deprecated
@ -579,3 +580,25 @@ def test_volume_tag_escaping():
snaps = [snap for snap in conn.get_all_snapshots() if snap.id == snapshot.id]
dict(snaps[0].tags).should.equal({'key': '</closed>'})
@mock_ec2
def test_search_for_many_snapshots():
ec2_client = boto3.client('ec2', region_name='eu-west-1')
volume_response = ec2_client.create_volume(
AvailabilityZone='eu-west-1a', Size=10
)
snapshot_ids = []
for i in range(1, 20):
create_snapshot_response = ec2_client.create_snapshot(
VolumeId=volume_response['VolumeId']
)
snapshot_ids.append(create_snapshot_response['SnapshotId'])
snapshots_response = ec2_client.describe_snapshots(
SnapshotIds=snapshot_ids
)
assert len(snapshots_response['Snapshots']) == len(snapshot_ids)

View file

@ -316,3 +316,30 @@ def test_modify_spot_fleet_request_down_no_terminate_after_custom_terminate():
SpotFleetRequestIds=[spot_fleet_id])['SpotFleetRequestConfigs'][0]['SpotFleetRequestConfig']
spot_fleet_config['TargetCapacity'].should.equal(1)
spot_fleet_config['FulfilledCapacity'].should.equal(2.0)
@mock_ec2
def test_create_spot_fleet_without_spot_price():
conn = boto3.client("ec2", region_name='us-west-2')
subnet_id = get_subnet_id(conn)
# remove prices to force a fallback to ondemand price
spot_config_without_price = spot_config(subnet_id)
del spot_config_without_price['SpotPrice']
for spec in spot_config_without_price['LaunchSpecifications']:
del spec['SpotPrice']
spot_fleet_id = conn.request_spot_fleet(SpotFleetRequestConfig=spot_config_without_price)['SpotFleetRequestId']
spot_fleet_requests = conn.describe_spot_fleet_requests(
SpotFleetRequestIds=[spot_fleet_id])['SpotFleetRequestConfigs']
len(spot_fleet_requests).should.equal(1)
spot_fleet_request = spot_fleet_requests[0]
spot_fleet_config = spot_fleet_request['SpotFleetRequestConfig']
len(spot_fleet_config['LaunchSpecifications']).should.equal(2)
launch_spec1 = spot_fleet_config['LaunchSpecifications'][0]
launch_spec2 = spot_fleet_config['LaunchSpecifications'][1]
# AWS will figure out the price
assert 'SpotPrice' not in launch_spec1
assert 'SpotPrice' not in launch_spec2

View file

@ -340,6 +340,10 @@ def test_create_target_group_and_listeners():
'Type': 'forward'}])
http_listener_arn = listener.get('ListenerArn')
response = conn.describe_target_groups(LoadBalancerArn=load_balancer_arn,
Names=['a-target'])
response.get('TargetGroups').should.have.length_of(1)
# And another with SSL
response = conn.create_listener(
LoadBalancerArn=load_balancer_arn,

View file

@ -1081,3 +1081,98 @@ def test_tagged_resource_not_found_error():
ResourceName='bad:arn'
).should.throw(ClientError, "Tagging is not supported for this type of resource")
@mock_redshift
def test_enable_snapshot_copy():
client = boto3.client('redshift', region_name='us-east-1')
client.create_cluster(
ClusterIdentifier='test',
ClusterType='single-node',
DBName='test',
Encrypted=True,
MasterUsername='user',
MasterUserPassword='password',
NodeType='ds2.xlarge',
)
client.enable_snapshot_copy(
ClusterIdentifier='test',
DestinationRegion='us-west-2',
RetentionPeriod=3,
SnapshotCopyGrantName='copy-us-east-1-to-us-west-2'
)
response = client.describe_clusters(ClusterIdentifier='test')
cluster_snapshot_copy_status = response['Clusters'][0]['ClusterSnapshotCopyStatus']
cluster_snapshot_copy_status['RetentionPeriod'].should.equal(3)
cluster_snapshot_copy_status['DestinationRegion'].should.equal('us-west-2')
cluster_snapshot_copy_status['SnapshotCopyGrantName'].should.equal('copy-us-east-1-to-us-west-2')
@mock_redshift
def test_enable_snapshot_copy_unencrypted():
client = boto3.client('redshift', region_name='us-east-1')
client.create_cluster(
ClusterIdentifier='test',
ClusterType='single-node',
DBName='test',
MasterUsername='user',
MasterUserPassword='password',
NodeType='ds2.xlarge',
)
client.enable_snapshot_copy(
ClusterIdentifier='test',
DestinationRegion='us-west-2',
)
response = client.describe_clusters(ClusterIdentifier='test')
cluster_snapshot_copy_status = response['Clusters'][0]['ClusterSnapshotCopyStatus']
cluster_snapshot_copy_status['RetentionPeriod'].should.equal(7)
cluster_snapshot_copy_status['DestinationRegion'].should.equal('us-west-2')
@mock_redshift
def test_disable_snapshot_copy():
client = boto3.client('redshift', region_name='us-east-1')
client.create_cluster(
DBName='test',
ClusterIdentifier='test',
ClusterType='single-node',
NodeType='ds2.xlarge',
MasterUsername='user',
MasterUserPassword='password',
)
client.enable_snapshot_copy(
ClusterIdentifier='test',
DestinationRegion='us-west-2',
RetentionPeriod=3,
SnapshotCopyGrantName='copy-us-east-1-to-us-west-2',
)
client.disable_snapshot_copy(
ClusterIdentifier='test',
)
response = client.describe_clusters(ClusterIdentifier='test')
response['Clusters'][0].shouldnt.contain('ClusterSnapshotCopyStatus')
@mock_redshift
def test_modify_snapshot_copy_retention_period():
client = boto3.client('redshift', region_name='us-east-1')
client.create_cluster(
DBName='test',
ClusterIdentifier='test',
ClusterType='single-node',
NodeType='ds2.xlarge',
MasterUsername='user',
MasterUserPassword='password',
)
client.enable_snapshot_copy(
ClusterIdentifier='test',
DestinationRegion='us-west-2',
RetentionPeriod=3,
SnapshotCopyGrantName='copy-us-east-1-to-us-west-2',
)
client.modify_snapshot_copy_retention_period(
ClusterIdentifier='test',
RetentionPeriod=5,
)
response = client.describe_clusters(ClusterIdentifier='test')
cluster_snapshot_copy_status = response['Clusters'][0]['ClusterSnapshotCopyStatus']
cluster_snapshot_copy_status['RetentionPeriod'].should.equal(5)

View file

@ -1,6 +1,6 @@
from __future__ import unicode_literals
from sure import expect
from moto.s3.utils import bucket_name_from_url, _VersionedKeyStore
from moto.s3.utils import bucket_name_from_url, _VersionedKeyStore, parse_region_from_url
def test_base_url():
@ -53,3 +53,21 @@ def test_versioned_key_store():
d.setlist('key', [[1], [2]])
d['key'].should.have.length_of(1)
d.getlist('key').should.be.equal([[1], [2]])
def test_parse_region_from_url():
expected = 'us-west-2'
for url in ['http://s3-us-west-2.amazonaws.com/bucket',
'http://s3.us-west-2.amazonaws.com/bucket',
'http://bucket.s3-us-west-2.amazonaws.com',
'https://s3-us-west-2.amazonaws.com/bucket',
'https://s3.us-west-2.amazonaws.com/bucket',
'https://bucket.s3-us-west-2.amazonaws.com']:
parse_region_from_url(url).should.equal(expected)
expected = 'us-east-1'
for url in ['http://s3.amazonaws.com/bucket',
'http://bucket.s3.amazonaws.com',
'https://s3.amazonaws.com/bucket',
'https://bucket.s3.amazonaws.com']:
parse_region_from_url(url).should.equal(expected)