Address pytest warnings (#3629)

* Address `boto` deprecation warnings

This commit eliminates the following warning:

../boto/ec2/connection.py:582:
  PendingDeprecationWarning: The current get_all_instances implementation will be replaced with get_all_reservations.

`boto` isn't likely to ever make good on this warning, but doing the replacement will
declutter the `moto` test output.

* Remove `invoke_lambda` tracebacks from unit test logging

If an exception is encountered, the details are returned in the response payload.
Printing the traceback was just adding noise to the pytest output.

* Use known AMIs in unit tests

This commit eliminates the following warning in the pytest output:

`PendingDeprecationWarning: Could not find AMI with image-id:ami-123456, in the near future this will cause an error.`

Known, pre-loaded AMI image ids are used instead of random ids that don't actually
exist in the moto backend.  The integrity of the tests is unaffected by this change.

A test has been added to provide explicit coverage of the PendingDeprecationWarning
raised when an invalid AMI image id is passed to moto.
This commit is contained in:
Brian Pandola 2021-01-29 03:31:56 -08:00 committed by GitHub
commit f4b81e69b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 98 additions and 72 deletions

View file

@ -222,7 +222,7 @@ def test_stack_ec2_integration():
conn.create_stack("ec2_stack", template_body=ec2_template_json)
ec2_conn = boto.ec2.connect_to_region("us-west-1")
reservation = ec2_conn.get_all_instances()[0]
reservation = ec2_conn.get_all_reservations()[0]
ec2_instance = reservation.instances[0]
stack = conn.describe_stacks()[0]
@ -269,7 +269,7 @@ def test_stack_elb_integration_with_attached_ec2_instances():
load_balancer = elb_conn.get_all_load_balancers()[0]
ec2_conn = boto.ec2.connect_to_region("us-west-1")
reservation = ec2_conn.get_all_instances()[0]
reservation = ec2_conn.get_all_reservations()[0]
ec2_instance = reservation.instances[0]
load_balancer.instances[0].id.should.equal(ec2_instance.id)
@ -465,7 +465,7 @@ def test_stack_security_groups():
filters={"description": ["My other group"]}
)[0]
reservation = ec2_conn.get_all_instances()[0]
reservation = ec2_conn.get_all_reservations()[0]
ec2_instance = reservation.instances[0]
ec2_instance.groups[0].id.should.equal(instance_group.id)
@ -692,7 +692,7 @@ def test_vpc_single_instance_in_subnet():
subnet.vpc_id.should.equal(vpc.id)
ec2_conn = boto.ec2.connect_to_region("us-west-1")
reservation = ec2_conn.get_all_instances()[0]
reservation = ec2_conn.get_all_reservations()[0]
instance = reservation.instances[0]
instance.tags["Foo"].should.equal("Bar")
# Check that the EIP is attached the the EC2 instance
@ -1011,7 +1011,7 @@ def test_single_instance_with_ebs_volume():
)
ec2_conn = boto.ec2.connect_to_region("us-west-1")
reservation = ec2_conn.get_all_instances()[0]
reservation = ec2_conn.get_all_reservations()[0]
ec2_instance = reservation.instances[0]
volumes = ec2_conn.get_all_volumes()
@ -1157,7 +1157,7 @@ def test_conditional_if_handling():
conn = boto.cloudformation.connect_to_region("us-west-1")
conn.create_stack("test_stack1", template_body=dummy_template_json)
ec2_conn = boto.ec2.connect_to_region("us-west-1")
reservation = ec2_conn.get_all_instances()[0]
reservation = ec2_conn.get_all_reservations()[0]
ec2_instance = reservation.instances[0]
ec2_instance.image_id.should.equal(EXAMPLE_AMI_ID2)
ec2_instance.terminate()
@ -1167,7 +1167,7 @@ def test_conditional_if_handling():
"test_stack1", template_body=dummy_template_json, parameters=[("ENV", "prd")]
)
ec2_conn = boto.ec2.connect_to_region("us-west-2")
reservation = ec2_conn.get_all_instances()[0]
reservation = ec2_conn.get_all_reservations()[0]
ec2_instance = reservation.instances[0]
ec2_instance.image_id.should.equal(EXAMPLE_AMI_ID)
@ -1179,11 +1179,11 @@ def test_cloudformation_mapping():
"AWSTemplateFormatVersion": "2010-09-09",
"Mappings": {
"RegionMap": {
"us-east-1": {"32": "ami-6411e20d", "64": "ami-7a11e213"},
"us-west-1": {"32": "ami-c9c7978c", "64": "ami-cfc7978a"},
"eu-west-1": {"32": "ami-37c2f643", "64": "ami-31c2f645"},
"ap-southeast-1": {"32": "ami-66f28c34", "64": "ami-60f28c32"},
"ap-northeast-1": {"32": "ami-9c03a89d", "64": "ami-a003a8a1"},
"us-east-1": {"32": EXAMPLE_AMI_ID, "64": EXAMPLE_AMI_ID2},
"us-west-1": {"32": EXAMPLE_AMI_ID, "64": EXAMPLE_AMI_ID2},
"eu-west-1": {"32": EXAMPLE_AMI_ID, "64": EXAMPLE_AMI_ID2},
"ap-southeast-1": {"32": EXAMPLE_AMI_ID, "64": EXAMPLE_AMI_ID2},
"ap-northeast-1": {"32": EXAMPLE_AMI_ID, "64": EXAMPLE_AMI_ID2},
}
},
"Resources": {
@ -1195,7 +1195,6 @@ def test_cloudformation_mapping():
},
"InstanceType": "m1.small",
},
"Type": "AWS::EC2::Instance",
}
},
}
@ -1205,16 +1204,16 @@ def test_cloudformation_mapping():
conn = boto.cloudformation.connect_to_region("us-east-1")
conn.create_stack("test_stack1", template_body=dummy_template_json)
ec2_conn = boto.ec2.connect_to_region("us-east-1")
reservation = ec2_conn.get_all_instances()[0]
reservation = ec2_conn.get_all_reservations()[0]
ec2_instance = reservation.instances[0]
ec2_instance.image_id.should.equal("ami-6411e20d")
ec2_instance.image_id.should.equal(EXAMPLE_AMI_ID)
conn = boto.cloudformation.connect_to_region("us-west-1")
conn.create_stack("test_stack1", template_body=dummy_template_json)
ec2_conn = boto.ec2.connect_to_region("us-west-1")
reservation = ec2_conn.get_all_instances()[0]
reservation = ec2_conn.get_all_reservations()[0]
ec2_instance = reservation.instances[0]
ec2_instance.image_id.should.equal("ami-c9c7978c")
ec2_instance.image_id.should.equal(EXAMPLE_AMI_ID)
@mock_cloudformation_deprecated()