This commit is contained in:
Steve Pulec 2017-02-23 21:37:43 -05:00
commit f37bad0e00
260 changed files with 6363 additions and 3766 deletions

View file

@ -20,10 +20,12 @@ def test_ami_create_and_delete():
instance = reservation.instances[0]
with assert_raises(EC2ResponseError) as ex:
image_id = conn.create_image(instance.id, "test-ami", "this is a test ami", dry_run=True)
image_id = conn.create_image(
instance.id, "test-ami", "this is a test ami", dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the CreateImage operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the CreateImage operation: Request would have succeeded, but DryRun flag is set')
image_id = conn.create_image(instance.id, "test-ami", "this is a test ami")
@ -47,8 +49,10 @@ def test_ami_create_and_delete():
snapshots.should.have.length_of(1)
snapshot = snapshots[0]
image.block_device_mapping.current_value.snapshot_id.should.equal(snapshot.id)
snapshot.description.should.equal("Auto-created snapshot for AMI {0}".format(image.id))
image.block_device_mapping.current_value.snapshot_id.should.equal(
snapshot.id)
snapshot.description.should.equal(
"Auto-created snapshot for AMI {0}".format(image.id))
snapshot.volume_id.should.equal(volume.id)
# Deregister
@ -56,7 +60,8 @@ def test_ami_create_and_delete():
success = conn.deregister_image(image_id, dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the DeregisterImage operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the DeregisterImage operation: Request would have succeeded, but DryRun flag is set')
success = conn.deregister_image(image_id)
success.should.be.true
@ -75,23 +80,29 @@ def test_ami_copy():
reservation = conn.run_instances('ami-1234abcd')
instance = reservation.instances[0]
source_image_id = conn.create_image(instance.id, "test-ami", "this is a test ami")
source_image_id = conn.create_image(
instance.id, "test-ami", "this is a test ami")
instance.terminate()
source_image = conn.get_all_images(image_ids=[source_image_id])[0]
# Boto returns a 'CopyImage' object with an image_id attribute here. Use the image_id to fetch the full info.
# Boto returns a 'CopyImage' object with an image_id attribute here. Use
# the image_id to fetch the full info.
with assert_raises(EC2ResponseError) as ex:
copy_image_ref = conn.copy_image(source_image.region.name, source_image.id, "test-copy-ami", "this is a test copy ami", dry_run=True)
copy_image_ref = conn.copy_image(
source_image.region.name, source_image.id, "test-copy-ami", "this is a test copy ami", dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the CopyImage operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the CopyImage operation: Request would have succeeded, but DryRun flag is set')
copy_image_ref = conn.copy_image(source_image.region.name, source_image.id, "test-copy-ami", "this is a test copy ami")
copy_image_ref = conn.copy_image(
source_image.region.name, source_image.id, "test-copy-ami", "this is a test copy ami")
copy_image_id = copy_image_ref.image_id
copy_image = conn.get_all_images(image_ids=[copy_image_id])[0]
copy_image.id.should.equal(copy_image_id)
copy_image.virtualization_type.should.equal(source_image.virtualization_type)
copy_image.virtualization_type.should.equal(
source_image.virtualization_type)
copy_image.architecture.should.equal(source_image.architecture)
copy_image.kernel_id.should.equal(source_image.kernel_id)
copy_image.platform.should.equal(source_image.platform)
@ -105,15 +116,18 @@ def test_ami_copy():
# Copy from non-existent source ID.
with assert_raises(EC2ResponseError) as cm:
conn.copy_image(source_image.region.name, 'ami-abcd1234', "test-copy-ami", "this is a test copy ami")
conn.copy_image(source_image.region.name, 'ami-abcd1234',
"test-copy-ami", "this is a test copy ami")
cm.exception.code.should.equal('InvalidAMIID.NotFound')
cm.exception.status.should.equal(400)
cm.exception.request_id.should_not.be.none
# Copy from non-existent source region.
with assert_raises(EC2ResponseError) as cm:
invalid_region = 'us-east-1' if (source_image.region.name != 'us-east-1') else 'us-west-1'
conn.copy_image(invalid_region, source_image.id, "test-copy-ami", "this is a test copy ami")
invalid_region = 'us-east-1' if (source_image.region.name !=
'us-east-1') else 'us-west-1'
conn.copy_image(invalid_region, source_image.id,
"test-copy-ami", "this is a test copy ami")
cm.exception.code.should.equal('InvalidAMIID.NotFound')
cm.exception.status.should.equal(400)
cm.exception.request_id.should_not.be.none
@ -131,7 +145,8 @@ def test_ami_tagging():
image.add_tag("a key", "some value", dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the CreateTags operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the CreateTags operation: Request would have succeeded, but DryRun flag is set')
image.add_tag("a key", "some value")
@ -179,7 +194,8 @@ def test_ami_filters():
instanceA.modify_attribute("kernel", "k-1234abcd")
instanceA.modify_attribute("platform", "windows")
instanceA.modify_attribute("virtualization_type", "hvm")
imageA_id = conn.create_image(instanceA.id, "test-ami-A", "this is a test ami")
imageA_id = conn.create_image(
instanceA.id, "test-ami-A", "this is a test ami")
imageA = conn.get_image(imageA_id)
reservationB = conn.run_instances('ami-abcd1234')
@ -188,18 +204,22 @@ def test_ami_filters():
instanceB.modify_attribute("kernel", "k-abcd1234")
instanceB.modify_attribute("platform", "linux")
instanceB.modify_attribute("virtualization_type", "paravirtual")
imageB_id = conn.create_image(instanceB.id, "test-ami-B", "this is a test ami")
imageB_id = conn.create_image(
instanceB.id, "test-ami-B", "this is a test ami")
imageB = conn.get_image(imageB_id)
imageB.set_launch_permissions(group_names=("all"))
amis_by_architecture = conn.get_all_images(filters={'architecture': 'x86_64'})
amis_by_architecture = conn.get_all_images(
filters={'architecture': 'x86_64'})
set([ami.id for ami in amis_by_architecture]).should.equal(set([imageB.id]))
amis_by_kernel = conn.get_all_images(filters={'kernel-id': 'k-abcd1234'})
set([ami.id for ami in amis_by_kernel]).should.equal(set([imageB.id]))
amis_by_virtualization = conn.get_all_images(filters={'virtualization-type': 'paravirtual'})
set([ami.id for ami in amis_by_virtualization]).should.equal(set([imageB.id]))
amis_by_virtualization = conn.get_all_images(
filters={'virtualization-type': 'paravirtual'})
set([ami.id for ami in amis_by_virtualization]
).should.equal(set([imageB.id]))
amis_by_platform = conn.get_all_images(filters={'platform': 'windows'})
set([ami.id for ami in amis_by_platform]).should.equal(set([imageA.id]))
@ -208,7 +228,8 @@ def test_ami_filters():
set([ami.id for ami in amis_by_id]).should.equal(set([imageA.id]))
amis_by_state = conn.get_all_images(filters={'state': 'available'})
set([ami.id for ami in amis_by_state]).should.equal(set([imageA.id, imageB.id]))
set([ami.id for ami in amis_by_state]).should.equal(
set([imageA.id, imageB.id]))
amis_by_name = conn.get_all_images(filters={'name': imageA.name})
set([ami.id for ami in amis_by_name]).should.equal(set([imageA.id]))
@ -226,20 +247,23 @@ def test_ami_filtering_via_tag():
reservationA = conn.run_instances('ami-1234abcd')
instanceA = reservationA.instances[0]
imageA_id = conn.create_image(instanceA.id, "test-ami-A", "this is a test ami")
imageA_id = conn.create_image(
instanceA.id, "test-ami-A", "this is a test ami")
imageA = conn.get_image(imageA_id)
imageA.add_tag("a key", "some value")
reservationB = conn.run_instances('ami-abcd1234')
instanceB = reservationB.instances[0]
imageB_id = conn.create_image(instanceB.id, "test-ami-B", "this is a test ami")
imageB_id = conn.create_image(
instanceB.id, "test-ami-B", "this is a test ami")
imageB = conn.get_image(imageB_id)
imageB.add_tag("another key", "some other value")
amis_by_tagA = conn.get_all_images(filters={'tag:a key': 'some value'})
set([ami.id for ami in amis_by_tagA]).should.equal(set([imageA.id]))
amis_by_tagB = conn.get_all_images(filters={'tag:another key': 'some other value'})
amis_by_tagB = conn.get_all_images(
filters={'tag:another key': 'some other value'})
set([ami.id for ami in amis_by_tagB]).should.equal(set([imageB.id]))
@ -274,7 +298,8 @@ def test_ami_attribute_group_permissions():
image = conn.get_image(image_id)
# Baseline
attributes = conn.get_image_attribute(image.id, attribute='launchPermission')
attributes = conn.get_image_attribute(
image.id, attribute='launchPermission')
attributes.name.should.equal('launch_permission')
attributes.attrs.should.have.length_of(0)
@ -290,32 +315,38 @@ def test_ami_attribute_group_permissions():
# Add 'all' group and confirm
with assert_raises(EC2ResponseError) as ex:
conn.modify_image_attribute(**dict(ADD_GROUP_ARGS, **{'dry_run': True}))
conn.modify_image_attribute(
**dict(ADD_GROUP_ARGS, **{'dry_run': True}))
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the ModifyImageAttribute operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the ModifyImageAttribute operation: Request would have succeeded, but DryRun flag is set')
conn.modify_image_attribute(**ADD_GROUP_ARGS)
attributes = conn.get_image_attribute(image.id, attribute='launchPermission')
attributes = conn.get_image_attribute(
image.id, attribute='launchPermission')
attributes.attrs['groups'].should.have.length_of(1)
attributes.attrs['groups'].should.equal(['all'])
image = conn.get_image(image_id)
image.is_public.should.equal(True)
# Add is idempotent
conn.modify_image_attribute.when.called_with(**ADD_GROUP_ARGS).should_not.throw(EC2ResponseError)
conn.modify_image_attribute.when.called_with(
**ADD_GROUP_ARGS).should_not.throw(EC2ResponseError)
# Remove 'all' group and confirm
conn.modify_image_attribute(**REMOVE_GROUP_ARGS)
attributes = conn.get_image_attribute(image.id, attribute='launchPermission')
attributes = conn.get_image_attribute(
image.id, attribute='launchPermission')
attributes.attrs.should.have.length_of(0)
image = conn.get_image(image_id)
image.is_public.should.equal(False)
# Remove is idempotent
conn.modify_image_attribute.when.called_with(**REMOVE_GROUP_ARGS).should_not.throw(EC2ResponseError)
conn.modify_image_attribute.when.called_with(
**REMOVE_GROUP_ARGS).should_not.throw(EC2ResponseError)
@mock_emr_deprecated
@ -327,7 +358,8 @@ def test_ami_attribute_user_permissions():
image = conn.get_image(image_id)
# Baseline
attributes = conn.get_image_attribute(image.id, attribute='launchPermission')
attributes = conn.get_image_attribute(
image.id, attribute='launchPermission')
attributes.name.should.equal('launch_permission')
attributes.attrs.should.have.length_of(0)
@ -353,19 +385,23 @@ def test_ami_attribute_user_permissions():
# Add multiple users and confirm
conn.modify_image_attribute(**ADD_USERS_ARGS)
attributes = conn.get_image_attribute(image.id, attribute='launchPermission')
attributes = conn.get_image_attribute(
image.id, attribute='launchPermission')
attributes.attrs['user_ids'].should.have.length_of(2)
set(attributes.attrs['user_ids']).should.equal(set([str(USER1), str(USER2)]))
set(attributes.attrs['user_ids']).should.equal(
set([str(USER1), str(USER2)]))
image = conn.get_image(image_id)
image.is_public.should.equal(False)
# Add is idempotent
conn.modify_image_attribute.when.called_with(**ADD_USERS_ARGS).should_not.throw(EC2ResponseError)
conn.modify_image_attribute.when.called_with(
**ADD_USERS_ARGS).should_not.throw(EC2ResponseError)
# Remove single user and confirm
conn.modify_image_attribute(**REMOVE_SINGLE_USER_ARGS)
attributes = conn.get_image_attribute(image.id, attribute='launchPermission')
attributes = conn.get_image_attribute(
image.id, attribute='launchPermission')
attributes.attrs['user_ids'].should.have.length_of(1)
set(attributes.attrs['user_ids']).should.equal(set([str(USER2)]))
image = conn.get_image(image_id)
@ -374,13 +410,15 @@ def test_ami_attribute_user_permissions():
# Remove multiple users and confirm
conn.modify_image_attribute(**REMOVE_USERS_ARGS)
attributes = conn.get_image_attribute(image.id, attribute='launchPermission')
attributes = conn.get_image_attribute(
image.id, attribute='launchPermission')
attributes.attrs.should.have.length_of(0)
image = conn.get_image(image_id)
image.is_public.should.equal(False)
# Remove is idempotent
conn.modify_image_attribute.when.called_with(**REMOVE_USERS_ARGS).should_not.throw(EC2ResponseError)
conn.modify_image_attribute.when.called_with(
**REMOVE_USERS_ARGS).should_not.throw(EC2ResponseError)
@mock_emr_deprecated
@ -397,7 +435,8 @@ def test_ami_attribute_user_and_group_permissions():
image = conn.get_image(image_id)
# Baseline
attributes = conn.get_image_attribute(image.id, attribute='launchPermission')
attributes = conn.get_image_attribute(
image.id, attribute='launchPermission')
attributes.name.should.equal('launch_permission')
attributes.attrs.should.have.length_of(0)
@ -419,7 +458,8 @@ def test_ami_attribute_user_and_group_permissions():
# Add and confirm
conn.modify_image_attribute(**ADD_ARGS)
attributes = conn.get_image_attribute(image.id, attribute='launchPermission')
attributes = conn.get_image_attribute(
image.id, attribute='launchPermission')
attributes.attrs['user_ids'].should.have.length_of(2)
set(attributes.attrs['user_ids']).should.equal(set([USER1, USER2]))
set(attributes.attrs['groups']).should.equal(set(['all']))
@ -429,7 +469,8 @@ def test_ami_attribute_user_and_group_permissions():
# Remove and confirm
conn.modify_image_attribute(**REMOVE_ARGS)
attributes = conn.get_image_attribute(image.id, attribute='launchPermission')
attributes = conn.get_image_attribute(
image.id, attribute='launchPermission')
attributes.attrs.should.have.length_of(0)
image = conn.get_image(image_id)
image.is_public.should.equal(False)
@ -483,7 +524,8 @@ def test_ami_attribute_error_cases():
cm.exception.status.should.equal(400)
cm.exception.request_id.should_not.be.none
# Error: Add with one invalid user ID among other valid IDs, ensure no partial changes.
# Error: Add with one invalid user ID among other valid IDs, ensure no
# partial changes.
with assert_raises(EC2ResponseError) as cm:
conn.modify_image_attribute(image.id,
attribute='launchPermission',
@ -493,7 +535,8 @@ def test_ami_attribute_error_cases():
cm.exception.status.should.equal(400)
cm.exception.request_id.should_not.be.none
attributes = conn.get_image_attribute(image.id, attribute='launchPermission')
attributes = conn.get_image_attribute(
image.id, attribute='launchPermission')
attributes.attrs.should.have.length_of(0)
# Error: Add with invalid image ID

View file

@ -12,26 +12,31 @@ from moto import mock_ec2_deprecated
def test_create_customer_gateways():
conn = boto.connect_vpc('the_key', 'the_secret')
customer_gateway = conn.create_customer_gateway('ipsec.1', '205.251.242.54', 65534)
customer_gateway = conn.create_customer_gateway(
'ipsec.1', '205.251.242.54', 65534)
customer_gateway.should_not.be.none
customer_gateway.id.should.match(r'cgw-\w+')
customer_gateway.type.should.equal('ipsec.1')
customer_gateway.bgp_asn.should.equal(65534)
customer_gateway.ip_address.should.equal('205.251.242.54')
@mock_ec2_deprecated
def test_describe_customer_gateways():
conn = boto.connect_vpc('the_key', 'the_secret')
customer_gateway = conn.create_customer_gateway('ipsec.1', '205.251.242.54', 65534)
customer_gateway = conn.create_customer_gateway(
'ipsec.1', '205.251.242.54', 65534)
cgws = conn.get_all_customer_gateways()
cgws.should.have.length_of(1)
cgws[0].id.should.match(customer_gateway.id)
@mock_ec2_deprecated
def test_delete_customer_gateways():
conn = boto.connect_vpc('the_key', 'the_secret')
customer_gateway = conn.create_customer_gateway('ipsec.1', '205.251.242.54', 65534)
customer_gateway = conn.create_customer_gateway(
'ipsec.1', '205.251.242.54', 65534)
customer_gateway.should_not.be.none
cgws = conn.get_all_customer_gateways()
cgws[0].id.should.match(customer_gateway.id)
@ -39,6 +44,7 @@ def test_delete_customer_gateways():
cgws = conn.get_all_customer_gateways()
cgws.should.have.length_of(0)
@mock_ec2_deprecated
def test_delete_customer_gateways_bad_id():
conn = boto.connect_vpc('the_key', 'the_secret')

View file

@ -19,7 +19,8 @@ SAMPLE_NAME_SERVERS = [u'10.0.0.6', u'10.0.0.7']
def test_dhcp_options_associate():
""" associate dhcp option """
conn = boto.connect_vpc('the_key', 'the_secret')
dhcp_options = conn.create_dhcp_options(SAMPLE_DOMAIN_NAME, SAMPLE_NAME_SERVERS)
dhcp_options = conn.create_dhcp_options(
SAMPLE_DOMAIN_NAME, SAMPLE_NAME_SERVERS)
vpc = conn.create_vpc("10.0.0.0/16")
rval = conn.associate_dhcp_options(dhcp_options.id, vpc.id)
@ -43,7 +44,8 @@ def test_dhcp_options_associate_invalid_dhcp_id():
def test_dhcp_options_associate_invalid_vpc_id():
""" associate dhcp option invalid vpc id """
conn = boto.connect_vpc('the_key', 'the_secret')
dhcp_options = conn.create_dhcp_options(SAMPLE_DOMAIN_NAME, SAMPLE_NAME_SERVERS)
dhcp_options = conn.create_dhcp_options(
SAMPLE_DOMAIN_NAME, SAMPLE_NAME_SERVERS)
with assert_raises(EC2ResponseError) as cm:
conn.associate_dhcp_options(dhcp_options.id, "foo")
@ -56,7 +58,8 @@ def test_dhcp_options_associate_invalid_vpc_id():
def test_dhcp_options_delete_with_vpc():
"""Test deletion of dhcp options with vpc"""
conn = boto.connect_vpc('the_key', 'the_secret')
dhcp_options = conn.create_dhcp_options(SAMPLE_DOMAIN_NAME, SAMPLE_NAME_SERVERS)
dhcp_options = conn.create_dhcp_options(
SAMPLE_DOMAIN_NAME, SAMPLE_NAME_SERVERS)
dhcp_options_id = dhcp_options.id
vpc = conn.create_vpc("10.0.0.0/16")
@ -83,10 +86,13 @@ def test_create_dhcp_options():
"""Create most basic dhcp option"""
conn = boto.connect_vpc('the_key', 'the_secret')
dhcp_option = conn.create_dhcp_options(SAMPLE_DOMAIN_NAME, SAMPLE_NAME_SERVERS)
dhcp_option = conn.create_dhcp_options(
SAMPLE_DOMAIN_NAME, SAMPLE_NAME_SERVERS)
dhcp_option.options[u'domain-name'][0].should.be.equal(SAMPLE_DOMAIN_NAME)
dhcp_option.options[u'domain-name-servers'][0].should.be.equal(SAMPLE_NAME_SERVERS[0])
dhcp_option.options[u'domain-name-servers'][1].should.be.equal(SAMPLE_NAME_SERVERS[1])
dhcp_option.options[
u'domain-name-servers'][0].should.be.equal(SAMPLE_NAME_SERVERS[0])
dhcp_option.options[
u'domain-name-servers'][1].should.be.equal(SAMPLE_NAME_SERVERS[1])
@mock_ec2_deprecated
@ -210,8 +216,10 @@ def test_dhcp_options_get_by_tag():
dhcp_options_sets = conn.get_all_dhcp_options(filters=filters)
dhcp_options_sets.should.have.length_of(1)
dhcp_options_sets[0].options['domain-name'][0].should.be.equal('example.com')
dhcp_options_sets[0].options['domain-name-servers'][0].should.be.equal('10.0.10.2')
dhcp_options_sets[0].options[
'domain-name'][0].should.be.equal('example.com')
dhcp_options_sets[0].options[
'domain-name-servers'][0].should.be.equal('10.0.10.2')
dhcp_options_sets[0].tags['Name'].should.equal('TestDhcpOptions1')
dhcp_options_sets[0].tags['test-tag'].should.equal('test-value')
@ -219,8 +227,10 @@ def test_dhcp_options_get_by_tag():
dhcp_options_sets = conn.get_all_dhcp_options(filters=filters)
dhcp_options_sets.should.have.length_of(1)
dhcp_options_sets[0].options['domain-name'][0].should.be.equal('example.com')
dhcp_options_sets[0].options['domain-name-servers'][0].should.be.equal('10.0.20.2')
dhcp_options_sets[0].options[
'domain-name'][0].should.be.equal('example.com')
dhcp_options_sets[0].options[
'domain-name-servers'][0].should.be.equal('10.0.20.2')
dhcp_options_sets[0].tags['Name'].should.equal('TestDhcpOptions2')
dhcp_options_sets[0].tags['test-tag'].should.equal('test-value')
@ -247,17 +257,21 @@ def test_dhcp_options_get_by_id():
dhcp_options_sets = conn.get_all_dhcp_options()
dhcp_options_sets.should.have.length_of(2)
dhcp_options_sets = conn.get_all_dhcp_options(filters={'dhcp-options-id': dhcp1_id})
dhcp_options_sets = conn.get_all_dhcp_options(
filters={'dhcp-options-id': dhcp1_id})
dhcp_options_sets.should.have.length_of(1)
dhcp_options_sets[0].options['domain-name'][0].should.be.equal('test1.com')
dhcp_options_sets[0].options['domain-name-servers'][0].should.be.equal('10.0.10.2')
dhcp_options_sets[0].options[
'domain-name-servers'][0].should.be.equal('10.0.10.2')
dhcp_options_sets = conn.get_all_dhcp_options(filters={'dhcp-options-id': dhcp2_id})
dhcp_options_sets = conn.get_all_dhcp_options(
filters={'dhcp-options-id': dhcp2_id})
dhcp_options_sets.should.have.length_of(1)
dhcp_options_sets[0].options['domain-name'][0].should.be.equal('test2.com')
dhcp_options_sets[0].options['domain-name-servers'][0].should.be.equal('10.0.20.2')
dhcp_options_sets[0].options[
'domain-name-servers'][0].should.be.equal('10.0.20.2')
@mock_ec2
@ -315,4 +329,5 @@ def test_dhcp_options_get_by_invalid_filter():
conn.create_dhcp_options(SAMPLE_DOMAIN_NAME, SAMPLE_NAME_SERVERS)
filters = {'invalid-filter': 'invalid-value'}
conn.get_all_dhcp_options.when.called_with(filters=filters).should.throw(NotImplementedError)
conn.get_all_dhcp_options.when.called_with(
filters=filters).should.throw(NotImplementedError)

View file

@ -28,7 +28,8 @@ def test_create_and_delete_volume():
volume.delete(dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the DeleteVolume operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the DeleteVolume operation: Request would have succeeded, but DryRun flag is set')
volume.delete()
@ -42,7 +43,6 @@ def test_create_and_delete_volume():
cm.exception.request_id.should_not.be.none
@mock_ec2_deprecated
def test_create_encrypted_volume_dryrun():
conn = boto.connect_ec2('the_key', 'the_secret')
@ -50,7 +50,8 @@ def test_create_encrypted_volume_dryrun():
conn.create_volume(80, "us-east-1a", encrypted=True, dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the CreateVolume operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the CreateVolume operation: Request would have succeeded, but DryRun flag is set')
@mock_ec2_deprecated
@ -62,7 +63,8 @@ def test_create_encrypted_volume():
conn.create_volume(80, "us-east-1a", encrypted=True, dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the CreateVolume operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the CreateVolume operation: Request would have succeeded, but DryRun flag is set')
all_volumes = conn.get_all_volumes()
all_volumes[0].encrypted.should.be(True)
@ -108,29 +110,42 @@ def test_volume_filters():
block_mapping = instance.block_device_mapping['/dev/sda1']
volumes_by_attach_time = conn.get_all_volumes(filters={'attachment.attach-time': block_mapping.attach_time})
set([vol.id for vol in volumes_by_attach_time]).should.equal(set([block_mapping.volume_id]))
volumes_by_attach_time = conn.get_all_volumes(
filters={'attachment.attach-time': block_mapping.attach_time})
set([vol.id for vol in volumes_by_attach_time]
).should.equal(set([block_mapping.volume_id]))
volumes_by_attach_device = conn.get_all_volumes(filters={'attachment.device': '/dev/sda1'})
set([vol.id for vol in volumes_by_attach_device]).should.equal(set([block_mapping.volume_id]))
volumes_by_attach_device = conn.get_all_volumes(
filters={'attachment.device': '/dev/sda1'})
set([vol.id for vol in volumes_by_attach_device]
).should.equal(set([block_mapping.volume_id]))
volumes_by_attach_instance_id = conn.get_all_volumes(filters={'attachment.instance-id': instance.id})
set([vol.id for vol in volumes_by_attach_instance_id]).should.equal(set([block_mapping.volume_id]))
volumes_by_attach_instance_id = conn.get_all_volumes(
filters={'attachment.instance-id': instance.id})
set([vol.id for vol in volumes_by_attach_instance_id]
).should.equal(set([block_mapping.volume_id]))
volumes_by_attach_status = conn.get_all_volumes(filters={'attachment.status': 'attached'})
set([vol.id for vol in volumes_by_attach_status]).should.equal(set([block_mapping.volume_id]))
volumes_by_attach_status = conn.get_all_volumes(
filters={'attachment.status': 'attached'})
set([vol.id for vol in volumes_by_attach_status]
).should.equal(set([block_mapping.volume_id]))
volumes_by_create_time = conn.get_all_volumes(filters={'create-time': volume4.create_time})
set([vol.create_time for vol in volumes_by_create_time]).should.equal(set([volume4.create_time]))
volumes_by_create_time = conn.get_all_volumes(
filters={'create-time': volume4.create_time})
set([vol.create_time for vol in volumes_by_create_time]
).should.equal(set([volume4.create_time]))
volumes_by_size = conn.get_all_volumes(filters={'size': volume2.size})
set([vol.id for vol in volumes_by_size]).should.equal(set([volume2.id]))
volumes_by_snapshot_id = conn.get_all_volumes(filters={'snapshot-id': snapshot.id})
set([vol.id for vol in volumes_by_snapshot_id]).should.equal(set([volume4.id]))
volumes_by_snapshot_id = conn.get_all_volumes(
filters={'snapshot-id': snapshot.id})
set([vol.id for vol in volumes_by_snapshot_id]
).should.equal(set([volume4.id]))
volumes_by_status = conn.get_all_volumes(filters={'status': 'in-use'})
set([vol.id for vol in volumes_by_status]).should.equal(set([block_mapping.volume_id]))
set([vol.id for vol in volumes_by_status]).should.equal(
set([block_mapping.volume_id]))
volumes_by_id = conn.get_all_volumes(filters={'volume-id': volume1.id})
set([vol.id for vol in volumes_by_id]).should.equal(set([volume1.id]))
@ -138,13 +153,17 @@ def test_volume_filters():
volumes_by_tag_key = conn.get_all_volumes(filters={'tag-key': 'testkey1'})
set([vol.id for vol in volumes_by_tag_key]).should.equal(set([volume1.id]))
volumes_by_tag_value = conn.get_all_volumes(filters={'tag-value': 'testvalue1'})
set([vol.id for vol in volumes_by_tag_value]).should.equal(set([volume1.id]))
volumes_by_tag_value = conn.get_all_volumes(
filters={'tag-value': 'testvalue1'})
set([vol.id for vol in volumes_by_tag_value]
).should.equal(set([volume1.id]))
volumes_by_tag = conn.get_all_volumes(filters={'tag:testkey1': 'testvalue1'})
volumes_by_tag = conn.get_all_volumes(
filters={'tag:testkey1': 'testvalue1'})
set([vol.id for vol in volumes_by_tag]).should.equal(set([volume1.id]))
volumes_by_unencrypted = conn.get_all_volumes(filters={'encrypted': 'false'})
volumes_by_unencrypted = conn.get_all_volumes(
filters={'encrypted': 'false'})
set([vol.id for vol in volumes_by_unencrypted]).should.equal(
set([block_mapping.volume_id, volume2.id])
)
@ -169,7 +188,8 @@ def test_volume_attach_and_detach():
volume.attach(instance.id, "/dev/sdh", dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the AttachVolume operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the AttachVolume operation: Request would have succeeded, but DryRun flag is set')
volume.attach(instance.id, "/dev/sdh")
@ -183,7 +203,8 @@ def test_volume_attach_and_detach():
volume.detach(dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the DetachVolume operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the DetachVolume operation: Request would have succeeded, but DryRun flag is set')
volume.detach()
@ -218,7 +239,8 @@ def test_create_snapshot():
snapshot = volume.create_snapshot('a dryrun snapshot', dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the CreateSnapshot operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the CreateSnapshot operation: Request would have succeeded, but DryRun flag is set')
snapshot = volume.create_snapshot('a test snapshot')
snapshot.update()
@ -294,32 +316,50 @@ def test_snapshot_filters():
conn.create_tags([snapshot1.id], {'testkey1': 'testvalue1'})
conn.create_tags([snapshot2.id], {'testkey2': 'testvalue2'})
snapshots_by_description = conn.get_all_snapshots(filters={'description': 'testsnapshot1'})
set([snap.id for snap in snapshots_by_description]).should.equal(set([snapshot1.id]))
snapshots_by_description = conn.get_all_snapshots(
filters={'description': 'testsnapshot1'})
set([snap.id for snap in snapshots_by_description]
).should.equal(set([snapshot1.id]))
snapshots_by_id = conn.get_all_snapshots(filters={'snapshot-id': snapshot1.id})
set([snap.id for snap in snapshots_by_id]).should.equal(set([snapshot1.id]))
snapshots_by_id = conn.get_all_snapshots(
filters={'snapshot-id': snapshot1.id})
set([snap.id for snap in snapshots_by_id]
).should.equal(set([snapshot1.id]))
snapshots_by_start_time = conn.get_all_snapshots(filters={'start-time': snapshot1.start_time})
set([snap.start_time for snap in snapshots_by_start_time]).should.equal(set([snapshot1.start_time]))
snapshots_by_start_time = conn.get_all_snapshots(
filters={'start-time': snapshot1.start_time})
set([snap.start_time for snap in snapshots_by_start_time]
).should.equal(set([snapshot1.start_time]))
snapshots_by_volume_id = conn.get_all_snapshots(filters={'volume-id': volume1.id})
set([snap.id for snap in snapshots_by_volume_id]).should.equal(set([snapshot1.id, snapshot2.id]))
snapshots_by_volume_id = conn.get_all_snapshots(
filters={'volume-id': volume1.id})
set([snap.id for snap in snapshots_by_volume_id]
).should.equal(set([snapshot1.id, snapshot2.id]))
snapshots_by_volume_size = conn.get_all_snapshots(filters={'volume-size': volume1.size})
set([snap.id for snap in snapshots_by_volume_size]).should.equal(set([snapshot1.id, snapshot2.id]))
snapshots_by_volume_size = conn.get_all_snapshots(
filters={'volume-size': volume1.size})
set([snap.id for snap in snapshots_by_volume_size]
).should.equal(set([snapshot1.id, snapshot2.id]))
snapshots_by_tag_key = conn.get_all_snapshots(filters={'tag-key': 'testkey1'})
set([snap.id for snap in snapshots_by_tag_key]).should.equal(set([snapshot1.id]))
snapshots_by_tag_key = conn.get_all_snapshots(
filters={'tag-key': 'testkey1'})
set([snap.id for snap in snapshots_by_tag_key]
).should.equal(set([snapshot1.id]))
snapshots_by_tag_value = conn.get_all_snapshots(filters={'tag-value': 'testvalue1'})
set([snap.id for snap in snapshots_by_tag_value]).should.equal(set([snapshot1.id]))
snapshots_by_tag_value = conn.get_all_snapshots(
filters={'tag-value': 'testvalue1'})
set([snap.id for snap in snapshots_by_tag_value]
).should.equal(set([snapshot1.id]))
snapshots_by_tag = conn.get_all_snapshots(filters={'tag:testkey1': 'testvalue1'})
set([snap.id for snap in snapshots_by_tag]).should.equal(set([snapshot1.id]))
snapshots_by_tag = conn.get_all_snapshots(
filters={'tag:testkey1': 'testvalue1'})
set([snap.id for snap in snapshots_by_tag]
).should.equal(set([snapshot1.id]))
snapshots_by_encrypted = conn.get_all_snapshots(filters={'encrypted': 'true'})
set([snap.id for snap in snapshots_by_encrypted]).should.equal(set([snapshot3.id]))
snapshots_by_encrypted = conn.get_all_snapshots(
filters={'encrypted': 'true'})
set([snap.id for snap in snapshots_by_encrypted]
).should.equal(set([snapshot3.id]))
@mock_ec2_deprecated
@ -331,7 +371,8 @@ def test_snapshot_attribute():
snapshot = volume.create_snapshot()
# Baseline
attributes = conn.get_snapshot_attribute(snapshot.id, attribute='createVolumePermission')
attributes = conn.get_snapshot_attribute(
snapshot.id, attribute='createVolumePermission')
attributes.name.should.equal('create_volume_permission')
attributes.attrs.should.have.length_of(0)
@ -348,34 +389,42 @@ def test_snapshot_attribute():
# Add 'all' group and confirm
with assert_raises(EC2ResponseError) as ex:
conn.modify_snapshot_attribute(**dict(ADD_GROUP_ARGS, **{'dry_run': True}))
conn.modify_snapshot_attribute(
**dict(ADD_GROUP_ARGS, **{'dry_run': True}))
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the ModifySnapshotAttribute operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the ModifySnapshotAttribute operation: Request would have succeeded, but DryRun flag is set')
conn.modify_snapshot_attribute(**ADD_GROUP_ARGS)
attributes = conn.get_snapshot_attribute(snapshot.id, attribute='createVolumePermission')
attributes = conn.get_snapshot_attribute(
snapshot.id, attribute='createVolumePermission')
attributes.attrs['groups'].should.have.length_of(1)
attributes.attrs['groups'].should.equal(['all'])
# Add is idempotent
conn.modify_snapshot_attribute.when.called_with(**ADD_GROUP_ARGS).should_not.throw(EC2ResponseError)
conn.modify_snapshot_attribute.when.called_with(
**ADD_GROUP_ARGS).should_not.throw(EC2ResponseError)
# Remove 'all' group and confirm
with assert_raises(EC2ResponseError) as ex:
conn.modify_snapshot_attribute(**dict(REMOVE_GROUP_ARGS, **{'dry_run': True}))
conn.modify_snapshot_attribute(
**dict(REMOVE_GROUP_ARGS, **{'dry_run': True}))
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the ModifySnapshotAttribute operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the ModifySnapshotAttribute operation: Request would have succeeded, but DryRun flag is set')
conn.modify_snapshot_attribute(**REMOVE_GROUP_ARGS)
attributes = conn.get_snapshot_attribute(snapshot.id, attribute='createVolumePermission')
attributes = conn.get_snapshot_attribute(
snapshot.id, attribute='createVolumePermission')
attributes.attrs.should.have.length_of(0)
# Remove is idempotent
conn.modify_snapshot_attribute.when.called_with(**REMOVE_GROUP_ARGS).should_not.throw(EC2ResponseError)
conn.modify_snapshot_attribute.when.called_with(
**REMOVE_GROUP_ARGS).should_not.throw(EC2ResponseError)
# Error: Add with group != 'all'
with assert_raises(EC2ResponseError) as cm:
@ -428,7 +477,8 @@ def test_create_volume_from_snapshot():
snapshot = volume.create_snapshot('a test snapshot', dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the CreateSnapshot operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the CreateSnapshot operation: Request would have succeeded, but DryRun flag is set')
snapshot = volume.create_snapshot('a test snapshot')
snapshot.update()
@ -469,16 +519,19 @@ def test_modify_attribute_blockDeviceMapping():
instance = reservation.instances[0]
with assert_raises(EC2ResponseError) as ex:
instance.modify_attribute('blockDeviceMapping', {'/dev/sda1': True}, dry_run=True)
instance.modify_attribute('blockDeviceMapping', {
'/dev/sda1': True}, dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the ModifyInstanceAttribute operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the ModifyInstanceAttribute operation: Request would have succeeded, but DryRun flag is set')
instance.modify_attribute('blockDeviceMapping', {'/dev/sda1': True})
instance = ec2_backends[conn.region.name].get_instance(instance.id)
instance.block_device_mapping.should.have.key('/dev/sda1')
instance.block_device_mapping['/dev/sda1'].delete_on_termination.should.be(True)
instance.block_device_mapping[
'/dev/sda1'].delete_on_termination.should.be(True)
@mock_ec2_deprecated
@ -491,8 +544,10 @@ def test_volume_tag_escaping():
snapshot.add_tags({'key': '</closed>'}, dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the CreateTags operation: Request would have succeeded, but DryRun flag is set')
dict(conn.get_all_snapshots()[0].tags).should_not.be.equal({'key': '</closed>'})
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the CreateTags operation: Request would have succeeded, but DryRun flag is set')
dict(conn.get_all_snapshots()[0].tags).should_not.be.equal(
{'key': '</closed>'})
snapshot.add_tags({'key': '</closed>'})

View file

@ -24,7 +24,8 @@ def test_eip_allocate_classic():
standard = conn.allocate_address(dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the AllocateAddress operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the AllocateAddress operation: Request would have succeeded, but DryRun flag is set')
standard = conn.allocate_address()
standard.should.be.a(boto.ec2.address.Address)
@ -36,7 +37,8 @@ def test_eip_allocate_classic():
standard.release(dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the ReleaseAddress operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the ReleaseAddress operation: Request would have succeeded, but DryRun flag is set')
standard.release()
standard.should_not.be.within(conn.get_all_addresses())
@ -51,7 +53,8 @@ def test_eip_allocate_vpc():
vpc = conn.allocate_address(domain="vpc", dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the AllocateAddress operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the AllocateAddress operation: Request would have succeeded, but DryRun flag is set')
vpc = conn.allocate_address(domain="vpc")
vpc.should.be.a(boto.ec2.address.Address)
@ -90,23 +93,28 @@ def test_eip_associate_classic():
cm.exception.request_id.should_not.be.none
with assert_raises(EC2ResponseError) as ex:
conn.associate_address(instance_id=instance.id, public_ip=eip.public_ip, dry_run=True)
conn.associate_address(instance_id=instance.id,
public_ip=eip.public_ip, dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the AssociateAddress operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the AssociateAddress operation: Request would have succeeded, but DryRun flag is set')
conn.associate_address(instance_id=instance.id, public_ip=eip.public_ip)
eip = conn.get_all_addresses(addresses=[eip.public_ip])[0] # no .update() on address ):
# no .update() on address ):
eip = conn.get_all_addresses(addresses=[eip.public_ip])[0]
eip.instance_id.should.be.equal(instance.id)
with assert_raises(EC2ResponseError) as ex:
conn.disassociate_address(public_ip=eip.public_ip, dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the DisAssociateAddress operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the DisAssociateAddress operation: Request would have succeeded, but DryRun flag is set')
conn.disassociate_address(public_ip=eip.public_ip)
eip = conn.get_all_addresses(addresses=[eip.public_ip])[0] # no .update() on address ):
# no .update() on address ):
eip = conn.get_all_addresses(addresses=[eip.public_ip])[0]
eip.instance_id.should.be.equal(u'')
eip.release()
eip.should_not.be.within(conn.get_all_addresses())
@ -114,6 +122,7 @@ def test_eip_associate_classic():
instance.terminate()
@mock_ec2_deprecated
def test_eip_associate_vpc():
"""Associate/Disassociate EIP to VPC instance"""
@ -131,11 +140,14 @@ def test_eip_associate_vpc():
cm.exception.status.should.equal(400)
cm.exception.request_id.should_not.be.none
conn.associate_address(instance_id=instance.id, allocation_id=eip.allocation_id)
eip = conn.get_all_addresses(addresses=[eip.public_ip])[0] # no .update() on address ):
conn.associate_address(instance_id=instance.id,
allocation_id=eip.allocation_id)
# no .update() on address ):
eip = conn.get_all_addresses(addresses=[eip.public_ip])[0]
eip.instance_id.should.be.equal(instance.id)
conn.disassociate_address(association_id=eip.association_id)
eip = conn.get_all_addresses(addresses=[eip.public_ip])[0] # no .update() on address ):
# no .update() on address ):
eip = conn.get_all_addresses(addresses=[eip.public_ip])[0]
eip.instance_id.should.be.equal(u'')
eip.association_id.should.be.none
@ -143,13 +155,15 @@ def test_eip_associate_vpc():
eip.release(dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the ReleaseAddress operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the ReleaseAddress operation: Request would have succeeded, but DryRun flag is set')
eip.release()
eip = None
instance.terminate()
@mock_ec2
def test_eip_boto3_vpc_association():
"""Associate EIP to VPC instance in a new subnet with boto3"""
@ -157,7 +171,7 @@ def test_eip_boto3_vpc_association():
client = boto3.client('ec2', region_name='us-west-1')
vpc_res = client.create_vpc(CidrBlock='10.0.0.0/24')
subnet_res = client.create_subnet(
VpcId=vpc_res['Vpc']['VpcId'], CidrBlock='10.0.0.0/24')
VpcId=vpc_res['Vpc']['VpcId'], CidrBlock='10.0.0.0/24')
instance = service.create_instances(**{
'InstanceType': 't2.micro',
'ImageId': 'ami-test',
@ -192,17 +206,21 @@ def test_eip_associate_network_interface():
cm.exception.status.should.equal(400)
cm.exception.request_id.should_not.be.none
conn.associate_address(network_interface_id=eni.id, allocation_id=eip.allocation_id)
eip = conn.get_all_addresses(addresses=[eip.public_ip])[0] # no .update() on address ):
conn.associate_address(network_interface_id=eni.id,
allocation_id=eip.allocation_id)
# no .update() on address ):
eip = conn.get_all_addresses(addresses=[eip.public_ip])[0]
eip.network_interface_id.should.be.equal(eni.id)
conn.disassociate_address(association_id=eip.association_id)
eip = conn.get_all_addresses(addresses=[eip.public_ip])[0] # no .update() on address ):
# no .update() on address ):
eip = conn.get_all_addresses(addresses=[eip.public_ip])[0]
eip.network_interface_id.should.be.equal(u'')
eip.association_id.should.be.none
eip.release()
eip = None
@mock_ec2_deprecated
def test_eip_reassociate():
"""reassociate EIP"""
@ -219,12 +237,14 @@ def test_eip_reassociate():
# Different ID detects resource association
with assert_raises(EC2ResponseError) as cm:
conn.associate_address(instance_id=instance2.id, public_ip=eip.public_ip, allow_reassociation=False)
conn.associate_address(
instance_id=instance2.id, public_ip=eip.public_ip, allow_reassociation=False)
cm.exception.code.should.equal('Resource.AlreadyAssociated')
cm.exception.status.should.equal(400)
cm.exception.request_id.should_not.be.none
conn.associate_address.when.called_with(instance_id=instance2.id, public_ip=eip.public_ip, allow_reassociation=True).should_not.throw(EC2ResponseError)
conn.associate_address.when.called_with(
instance_id=instance2.id, public_ip=eip.public_ip, allow_reassociation=True).should_not.throw(EC2ResponseError)
eip.release()
eip = None
@ -232,6 +252,7 @@ def test_eip_reassociate():
instance1.terminate()
instance2.terminate()
@mock_ec2_deprecated
def test_eip_reassociate_nic():
"""reassociate EIP"""
@ -243,23 +264,28 @@ def test_eip_reassociate_nic():
eni2 = conn.create_network_interface(subnet.id)
eip = conn.allocate_address()
conn.associate_address(network_interface_id=eni1.id, public_ip=eip.public_ip)
conn.associate_address(network_interface_id=eni1.id,
public_ip=eip.public_ip)
# Same ID is idempotent
conn.associate_address(network_interface_id=eni1.id, public_ip=eip.public_ip)
conn.associate_address(network_interface_id=eni1.id,
public_ip=eip.public_ip)
# Different ID detects resource association
with assert_raises(EC2ResponseError) as cm:
conn.associate_address(network_interface_id=eni2.id, public_ip=eip.public_ip)
conn.associate_address(
network_interface_id=eni2.id, public_ip=eip.public_ip)
cm.exception.code.should.equal('Resource.AlreadyAssociated')
cm.exception.status.should.equal(400)
cm.exception.request_id.should_not.be.none
conn.associate_address.when.called_with(network_interface_id=eni2.id, public_ip=eip.public_ip, allow_reassociation=True).should_not.throw(EC2ResponseError)
conn.associate_address.when.called_with(
network_interface_id=eni2.id, public_ip=eip.public_ip, allow_reassociation=True).should_not.throw(EC2ResponseError)
eip.release()
eip = None
@mock_ec2_deprecated
def test_eip_associate_invalid_args():
"""Associate EIP, invalid args """
@ -290,6 +316,7 @@ def test_eip_disassociate_bogus_association():
cm.exception.status.should.equal(400)
cm.exception.request_id.should_not.be.none
@mock_ec2_deprecated
def test_eip_release_bogus_eip():
"""Release bogus EIP"""
@ -334,7 +361,7 @@ def test_eip_describe():
number_of_classic_ips = 2
number_of_vpc_ips = 2
#allocate some IPs
# allocate some IPs
for _ in range(number_of_classic_ips):
eips.append(conn.allocate_address())
for _ in range(number_of_vpc_ips):
@ -344,19 +371,22 @@ def test_eip_describe():
# Can we find each one individually?
for eip in eips:
if eip.allocation_id:
lookup_addresses = conn.get_all_addresses(allocation_ids=[eip.allocation_id])
lookup_addresses = conn.get_all_addresses(
allocation_ids=[eip.allocation_id])
else:
lookup_addresses = conn.get_all_addresses(addresses=[eip.public_ip])
lookup_addresses = conn.get_all_addresses(
addresses=[eip.public_ip])
len(lookup_addresses).should.be.equal(1)
lookup_addresses[0].public_ip.should.be.equal(eip.public_ip)
# Can we find first two when we search for them?
lookup_addresses = conn.get_all_addresses(addresses=[eips[0].public_ip, eips[1].public_ip])
lookup_addresses = conn.get_all_addresses(
addresses=[eips[0].public_ip, eips[1].public_ip])
len(lookup_addresses).should.be.equal(2)
lookup_addresses[0].public_ip.should.be.equal(eips[0].public_ip)
lookup_addresses[1].public_ip.should.be.equal(eips[1].public_ip)
#Release all IPs
# Release all IPs
for eip in eips:
eip.release()
len(conn.get_all_addresses()).should.be.equal(0)
@ -372,4 +402,3 @@ def test_eip_describe_none():
cm.exception.code.should.equal('InvalidAddress.NotFound')
cm.exception.status.should.equal(400)
cm.exception.request_id.should_not.be.none

View file

@ -27,7 +27,8 @@ def test_elastic_network_interfaces():
eni = conn.create_network_interface(subnet.id, dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the CreateNetworkInterface operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the CreateNetworkInterface operation: Request would have succeeded, but DryRun flag is set')
eni = conn.create_network_interface(subnet.id)
@ -41,7 +42,8 @@ def test_elastic_network_interfaces():
conn.delete_network_interface(eni.id, dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the DeleteNetworkInterface operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the DeleteNetworkInterface operation: Request would have succeeded, but DryRun flag is set')
conn.delete_network_interface(eni.id)
@ -89,16 +91,20 @@ def test_elastic_network_interfaces_with_groups():
conn = boto.connect_vpc('the_key', 'the_secret')
vpc = conn.create_vpc("10.0.0.0/16")
subnet = conn.create_subnet(vpc.id, "10.0.0.0/18")
security_group1 = conn.create_security_group('test security group #1', 'this is a test security group')
security_group2 = conn.create_security_group('test security group #2', 'this is a test security group')
conn.create_network_interface(subnet.id, groups=[security_group1.id, security_group2.id])
security_group1 = conn.create_security_group(
'test security group #1', 'this is a test security group')
security_group2 = conn.create_security_group(
'test security group #2', 'this is a test security group')
conn.create_network_interface(
subnet.id, groups=[security_group1.id, security_group2.id])
all_enis = conn.get_all_network_interfaces()
all_enis.should.have.length_of(1)
eni = all_enis[0]
eni.groups.should.have.length_of(2)
set([group.id for group in eni.groups]).should.equal(set([security_group1.id, security_group2.id]))
set([group.id for group in eni.groups]).should.equal(
set([security_group1.id, security_group2.id]))
@requires_boto_gte("2.12.0")
@ -107,8 +113,10 @@ def test_elastic_network_interfaces_modify_attribute():
conn = boto.connect_vpc('the_key', 'the_secret')
vpc = conn.create_vpc("10.0.0.0/16")
subnet = conn.create_subnet(vpc.id, "10.0.0.0/18")
security_group1 = conn.create_security_group('test security group #1', 'this is a test security group')
security_group2 = conn.create_security_group('test security group #2', 'this is a test security group')
security_group1 = conn.create_security_group(
'test security group #1', 'this is a test security group')
security_group2 = conn.create_security_group(
'test security group #2', 'this is a test security group')
conn.create_network_interface(subnet.id, groups=[security_group1.id])
all_enis = conn.get_all_network_interfaces()
@ -119,12 +127,15 @@ def test_elastic_network_interfaces_modify_attribute():
eni.groups[0].id.should.equal(security_group1.id)
with assert_raises(EC2ResponseError) as ex:
conn.modify_network_interface_attribute(eni.id, 'groupset', [security_group2.id], dry_run=True)
conn.modify_network_interface_attribute(
eni.id, 'groupset', [security_group2.id], dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the ModifyNetworkInterface operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the ModifyNetworkInterface operation: Request would have succeeded, but DryRun flag is set')
conn.modify_network_interface_attribute(eni.id, 'groupset', [security_group2.id])
conn.modify_network_interface_attribute(
eni.id, 'groupset', [security_group2.id])
all_enis = conn.get_all_network_interfaces()
all_enis.should.have.length_of(1)
@ -140,11 +151,15 @@ def test_elastic_network_interfaces_filtering():
vpc = conn.create_vpc("10.0.0.0/16")
subnet = conn.create_subnet(vpc.id, "10.0.0.0/18")
security_group1 = conn.create_security_group('test security group #1', 'this is a test security group')
security_group2 = conn.create_security_group('test security group #2', 'this is a test security group')
security_group1 = conn.create_security_group(
'test security group #1', 'this is a test security group')
security_group2 = conn.create_security_group(
'test security group #2', 'this is a test security group')
eni1 = conn.create_network_interface(subnet.id, groups=[security_group1.id, security_group2.id])
eni2 = conn.create_network_interface(subnet.id, groups=[security_group1.id])
eni1 = conn.create_network_interface(
subnet.id, groups=[security_group1.id, security_group2.id])
eni2 = conn.create_network_interface(
subnet.id, groups=[security_group1.id])
eni3 = conn.create_network_interface(subnet.id)
all_enis = conn.get_all_network_interfaces()
@ -156,22 +171,26 @@ def test_elastic_network_interfaces_filtering():
set([eni.id for eni in enis_by_id]).should.equal(set([eni1.id]))
# Filter by ENI ID
enis_by_id = conn.get_all_network_interfaces(filters={'network-interface-id': eni1.id})
enis_by_id = conn.get_all_network_interfaces(
filters={'network-interface-id': eni1.id})
enis_by_id.should.have.length_of(1)
set([eni.id for eni in enis_by_id]).should.equal(set([eni1.id]))
# Filter by Security Group
enis_by_group = conn.get_all_network_interfaces(filters={'group-id': security_group1.id})
enis_by_group = conn.get_all_network_interfaces(
filters={'group-id': security_group1.id})
enis_by_group.should.have.length_of(2)
set([eni.id for eni in enis_by_group]).should.equal(set([eni1.id, eni2.id]))
# Filter by ENI ID and Security Group
enis_by_group = conn.get_all_network_interfaces(filters={'network-interface-id': eni1.id, 'group-id': security_group1.id})
enis_by_group = conn.get_all_network_interfaces(
filters={'network-interface-id': eni1.id, 'group-id': security_group1.id})
enis_by_group.should.have.length_of(1)
set([eni.id for eni in enis_by_group]).should.equal(set([eni1.id]))
# Unsupported filter
conn.get_all_network_interfaces.when.called_with(filters={'not-implemented-filter': 'foobar'}).should.throw(NotImplementedError)
conn.get_all_network_interfaces.when.called_with(
filters={'not-implemented-filter': 'foobar'}).should.throw(NotImplementedError)
@mock_ec2
@ -180,15 +199,19 @@ def test_elastic_network_interfaces_get_by_tag_name():
ec2_client = boto3.client('ec2', region_name='us-west-2')
vpc = ec2.create_vpc(CidrBlock='10.0.0.0/16')
subnet = ec2.create_subnet(VpcId=vpc.id, CidrBlock='10.0.0.0/24', AvailabilityZone='us-west-2a')
subnet = ec2.create_subnet(
VpcId=vpc.id, CidrBlock='10.0.0.0/24', AvailabilityZone='us-west-2a')
eni1 = ec2.create_network_interface(SubnetId=subnet.id, PrivateIpAddress='10.0.10.5')
eni1 = ec2.create_network_interface(
SubnetId=subnet.id, PrivateIpAddress='10.0.10.5')
with assert_raises(ClientError) as ex:
eni1.create_tags(Tags=[{'Key': 'Name', 'Value': 'eni1'}], DryRun=True)
ex.exception.response['Error']['Code'].should.equal('DryRunOperation')
ex.exception.response['ResponseMetadata']['HTTPStatusCode'].should.equal(400)
ex.exception.response['Error']['Message'].should.equal('An error occurred (DryRunOperation) when calling the CreateTags operation: Request would have succeeded, but DryRun flag is set')
ex.exception.response['ResponseMetadata'][
'HTTPStatusCode'].should.equal(400)
ex.exception.response['Error']['Message'].should.equal(
'An error occurred (DryRunOperation) when calling the CreateTags operation: Request would have succeeded, but DryRun flag is set')
eni1.create_tags(Tags=[{'Key': 'Name', 'Value': 'eni1'}])
@ -211,9 +234,11 @@ def test_elastic_network_interfaces_get_by_private_ip():
ec2_client = boto3.client('ec2', region_name='us-west-2')
vpc = ec2.create_vpc(CidrBlock='10.0.0.0/16')
subnet = ec2.create_subnet(VpcId=vpc.id, CidrBlock='10.0.0.0/24', AvailabilityZone='us-west-2a')
subnet = ec2.create_subnet(
VpcId=vpc.id, CidrBlock='10.0.0.0/24', AvailabilityZone='us-west-2a')
eni1 = ec2.create_network_interface(SubnetId=subnet.id, PrivateIpAddress='10.0.10.5')
eni1 = ec2.create_network_interface(
SubnetId=subnet.id, PrivateIpAddress='10.0.10.5')
# The status of the new interface should be 'available'
waiter = ec2_client.get_waiter('network_interface_available')
@ -242,9 +267,11 @@ def test_elastic_network_interfaces_get_by_vpc_id():
ec2_client = boto3.client('ec2', region_name='us-west-2')
vpc = ec2.create_vpc(CidrBlock='10.0.0.0/16')
subnet = ec2.create_subnet(VpcId=vpc.id, CidrBlock='10.0.0.0/24', AvailabilityZone='us-west-2a')
subnet = ec2.create_subnet(
VpcId=vpc.id, CidrBlock='10.0.0.0/24', AvailabilityZone='us-west-2a')
eni1 = ec2.create_network_interface(SubnetId=subnet.id, PrivateIpAddress='10.0.10.5')
eni1 = ec2.create_network_interface(
SubnetId=subnet.id, PrivateIpAddress='10.0.10.5')
# The status of the new interface should be 'available'
waiter = ec2_client.get_waiter('network_interface_available')
@ -265,9 +292,11 @@ def test_elastic_network_interfaces_get_by_subnet_id():
ec2_client = boto3.client('ec2', region_name='us-west-2')
vpc = ec2.create_vpc(CidrBlock='10.0.0.0/16')
subnet = ec2.create_subnet(VpcId=vpc.id, CidrBlock='10.0.0.0/24', AvailabilityZone='us-west-2a')
subnet = ec2.create_subnet(
VpcId=vpc.id, CidrBlock='10.0.0.0/24', AvailabilityZone='us-west-2a')
eni1 = ec2.create_network_interface(SubnetId=subnet.id, PrivateIpAddress='10.0.10.5')
eni1 = ec2.create_network_interface(
SubnetId=subnet.id, PrivateIpAddress='10.0.10.5')
# The status of the new interface should be 'available'
waiter = ec2_client.get_waiter('network_interface_available')
@ -297,5 +326,6 @@ def test_elastic_network_interfaces_cloudformation():
stack = conn.describe_stacks()[0]
resources = stack.describe_resources()
cfn_eni = [resource for resource in resources if resource.resource_type == 'AWS::EC2::NetworkInterface'][0]
cfn_eni = [resource for resource in resources if resource.resource_type ==
'AWS::EC2::NetworkInterface'][0]
cfn_eni.physical_resource_id.should.equal(eni.id)

View file

@ -45,7 +45,8 @@ def test_instance_launch_and_terminate():
reservation = conn.run_instances('ami-1234abcd', dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the RunInstance operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the RunInstance operation: Request would have succeeded, but DryRun flag is set')
reservation = conn.run_instances('ami-1234abcd')
reservation.should.be.a(Reservation)
@ -66,7 +67,8 @@ def test_instance_launch_and_terminate():
instance.placement.should.equal('us-east-1a')
root_device_name = instance.root_device_name
instance.block_device_mapping[root_device_name].status.should.equal('in-use')
instance.block_device_mapping[
root_device_name].status.should.equal('in-use')
volume_id = instance.block_device_mapping[root_device_name].volume_id
volume_id.should.match(r'vol-\w+')
@ -78,7 +80,8 @@ def test_instance_launch_and_terminate():
conn.terminate_instances([instance.id], dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the TerminateInstance operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the TerminateInstance operation: Request would have succeeded, but DryRun flag is set')
conn.terminate_instances([instance.id])
@ -90,7 +93,8 @@ def test_instance_launch_and_terminate():
@mock_ec2_deprecated
def test_terminate_empty_instances():
conn = boto.connect_ec2('the_key', 'the_secret')
conn.terminate_instances.when.called_with([]).should.throw(EC2ResponseError)
conn.terminate_instances.when.called_with(
[]).should.throw(EC2ResponseError)
@freeze_time("2014-01-01 05:00:00")
@ -117,8 +121,10 @@ def test_instance_attach_volume():
for v in conn.get_all_volumes(volume_ids=[instance.block_device_mapping['/dev/sdc1'].volume_id]):
v.attach_data.instance_id.should.equal(instance.id)
v.attach_data.attach_time.should.equal(instance.launch_time) # can do due to freeze_time decorator.
v.create_time.should.equal(instance.launch_time) # can do due to freeze_time decorator.
# can do due to freeze_time decorator.
v.attach_data.attach_time.should.equal(instance.launch_time)
# can do due to freeze_time decorator.
v.create_time.should.equal(instance.launch_time)
v.region.name.should.equal(instance.region.name)
v.status.should.equal('in-use')
@ -135,7 +141,8 @@ def test_get_instances_by_id():
reservation.instances.should.have.length_of(1)
reservation.instances[0].id.should.equal(instance1.id)
reservations = conn.get_all_instances(instance_ids=[instance1.id, instance2.id])
reservations = conn.get_all_instances(
instance_ids=[instance1.id, instance2.id])
reservations.should.have.length_of(1)
reservation = reservations[0]
reservation.instances.should.have.length_of(2)
@ -158,25 +165,31 @@ def test_get_instances_filtering_by_state():
conn.terminate_instances([instance1.id])
reservations = conn.get_all_instances(filters={'instance-state-name': 'running'})
reservations = conn.get_all_instances(
filters={'instance-state-name': 'running'})
reservations.should.have.length_of(1)
# Since we terminated instance1, only instance2 and instance3 should be returned
# Since we terminated instance1, only instance2 and instance3 should be
# returned
instance_ids = [instance.id for instance in reservations[0].instances]
set(instance_ids).should.equal(set([instance2.id, instance3.id]))
reservations = conn.get_all_instances([instance2.id], filters={'instance-state-name': 'running'})
reservations = conn.get_all_instances(
[instance2.id], filters={'instance-state-name': 'running'})
reservations.should.have.length_of(1)
instance_ids = [instance.id for instance in reservations[0].instances]
instance_ids.should.equal([instance2.id])
reservations = conn.get_all_instances([instance2.id], filters={'instance-state-name': 'terminated'})
reservations = conn.get_all_instances(
[instance2.id], filters={'instance-state-name': 'terminated'})
list(reservations).should.equal([])
# get_all_instances should still return all 3
reservations = conn.get_all_instances()
reservations[0].instances.should.have.length_of(3)
conn.get_all_instances.when.called_with(filters={'not-implemented-filter': 'foobar'}).should.throw(NotImplementedError)
conn.get_all_instances.when.called_with(
filters={'not-implemented-filter': 'foobar'}).should.throw(NotImplementedError)
@mock_ec2_deprecated
def test_get_instances_filtering_by_instance_id():
@ -184,16 +197,19 @@ def test_get_instances_filtering_by_instance_id():
reservation = conn.run_instances('ami-1234abcd', min_count=3)
instance1, instance2, instance3 = reservation.instances
reservations = conn.get_all_instances(filters={'instance-id': instance1.id})
reservations = conn.get_all_instances(
filters={'instance-id': instance1.id})
# get_all_instances should return just instance1
reservations[0].instances.should.have.length_of(1)
reservations[0].instances[0].id.should.equal(instance1.id)
reservations = conn.get_all_instances(filters={'instance-id': [instance1.id, instance2.id]})
reservations = conn.get_all_instances(
filters={'instance-id': [instance1.id, instance2.id]})
# get_all_instances should return two
reservations[0].instances.should.have.length_of(2)
reservations = conn.get_all_instances(filters={'instance-id': 'non-existing-id'})
reservations = conn.get_all_instances(
filters={'instance-id': 'non-existing-id'})
reservations.should.have.length_of(0)
@ -207,22 +223,25 @@ def test_get_instances_filtering_by_instance_type():
reservation3 = conn.run_instances('ami-1234abcd', instance_type='t1.micro')
instance3 = reservation3.instances[0]
reservations = conn.get_all_instances(filters={'instance-type': 'm1.small'})
reservations = conn.get_all_instances(
filters={'instance-type': 'm1.small'})
# get_all_instances should return instance1,2
reservations.should.have.length_of(2)
reservations[0].instances.should.have.length_of(1)
reservations[1].instances.should.have.length_of(1)
instance_ids = [ reservations[0].instances[0].id,
reservations[1].instances[0].id ]
instance_ids = [reservations[0].instances[0].id,
reservations[1].instances[0].id]
set(instance_ids).should.equal(set([instance1.id, instance2.id]))
reservations = conn.get_all_instances(filters={'instance-type': 't1.micro'})
reservations = conn.get_all_instances(
filters={'instance-type': 't1.micro'})
# get_all_instances should return one
reservations.should.have.length_of(1)
reservations[0].instances.should.have.length_of(1)
reservations[0].instances[0].id.should.equal(instance3.id)
reservations = conn.get_all_instances(filters={'instance-type': ['t1.micro', 'm1.small']})
reservations = conn.get_all_instances(
filters={'instance-type': ['t1.micro', 'm1.small']})
reservations.should.have.length_of(3)
reservations[0].instances.should.have.length_of(1)
reservations[1].instances.should.have.length_of(1)
@ -231,13 +250,15 @@ def test_get_instances_filtering_by_instance_type():
reservations[0].instances[0].id,
reservations[1].instances[0].id,
reservations[2].instances[0].id,
]
set(instance_ids).should.equal(set([instance1.id, instance2.id, instance3.id]))
]
set(instance_ids).should.equal(
set([instance1.id, instance2.id, instance3.id]))
reservations = conn.get_all_instances(filters={'instance-type': 'bogus'})
#bogus instance-type should return none
# bogus instance-type should return none
reservations.should.have.length_of(0)
@mock_ec2_deprecated
def test_get_instances_filtering_by_reason_code():
conn = boto.connect_ec2()
@ -246,10 +267,12 @@ def test_get_instances_filtering_by_reason_code():
instance1.stop()
instance2.terminate()
reservations = conn.get_all_instances(filters={'state-reason-code': 'Client.UserInitiatedShutdown'})
reservations = conn.get_all_instances(
filters={'state-reason-code': 'Client.UserInitiatedShutdown'})
# get_all_instances should return instance1 and instance2
reservations[0].instances.should.have.length_of(2)
set([instance1.id, instance2.id]).should.equal(set([i.id for i in reservations[0].instances]))
set([instance1.id, instance2.id]).should.equal(
set([i.id for i in reservations[0].instances]))
reservations = conn.get_all_instances(filters={'state-reason-code': ''})
# get_all_instances should return instance 3
@ -262,10 +285,13 @@ def test_get_instances_filtering_by_source_dest_check():
conn = boto.connect_ec2()
reservation = conn.run_instances('ami-1234abcd', min_count=2)
instance1, instance2 = reservation.instances
conn.modify_instance_attribute(instance1.id, attribute='sourceDestCheck', value=False)
conn.modify_instance_attribute(
instance1.id, attribute='sourceDestCheck', value=False)
source_dest_check_false = conn.get_all_instances(filters={'source-dest-check': 'false'})
source_dest_check_true = conn.get_all_instances(filters={'source-dest-check': 'true'})
source_dest_check_false = conn.get_all_instances(
filters={'source-dest-check': 'false'})
source_dest_check_true = conn.get_all_instances(
filters={'source-dest-check': 'true'})
source_dest_check_false[0].instances.should.have.length_of(1)
source_dest_check_false[0].instances[0].id.should.equal(instance1.id)
@ -279,12 +305,14 @@ def test_get_instances_filtering_by_vpc_id():
conn = boto.connect_vpc('the_key', 'the_secret')
vpc1 = conn.create_vpc("10.0.0.0/16")
subnet1 = conn.create_subnet(vpc1.id, "10.0.0.0/27")
reservation1 = conn.run_instances('ami-1234abcd', min_count=1, subnet_id=subnet1.id)
reservation1 = conn.run_instances(
'ami-1234abcd', min_count=1, subnet_id=subnet1.id)
instance1 = reservation1.instances[0]
vpc2 = conn.create_vpc("10.1.0.0/16")
subnet2 = conn.create_subnet(vpc2.id, "10.1.0.0/27")
reservation2 = conn.run_instances('ami-1234abcd', min_count=1, subnet_id=subnet2.id)
reservation2 = conn.run_instances(
'ami-1234abcd', min_count=1, subnet_id=subnet2.id)
instance2 = reservation2.instances[0]
reservations1 = conn.get_all_instances(filters={'vpc-id': vpc1.id})
@ -320,31 +348,35 @@ def test_get_instances_filtering_by_tag():
instance2.add_tag('tag2', 'wrong value')
instance3.add_tag('tag2', 'value2')
reservations = conn.get_all_instances(filters={'tag:tag0' : 'value0'})
reservations = conn.get_all_instances(filters={'tag:tag0': 'value0'})
# get_all_instances should return no instances
reservations.should.have.length_of(0)
reservations = conn.get_all_instances(filters={'tag:tag1' : 'value1'})
reservations = conn.get_all_instances(filters={'tag:tag1': 'value1'})
# get_all_instances should return both instances with this tag value
reservations.should.have.length_of(1)
reservations[0].instances.should.have.length_of(2)
reservations[0].instances[0].id.should.equal(instance1.id)
reservations[0].instances[1].id.should.equal(instance2.id)
reservations = conn.get_all_instances(filters={'tag:tag1' : 'value1', 'tag:tag2' : 'value2'})
reservations = conn.get_all_instances(
filters={'tag:tag1': 'value1', 'tag:tag2': 'value2'})
# get_all_instances should return the instance with both tag values
reservations.should.have.length_of(1)
reservations[0].instances.should.have.length_of(1)
reservations[0].instances[0].id.should.equal(instance1.id)
reservations = conn.get_all_instances(filters={'tag:tag1' : 'value1', 'tag:tag2' : 'value2'})
reservations = conn.get_all_instances(
filters={'tag:tag1': 'value1', 'tag:tag2': 'value2'})
# get_all_instances should return the instance with both tag values
reservations.should.have.length_of(1)
reservations[0].instances.should.have.length_of(1)
reservations[0].instances[0].id.should.equal(instance1.id)
reservations = conn.get_all_instances(filters={'tag:tag2' : ['value2', 'bogus']})
# get_all_instances should return both instances with one of the acceptable tag values
reservations = conn.get_all_instances(
filters={'tag:tag2': ['value2', 'bogus']})
# get_all_instances should return both instances with one of the
# acceptable tag values
reservations.should.have.length_of(1)
reservations[0].instances.should.have.length_of(2)
reservations[0].instances[0].id.should.equal(instance1.id)
@ -362,32 +394,37 @@ def test_get_instances_filtering_by_tag_value():
instance2.add_tag('tag2', 'wrong value')
instance3.add_tag('tag2', 'value2')
reservations = conn.get_all_instances(filters={'tag-value' : 'value0'})
reservations = conn.get_all_instances(filters={'tag-value': 'value0'})
# get_all_instances should return no instances
reservations.should.have.length_of(0)
reservations = conn.get_all_instances(filters={'tag-value' : 'value1'})
reservations = conn.get_all_instances(filters={'tag-value': 'value1'})
# get_all_instances should return both instances with this tag value
reservations.should.have.length_of(1)
reservations[0].instances.should.have.length_of(2)
reservations[0].instances[0].id.should.equal(instance1.id)
reservations[0].instances[1].id.should.equal(instance2.id)
reservations = conn.get_all_instances(filters={'tag-value' : ['value2', 'value1']})
# get_all_instances should return both instances with one of the acceptable tag values
reservations = conn.get_all_instances(
filters={'tag-value': ['value2', 'value1']})
# get_all_instances should return both instances with one of the
# acceptable tag values
reservations.should.have.length_of(1)
reservations[0].instances.should.have.length_of(3)
reservations[0].instances[0].id.should.equal(instance1.id)
reservations[0].instances[1].id.should.equal(instance2.id)
reservations[0].instances[2].id.should.equal(instance3.id)
reservations = conn.get_all_instances(filters={'tag-value' : ['value2', 'bogus']})
# get_all_instances should return both instances with one of the acceptable tag values
reservations = conn.get_all_instances(
filters={'tag-value': ['value2', 'bogus']})
# get_all_instances should return both instances with one of the
# acceptable tag values
reservations.should.have.length_of(1)
reservations[0].instances.should.have.length_of(2)
reservations[0].instances[0].id.should.equal(instance1.id)
reservations[0].instances[1].id.should.equal(instance3.id)
@mock_ec2_deprecated
def test_get_instances_filtering_by_tag_name():
conn = boto.connect_ec2()
@ -399,25 +436,28 @@ def test_get_instances_filtering_by_tag_name():
instance2.add_tag('tag2X')
instance3.add_tag('tag3')
reservations = conn.get_all_instances(filters={'tag-key' : 'tagX'})
reservations = conn.get_all_instances(filters={'tag-key': 'tagX'})
# get_all_instances should return no instances
reservations.should.have.length_of(0)
reservations = conn.get_all_instances(filters={'tag-key' : 'tag1'})
reservations = conn.get_all_instances(filters={'tag-key': 'tag1'})
# get_all_instances should return both instances with this tag value
reservations.should.have.length_of(1)
reservations[0].instances.should.have.length_of(2)
reservations[0].instances[0].id.should.equal(instance1.id)
reservations[0].instances[1].id.should.equal(instance2.id)
reservations = conn.get_all_instances(filters={'tag-key' : ['tag1', 'tag3']})
# get_all_instances should return both instances with one of the acceptable tag values
reservations = conn.get_all_instances(
filters={'tag-key': ['tag1', 'tag3']})
# get_all_instances should return both instances with one of the
# acceptable tag values
reservations.should.have.length_of(1)
reservations[0].instances.should.have.length_of(3)
reservations[0].instances[0].id.should.equal(instance1.id)
reservations[0].instances[1].id.should.equal(instance2.id)
reservations[0].instances[2].id.should.equal(instance3.id)
@mock_ec2_deprecated
def test_instance_start_and_stop():
conn = boto.connect_ec2('the_key', 'the_secret')
@ -431,7 +471,8 @@ def test_instance_start_and_stop():
stopped_instances = conn.stop_instances(instance_ids, dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the StopInstance operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the StopInstance operation: Request would have succeeded, but DryRun flag is set')
stopped_instances = conn.stop_instances(instance_ids)
@ -439,10 +480,12 @@ def test_instance_start_and_stop():
instance.state.should.equal('stopping')
with assert_raises(EC2ResponseError) as ex:
started_instances = conn.start_instances([instances[0].id], dry_run=True)
started_instances = conn.start_instances(
[instances[0].id], dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the StartInstance operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the StartInstance operation: Request would have succeeded, but DryRun flag is set')
started_instances = conn.start_instances([instances[0].id])
started_instances[0].state.should.equal('pending')
@ -458,7 +501,8 @@ def test_instance_reboot():
instance.reboot(dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the RebootInstance operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the RebootInstance operation: Request would have succeeded, but DryRun flag is set')
instance.reboot()
instance.state.should.equal('pending')
@ -474,7 +518,8 @@ def test_instance_attribute_instance_type():
instance.modify_attribute("instanceType", "m1.small", dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the ModifyInstanceType operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the ModifyInstanceType operation: Request would have succeeded, but DryRun flag is set')
instance.modify_attribute("instanceType", "m1.small")
@ -482,6 +527,7 @@ def test_instance_attribute_instance_type():
instance_attribute.should.be.a(InstanceAttribute)
instance_attribute.get('instanceType').should.equal("m1.small")
@mock_ec2_deprecated
def test_modify_instance_attribute_security_groups():
conn = boto.connect_ec2('the_key', 'the_secret')
@ -495,7 +541,8 @@ def test_modify_instance_attribute_security_groups():
instance.modify_attribute("groupSet", [sg_id, sg_id2], dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the ModifyInstanceSecurityGroups operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the ModifyInstanceSecurityGroups operation: Request would have succeeded, but DryRun flag is set')
instance.modify_attribute("groupSet", [sg_id, sg_id2])
@ -513,10 +560,12 @@ def test_instance_attribute_user_data():
instance = reservation.instances[0]
with assert_raises(EC2ResponseError) as ex:
instance.modify_attribute("userData", "this is my user data", dry_run=True)
instance.modify_attribute(
"userData", "this is my user data", dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the ModifyUserData operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the ModifyUserData operation: Request would have succeeded, but DryRun flag is set')
instance.modify_attribute("userData", "this is my user data")
@ -544,7 +593,8 @@ def test_instance_attribute_source_dest_check():
instance.modify_attribute("sourceDestCheck", False, dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the ModifySourceDestCheck operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the ModifySourceDestCheck operation: Request would have succeeded, but DryRun flag is set')
instance.modify_attribute("sourceDestCheck", False)
@ -585,10 +635,12 @@ def test_run_instance_with_security_group_name():
conn = boto.connect_ec2('the_key', 'the_secret')
with assert_raises(EC2ResponseError) as ex:
group = conn.create_security_group('group1', "some description", dry_run=True)
group = conn.create_security_group(
'group1', "some description", dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the CreateSecurityGroup operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the CreateSecurityGroup operation: Request would have succeeded, but DryRun flag is set')
group = conn.create_security_group('group1', "some description")
@ -658,14 +710,16 @@ def test_run_instance_with_nic_autocreated():
conn = boto.connect_vpc('the_key', 'the_secret')
vpc = conn.create_vpc("10.0.0.0/16")
subnet = conn.create_subnet(vpc.id, "10.0.0.0/18")
security_group1 = conn.create_security_group('test security group #1', 'this is a test security group')
security_group2 = conn.create_security_group('test security group #2', 'this is a test security group')
security_group1 = conn.create_security_group(
'test security group #1', 'this is a test security group')
security_group2 = conn.create_security_group(
'test security group #2', 'this is a test security group')
private_ip = "54.0.0.1"
reservation = conn.run_instances('ami-1234abcd', subnet_id=subnet.id,
security_groups=[security_group1.name],
security_group_ids=[security_group2.id],
private_ip_address=private_ip)
security_groups=[security_group1.name],
security_group_ids=[security_group2.id],
private_ip_address=private_ip)
instance = reservation.instances[0]
all_enis = conn.get_all_network_interfaces()
@ -677,11 +731,13 @@ def test_run_instance_with_nic_autocreated():
instance.subnet_id.should.equal(subnet.id)
instance.groups.should.have.length_of(2)
set([group.id for group in instance.groups]).should.equal(set([security_group1.id,security_group2.id]))
set([group.id for group in instance.groups]).should.equal(
set([security_group1.id, security_group2.id]))
eni.subnet_id.should.equal(subnet.id)
eni.groups.should.have.length_of(2)
set([group.id for group in eni.groups]).should.equal(set([security_group1.id,security_group2.id]))
set([group.id for group in eni.groups]).should.equal(
set([security_group1.id, security_group2.id]))
eni.private_ip_addresses.should.have.length_of(1)
eni.private_ip_addresses[0].private_ip_address.should.equal(private_ip)
@ -691,20 +747,24 @@ def test_run_instance_with_nic_preexisting():
conn = boto.connect_vpc('the_key', 'the_secret')
vpc = conn.create_vpc("10.0.0.0/16")
subnet = conn.create_subnet(vpc.id, "10.0.0.0/18")
security_group1 = conn.create_security_group('test security group #1', 'this is a test security group')
security_group2 = conn.create_security_group('test security group #2', 'this is a test security group')
security_group1 = conn.create_security_group(
'test security group #1', 'this is a test security group')
security_group2 = conn.create_security_group(
'test security group #2', 'this is a test security group')
private_ip = "54.0.0.1"
eni = conn.create_network_interface(subnet.id, private_ip, groups=[security_group1.id])
eni = conn.create_network_interface(
subnet.id, private_ip, groups=[security_group1.id])
# Boto requires NetworkInterfaceCollection of NetworkInterfaceSpecifications...
# annoying, but generates the desired querystring.
from boto.ec2.networkinterface import NetworkInterfaceSpecification, NetworkInterfaceCollection
interface = NetworkInterfaceSpecification(network_interface_id=eni.id, device_index=0)
interface = NetworkInterfaceSpecification(
network_interface_id=eni.id, device_index=0)
interfaces = NetworkInterfaceCollection(interface)
# end Boto objects
reservation = conn.run_instances('ami-1234abcd', network_interfaces=interfaces,
security_group_ids=[security_group2.id])
security_group_ids=[security_group2.id])
instance = reservation.instances[0]
instance.subnet_id.should.equal(subnet.id)
@ -718,9 +778,11 @@ def test_run_instance_with_nic_preexisting():
instance_eni.subnet_id.should.equal(subnet.id)
instance_eni.groups.should.have.length_of(2)
set([group.id for group in instance_eni.groups]).should.equal(set([security_group1.id,security_group2.id]))
set([group.id for group in instance_eni.groups]).should.equal(
set([security_group1.id, security_group2.id]))
instance_eni.private_ip_addresses.should.have.length_of(1)
instance_eni.private_ip_addresses[0].private_ip_address.should.equal(private_ip)
instance_eni.private_ip_addresses[
0].private_ip_address.should.equal(private_ip)
@requires_boto_gte("2.32.0")
@ -730,10 +792,13 @@ def test_instance_with_nic_attach_detach():
vpc = conn.create_vpc("10.0.0.0/16")
subnet = conn.create_subnet(vpc.id, "10.0.0.0/18")
security_group1 = conn.create_security_group('test security group #1', 'this is a test security group')
security_group2 = conn.create_security_group('test security group #2', 'this is a test security group')
security_group1 = conn.create_security_group(
'test security group #1', 'this is a test security group')
security_group2 = conn.create_security_group(
'test security group #2', 'this is a test security group')
reservation = conn.run_instances('ami-1234abcd', security_group_ids=[security_group1.id])
reservation = conn.run_instances(
'ami-1234abcd', security_group_ids=[security_group1.id])
instance = reservation.instances[0]
eni = conn.create_network_interface(subnet.id, groups=[security_group2.id])
@ -742,14 +807,17 @@ def test_instance_with_nic_attach_detach():
instance.interfaces.should.have.length_of(1)
eni.groups.should.have.length_of(1)
set([group.id for group in eni.groups]).should.equal(set([security_group2.id]))
set([group.id for group in eni.groups]).should.equal(
set([security_group2.id]))
# Attach
with assert_raises(EC2ResponseError) as ex:
conn.attach_network_interface(eni.id, instance.id, device_index=1, dry_run=True)
conn.attach_network_interface(
eni.id, instance.id, device_index=1, dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the AttachNetworkInterface operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the AttachNetworkInterface operation: Request would have succeeded, but DryRun flag is set')
conn.attach_network_interface(eni.id, instance.id, device_index=1)
@ -759,18 +827,22 @@ def test_instance_with_nic_attach_detach():
instance_eni = instance.interfaces[1]
instance_eni.id.should.equal(eni.id)
instance_eni.groups.should.have.length_of(2)
set([group.id for group in instance_eni.groups]).should.equal(set([security_group1.id,security_group2.id]))
set([group.id for group in instance_eni.groups]).should.equal(
set([security_group1.id, security_group2.id]))
eni = conn.get_all_network_interfaces(filters={'network-interface-id': eni.id})[0]
eni = conn.get_all_network_interfaces(
filters={'network-interface-id': eni.id})[0]
eni.groups.should.have.length_of(2)
set([group.id for group in eni.groups]).should.equal(set([security_group1.id,security_group2.id]))
set([group.id for group in eni.groups]).should.equal(
set([security_group1.id, security_group2.id]))
# Detach
with assert_raises(EC2ResponseError) as ex:
conn.detach_network_interface(instance_eni.attachment.id, dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the DetachNetworkInterface operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the DetachNetworkInterface operation: Request would have succeeded, but DryRun flag is set')
conn.detach_network_interface(instance_eni.attachment.id)
@ -778,9 +850,11 @@ def test_instance_with_nic_attach_detach():
instance.update()
instance.interfaces.should.have.length_of(1)
eni = conn.get_all_network_interfaces(filters={'network-interface-id': eni.id})[0]
eni = conn.get_all_network_interfaces(
filters={'network-interface-id': eni.id})[0]
eni.groups.should.have.length_of(1)
set([group.id for group in eni.groups]).should.equal(set([security_group2.id]))
set([group.id for group in eni.groups]).should.equal(
set([security_group2.id]))
# Detach with invalid attachment ID
with assert_raises(EC2ResponseError) as cm:
@ -851,6 +925,7 @@ def test_describe_instance_status_with_instance_filter():
cm.exception.status.should.equal(400)
cm.exception.request_id.should_not.be.none
@requires_boto_gte("2.32.0")
@mock_ec2_deprecated
def test_describe_instance_status_with_non_running_instances():
@ -877,6 +952,7 @@ def test_describe_instance_status_with_non_running_instances():
status3 = next((s for s in all_status if s.id == instance3.id), None)
status3.state_name.should.equal('running')
@mock_ec2_deprecated
def test_get_instance_by_security_group():
conn = boto.connect_ec2('the_key', 'the_secret')
@ -887,12 +963,15 @@ def test_get_instance_by_security_group():
security_group = conn.create_security_group('test', 'test')
with assert_raises(EC2ResponseError) as ex:
conn.modify_instance_attribute(instance.id, "groupSet", [security_group.id], dry_run=True)
conn.modify_instance_attribute(instance.id, "groupSet", [
security_group.id], dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the ModifyInstanceSecurityGroups operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the ModifyInstanceSecurityGroups operation: Request would have succeeded, but DryRun flag is set')
conn.modify_instance_attribute(instance.id, "groupSet", [security_group.id])
conn.modify_instance_attribute(
instance.id, "groupSet", [security_group.id])
security_group_instances = security_group.instances()

View file

@ -13,9 +13,10 @@ import sure # noqa
from moto import mock_ec2_deprecated
VPC_CIDR="10.0.0.0/16"
BAD_VPC="vpc-deadbeef"
BAD_IGW="igw-deadbeef"
VPC_CIDR = "10.0.0.0/16"
BAD_VPC = "vpc-deadbeef"
BAD_IGW = "igw-deadbeef"
@mock_ec2_deprecated
def test_igw_create():
@ -28,7 +29,8 @@ def test_igw_create():
igw = conn.create_internet_gateway(dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the CreateInternetGateway operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the CreateInternetGateway operation: Request would have succeeded, but DryRun flag is set')
igw = conn.create_internet_gateway()
conn.get_all_internet_gateways().should.have.length_of(1)
@ -37,6 +39,7 @@ def test_igw_create():
igw = conn.get_all_internet_gateways()[0]
igw.attachments.should.have.length_of(0)
@mock_ec2_deprecated
def test_igw_attach():
""" internet gateway attach """
@ -48,13 +51,15 @@ def test_igw_attach():
conn.attach_internet_gateway(igw.id, vpc.id, dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the AttachInternetGateway operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the AttachInternetGateway operation: Request would have succeeded, but DryRun flag is set')
conn.attach_internet_gateway(igw.id, vpc.id)
igw = conn.get_all_internet_gateways()[0]
igw.attachments[0].vpc_id.should.be.equal(vpc.id)
@mock_ec2_deprecated
def test_igw_attach_bad_vpc():
""" internet gateway fail to attach w/ bad vpc """
@ -67,6 +72,7 @@ def test_igw_attach_bad_vpc():
cm.exception.status.should.equal(400)
cm.exception.request_id.should_not.be.none
@mock_ec2_deprecated
def test_igw_attach_twice():
""" internet gateway fail to attach twice """
@ -82,6 +88,7 @@ def test_igw_attach_twice():
cm.exception.status.should.equal(400)
cm.exception.request_id.should_not.be.none
@mock_ec2_deprecated
def test_igw_detach():
""" internet gateway detach"""
@ -94,12 +101,14 @@ def test_igw_detach():
conn.detach_internet_gateway(igw.id, vpc.id, dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the DetachInternetGateway operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the DetachInternetGateway operation: Request would have succeeded, but DryRun flag is set')
conn.detach_internet_gateway(igw.id, vpc.id)
igw = conn.get_all_internet_gateways()[0]
igw.attachments.should.have.length_of(0)
@mock_ec2_deprecated
def test_igw_detach_wrong_vpc():
""" internet gateway fail to detach w/ wrong vpc """
@ -115,6 +124,7 @@ def test_igw_detach_wrong_vpc():
cm.exception.status.should.equal(400)
cm.exception.request_id.should_not.be.none
@mock_ec2_deprecated
def test_igw_detach_invalid_vpc():
""" internet gateway fail to detach w/ invalid vpc """
@ -129,6 +139,7 @@ def test_igw_detach_invalid_vpc():
cm.exception.status.should.equal(400)
cm.exception.request_id.should_not.be.none
@mock_ec2_deprecated
def test_igw_detach_unattached():
""" internet gateway fail to detach unattached """
@ -142,6 +153,7 @@ def test_igw_detach_unattached():
cm.exception.status.should.equal(400)
cm.exception.request_id.should_not.be.none
@mock_ec2_deprecated
def test_igw_delete():
""" internet gateway delete"""
@ -155,11 +167,13 @@ def test_igw_delete():
conn.delete_internet_gateway(igw.id, dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the DeleteInternetGateway operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the DeleteInternetGateway operation: Request would have succeeded, but DryRun flag is set')
conn.delete_internet_gateway(igw.id)
conn.get_all_internet_gateways().should.have.length_of(0)
@mock_ec2_deprecated
def test_igw_delete_attached():
""" internet gateway fail to delete attached """
@ -174,6 +188,7 @@ def test_igw_delete_attached():
cm.exception.status.should.equal(400)
cm.exception.request_id.should_not.be.none
@mock_ec2_deprecated
def test_igw_desribe():
""" internet gateway fetch by id """
@ -182,6 +197,7 @@ def test_igw_desribe():
igw_by_search = conn.get_all_internet_gateways([igw.id])[0]
igw.id.should.equal(igw_by_search.id)
@mock_ec2_deprecated
def test_igw_desribe_bad_id():
""" internet gateway fail to fetch by bad id """
@ -203,7 +219,8 @@ def test_igw_filter_by_vpc_id():
vpc = conn.create_vpc(VPC_CIDR)
conn.attach_internet_gateway(igw1.id, vpc.id)
result = conn.get_all_internet_gateways(filters={"attachment.vpc-id": vpc.id})
result = conn.get_all_internet_gateways(
filters={"attachment.vpc-id": vpc.id})
result.should.have.length_of(1)
result[0].id.should.equal(igw1.id)
@ -230,7 +247,8 @@ def test_igw_filter_by_internet_gateway_id():
igw1 = conn.create_internet_gateway()
igw2 = conn.create_internet_gateway()
result = conn.get_all_internet_gateways(filters={"internet-gateway-id": igw1.id})
result = conn.get_all_internet_gateways(
filters={"internet-gateway-id": igw1.id})
result.should.have.length_of(1)
result[0].id.should.equal(igw1.id)
@ -245,6 +263,7 @@ def test_igw_filter_by_attachment_state():
vpc = conn.create_vpc(VPC_CIDR)
conn.attach_internet_gateway(igw1.id, vpc.id)
result = conn.get_all_internet_gateways(filters={"attachment.state": "available"})
result = conn.get_all_internet_gateways(
filters={"attachment.state": "available"})
result.should.have.length_of(1)
result[0].id.should.equal(igw1.id)

View file

@ -36,7 +36,8 @@ def test_key_pairs_create():
kp = conn.create_key_pair('foo', dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the CreateKeyPair operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the CreateKeyPair operation: Request would have succeeded, but DryRun flag is set')
kp = conn.create_key_pair('foo')
assert kp.material.startswith('---- BEGIN RSA PRIVATE KEY ----')
@ -91,7 +92,8 @@ def test_key_pairs_delete_exist():
r = conn.delete_key_pair('foo', dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the DeleteKeyPair operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the DeleteKeyPair operation: Request would have succeeded, but DryRun flag is set')
r = conn.delete_key_pair('foo')
r.should.be.ok
@ -106,7 +108,8 @@ def test_key_pairs_import():
kp = conn.import_key_pair('foo', b'content', dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the ImportKeyPair operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the ImportKeyPair operation: Request would have succeeded, but DryRun flag is set')
kp = conn.import_key_pair('foo', b'content')
assert kp.name == 'foo'

View file

@ -56,7 +56,8 @@ def test_delete_nat_gateway():
nat_gateway_id = nat_gateway['NatGateway']['NatGatewayId']
response = conn.delete_nat_gateway(NatGatewayId=nat_gateway_id)
response['ResponseMetadata'].pop('HTTPHeaders', None) # this is hard to match against, so remove it
# this is hard to match against, so remove it
response['ResponseMetadata'].pop('HTTPHeaders', None)
response['ResponseMetadata'].pop('RetryAttempts', None)
response.should.equal({
'NatGatewayId': nat_gateway_id,
@ -89,14 +90,20 @@ def test_create_and_describe_nat_gateway():
enis = conn.describe_network_interfaces()['NetworkInterfaces']
eni_id = enis[0]['NetworkInterfaceId']
public_ip = conn.describe_addresses(AllocationIds=[allocation_id])['Addresses'][0]['PublicIp']
public_ip = conn.describe_addresses(AllocationIds=[allocation_id])[
'Addresses'][0]['PublicIp']
describe_response['NatGateways'].should.have.length_of(1)
describe_response['NatGateways'][0]['NatGatewayId'].should.equal(nat_gateway_id)
describe_response['NatGateways'][0][
'NatGatewayId'].should.equal(nat_gateway_id)
describe_response['NatGateways'][0]['State'].should.equal('available')
describe_response['NatGateways'][0]['SubnetId'].should.equal(subnet_id)
describe_response['NatGateways'][0]['VpcId'].should.equal(vpc_id)
describe_response['NatGateways'][0]['NatGatewayAddresses'][0]['AllocationId'].should.equal(allocation_id)
describe_response['NatGateways'][0]['NatGatewayAddresses'][0]['NetworkInterfaceId'].should.equal(eni_id)
assert describe_response['NatGateways'][0]['NatGatewayAddresses'][0]['PrivateIp'].startswith('10.')
describe_response['NatGateways'][0]['NatGatewayAddresses'][0]['PublicIp'].should.equal(public_ip)
describe_response['NatGateways'][0]['NatGatewayAddresses'][
0]['AllocationId'].should.equal(allocation_id)
describe_response['NatGateways'][0]['NatGatewayAddresses'][
0]['NetworkInterfaceId'].should.equal(eni_id)
assert describe_response['NatGateways'][0][
'NatGatewayAddresses'][0]['PrivateIp'].startswith('10.')
describe_response['NatGateways'][0]['NatGatewayAddresses'][
0]['PublicIp'].should.equal(public_ip)

View file

@ -50,9 +50,11 @@ def test_add_servers_to_multiple_regions():
@mock_elb_deprecated
def test_create_autoscaling_group():
elb_conn = boto.ec2.elb.connect_to_region('us-east-1')
elb_conn.create_load_balancer('us_test_lb', zones=[], listeners=[(80, 8080, 'http')])
elb_conn.create_load_balancer(
'us_test_lb', zones=[], listeners=[(80, 8080, 'http')])
elb_conn = boto.ec2.elb.connect_to_region('ap-northeast-1')
elb_conn.create_load_balancer('ap_test_lb', zones=[], listeners=[(80, 8080, 'http')])
elb_conn.create_load_balancer(
'ap_test_lb', zones=[], listeners=[(80, 8080, 'http')])
us_conn = boto.ec2.autoscale.connect_to_region('us-east-1')
config = boto.ec2.autoscale.LaunchConfiguration(
@ -79,7 +81,6 @@ def test_create_autoscaling_group():
)
us_conn.create_auto_scaling_group(group)
ap_conn = boto.ec2.autoscale.connect_to_region('ap-northeast-1')
config = boto.ec2.autoscale.LaunchConfiguration(
name='ap_tester',
@ -105,7 +106,6 @@ def test_create_autoscaling_group():
)
ap_conn.create_auto_scaling_group(group)
len(us_conn.get_all_groups()).should.equal(1)
len(ap_conn.get_all_groups()).should.equal(1)
@ -122,7 +122,8 @@ def test_create_autoscaling_group():
us_group.health_check_type.should.equal("EC2")
list(us_group.load_balancers).should.equal(["us_test_lb"])
us_group.placement_group.should.equal("us_test_placement")
list(us_group.termination_policies).should.equal(["OldestInstance", "NewestInstance"])
list(us_group.termination_policies).should.equal(
["OldestInstance", "NewestInstance"])
ap_group = ap_conn.get_all_groups()[0]
ap_group.name.should.equal('ap_tester_group')
@ -137,4 +138,5 @@ def test_create_autoscaling_group():
ap_group.health_check_type.should.equal("EC2")
list(ap_group.load_balancers).should.equal(["ap_test_lb"])
ap_group.placement_group.should.equal("ap_test_placement")
list(ap_group.termination_policies).should.equal(["OldestInstance", "NewestInstance"])
list(ap_group.termination_policies).should.equal(
["OldestInstance", "NewestInstance"])

View file

@ -91,28 +91,34 @@ def test_route_tables_filters_standard():
all_route_tables.should.have.length_of(5)
# Filter by main route table
main_route_tables = conn.get_all_route_tables(filters={'association.main':'true'})
main_route_tables = conn.get_all_route_tables(
filters={'association.main': 'true'})
main_route_tables.should.have.length_of(3)
main_route_table_ids = [route_table.id for route_table in main_route_tables]
main_route_table_ids = [
route_table.id for route_table in main_route_tables]
main_route_table_ids.should_not.contain(route_table1.id)
main_route_table_ids.should_not.contain(route_table2.id)
# Filter by VPC
vpc1_route_tables = conn.get_all_route_tables(filters={'vpc-id':vpc1.id})
vpc1_route_tables = conn.get_all_route_tables(filters={'vpc-id': vpc1.id})
vpc1_route_tables.should.have.length_of(2)
vpc1_route_table_ids = [route_table.id for route_table in vpc1_route_tables]
vpc1_route_table_ids = [
route_table.id for route_table in vpc1_route_tables]
vpc1_route_table_ids.should.contain(route_table1.id)
vpc1_route_table_ids.should_not.contain(route_table2.id)
# Filter by VPC and main route table
vpc2_main_route_tables = conn.get_all_route_tables(filters={'association.main':'true', 'vpc-id':vpc2.id})
vpc2_main_route_tables = conn.get_all_route_tables(
filters={'association.main': 'true', 'vpc-id': vpc2.id})
vpc2_main_route_tables.should.have.length_of(1)
vpc2_main_route_table_ids = [route_table.id for route_table in vpc2_main_route_tables]
vpc2_main_route_table_ids = [
route_table.id for route_table in vpc2_main_route_tables]
vpc2_main_route_table_ids.should_not.contain(route_table1.id)
vpc2_main_route_table_ids.should_not.contain(route_table2.id)
# Unsupported filter
conn.get_all_route_tables.when.called_with(filters={'not-implemented-filter': 'foobar'}).should.throw(NotImplementedError)
conn.get_all_route_tables.when.called_with(
filters={'not-implemented-filter': 'foobar'}).should.throw(NotImplementedError)
@mock_ec2_deprecated
@ -134,19 +140,22 @@ def test_route_tables_filters_associations():
all_route_tables.should.have.length_of(4)
# Filter by association ID
association1_route_tables = conn.get_all_route_tables(filters={'association.route-table-association-id':association_id1})
association1_route_tables = conn.get_all_route_tables(
filters={'association.route-table-association-id': association_id1})
association1_route_tables.should.have.length_of(1)
association1_route_tables[0].id.should.equal(route_table1.id)
association1_route_tables[0].associations.should.have.length_of(2)
# Filter by route table ID
route_table2_route_tables = conn.get_all_route_tables(filters={'association.route-table-id':route_table2.id})
route_table2_route_tables = conn.get_all_route_tables(
filters={'association.route-table-id': route_table2.id})
route_table2_route_tables.should.have.length_of(1)
route_table2_route_tables[0].id.should.equal(route_table2.id)
route_table2_route_tables[0].associations.should.have.length_of(1)
# Filter by subnet ID
subnet_route_tables = conn.get_all_route_tables(filters={'association.subnet-id':subnet1.id})
subnet_route_tables = conn.get_all_route_tables(
filters={'association.subnet-id': subnet1.id})
subnet_route_tables.should.have.length_of(1)
subnet_route_tables[0].id.should.equal(route_table1.id)
association1_route_tables[0].associations.should.have.length_of(2)
@ -179,7 +188,8 @@ def test_route_table_associations():
route_table.associations[0].subnet_id.should.equal(subnet.id)
# Associate is idempotent
association_id_idempotent = conn.associate_route_table(route_table.id, subnet.id)
association_id_idempotent = conn.associate_route_table(
route_table.id, subnet.id)
association_id_idempotent.should.equal(association_id)
# Error: Attempt delete associated route table.
@ -255,7 +265,8 @@ def test_route_table_replace_route_table_association():
route_table1.associations[0].subnet_id.should.equal(subnet.id)
# Replace Association
association_id2 = conn.replace_route_table_association_with_assoc(association_id1, route_table2.id)
association_id2 = conn.replace_route_table_association_with_assoc(
association_id1, route_table2.id)
# Refresh
route_table1 = conn.get_all_route_tables(route_table1.id)[0]
@ -271,19 +282,22 @@ def test_route_table_replace_route_table_association():
route_table2.associations[0].subnet_id.should.equal(subnet.id)
# Replace Association is idempotent
association_id_idempotent = conn.replace_route_table_association_with_assoc(association_id2, route_table2.id)
association_id_idempotent = conn.replace_route_table_association_with_assoc(
association_id2, route_table2.id)
association_id_idempotent.should.equal(association_id2)
# Error: Replace association with invalid association ID
with assert_raises(EC2ResponseError) as cm:
conn.replace_route_table_association_with_assoc("rtbassoc-1234abcd", route_table1.id)
conn.replace_route_table_association_with_assoc(
"rtbassoc-1234abcd", route_table1.id)
cm.exception.code.should.equal('InvalidAssociationID.NotFound')
cm.exception.status.should.equal(400)
cm.exception.request_id.should_not.be.none
# Error: Replace association with invalid route table ID
with assert_raises(EC2ResponseError) as cm:
conn.replace_route_table_association_with_assoc(association_id2, "rtb-1234abcd")
conn.replace_route_table_association_with_assoc(
association_id2, "rtb-1234abcd")
cm.exception.code.should.equal('InvalidRouteTableID.NotFound')
cm.exception.status.should.equal(400)
cm.exception.request_id.should_not.be.none
@ -298,7 +312,8 @@ def test_route_table_get_by_tag():
route_table = conn.create_route_table(vpc.id)
route_table.add_tag('Name', 'TestRouteTable')
route_tables = conn.get_all_route_tables(filters={'tag:Name': 'TestRouteTable'})
route_tables = conn.get_all_route_tables(
filters={'tag:Name': 'TestRouteTable'})
route_tables.should.have.length_of(1)
route_tables[0].vpc_id.should.equal(vpc.id)
@ -323,7 +338,8 @@ def test_route_table_get_by_tag_boto3():
route_tables[0].vpc_id.should.equal(vpc.id)
route_tables[0].id.should.equal(route_table.id)
route_tables[0].tags.should.have.length_of(1)
route_tables[0].tags[0].should.equal({'Key': 'Name', 'Value': 'TestRouteTable'})
route_tables[0].tags[0].should.equal(
{'Key': 'Name', 'Value': 'TestRouteTable'})
@mock_ec2_deprecated
@ -337,10 +353,12 @@ def test_routes_additional():
conn.create_route(main_route_table.id, ROUTE_CIDR, gateway_id=igw.id)
main_route_table = conn.get_all_route_tables(filters={'vpc-id': vpc.id})[0] # Refresh route table
main_route_table = conn.get_all_route_tables(
filters={'vpc-id': vpc.id})[0] # Refresh route table
main_route_table.routes.should.have.length_of(2)
new_routes = [route for route in main_route_table.routes if route.destination_cidr_block != vpc.cidr_block]
new_routes = [
route for route in main_route_table.routes if route.destination_cidr_block != vpc.cidr_block]
new_routes.should.have.length_of(1)
new_route = new_routes[0]
@ -351,10 +369,12 @@ def test_routes_additional():
conn.delete_route(main_route_table.id, ROUTE_CIDR)
main_route_table = conn.get_all_route_tables(filters={'vpc-id': vpc.id})[0] # Refresh route table
main_route_table = conn.get_all_route_tables(
filters={'vpc-id': vpc.id})[0] # Refresh route table
main_route_table.routes.should.have.length_of(1)
new_routes = [route for route in main_route_table.routes if route.destination_cidr_block != vpc.cidr_block]
new_routes = [
route for route in main_route_table.routes if route.destination_cidr_block != vpc.cidr_block]
new_routes.should.have.length_of(0)
with assert_raises(EC2ResponseError) as cm:
@ -368,7 +388,8 @@ def test_routes_additional():
def test_routes_replace():
conn = boto.connect_vpc('the_key', 'the_secret')
vpc = conn.create_vpc("10.0.0.0/16")
main_route_table = conn.get_all_route_tables(filters={'association.main':'true','vpc-id':vpc.id})[0]
main_route_table = conn.get_all_route_tables(
filters={'association.main': 'true', 'vpc-id': vpc.id})[0]
local_route = main_route_table.routes[0]
ROUTE_CIDR = "10.0.0.4/24"
@ -384,11 +405,13 @@ def test_routes_replace():
# Replace...
def get_target_route():
route_table = conn.get_all_route_tables(main_route_table.id)[0]
routes = [route for route in route_table.routes if route.destination_cidr_block != vpc.cidr_block]
routes = [
route for route in route_table.routes if route.destination_cidr_block != vpc.cidr_block]
routes.should.have.length_of(1)
return routes[0]
conn.replace_route(main_route_table.id, ROUTE_CIDR, instance_id=instance.id)
conn.replace_route(main_route_table.id, ROUTE_CIDR,
instance_id=instance.id)
target_route = get_target_route()
target_route.gateway_id.should.be.none
@ -422,12 +445,14 @@ def test_routes_not_supported():
ROUTE_CIDR = "10.0.0.4/24"
# Create
conn.create_route.when.called_with(main_route_table.id, ROUTE_CIDR, interface_id='eni-1234abcd').should.throw(NotImplementedError)
conn.create_route.when.called_with(
main_route_table.id, ROUTE_CIDR, interface_id='eni-1234abcd').should.throw(NotImplementedError)
# Replace
igw = conn.create_internet_gateway()
conn.create_route(main_route_table.id, ROUTE_CIDR, gateway_id=igw.id)
conn.replace_route.when.called_with(main_route_table.id, ROUTE_CIDR, interface_id='eni-1234abcd').should.throw(NotImplementedError)
conn.replace_route.when.called_with(
main_route_table.id, ROUTE_CIDR, interface_id='eni-1234abcd').should.throw(NotImplementedError)
@requires_boto_gte("2.34.0")
@ -435,18 +460,21 @@ def test_routes_not_supported():
def test_routes_vpc_peering_connection():
conn = boto.connect_vpc('the_key', 'the_secret')
vpc = conn.create_vpc("10.0.0.0/16")
main_route_table = conn.get_all_route_tables(filters={'association.main':'true','vpc-id':vpc.id})[0]
main_route_table = conn.get_all_route_tables(
filters={'association.main': 'true', 'vpc-id': vpc.id})[0]
local_route = main_route_table.routes[0]
ROUTE_CIDR = "10.0.0.4/24"
peer_vpc = conn.create_vpc("11.0.0.0/16")
vpc_pcx = conn.create_vpc_peering_connection(vpc.id, peer_vpc.id)
conn.create_route(main_route_table.id, ROUTE_CIDR, vpc_peering_connection_id=vpc_pcx.id)
conn.create_route(main_route_table.id, ROUTE_CIDR,
vpc_peering_connection_id=vpc_pcx.id)
# Refresh route table
main_route_table = conn.get_all_route_tables(main_route_table.id)[0]
new_routes = [route for route in main_route_table.routes if route.destination_cidr_block != vpc.cidr_block]
new_routes = [
route for route in main_route_table.routes if route.destination_cidr_block != vpc.cidr_block]
new_routes.should.have.length_of(1)
new_route = new_routes[0]
@ -463,7 +491,8 @@ def test_routes_vpn_gateway():
conn = boto.connect_vpc('the_key', 'the_secret')
vpc = conn.create_vpc("10.0.0.0/16")
main_route_table = conn.get_all_route_tables(filters={'association.main':'true','vpc-id':vpc.id})[0]
main_route_table = conn.get_all_route_tables(
filters={'association.main': 'true', 'vpc-id': vpc.id})[0]
ROUTE_CIDR = "10.0.0.4/24"
vpn_gw = conn.create_vpn_gateway(type="ipsec.1")
@ -471,7 +500,8 @@ def test_routes_vpn_gateway():
conn.create_route(main_route_table.id, ROUTE_CIDR, gateway_id=vpn_gw.id)
main_route_table = conn.get_all_route_tables(main_route_table.id)[0]
new_routes = [route for route in main_route_table.routes if route.destination_cidr_block != vpc.cidr_block]
new_routes = [
route for route in main_route_table.routes if route.destination_cidr_block != vpc.cidr_block]
new_routes.should.have.length_of(1)
new_route = new_routes[0]

View file

@ -20,25 +20,30 @@ def test_create_and_describe_security_group():
conn = boto.connect_ec2('the_key', 'the_secret')
with assert_raises(EC2ResponseError) as ex:
security_group = conn.create_security_group('test security group', 'this is a test security group', dry_run=True)
security_group = conn.create_security_group(
'test security group', 'this is a test security group', dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the CreateSecurityGroup operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the CreateSecurityGroup operation: Request would have succeeded, but DryRun flag is set')
security_group = conn.create_security_group('test security group', 'this is a test security group')
security_group = conn.create_security_group(
'test security group', 'this is a test security group')
security_group.name.should.equal('test security group')
security_group.description.should.equal('this is a test security group')
# Trying to create another group with the same name should throw an error
with assert_raises(EC2ResponseError) as cm:
conn.create_security_group('test security group', 'this is a test security group')
conn.create_security_group(
'test security group', 'this is a test security group')
cm.exception.code.should.equal('InvalidGroup.Duplicate')
cm.exception.status.should.equal(400)
cm.exception.request_id.should_not.be.none
all_groups = conn.get_all_security_groups()
all_groups.should.have.length_of(3) # The default group gets created automatically
# The default group gets created automatically
all_groups.should.have.length_of(3)
group_names = [group.name for group in all_groups]
set(group_names).should.equal(set(["default", "test security group"]))
@ -66,16 +71,19 @@ def test_default_security_group():
def test_create_and_describe_vpc_security_group():
conn = boto.connect_ec2('the_key', 'the_secret')
vpc_id = 'vpc-5300000c'
security_group = conn.create_security_group('test security group', 'this is a test security group', vpc_id=vpc_id)
security_group = conn.create_security_group(
'test security group', 'this is a test security group', vpc_id=vpc_id)
security_group.vpc_id.should.equal(vpc_id)
security_group.name.should.equal('test security group')
security_group.description.should.equal('this is a test security group')
# Trying to create another group with the same name in the same VPC should throw an error
# Trying to create another group with the same name in the same VPC should
# throw an error
with assert_raises(EC2ResponseError) as cm:
conn.create_security_group('test security group', 'this is a test security group', vpc_id)
conn.create_security_group(
'test security group', 'this is a test security group', vpc_id)
cm.exception.code.should.equal('InvalidGroup.Duplicate')
cm.exception.status.should.equal(400)
cm.exception.request_id.should_not.be.none
@ -94,8 +102,10 @@ def test_create_two_security_groups_with_same_name_in_different_vpc():
vpc_id = 'vpc-5300000c'
vpc_id2 = 'vpc-5300000d'
conn.create_security_group('test security group', 'this is a test security group', vpc_id)
conn.create_security_group('test security group', 'this is a test security group', vpc_id2)
conn.create_security_group(
'test security group', 'this is a test security group', vpc_id)
conn.create_security_group(
'test security group', 'this is a test security group', vpc_id2)
all_groups = conn.get_all_security_groups()
@ -125,7 +135,8 @@ def test_deleting_security_groups():
conn.delete_security_group('test2', dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the DeleteSecurityGroup operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the DeleteSecurityGroup operation: Request would have succeeded, but DryRun flag is set')
conn.delete_security_group('test2')
conn.get_all_security_groups().should.have.length_of(3)
@ -151,65 +162,83 @@ def test_authorize_ip_range_and_revoke():
security_group = conn.create_security_group('test', 'test')
with assert_raises(EC2ResponseError) as ex:
success = security_group.authorize(ip_protocol="tcp", from_port="22", to_port="2222", cidr_ip="123.123.123.123/32", dry_run=True)
success = security_group.authorize(
ip_protocol="tcp", from_port="22", to_port="2222", cidr_ip="123.123.123.123/32", dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the GrantSecurityGroupIngress operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the GrantSecurityGroupIngress operation: Request would have succeeded, but DryRun flag is set')
success = security_group.authorize(ip_protocol="tcp", from_port="22", to_port="2222", cidr_ip="123.123.123.123/32")
success = security_group.authorize(
ip_protocol="tcp", from_port="22", to_port="2222", cidr_ip="123.123.123.123/32")
assert success.should.be.true
security_group = conn.get_all_security_groups(groupnames=['test'])[0]
int(security_group.rules[0].to_port).should.equal(2222)
security_group.rules[0].grants[0].cidr_ip.should.equal("123.123.123.123/32")
security_group.rules[0].grants[
0].cidr_ip.should.equal("123.123.123.123/32")
# Wrong Cidr should throw error
with assert_raises(EC2ResponseError) as cm:
security_group.revoke(ip_protocol="tcp", from_port="22", to_port="2222", cidr_ip="123.123.123.122/32")
security_group.revoke(ip_protocol="tcp", from_port="22",
to_port="2222", cidr_ip="123.123.123.122/32")
cm.exception.code.should.equal('InvalidPermission.NotFound')
cm.exception.status.should.equal(400)
cm.exception.request_id.should_not.be.none
# Actually revoke
with assert_raises(EC2ResponseError) as ex:
security_group.revoke(ip_protocol="tcp", from_port="22", to_port="2222", cidr_ip="123.123.123.123/32", dry_run=True)
security_group.revoke(ip_protocol="tcp", from_port="22",
to_port="2222", cidr_ip="123.123.123.123/32", dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the RevokeSecurityGroupIngress operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the RevokeSecurityGroupIngress operation: Request would have succeeded, but DryRun flag is set')
security_group.revoke(ip_protocol="tcp", from_port="22", to_port="2222", cidr_ip="123.123.123.123/32")
security_group.revoke(ip_protocol="tcp", from_port="22",
to_port="2222", cidr_ip="123.123.123.123/32")
security_group = conn.get_all_security_groups()[0]
security_group.rules.should.have.length_of(0)
# Test for egress as well
egress_security_group = conn.create_security_group('testegress', 'testegress', vpc_id='vpc-3432589')
egress_security_group = conn.create_security_group(
'testegress', 'testegress', vpc_id='vpc-3432589')
with assert_raises(EC2ResponseError) as ex:
success = conn.authorize_security_group_egress(egress_security_group.id, "tcp", from_port="22", to_port="2222", cidr_ip="123.123.123.123/32", dry_run=True)
success = conn.authorize_security_group_egress(
egress_security_group.id, "tcp", from_port="22", to_port="2222", cidr_ip="123.123.123.123/32", dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the GrantSecurityGroupEgress operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the GrantSecurityGroupEgress operation: Request would have succeeded, but DryRun flag is set')
success = conn.authorize_security_group_egress(egress_security_group.id, "tcp", from_port="22", to_port="2222", cidr_ip="123.123.123.123/32")
success = conn.authorize_security_group_egress(
egress_security_group.id, "tcp", from_port="22", to_port="2222", cidr_ip="123.123.123.123/32")
assert success.should.be.true
egress_security_group = conn.get_all_security_groups(groupnames='testegress')[0]
egress_security_group = conn.get_all_security_groups(
groupnames='testegress')[0]
# There are two egress rules associated with the security group:
# the default outbound rule and the new one
int(egress_security_group.rules_egress[1].to_port).should.equal(2222)
egress_security_group.rules_egress[1].grants[0].cidr_ip.should.equal("123.123.123.123/32")
egress_security_group.rules_egress[1].grants[
0].cidr_ip.should.equal("123.123.123.123/32")
# Wrong Cidr should throw error
egress_security_group.revoke.when.called_with(ip_protocol="tcp", from_port="22", to_port="2222", cidr_ip="123.123.123.122/32").should.throw(EC2ResponseError)
egress_security_group.revoke.when.called_with(
ip_protocol="tcp", from_port="22", to_port="2222", cidr_ip="123.123.123.122/32").should.throw(EC2ResponseError)
# Actually revoke
with assert_raises(EC2ResponseError) as ex:
conn.revoke_security_group_egress(egress_security_group.id, "tcp", from_port="22", to_port="2222", cidr_ip="123.123.123.123/32", dry_run=True)
conn.revoke_security_group_egress(
egress_security_group.id, "tcp", from_port="22", to_port="2222", cidr_ip="123.123.123.123/32", dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the RevokeSecurityGroupEgress operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the RevokeSecurityGroupEgress operation: Request would have succeeded, but DryRun flag is set')
conn.revoke_security_group_egress(egress_security_group.id, "tcp", from_port="22", to_port="2222", cidr_ip="123.123.123.123/32")
conn.revoke_security_group_egress(
egress_security_group.id, "tcp", from_port="22", to_port="2222", cidr_ip="123.123.123.123/32")
egress_security_group = conn.get_all_security_groups()[0]
# There is still the default outbound rule
@ -223,24 +252,30 @@ def test_authorize_other_group_and_revoke():
other_security_group = conn.create_security_group('other', 'other')
wrong_group = conn.create_security_group('wrong', 'wrong')
success = security_group.authorize(ip_protocol="tcp", from_port="22", to_port="2222", src_group=other_security_group)
success = security_group.authorize(
ip_protocol="tcp", from_port="22", to_port="2222", src_group=other_security_group)
assert success.should.be.true
security_group = [group for group in conn.get_all_security_groups() if group.name == 'test'][0]
security_group = [
group for group in conn.get_all_security_groups() if group.name == 'test'][0]
int(security_group.rules[0].to_port).should.equal(2222)
security_group.rules[0].grants[0].group_id.should.equal(other_security_group.id)
security_group.rules[0].grants[
0].group_id.should.equal(other_security_group.id)
# Wrong source group should throw error
with assert_raises(EC2ResponseError) as cm:
security_group.revoke(ip_protocol="tcp", from_port="22", to_port="2222", src_group=wrong_group)
security_group.revoke(ip_protocol="tcp", from_port="22",
to_port="2222", src_group=wrong_group)
cm.exception.code.should.equal('InvalidPermission.NotFound')
cm.exception.status.should.equal(400)
cm.exception.request_id.should_not.be.none
# Actually revoke
security_group.revoke(ip_protocol="tcp", from_port="22", to_port="2222", src_group=other_security_group)
security_group.revoke(ip_protocol="tcp", from_port="22",
to_port="2222", src_group=other_security_group)
security_group = [group for group in conn.get_all_security_groups() if group.name == 'test'][0]
security_group = [
group for group in conn.get_all_security_groups() if group.name == 'test'][0]
security_group.rules.should.have.length_of(0)
@ -250,8 +285,10 @@ def test_authorize_other_group_egress_and_revoke():
vpc = ec2.create_vpc(CidrBlock='10.0.0.0/16')
sg01 = ec2.create_security_group(GroupName='sg01', Description='Test security group sg01', VpcId=vpc.id)
sg02 = ec2.create_security_group(GroupName='sg02', Description='Test security group sg02', VpcId=vpc.id)
sg01 = ec2.create_security_group(
GroupName='sg01', Description='Test security group sg01', VpcId=vpc.id)
sg02 = ec2.create_security_group(
GroupName='sg02', Description='Test security group sg02', VpcId=vpc.id)
ip_permission = {
'IpProtocol': 'tcp',
@ -278,27 +315,33 @@ def test_authorize_group_in_vpc():
security_group = conn.create_security_group('test1', 'test1', vpc_id)
other_security_group = conn.create_security_group('test2', 'test2', vpc_id)
success = security_group.authorize(ip_protocol="tcp", from_port="22", to_port="2222", src_group=other_security_group)
success = security_group.authorize(
ip_protocol="tcp", from_port="22", to_port="2222", src_group=other_security_group)
success.should.be.true
# Check that the rule is accurate
security_group = [group for group in conn.get_all_security_groups() if group.name == 'test1'][0]
security_group = [
group for group in conn.get_all_security_groups() if group.name == 'test1'][0]
int(security_group.rules[0].to_port).should.equal(2222)
security_group.rules[0].grants[0].group_id.should.equal(other_security_group.id)
security_group.rules[0].grants[
0].group_id.should.equal(other_security_group.id)
# Now remove the rule
success = security_group.revoke(ip_protocol="tcp", from_port="22", to_port="2222", src_group=other_security_group)
success = security_group.revoke(
ip_protocol="tcp", from_port="22", to_port="2222", src_group=other_security_group)
success.should.be.true
# And check that it gets revoked
security_group = [group for group in conn.get_all_security_groups() if group.name == 'test1'][0]
security_group = [
group for group in conn.get_all_security_groups() if group.name == 'test1'][0]
security_group.rules.should.have.length_of(0)
@mock_ec2_deprecated
def test_get_all_security_groups():
conn = boto.connect_ec2()
sg1 = conn.create_security_group(name='test1', description='test1', vpc_id='vpc-mjm05d27')
sg1 = conn.create_security_group(
name='test1', description='test1', vpc_id='vpc-mjm05d27')
conn.create_security_group(name='test2', description='test2')
resp = conn.get_all_security_groups(groupnames=['test1'])
@ -326,7 +369,8 @@ def test_authorize_bad_cidr_throws_invalid_parameter_value():
conn = boto.connect_ec2('the_key', 'the_secret')
security_group = conn.create_security_group('test', 'test')
with assert_raises(EC2ResponseError) as cm:
security_group.authorize(ip_protocol="tcp", from_port="22", to_port="2222", cidr_ip="123.123.123.123")
security_group.authorize(
ip_protocol="tcp", from_port="22", to_port="2222", cidr_ip="123.123.123.123")
cm.exception.code.should.equal('InvalidParameterValue')
cm.exception.status.should.equal(400)
cm.exception.request_id.should_not.be.none
@ -343,7 +387,8 @@ def test_security_group_tagging():
sg.add_tag("Test", "Tag", dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the CreateTags operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the CreateTags operation: Request would have succeeded, but DryRun flag is set')
sg.add_tag("Test", "Tag")
@ -362,7 +407,8 @@ def test_security_group_tag_filtering():
sg = conn.create_security_group("test-sg", "Test SG")
sg.add_tag("test-tag", "test-value")
groups = conn.get_all_security_groups(filters={"tag:test-tag": "test-value"})
groups = conn.get_all_security_groups(
filters={"tag:test-tag": "test-value"})
groups.should.have.length_of(1)
@ -507,18 +553,18 @@ def test_sec_group_rule_limit_vpc():
cm.exception.error_code.should.equal('RulesPerSecurityGroupLimitExceeded')
'''
Boto3
'''
@mock_ec2
def test_add_same_rule_twice_throws_error():
ec2 = boto3.resource('ec2', region_name='us-west-1')
vpc = ec2.create_vpc(CidrBlock='10.0.0.0/16')
sg = ec2.create_security_group(GroupName='sg1', Description='Test security group sg1', VpcId=vpc.id)
sg = ec2.create_security_group(
GroupName='sg1', Description='Test security group sg1', VpcId=vpc.id)
ip_permissions = [
{
@ -541,13 +587,18 @@ def test_security_group_tagging_boto3():
sg = conn.create_security_group(GroupName="test-sg", Description="Test SG")
with assert_raises(ClientError) as ex:
conn.create_tags(Resources=[sg['GroupId']], Tags=[{'Key': 'Test', 'Value': 'Tag'}], DryRun=True)
conn.create_tags(Resources=[sg['GroupId']], Tags=[
{'Key': 'Test', 'Value': 'Tag'}], DryRun=True)
ex.exception.response['Error']['Code'].should.equal('DryRunOperation')
ex.exception.response['ResponseMetadata']['HTTPStatusCode'].should.equal(400)
ex.exception.response['Error']['Message'].should.equal('An error occurred (DryRunOperation) when calling the CreateTags operation: Request would have succeeded, but DryRun flag is set')
ex.exception.response['ResponseMetadata'][
'HTTPStatusCode'].should.equal(400)
ex.exception.response['Error']['Message'].should.equal(
'An error occurred (DryRunOperation) when calling the CreateTags operation: Request would have succeeded, but DryRun flag is set')
conn.create_tags(Resources=[sg['GroupId']], Tags=[{'Key': 'Test', 'Value': 'Tag'}])
describe = conn.describe_security_groups(Filters=[{'Name': 'tag-value', 'Values': ['Tag']}])
conn.create_tags(Resources=[sg['GroupId']], Tags=[
{'Key': 'Test', 'Value': 'Tag'}])
describe = conn.describe_security_groups(
Filters=[{'Name': 'tag-value', 'Values': ['Tag']}])
tag = describe["SecurityGroups"][0]['Tags'][0]
tag['Value'].should.equal("Tag")
tag['Key'].should.equal("Test")
@ -559,9 +610,12 @@ def test_authorize_and_revoke_in_bulk():
vpc = ec2.create_vpc(CidrBlock='10.0.0.0/16')
sg01 = ec2.create_security_group(GroupName='sg01', Description='Test security group sg01', VpcId=vpc.id)
sg02 = ec2.create_security_group(GroupName='sg02', Description='Test security group sg02', VpcId=vpc.id)
sg03 = ec2.create_security_group(GroupName='sg03', Description='Test security group sg03')
sg01 = ec2.create_security_group(
GroupName='sg01', Description='Test security group sg01', VpcId=vpc.id)
sg02 = ec2.create_security_group(
GroupName='sg02', Description='Test security group sg02', VpcId=vpc.id)
sg03 = ec2.create_security_group(
GroupName='sg03', Description='Test security group sg03')
ip_permissions = [
{
@ -611,15 +665,19 @@ def test_authorize_and_revoke_in_bulk():
for ip_permission in expected_ip_permissions:
sg01.ip_permissions_egress.shouldnt.contain(ip_permission)
@mock_ec2_deprecated
def test_get_all_security_groups_filter_with_same_vpc_id():
conn = boto.connect_ec2('the_key', 'the_secret')
vpc_id = 'vpc-5300000c'
security_group = conn.create_security_group('test1', 'test1', vpc_id=vpc_id)
security_group2 = conn.create_security_group('test2', 'test2', vpc_id=vpc_id)
security_group = conn.create_security_group(
'test1', 'test1', vpc_id=vpc_id)
security_group2 = conn.create_security_group(
'test2', 'test2', vpc_id=vpc_id)
security_group.vpc_id.should.equal(vpc_id)
security_group2.vpc_id.should.equal(vpc_id)
security_groups = conn.get_all_security_groups(group_ids=[security_group.id], filters={'vpc-id': [vpc_id]})
security_groups = conn.get_all_security_groups(
group_ids=[security_group.id], filters={'vpc-id': [vpc_id]})
security_groups.should.have.length_of(1)

View file

@ -18,7 +18,8 @@ def test_ec2_server_get():
headers={"Host": "ec2.us-east-1.amazonaws.com"}
)
groups = re.search("<instanceId>(.*)</instanceId>", res.data.decode('utf-8'))
groups = re.search("<instanceId>(.*)</instanceId>",
res.data.decode('utf-8'))
instance_id = groups.groups()[0]
res = test_client.get('/?Action=DescribeInstances')

View file

@ -5,9 +5,11 @@ import sure # noqa
from moto import mock_ec2
def get_subnet_id(conn):
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 = conn.create_subnet(
VpcId=vpc['VpcId'], CidrBlock='10.0.0.0/16', AvailabilityZone='us-east-1a')['Subnet']
subnet_id = subnet['SubnetId']
return subnet_id
@ -19,60 +21,60 @@ def spot_config(subnet_id, allocation_strategy="lowestPrice"):
'TargetCapacity': 6,
'IamFleetRole': 'arn:aws:iam::123456789012:role/fleet',
'LaunchSpecifications': [{
'ImageId': 'ami-123',
'KeyName': 'my-key',
'SecurityGroups': [
{
'ImageId': 'ami-123',
'KeyName': 'my-key',
'SecurityGroups': [
{
'GroupId': 'sg-123'
},
],
'UserData': 'some user data',
'InstanceType': 't2.small',
'BlockDeviceMappings': [
{
},
],
'UserData': 'some user data',
'InstanceType': 't2.small',
'BlockDeviceMappings': [
{
'VirtualName': 'string',
'DeviceName': 'string',
'Ebs': {
'SnapshotId': 'string',
'VolumeSize': 123,
'DeleteOnTermination': True|False,
'DeleteOnTermination': True | False,
'VolumeType': 'standard',
'Iops': 123,
'Encrypted': True|False
'Encrypted': True | False
},
'NoDevice': 'string'
},
],
'Monitoring': {
'Enabled': True
'NoDevice': 'string'
},
'SubnetId': subnet_id,
'IamInstanceProfile': {
'Arn': 'arn:aws:iam::123456789012:role/fleet'
},
'EbsOptimized': False,
'WeightedCapacity': 2.0,
'SpotPrice': '0.13'
],
'Monitoring': {
'Enabled': True
},
'SubnetId': subnet_id,
'IamInstanceProfile': {
'Arn': 'arn:aws:iam::123456789012:role/fleet'
},
'EbsOptimized': False,
'WeightedCapacity': 2.0,
'SpotPrice': '0.13'
}, {
'ImageId': 'ami-123',
'KeyName': 'my-key',
'SecurityGroups': [
{
'GroupId': 'sg-123'
},
],
'UserData': 'some user data',
'InstanceType': 't2.large',
'Monitoring': {
'Enabled': True
'ImageId': 'ami-123',
'KeyName': 'my-key',
'SecurityGroups': [
{
'GroupId': 'sg-123'
},
'SubnetId': subnet_id,
'IamInstanceProfile': {
'Arn': 'arn:aws:iam::123456789012:role/fleet'
},
'EbsOptimized': False,
'WeightedCapacity': 4.0,
'SpotPrice': '10.00',
],
'UserData': 'some user data',
'InstanceType': 't2.large',
'Monitoring': {
'Enabled': True
},
'SubnetId': subnet_id,
'IamInstanceProfile': {
'Arn': 'arn:aws:iam::123456789012:role/fleet'
},
'EbsOptimized': False,
'WeightedCapacity': 4.0,
'SpotPrice': '10.00',
}],
'AllocationStrategy': allocation_strategy,
'FulfilledCapacity': 6,
@ -89,7 +91,8 @@ def test_create_spot_fleet_with_lowest_price():
)
spot_fleet_id = spot_fleet_res['SpotFleetRequestId']
spot_fleet_requests = conn.describe_spot_fleet_requests(SpotFleetRequestIds=[spot_fleet_id])['SpotFleetRequestConfigs']
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")
@ -97,7 +100,8 @@ def test_create_spot_fleet_with_lowest_price():
spot_fleet_config['SpotPrice'].should.equal('0.12')
spot_fleet_config['TargetCapacity'].should.equal(6)
spot_fleet_config['IamFleetRole'].should.equal('arn:aws:iam::123456789012:role/fleet')
spot_fleet_config['IamFleetRole'].should.equal(
'arn:aws:iam::123456789012:role/fleet')
spot_fleet_config['AllocationStrategy'].should.equal('lowestPrice')
spot_fleet_config['FulfilledCapacity'].should.equal(6.0)
@ -106,7 +110,8 @@ def test_create_spot_fleet_with_lowest_price():
launch_spec['EbsOptimized'].should.equal(False)
launch_spec['SecurityGroups'].should.equal([{"GroupId": "sg-123"}])
launch_spec['IamInstanceProfile'].should.equal({"Arn": "arn:aws:iam::123456789012:role/fleet"})
launch_spec['IamInstanceProfile'].should.equal(
{"Arn": "arn:aws:iam::123456789012:role/fleet"})
launch_spec['ImageId'].should.equal("ami-123")
launch_spec['InstanceType'].should.equal("t2.small")
launch_spec['KeyName'].should.equal("my-key")
@ -116,7 +121,8 @@ def test_create_spot_fleet_with_lowest_price():
launch_spec['UserData'].should.equal("some user data")
launch_spec['WeightedCapacity'].should.equal(2.0)
instance_res = conn.describe_spot_fleet_instances(SpotFleetRequestId=spot_fleet_id)
instance_res = conn.describe_spot_fleet_instances(
SpotFleetRequestId=spot_fleet_id)
instances = instance_res['ActiveInstances']
len(instances).should.equal(3)
@ -125,14 +131,16 @@ def test_create_spot_fleet_with_lowest_price():
def test_create_diversified_spot_fleet():
conn = boto3.client("ec2", region_name='us-west-2')
subnet_id = get_subnet_id(conn)
diversified_config = spot_config(subnet_id, allocation_strategy='diversified')
diversified_config = spot_config(
subnet_id, allocation_strategy='diversified')
spot_fleet_res = conn.request_spot_fleet(
SpotFleetRequestConfig=diversified_config
)
spot_fleet_id = spot_fleet_res['SpotFleetRequestId']
instance_res = conn.describe_spot_fleet_instances(SpotFleetRequestId=spot_fleet_id)
instance_res = conn.describe_spot_fleet_instances(
SpotFleetRequestId=spot_fleet_id)
instances = instance_res['ActiveInstances']
len(instances).should.equal(2)
instance_types = set([instance['InstanceType'] for instance in instances])
@ -150,7 +158,9 @@ def test_cancel_spot_fleet_request():
)
spot_fleet_id = spot_fleet_res['SpotFleetRequestId']
conn.cancel_spot_fleet_requests(SpotFleetRequestIds=[spot_fleet_id], TerminateInstances=True)
conn.cancel_spot_fleet_requests(
SpotFleetRequestIds=[spot_fleet_id], TerminateInstances=True)
spot_fleet_requests = conn.describe_spot_fleet_requests(SpotFleetRequestIds=[spot_fleet_id])['SpotFleetRequestConfigs']
spot_fleet_requests = conn.describe_spot_fleet_requests(
SpotFleetRequestIds=[spot_fleet_id])['SpotFleetRequestConfigs']
len(spot_fleet_requests).should.equal(0)

View file

@ -18,7 +18,8 @@ from moto.core.utils import iso_8601_datetime_with_milliseconds
def test_request_spot_instances():
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 = conn.create_subnet(
VpcId=vpc['VpcId'], CidrBlock='10.0.0.0/16', AvailabilityZone='us-east-1a')['Subnet']
subnet_id = subnet['SubnetId']
conn.create_security_group(GroupName='group1', Description='description')
@ -53,29 +54,31 @@ def test_request_spot_instances():
DryRun=True,
)
ex.exception.response['Error']['Code'].should.equal('DryRunOperation')
ex.exception.response['ResponseMetadata']['HTTPStatusCode'].should.equal(400)
ex.exception.response['Error']['Message'].should.equal('An error occurred (DryRunOperation) when calling the RequestSpotInstance operation: Request would have succeeded, but DryRun flag is set')
ex.exception.response['ResponseMetadata'][
'HTTPStatusCode'].should.equal(400)
ex.exception.response['Error']['Message'].should.equal(
'An error occurred (DryRunOperation) when calling the RequestSpotInstance operation: Request would have succeeded, but DryRun flag is set')
request = conn.request_spot_instances(
SpotPrice="0.5", InstanceCount=1, Type='one-time',
ValidFrom=start, ValidUntil=end, LaunchGroup="the-group",
AvailabilityZoneGroup='my-group',
LaunchSpecification={
"ImageId": 'ami-abcd1234',
"KeyName": "test",
"SecurityGroups": ['group1', 'group2'],
"UserData": b"some test data",
"InstanceType": 'm1.small',
"Placement": {
"AvailabilityZone": 'us-east-1c',
},
"KernelId": "test-kernel",
"RamdiskId": "test-ramdisk",
"Monitoring": {
"Enabled": True,
},
"SubnetId": subnet_id,
SpotPrice="0.5", InstanceCount=1, Type='one-time',
ValidFrom=start, ValidUntil=end, LaunchGroup="the-group",
AvailabilityZoneGroup='my-group',
LaunchSpecification={
"ImageId": 'ami-abcd1234',
"KeyName": "test",
"SecurityGroups": ['group1', 'group2'],
"UserData": b"some test data",
"InstanceType": 'm1.small',
"Placement": {
"AvailabilityZone": 'us-east-1c',
},
"KernelId": "test-kernel",
"RamdiskId": "test-ramdisk",
"Monitoring": {
"Enabled": True,
},
"SubnetId": subnet_id,
},
)
requests = conn.describe_spot_instance_requests()['SpotInstanceRequests']
@ -91,7 +94,8 @@ def test_request_spot_instances():
request['AvailabilityZoneGroup'].should.equal('my-group')
launch_spec = request['LaunchSpecification']
security_group_names = [group['GroupName'] for group in launch_spec['SecurityGroups']]
security_group_names = [group['GroupName']
for group in launch_spec['SecurityGroups']]
set(security_group_names).should.equal(set(['group1', 'group2']))
launch_spec['ImageId'].should.equal('ami-abcd1234')
@ -112,7 +116,7 @@ def test_request_spot_instances_default_arguments():
request = conn.request_spot_instances(
SpotPrice="0.5",
LaunchSpecification={
"ImageId": 'ami-abcd1234',
"ImageId": 'ami-abcd1234',
}
)
@ -130,7 +134,8 @@ def test_request_spot_instances_default_arguments():
launch_spec = request['LaunchSpecification']
security_group_names = [group['GroupName'] for group in launch_spec['SecurityGroups']]
security_group_names = [group['GroupName']
for group in launch_spec['SecurityGroups']]
security_group_names.should.equal(["default"])
launch_spec['ImageId'].should.equal('ami-abcd1234')
@ -152,12 +157,12 @@ def test_cancel_spot_instance_request():
requests = conn.get_all_spot_instance_requests()
requests.should.have.length_of(1)
with assert_raises(EC2ResponseError) as ex:
conn.cancel_spot_instance_requests([requests[0].id], dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the CancelSpotInstance operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the CancelSpotInstance operation: Request would have succeeded, but DryRun flag is set')
conn.cancel_spot_instance_requests([requests[0].id])
@ -239,10 +244,12 @@ def test_get_all_spot_instance_requests_filtering():
requests = conn.get_all_spot_instance_requests(filters={'state': 'open'})
requests.should.have.length_of(3)
requests = conn.get_all_spot_instance_requests(filters={'tag:tag1': 'value1'})
requests = conn.get_all_spot_instance_requests(
filters={'tag:tag1': 'value1'})
requests.should.have.length_of(2)
requests = conn.get_all_spot_instance_requests(filters={'tag:tag1': 'value1', 'tag:tag2': 'value2'})
requests = conn.get_all_spot_instance_requests(
filters={'tag:tag1': 'value1', 'tag:tag2': 'value2'})
requests.should.have.length_of(1)
@ -259,4 +266,3 @@ def test_request_spot_instances_setting_instance_id():
request = conn.get_all_spot_instance_requests()[0]
assert request.state == 'active'
assert request.instance_id == 'i-12345678'

View file

@ -69,7 +69,8 @@ def test_subnet_tagging():
def test_subnet_should_have_proper_availability_zone_set():
conn = boto.vpc.connect_to_region('us-west-1')
vpcA = conn.create_vpc("10.0.0.0/16")
subnetA = conn.create_subnet(vpcA.id, "10.0.0.0/24", availability_zone='us-west-1b')
subnetA = conn.create_subnet(
vpcA.id, "10.0.0.0/24", availability_zone='us-west-1b')
subnetA.availability_zone.should.equal('us-west-1b')
@ -82,7 +83,8 @@ def test_default_subnet():
default_vpc.reload()
default_vpc.is_default.should.be.ok
subnet = ec2.create_subnet(VpcId=default_vpc.id, CidrBlock='172.31.0.0/20', AvailabilityZone='us-west-1a')
subnet = ec2.create_subnet(
VpcId=default_vpc.id, CidrBlock='172.31.0.0/20', AvailabilityZone='us-west-1a')
subnet.reload()
subnet.map_public_ip_on_launch.shouldnt.be.ok
@ -109,7 +111,8 @@ def test_boto3_non_default_subnet():
vpc.reload()
vpc.is_default.shouldnt.be.ok
subnet = ec2.create_subnet(VpcId=vpc.id, CidrBlock='10.0.0.0/24', AvailabilityZone='us-west-1a')
subnet = ec2.create_subnet(
VpcId=vpc.id, CidrBlock='10.0.0.0/24', AvailabilityZone='us-west-1a')
subnet.reload()
subnet.map_public_ip_on_launch.shouldnt.be.ok
@ -122,7 +125,8 @@ def test_modify_subnet_attribute():
# Get the default VPC
vpc = list(ec2.vpcs.all())[0]
subnet = ec2.create_subnet(VpcId=vpc.id, CidrBlock='10.0.0.0/24', AvailabilityZone='us-west-1a')
subnet = ec2.create_subnet(
VpcId=vpc.id, CidrBlock='10.0.0.0/24', AvailabilityZone='us-west-1a')
# 'map_public_ip_on_launch' is set when calling 'DescribeSubnets' action
subnet.reload()
@ -130,11 +134,13 @@ def test_modify_subnet_attribute():
# For non default subnet, attribute value should be 'False'
subnet.map_public_ip_on_launch.shouldnt.be.ok
client.modify_subnet_attribute(SubnetId=subnet.id, MapPublicIpOnLaunch={'Value': False})
client.modify_subnet_attribute(
SubnetId=subnet.id, MapPublicIpOnLaunch={'Value': False})
subnet.reload()
subnet.map_public_ip_on_launch.shouldnt.be.ok
client.modify_subnet_attribute(SubnetId=subnet.id, MapPublicIpOnLaunch={'Value': True})
client.modify_subnet_attribute(
SubnetId=subnet.id, MapPublicIpOnLaunch={'Value': True})
subnet.reload()
subnet.map_public_ip_on_launch.should.be.ok
@ -144,10 +150,12 @@ def test_modify_subnet_attribute_validation():
ec2 = boto3.resource('ec2', region_name='us-west-1')
client = boto3.client('ec2', region_name='us-west-1')
vpc = ec2.create_vpc(CidrBlock='10.0.0.0/16')
subnet = ec2.create_subnet(VpcId=vpc.id, CidrBlock='10.0.0.0/24', AvailabilityZone='us-west-1a')
subnet = ec2.create_subnet(
VpcId=vpc.id, CidrBlock='10.0.0.0/24', AvailabilityZone='us-west-1a')
with assert_raises(ParamValidationError):
client.modify_subnet_attribute(SubnetId=subnet.id, MapPublicIpOnLaunch={'Value': 'invalid'})
client.modify_subnet_attribute(
SubnetId=subnet.id, MapPublicIpOnLaunch={'Value': 'invalid'})
@mock_ec2_deprecated
@ -155,10 +163,13 @@ def test_get_subnets_filtering():
ec2 = boto.ec2.connect_to_region('us-west-1')
conn = boto.vpc.connect_to_region('us-west-1')
vpcA = conn.create_vpc("10.0.0.0/16")
subnetA = conn.create_subnet(vpcA.id, "10.0.0.0/24", availability_zone='us-west-1a')
subnetA = conn.create_subnet(
vpcA.id, "10.0.0.0/24", availability_zone='us-west-1a')
vpcB = conn.create_vpc("10.0.0.0/16")
subnetB1 = conn.create_subnet(vpcB.id, "10.0.0.0/24", availability_zone='us-west-1a')
subnetB2 = conn.create_subnet(vpcB.id, "10.0.1.0/24", availability_zone='us-west-1b')
subnetB1 = conn.create_subnet(
vpcB.id, "10.0.0.0/24", availability_zone='us-west-1a')
subnetB2 = conn.create_subnet(
vpcB.id, "10.0.1.0/24", availability_zone='us-west-1b')
all_subnets = conn.get_all_subnets()
all_subnets.should.have.length_of(3 + len(ec2.get_all_zones()))
@ -166,25 +177,33 @@ def test_get_subnets_filtering():
# Filter by VPC ID
subnets_by_vpc = conn.get_all_subnets(filters={'vpc-id': vpcB.id})
subnets_by_vpc.should.have.length_of(2)
set([subnet.id for subnet in subnets_by_vpc]).should.equal(set([subnetB1.id, subnetB2.id]))
set([subnet.id for subnet in subnets_by_vpc]).should.equal(
set([subnetB1.id, subnetB2.id]))
# Filter by CIDR variations
subnets_by_cidr1 = conn.get_all_subnets(filters={'cidr': "10.0.0.0/24"})
subnets_by_cidr1.should.have.length_of(2)
set([subnet.id for subnet in subnets_by_cidr1]).should.equal(set([subnetA.id, subnetB1.id]))
set([subnet.id for subnet in subnets_by_cidr1]
).should.equal(set([subnetA.id, subnetB1.id]))
subnets_by_cidr2 = conn.get_all_subnets(filters={'cidr-block': "10.0.0.0/24"})
subnets_by_cidr2 = conn.get_all_subnets(
filters={'cidr-block': "10.0.0.0/24"})
subnets_by_cidr2.should.have.length_of(2)
set([subnet.id for subnet in subnets_by_cidr2]).should.equal(set([subnetA.id, subnetB1.id]))
set([subnet.id for subnet in subnets_by_cidr2]
).should.equal(set([subnetA.id, subnetB1.id]))
subnets_by_cidr3 = conn.get_all_subnets(filters={'cidrBlock': "10.0.0.0/24"})
subnets_by_cidr3 = conn.get_all_subnets(
filters={'cidrBlock': "10.0.0.0/24"})
subnets_by_cidr3.should.have.length_of(2)
set([subnet.id for subnet in subnets_by_cidr3]).should.equal(set([subnetA.id, subnetB1.id]))
set([subnet.id for subnet in subnets_by_cidr3]
).should.equal(set([subnetA.id, subnetB1.id]))
# Filter by VPC ID and CIDR
subnets_by_vpc_and_cidr = conn.get_all_subnets(filters={'vpc-id': vpcB.id, 'cidr': "10.0.0.0/24"})
subnets_by_vpc_and_cidr = conn.get_all_subnets(
filters={'vpc-id': vpcB.id, 'cidr': "10.0.0.0/24"})
subnets_by_vpc_and_cidr.should.have.length_of(1)
set([subnet.id for subnet in subnets_by_vpc_and_cidr]).should.equal(set([subnetB1.id]))
set([subnet.id for subnet in subnets_by_vpc_and_cidr]
).should.equal(set([subnetB1.id]))
# Filter by subnet ID
subnets_by_id = conn.get_all_subnets(filters={'subnet-id': subnetA.id})
@ -192,9 +211,11 @@ def test_get_subnets_filtering():
set([subnet.id for subnet in subnets_by_id]).should.equal(set([subnetA.id]))
# Filter by availabilityZone
subnets_by_az = conn.get_all_subnets(filters={'availabilityZone': 'us-west-1a', 'vpc-id': vpcB.id})
subnets_by_az = conn.get_all_subnets(
filters={'availabilityZone': 'us-west-1a', 'vpc-id': vpcB.id})
subnets_by_az.should.have.length_of(1)
set([subnet.id for subnet in subnets_by_az]).should.equal(set([subnetB1.id]))
set([subnet.id for subnet in subnets_by_az]
).should.equal(set([subnetB1.id]))
# Filter by defaultForAz
@ -202,7 +223,8 @@ def test_get_subnets_filtering():
subnets_by_az.should.have.length_of(len(conn.get_all_zones()))
# Unsupported filter
conn.get_all_subnets.when.called_with(filters={'not-implemented-filter': 'foobar'}).should.throw(NotImplementedError)
conn.get_all_subnets.when.called_with(
filters={'not-implemented-filter': 'foobar'}).should.throw(NotImplementedError)
@mock_ec2_deprecated

View file

@ -22,11 +22,13 @@ def test_add_tag():
instance.add_tag("a key", "some value", dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the CreateTags operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the CreateTags operation: Request would have succeeded, but DryRun flag is set')
instance.add_tag("a key", "some value")
chain = itertools.chain.from_iterable
existing_instances = list(chain([res.instances for res in conn.get_all_instances()]))
existing_instances = list(
chain([res.instances for res in conn.get_all_instances()]))
existing_instances.should.have.length_of(1)
existing_instance = existing_instances[0]
existing_instance.tags["a key"].should.equal("some value")
@ -49,7 +51,8 @@ def test_remove_tag():
instance.remove_tag("a key", dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the DeleteTags operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the DeleteTags operation: Request would have succeeded, but DryRun flag is set')
instance.remove_tag("a key")
conn.get_all_tags().should.have.length_of(0)
@ -100,12 +103,15 @@ def test_create_tags():
conn.create_tags(instance.id, tag_dict, dry_run=True)
ex.exception.error_code.should.equal('DryRunOperation')
ex.exception.status.should.equal(400)
ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the CreateTags operation: Request would have succeeded, but DryRun flag is set')
ex.exception.message.should.equal(
'An error occurred (DryRunOperation) when calling the CreateTags operation: Request would have succeeded, but DryRun flag is set')
conn.create_tags(instance.id, tag_dict)
tags = conn.get_all_tags()
set([key for key in tag_dict]).should.equal(set([tag.name for tag in tags]))
set([tag_dict[key] for key in tag_dict]).should.equal(set([tag.value for tag in tags]))
set([key for key in tag_dict]).should.equal(
set([tag.name for tag in tags]))
set([tag_dict[key] for key in tag_dict]).should.equal(
set([tag.value for tag in tags]))
@mock_ec2_deprecated
@ -115,7 +121,7 @@ def test_tag_limit_exceeded():
instance = reservation.instances[0]
tag_dict = {}
for i in range(51):
tag_dict['{0:02d}'.format(i+1)] = ''
tag_dict['{0:02d}'.format(i + 1)] = ''
with assert_raises(EC2ResponseError) as cm:
conn.create_tags(instance.id, tag_dict)
@ -342,7 +348,8 @@ def test_retrieved_snapshots_must_contain_their_tags():
tag_key = 'Tag name'
tag_value = 'Tag value'
tags_to_be_set = {tag_key: tag_value}
conn = boto.connect_ec2(aws_access_key_id='the_key', aws_secret_access_key='the_secret')
conn = boto.connect_ec2(aws_access_key_id='the_key',
aws_secret_access_key='the_secret')
volume = conn.create_volume(80, "eu-west-1a")
snapshot = conn.create_snapshot(volume.id)
conn.create_tags([snapshot.id], tags_to_be_set)
@ -361,7 +368,8 @@ def test_retrieved_snapshots_must_contain_their_tags():
@mock_ec2_deprecated
def test_filter_instances_by_wildcard_tags():
conn = boto.connect_ec2(aws_access_key_id='the_key', aws_secret_access_key='the_secret')
conn = boto.connect_ec2(aws_access_key_id='the_key',
aws_secret_access_key='the_secret')
reservation = conn.run_instances('ami-1234abcd')
instance_a = reservation.instances[0]
instance_a.add_tag("Key1", "Value1")

View file

@ -16,6 +16,7 @@ def test_virtual_private_gateways():
vpn_gateway.state.should.equal('available')
vpn_gateway.availability_zone.should.equal('us-east-1a')
@mock_ec2_deprecated
def test_describe_vpn_gateway():
conn = boto.connect_vpc('the_key', 'the_secret')

View file

@ -93,4 +93,3 @@ def test_vpc_peering_connections_delete():
cm.exception.code.should.equal('InvalidVpcPeeringConnectionId.NotFound')
cm.exception.status.should.equal(400)
cm.exception.request_id.should_not.be.none

View file

@ -42,13 +42,16 @@ def test_vpc_defaults():
conn.get_all_vpcs().should.have.length_of(2)
conn.get_all_route_tables().should.have.length_of(2)
conn.get_all_security_groups(filters={'vpc-id': [vpc.id]}).should.have.length_of(1)
conn.get_all_security_groups(
filters={'vpc-id': [vpc.id]}).should.have.length_of(1)
vpc.delete()
conn.get_all_vpcs().should.have.length_of(1)
conn.get_all_route_tables().should.have.length_of(1)
conn.get_all_security_groups(filters={'vpc-id': [vpc.id]}).should.have.length_of(0)
conn.get_all_security_groups(
filters={'vpc-id': [vpc.id]}).should.have.length_of(0)
@mock_ec2_deprecated
def test_vpc_isdefault_filter():
@ -80,6 +83,7 @@ def test_vpc_state_available_filter():
vpc.delete()
conn.get_all_vpcs(filters={'state': 'available'}).should.have.length_of(2)
@mock_ec2_deprecated
def test_vpc_tagging():
conn = boto.connect_vpc()
@ -127,7 +131,8 @@ def test_vpc_get_by_cidr_block():
@mock_ec2_deprecated
def test_vpc_get_by_dhcp_options_id():
conn = boto.connect_vpc()
dhcp_options = conn.create_dhcp_options(SAMPLE_DOMAIN_NAME, SAMPLE_NAME_SERVERS)
dhcp_options = conn.create_dhcp_options(
SAMPLE_DOMAIN_NAME, SAMPLE_NAME_SERVERS)
vpc1 = conn.create_vpc("10.0.0.0/16")
vpc2 = conn.create_vpc("10.0.0.0/16")
conn.create_vpc("10.0.0.0/24")
@ -284,6 +289,7 @@ def test_non_default_vpc():
attr = response.get('EnableDnsHostnames')
attr.get('Value').shouldnt.be.ok
@mock_ec2
def test_vpc_dedicated_tenancy():
ec2 = boto3.resource('ec2', region_name='us-west-1')
@ -298,6 +304,7 @@ def test_vpc_dedicated_tenancy():
vpc.instance_tenancy.should.equal('dedicated')
@mock_ec2
def test_vpc_modify_enable_dns_support():
ec2 = boto3.resource('ec2', region_name='us-west-1')
@ -339,10 +346,12 @@ def test_vpc_modify_enable_dns_hostnames():
attr = response.get('EnableDnsHostnames')
attr.get('Value').should.be.ok
@mock_ec2_deprecated
def test_vpc_associate_dhcp_options():
conn = boto.connect_vpc()
dhcp_options = conn.create_dhcp_options(SAMPLE_DOMAIN_NAME, SAMPLE_NAME_SERVERS)
dhcp_options = conn.create_dhcp_options(
SAMPLE_DOMAIN_NAME, SAMPLE_NAME_SERVERS)
vpc = conn.create_vpc("10.0.0.0/16")
conn.associate_dhcp_options(dhcp_options.id, vpc.id)

View file

@ -10,27 +10,32 @@ from moto import mock_ec2_deprecated
@mock_ec2_deprecated
def test_create_vpn_connections():
conn = boto.connect_vpc('the_key', 'the_secret')
vpn_connection = conn.create_vpn_connection('ipsec.1', 'vgw-0123abcd', 'cgw-0123abcd')
vpn_connection = conn.create_vpn_connection(
'ipsec.1', 'vgw-0123abcd', 'cgw-0123abcd')
vpn_connection.should_not.be.none
vpn_connection.id.should.match(r'vpn-\w+')
vpn_connection.type.should.equal('ipsec.1')
@mock_ec2_deprecated
def test_delete_vpn_connections():
conn = boto.connect_vpc('the_key', 'the_secret')
vpn_connection = conn.create_vpn_connection('ipsec.1', 'vgw-0123abcd', 'cgw-0123abcd')
vpn_connection = conn.create_vpn_connection(
'ipsec.1', 'vgw-0123abcd', 'cgw-0123abcd')
list_of_vpn_connections = conn.get_all_vpn_connections()
list_of_vpn_connections.should.have.length_of(1)
conn.delete_vpn_connection(vpn_connection.id)
list_of_vpn_connections = conn.get_all_vpn_connections()
list_of_vpn_connections.should.have.length_of(0)
@mock_ec2_deprecated
def test_delete_vpn_connections_bad_id():
conn = boto.connect_vpc('the_key', 'the_secret')
with assert_raises(EC2ResponseError):
conn.delete_vpn_connection('vpn-0123abcd')
@mock_ec2_deprecated
def test_describe_vpn_connections():
conn = boto.connect_vpc('the_key', 'the_secret')