Lints.
This commit is contained in:
parent
1433f28846
commit
f37bad0e00
260 changed files with 6363 additions and 3766 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue