From 77dd35e3b8fe782a0bddba19a3b28543ce687303 Mon Sep 17 00:00:00 2001 From: Bert Blommers Date: Wed, 13 Jan 2021 09:02:11 +0000 Subject: [PATCH] Use known ImageID in internal tests (#3555) --- tests/__init__.py | 4 + tests/test_autoscaling/test_autoscaling.py | 60 +++---- .../test_autoscaling_cloudformation.py | 27 ++-- tests/test_autoscaling/test_policies.py | 3 +- .../test_cloudformation_stack_crud_boto3.py | 9 +- .../test_cloudformation_stack_integration.py | 31 ++-- tests/test_cloudformation/test_validate.py | 3 +- tests/test_ec2/test_amis.py | 37 ++--- tests/test_ec2/test_ec2_cloudformation.py | 3 +- tests/test_ec2/test_elastic_block_store.py | 9 +- tests/test_ec2/test_elastic_ip_addresses.py | 13 +- tests/test_ec2/test_general.py | 5 +- .../test_iam_instance_profile_associations.py | 8 +- tests/test_ec2/test_instances.py | 146 +++++++++--------- tests/test_ec2/test_regions.py | 22 +-- tests/test_ec2/test_route_tables.py | 3 +- tests/test_ec2/test_server.py | 3 +- tests/test_ec2/test_spot_fleet.py | 7 +- tests/test_ec2/test_spot_instances.py | 25 +-- tests/test_ec2/test_subnets.py | 5 +- tests/test_ec2/test_tags.py | 39 ++--- tests/test_ecs/test_ecs_boto3.py | 43 +++--- .../test_resourcegroupstaggingapi.py | 13 +- 23 files changed, 258 insertions(+), 260 deletions(-) diff --git a/tests/__init__.py b/tests/__init__.py index 01fe5ab1f..12866f610 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -6,3 +6,7 @@ import logging logging.getLogger("boto").setLevel(logging.CRITICAL) logging.getLogger("boto3").setLevel(logging.CRITICAL) logging.getLogger("botocore").setLevel(logging.CRITICAL) + + +EXAMPLE_AMI_ID = "ami-12c6146b" +EXAMPLE_AMI_ID2 = "ami-03cf127a" diff --git a/tests/test_autoscaling/test_autoscaling.py b/tests/test_autoscaling/test_autoscaling.py index cbcd8eb20..ff85ae119 100644 --- a/tests/test_autoscaling/test_autoscaling.py +++ b/tests/test_autoscaling/test_autoscaling.py @@ -26,6 +26,7 @@ from .utils import ( setup_networking_deprecated, setup_instance_with_networking, ) +from tests import EXAMPLE_AMI_ID @mock_autoscaling_deprecated @@ -37,7 +38,7 @@ def test_create_autoscaling_group(): conn = boto.ec2.autoscale.connect_to_region("us-east-1") config = LaunchConfiguration( - name="tester", image_id="ami-abcd1234", instance_type="t2.medium" + name="tester", image_id=EXAMPLE_AMI_ID, instance_type="t2.medium" ) conn.create_launch_configuration(config) @@ -103,7 +104,7 @@ def test_create_autoscaling_groups_defaults(): mocked_networking = setup_networking_deprecated() conn = boto.connect_autoscale() config = LaunchConfiguration( - name="tester", image_id="ami-abcd1234", instance_type="t2.medium" + name="tester", image_id=EXAMPLE_AMI_ID, instance_type="t2.medium" ) conn.create_launch_configuration(config) @@ -200,7 +201,7 @@ def test_autoscaling_group_describe_filter(): mocked_networking = setup_networking_deprecated() conn = boto.connect_autoscale() config = LaunchConfiguration( - name="tester", image_id="ami-abcd1234", instance_type="t2.medium" + name="tester", image_id=EXAMPLE_AMI_ID, instance_type="t2.medium" ) conn.create_launch_configuration(config) @@ -228,7 +229,7 @@ def test_autoscaling_update(): mocked_networking = setup_networking_deprecated() conn = boto.connect_autoscale() config = LaunchConfiguration( - name="tester", image_id="ami-abcd1234", instance_type="t2.medium" + name="tester", image_id=EXAMPLE_AMI_ID, instance_type="t2.medium" ) conn.create_launch_configuration(config) @@ -260,7 +261,7 @@ def test_autoscaling_tags_update(): mocked_networking = setup_networking_deprecated() conn = boto.connect_autoscale() config = LaunchConfiguration( - name="tester", image_id="ami-abcd1234", instance_type="t2.medium" + name="tester", image_id=EXAMPLE_AMI_ID, instance_type="t2.medium" ) conn.create_launch_configuration(config) @@ -308,7 +309,7 @@ def test_autoscaling_group_delete(): mocked_networking = setup_networking_deprecated() conn = boto.connect_autoscale() config = LaunchConfiguration( - name="tester", image_id="ami-abcd1234", instance_type="t2.medium" + name="tester", image_id=EXAMPLE_AMI_ID, instance_type="t2.medium" ) conn.create_launch_configuration(config) @@ -333,7 +334,7 @@ def test_autoscaling_group_describe_instances(): mocked_networking = setup_networking_deprecated() conn = boto.ec2.autoscale.connect_to_region("us-east-1") config = LaunchConfiguration( - name="tester", image_id="ami-abcd1234", instance_type="t2.medium" + name="tester", image_id=EXAMPLE_AMI_ID, instance_type="t2.medium" ) conn.create_launch_configuration(config) @@ -367,7 +368,7 @@ def test_set_desired_capacity_up(): mocked_networking = setup_networking_deprecated() conn = boto.connect_autoscale() config = LaunchConfiguration( - name="tester", image_id="ami-abcd1234", instance_type="t2.medium" + name="tester", image_id=EXAMPLE_AMI_ID, instance_type="t2.medium" ) conn.create_launch_configuration(config) @@ -401,7 +402,7 @@ def test_set_desired_capacity_down(): mocked_networking = setup_networking_deprecated() conn = boto.connect_autoscale() config = LaunchConfiguration( - name="tester", image_id="ami-abcd1234", instance_type="t2.medium" + name="tester", image_id=EXAMPLE_AMI_ID, instance_type="t2.medium" ) conn.create_launch_configuration(config) @@ -435,7 +436,7 @@ def test_set_desired_capacity_the_same(): mocked_networking = setup_networking_deprecated() conn = boto.connect_autoscale() config = LaunchConfiguration( - name="tester", image_id="ami-abcd1234", instance_type="t2.medium" + name="tester", image_id=EXAMPLE_AMI_ID, instance_type="t2.medium" ) conn.create_launch_configuration(config) @@ -476,7 +477,7 @@ def test_autoscaling_group_with_elb(): conn = boto.connect_autoscale() config = LaunchConfiguration( - name="tester", image_id="ami-abcd1234", instance_type="t2.medium" + name="tester", image_id=EXAMPLE_AMI_ID, instance_type="t2.medium" ) conn.create_launch_configuration(config) group = AutoScalingGroup( @@ -727,7 +728,7 @@ def test_create_autoscaling_group_boto3(): @mock_autoscaling def test_create_autoscaling_group_from_instance(): autoscaling_group_name = "test_asg" - image_id = "ami-0cc293023f983ed53" + image_id = EXAMPLE_AMI_ID instance_type = "t2.micro" mocked_instance_with_networking = setup_instance_with_networking( @@ -806,10 +807,7 @@ def test_create_autoscaling_group_from_template(): ec2_client = boto3.client("ec2", region_name="us-east-1") template = ec2_client.create_launch_template( LaunchTemplateName="test_launch_template", - LaunchTemplateData={ - "ImageId": "ami-0cc293023f983ed53", - "InstanceType": "t2.micro", - }, + LaunchTemplateData={"ImageId": EXAMPLE_AMI_ID, "InstanceType": "t2.micro",}, )["LaunchTemplate"] client = boto3.client("autoscaling", region_name="us-east-1") response = client.create_auto_scaling_group( @@ -835,10 +833,7 @@ def test_create_autoscaling_group_no_template_ref(): ec2_client = boto3.client("ec2", region_name="us-east-1") template = ec2_client.create_launch_template( LaunchTemplateName="test_launch_template", - LaunchTemplateData={ - "ImageId": "ami-0cc293023f983ed53", - "InstanceType": "t2.micro", - }, + LaunchTemplateData={"ImageId": EXAMPLE_AMI_ID, "InstanceType": "t2.micro",}, )["LaunchTemplate"] client = boto3.client("autoscaling", region_name="us-east-1") @@ -867,10 +862,7 @@ def test_create_autoscaling_group_multiple_template_ref(): ec2_client = boto3.client("ec2", region_name="us-east-1") template = ec2_client.create_launch_template( LaunchTemplateName="test_launch_template", - LaunchTemplateData={ - "ImageId": "ami-0cc293023f983ed53", - "InstanceType": "t2.micro", - }, + LaunchTemplateData={"ImageId": EXAMPLE_AMI_ID, "InstanceType": "t2.micro",}, )["LaunchTemplate"] client = boto3.client("autoscaling", region_name="us-east-1") @@ -924,10 +916,7 @@ def test_create_autoscaling_group_boto3_multiple_launch_configurations(): ec2_client = boto3.client("ec2", region_name="us-east-1") template = ec2_client.create_launch_template( LaunchTemplateName="test_launch_template", - LaunchTemplateData={ - "ImageId": "ami-0cc293023f983ed53", - "InstanceType": "t2.micro", - }, + LaunchTemplateData={"ImageId": EXAMPLE_AMI_ID, "InstanceType": "t2.micro",}, )["LaunchTemplate"] client = boto3.client("autoscaling", region_name="us-east-1") client.create_launch_configuration( @@ -997,10 +986,7 @@ def test_describe_autoscaling_groups_boto3_launch_template(): ec2_client = boto3.client("ec2", region_name="us-east-1") template = ec2_client.create_launch_template( LaunchTemplateName="test_launch_template", - LaunchTemplateData={ - "ImageId": "ami-0cc293023f983ed53", - "InstanceType": "t2.micro", - }, + LaunchTemplateData={"ImageId": EXAMPLE_AMI_ID, "InstanceType": "t2.micro",}, )["LaunchTemplate"] client = boto3.client("autoscaling", region_name="us-east-1") client.create_auto_scaling_group( @@ -1070,10 +1056,7 @@ def test_describe_autoscaling_instances_boto3_launch_template(): ec2_client = boto3.client("ec2", region_name="us-east-1") template = ec2_client.create_launch_template( LaunchTemplateName="test_launch_template", - LaunchTemplateData={ - "ImageId": "ami-0cc293023f983ed53", - "InstanceType": "t2.micro", - }, + LaunchTemplateData={"ImageId": EXAMPLE_AMI_ID, "InstanceType": "t2.micro",}, )["LaunchTemplate"] client = boto3.client("autoscaling", region_name="us-east-1") client.create_auto_scaling_group( @@ -1180,10 +1163,7 @@ def test_update_autoscaling_group_boto3_launch_template(): ec2_client = boto3.client("ec2", region_name="us-east-1") ec2_client.create_launch_template( LaunchTemplateName="test_launch_template", - LaunchTemplateData={ - "ImageId": "ami-0cc293023f983ed53", - "InstanceType": "t2.micro", - }, + LaunchTemplateData={"ImageId": EXAMPLE_AMI_ID, "InstanceType": "t2.micro",}, ) template = ec2_client.create_launch_template( LaunchTemplateName="test_launch_template_new", diff --git a/tests/test_autoscaling/test_autoscaling_cloudformation.py b/tests/test_autoscaling/test_autoscaling_cloudformation.py index 24a5b5628..9d5817189 100644 --- a/tests/test_autoscaling/test_autoscaling_cloudformation.py +++ b/tests/test_autoscaling/test_autoscaling_cloudformation.py @@ -8,6 +8,7 @@ from moto import ( ) from .utils import setup_networking +from tests import EXAMPLE_AMI_ID @mock_autoscaling @@ -23,13 +24,15 @@ Resources: LaunchConfiguration: Type: AWS::AutoScaling::LaunchConfiguration Properties: - ImageId: ami-0cc293023f983ed53 + ImageId: {0} InstanceType: t2.micro LaunchConfigurationName: test_launch_configuration Outputs: LaunchConfigurationName: Value: !Ref LaunchConfiguration -""".strip() +""".strip().format( + EXAMPLE_AMI_ID + ) cf_client.create_stack( StackName=stack_name, TemplateBody=cf_template, @@ -39,7 +42,7 @@ Outputs: lc = client.describe_launch_configurations()["LaunchConfigurations"][0] lc["LaunchConfigurationName"].should.be.equal("test_launch_configuration") - lc["ImageId"].should.be.equal("ami-0cc293023f983ed53") + lc["ImageId"].should.be.equal(EXAMPLE_AMI_ID) lc["InstanceType"].should.be.equal("t2.micro") cf_template = """ @@ -47,13 +50,15 @@ Resources: LaunchConfiguration: Type: AWS::AutoScaling::LaunchConfiguration Properties: - ImageId: ami-1ea5b10a3d8867db4 + ImageId: {0} InstanceType: m5.large LaunchConfigurationName: test_launch_configuration Outputs: LaunchConfigurationName: Value: !Ref LaunchConfiguration -""".strip() +""".strip().format( + EXAMPLE_AMI_ID + ) cf_client.update_stack( StackName=stack_name, TemplateBody=cf_template, @@ -63,7 +68,7 @@ Outputs: lc = client.describe_launch_configurations()["LaunchConfigurations"][0] lc["LaunchConfigurationName"].should.be.equal("test_launch_configuration") - lc["ImageId"].should.be.equal("ami-1ea5b10a3d8867db4") + lc["ImageId"].should.be.equal(EXAMPLE_AMI_ID) lc["InstanceType"].should.be.equal("m5.large") @@ -168,10 +173,7 @@ def test_autoscaling_group_from_launch_template(): template_response = ec2_client.create_launch_template( LaunchTemplateName="test_launch_template", - LaunchTemplateData={ - "ImageId": "ami-0cc293023f983ed53", - "InstanceType": "t2.micro", - }, + LaunchTemplateData={"ImageId": EXAMPLE_AMI_ID, "InstanceType": "t2.micro",}, ) launch_template_id = template_response["LaunchTemplate"]["LaunchTemplateId"] stack_name = "test-auto-scaling-group" @@ -223,10 +225,7 @@ Outputs: template_response = ec2_client.create_launch_template( LaunchTemplateName="test_launch_template_new", - LaunchTemplateData={ - "ImageId": "ami-1ea5b10a3d8867db4", - "InstanceType": "m5.large", - }, + LaunchTemplateData={"ImageId": EXAMPLE_AMI_ID, "InstanceType": "m5.large",}, ) launch_template_id = template_response["LaunchTemplate"]["LaunchTemplateId"] diff --git a/tests/test_autoscaling/test_policies.py b/tests/test_autoscaling/test_policies.py index ca1009dbe..a801a3852 100644 --- a/tests/test_autoscaling/test_policies.py +++ b/tests/test_autoscaling/test_policies.py @@ -8,13 +8,14 @@ import sure # noqa from moto import mock_autoscaling_deprecated from .utils import setup_networking_deprecated +from tests import EXAMPLE_AMI_ID def setup_autoscale_group(): mocked_networking = setup_networking_deprecated() conn = boto.connect_autoscale() config = LaunchConfiguration( - name="tester", image_id="ami-abcd1234", instance_type="m1.small" + name="tester", image_id=EXAMPLE_AMI_ID, instance_type="m1.small" ) conn.create_launch_configuration(config) diff --git a/tests/test_cloudformation/test_cloudformation_stack_crud_boto3.py b/tests/test_cloudformation/test_cloudformation_stack_crud_boto3.py index 600a727fa..3eb2c7291 100644 --- a/tests/test_cloudformation/test_cloudformation_stack_crud_boto3.py +++ b/tests/test_cloudformation/test_cloudformation_stack_crud_boto3.py @@ -14,6 +14,7 @@ import pytest from moto import mock_cloudformation, mock_s3, mock_sqs, mock_ec2 from moto.core import ACCOUNT_ID from .test_cloudformation_stack_crud import dummy_template_json2 +from tests import EXAMPLE_AMI_ID dummy_template = { "AWSTemplateFormatVersion": "2010-09-09", @@ -22,7 +23,7 @@ dummy_template = { "EC2Instance1": { "Type": "AWS::EC2::Instance", "Properties": { - "ImageId": "ami-d3adb33f", + "ImageId": EXAMPLE_AMI_ID, "KeyName": "dummy", "InstanceType": "t2.micro", "Tags": [ @@ -112,7 +113,7 @@ dummy_update_template = { "Resources": { "Instance": { "Type": "AWS::EC2::Instance", - "Properties": {"ImageId": "ami-08111162"}, + "Properties": {"ImageId": EXAMPLE_AMI_ID}, } }, } @@ -123,7 +124,7 @@ dummy_output_template = { "Resources": { "Instance": { "Type": "AWS::EC2::Instance", - "Properties": {"ImageId": "ami-08111162"}, + "Properties": {"ImageId": EXAMPLE_AMI_ID}, } }, "Outputs": { @@ -177,7 +178,7 @@ dummy_template_special_chars_in_description = { "EC2Instance1": { "Type": "AWS::EC2::Instance", "Properties": { - "ImageId": "ami-d3adb33f", + "ImageId": EXAMPLE_AMI_ID, "KeyName": "dummy", "InstanceType": "t2.micro", "Tags": [ diff --git a/tests/test_cloudformation/test_cloudformation_stack_integration.py b/tests/test_cloudformation/test_cloudformation_stack_integration.py index 9949bb4a5..6ea4263e4 100644 --- a/tests/test_cloudformation/test_cloudformation_stack_integration.py +++ b/tests/test_cloudformation/test_cloudformation_stack_integration.py @@ -45,6 +45,7 @@ from moto import ( ) from moto.core import ACCOUNT_ID +from tests import EXAMPLE_AMI_ID, EXAMPLE_AMI_ID2 from tests.test_cloudformation.fixtures import ( ec2_classic_eip, fn_join, @@ -208,7 +209,7 @@ def test_stack_ec2_integration(): "Resources": { "WebServerGroup": { "Type": "AWS::EC2::Instance", - "Properties": {"ImageId": "ami-1234abcd", "UserData": "some user data"}, + "Properties": {"ImageId": EXAMPLE_AMI_ID, "UserData": "some user data"}, } }, } @@ -252,7 +253,7 @@ def test_stack_elb_integration_with_attached_ec2_instances(): }, "Ec2Instance1": { "Type": "AWS::EC2::Instance", - "Properties": {"ImageId": "ami-1234abcd", "UserData": "some user data"}, + "Properties": {"ImageId": EXAMPLE_AMI_ID, "UserData": "some user data"}, }, }, } @@ -418,7 +419,7 @@ def test_stack_security_groups(): "Type": "AWS::EC2::Instance", "Properties": { "SecurityGroups": [{"Ref": "InstanceSecurityGroup"}], - "ImageId": "ami-1234abcd", + "ImageId": EXAMPLE_AMI_ID, }, }, "InstanceSecurityGroup": { @@ -513,7 +514,7 @@ def test_autoscaling_group_with_elb(): }, "my-launch-config": { "Type": "AWS::AutoScaling::LaunchConfiguration", - "Properties": {"ImageId": "ami-1234abcd", "UserData": "some user data"}, + "Properties": {"ImageId": EXAMPLE_AMI_ID, "UserData": "some user data"}, }, "my-elb": { "Type": "AWS::ElasticLoadBalancing::LoadBalancer", @@ -609,7 +610,7 @@ def test_autoscaling_group_update(): }, "my-launch-config": { "Type": "AWS::AutoScaling::LaunchConfiguration", - "Properties": {"ImageId": "ami-1234abcd", "UserData": "some user data"}, + "Properties": {"ImageId": EXAMPLE_AMI_ID, "UserData": "some user data"}, }, }, } @@ -844,7 +845,7 @@ def test_iam_roles(): "my-launch-config": { "Properties": { "IamInstanceProfile": {"Ref": "my-instance-profile-with-path"}, - "ImageId": "ami-1234abcd", + "ImageId": EXAMPLE_AMI_ID, }, "Type": "AWS::AutoScaling::LaunchConfiguration", }, @@ -1132,7 +1133,7 @@ def test_conditional_if_handling(): "App1": { "Properties": { "ImageId": { - "Fn::If": ["EnvEqualsPrd", "ami-00000000", "ami-ffffffff"] + "Fn::If": ["EnvEqualsPrd", EXAMPLE_AMI_ID, EXAMPLE_AMI_ID2] } }, "Type": "AWS::EC2::Instance", @@ -1146,7 +1147,7 @@ def test_conditional_if_handling(): ec2_conn = boto.ec2.connect_to_region("us-west-1") reservation = ec2_conn.get_all_instances()[0] ec2_instance = reservation.instances[0] - ec2_instance.image_id.should.equal("ami-ffffffff") + ec2_instance.image_id.should.equal(EXAMPLE_AMI_ID2) ec2_instance.terminate() conn = boto.cloudformation.connect_to_region("us-west-2") @@ -1156,7 +1157,7 @@ def test_conditional_if_handling(): ec2_conn = boto.ec2.connect_to_region("us-west-2") reservation = ec2_conn.get_all_instances()[0] ec2_instance = reservation.instances[0] - ec2_instance.image_id.should.equal("ami-00000000") + ec2_instance.image_id.should.equal(EXAMPLE_AMI_ID) @mock_cloudformation_deprecated() @@ -1927,7 +1928,7 @@ def test_stack_spot_fleet(): { "EbsOptimized": "false", "InstanceType": "t2.small", - "ImageId": "ami-1234", + "ImageId": EXAMPLE_AMI_ID, "SubnetId": subnet_id, "WeightedCapacity": "2", "SpotPrice": "0.13", @@ -1935,7 +1936,7 @@ def test_stack_spot_fleet(): { "EbsOptimized": "true", "InstanceType": "t2.large", - "ImageId": "ami-1234", + "ImageId": EXAMPLE_AMI_ID, "Monitoring": {"Enabled": "true"}, "SecurityGroups": [{"GroupId": "sg-123"}], "SubnetId": subnet_id, @@ -1984,7 +1985,7 @@ def test_stack_spot_fleet(): launch_spec = spot_fleet_config["LaunchSpecifications"][0] launch_spec["EbsOptimized"].should.equal(False) - launch_spec["ImageId"].should.equal("ami-1234") + launch_spec["ImageId"].should.equal(EXAMPLE_AMI_ID) launch_spec["InstanceType"].should.equal("t2.small") launch_spec["SubnetId"].should.equal(subnet_id) launch_spec["SpotPrice"].should.equal("0.13") @@ -2015,14 +2016,14 @@ def test_stack_spot_fleet_should_figure_out_default_price(): { "EbsOptimized": "false", "InstanceType": "t2.small", - "ImageId": "ami-1234", + "ImageId": EXAMPLE_AMI_ID, "SubnetId": subnet_id, "WeightedCapacity": "2", }, { "EbsOptimized": "true", "InstanceType": "t2.large", - "ImageId": "ami-1234", + "ImageId": EXAMPLE_AMI_ID, "Monitoring": {"Enabled": "true"}, "SecurityGroups": [{"GroupId": "sg-123"}], "SubnetId": subnet_id, @@ -2165,7 +2166,7 @@ def test_stack_elbv2_resources_integration(): }, "ec2instance": { "Type": "AWS::EC2::Instance", - "Properties": {"ImageId": "ami-1234abcd", "UserData": "some user data"}, + "Properties": {"ImageId": EXAMPLE_AMI_ID, "UserData": "some user data"}, }, }, } diff --git a/tests/test_cloudformation/test_validate.py b/tests/test_cloudformation/test_validate.py index a4c65a4c7..56d350583 100644 --- a/tests/test_cloudformation/test_validate.py +++ b/tests/test_cloudformation/test_validate.py @@ -19,6 +19,7 @@ from moto.s3.models import FakeBucket from moto.cloudformation.utils import yaml_tag_constructor from boto.cloudformation.stack import Output from moto import mock_cloudformation, mock_s3, mock_sqs, mock_ec2 +from tests import EXAMPLE_AMI_ID json_template = { "AWSTemplateFormatVersion": "2010-09-09", @@ -27,7 +28,7 @@ json_template = { "EC2Instance1": { "Type": "AWS::EC2::Instance", "Properties": { - "ImageId": "ami-d3adb33f", + "ImageId": EXAMPLE_AMI_ID, "KeyName": "dummy", "InstanceType": "t2.micro", "Tags": [ diff --git a/tests/test_ec2/test_amis.py b/tests/test_ec2/test_amis.py index db1e263b3..57e64cb55 100644 --- a/tests/test_ec2/test_amis.py +++ b/tests/test_ec2/test_amis.py @@ -13,6 +13,7 @@ import sure # noqa from moto import mock_ec2_deprecated, mock_ec2 from moto.ec2.models import AMIS, OWNER_ID from moto.core import ACCOUNT_ID +from tests import EXAMPLE_AMI_ID from tests.helpers import requires_boto_gte @@ -24,7 +25,7 @@ def test_ami_create_and_delete(): conn.get_all_volumes().should.have.length_of(0) conn.get_all_snapshots().should.have.length_of(initial_ami_count) - reservation = conn.run_instances("ami-1234abcd") + reservation = conn.run_instances(EXAMPLE_AMI_ID) instance = reservation.instances[0] with pytest.raises(EC2ResponseError) as ex: @@ -103,7 +104,7 @@ def test_ami_copy(): conn.get_all_volumes().should.have.length_of(0) conn.get_all_snapshots().should.have.length_of(initial_ami_count) - reservation = conn.run_instances("ami-1234abcd") + reservation = conn.run_instances(EXAMPLE_AMI_ID) instance = reservation.instances[0] source_image_id = conn.create_image(instance.id, "test-ami", "this is a test ami") @@ -203,7 +204,7 @@ def test_copy_image_changes_owner_id(): @mock_ec2_deprecated def test_ami_tagging(): conn = boto.connect_vpc("the_key", "the_secret") - reservation = conn.run_instances("ami-1234abcd") + reservation = conn.run_instances(EXAMPLE_AMI_ID) instance = reservation.instances[0] conn.create_image(instance.id, "test-ami", "this is a test ami") image = conn.get_all_images()[0] @@ -243,7 +244,7 @@ def test_ami_create_from_missing_instance(): @mock_ec2_deprecated def test_ami_pulls_attributes_from_instance(): conn = boto.connect_ec2("the_key", "the_secret") - reservation = conn.run_instances("ami-1234abcd") + reservation = conn.run_instances(EXAMPLE_AMI_ID) instance = reservation.instances[0] instance.modify_attribute("kernel", "test-kernel") @@ -256,7 +257,7 @@ def test_ami_pulls_attributes_from_instance(): def test_ami_uses_account_id_if_valid_access_key_is_supplied(): access_key = "AKIAXXXXXXXXXXXXXXXX" conn = boto.connect_ec2(access_key, "the_secret") - reservation = conn.run_instances("ami-1234abcd") + reservation = conn.run_instances(EXAMPLE_AMI_ID) instance = reservation.instances[0] instance.modify_attribute("kernel", "test-kernel") @@ -269,7 +270,7 @@ def test_ami_uses_account_id_if_valid_access_key_is_supplied(): def test_ami_filters(): conn = boto.connect_ec2("the_key", "the_secret") - reservationA = conn.run_instances("ami-1234abcd") + reservationA = conn.run_instances(EXAMPLE_AMI_ID) instanceA = reservationA.instances[0] instanceA.modify_attribute("architecture", "i386") instanceA.modify_attribute("kernel", "k-1234abcd") @@ -278,7 +279,7 @@ def test_ami_filters(): 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") + reservationB = conn.run_instances(EXAMPLE_AMI_ID) instanceB = reservationB.instances[0] instanceB.modify_attribute("architecture", "x86_64") instanceB.modify_attribute("kernel", "k-abcd1234") @@ -330,13 +331,13 @@ def test_ami_filters(): def test_ami_filtering_via_tag(): conn = boto.connect_vpc("the_key", "the_secret") - reservationA = conn.run_instances("ami-1234abcd") + reservationA = conn.run_instances(EXAMPLE_AMI_ID) instanceA = reservationA.instances[0] 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") + reservationB = conn.run_instances(EXAMPLE_AMI_ID) instanceB = reservationB.instances[0] imageB_id = conn.create_image(instanceB.id, "test-ami-B", "this is a test ami") imageB = conn.get_image(imageB_id) @@ -374,7 +375,7 @@ def test_getting_malformed_ami(): @mock_ec2_deprecated def test_ami_attribute_group_permissions(): conn = boto.connect_ec2("the_key", "the_secret") - reservation = conn.run_instances("ami-1234abcd") + reservation = conn.run_instances(EXAMPLE_AMI_ID) instance = reservation.instances[0] image_id = conn.create_image(instance.id, "test-ami", "this is a test ami") image = conn.get_image(image_id) @@ -437,7 +438,7 @@ def test_ami_attribute_group_permissions(): @mock_ec2_deprecated def test_ami_attribute_user_permissions(): conn = boto.connect_ec2("the_key", "the_secret") - reservation = conn.run_instances("ami-1234abcd") + reservation = conn.run_instances(EXAMPLE_AMI_ID) instance = reservation.instances[0] image_id = conn.create_image(instance.id, "test-ami", "this is a test ami") image = conn.get_image(image_id) @@ -513,7 +514,7 @@ def test_ami_attribute_user_permissions(): def test_ami_describe_executable_users(): conn = boto3.client("ec2", region_name="us-east-1") ec2 = boto3.resource("ec2", "us-east-1") - ec2.create_instances(ImageId="", MinCount=1, MaxCount=1) + ec2.create_instances(ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1) response = conn.describe_instances( Filters=[{"Name": "instance-state-name", "Values": ["running"]}] ) @@ -546,7 +547,7 @@ def test_ami_describe_executable_users(): def test_ami_describe_executable_users_negative(): conn = boto3.client("ec2", region_name="us-east-1") ec2 = boto3.resource("ec2", "us-east-1") - ec2.create_instances(ImageId="", MinCount=1, MaxCount=1) + ec2.create_instances(ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1) response = conn.describe_instances( Filters=[{"Name": "instance-state-name", "Values": ["running"]}] ) @@ -580,7 +581,7 @@ def test_ami_describe_executable_users_negative(): def test_ami_describe_executable_users_and_filter(): conn = boto3.client("ec2", region_name="us-east-1") ec2 = boto3.resource("ec2", "us-east-1") - ec2.create_instances(ImageId="", MinCount=1, MaxCount=1) + ec2.create_instances(ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1) response = conn.describe_instances( Filters=[{"Name": "instance-state-name", "Values": ["running"]}] ) @@ -621,7 +622,7 @@ def test_ami_attribute_user_and_group_permissions(): via user-specific and group-specific tests above. """ conn = boto.connect_ec2("the_key", "the_secret") - reservation = conn.run_instances("ami-1234abcd") + reservation = conn.run_instances(EXAMPLE_AMI_ID) instance = reservation.instances[0] image_id = conn.create_image(instance.id, "test-ami", "this is a test ami") image = conn.get_image(image_id) @@ -672,7 +673,7 @@ def test_ami_attribute_user_and_group_permissions(): @mock_ec2_deprecated def test_ami_attribute_error_cases(): conn = boto.connect_ec2("the_key", "the_secret") - reservation = conn.run_instances("ami-1234abcd") + reservation = conn.run_instances(EXAMPLE_AMI_ID) instance = reservation.instances[0] image_id = conn.create_image(instance.id, "test-ami", "this is a test ami") image = conn.get_image(image_id) @@ -799,7 +800,7 @@ def test_ami_filter_wildcard(): ec2_client = boto3.client("ec2", region_name="us-west-1") instance = ec2_resource.create_instances( - ImageId="ami-1234abcd", MinCount=1, MaxCount=1 + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1 )[0] instance.create_image(Name="test-image") @@ -840,7 +841,7 @@ def test_ami_filter_by_self(): # Create a new image instance = ec2_resource.create_instances( - ImageId="ami-1234abcd", MinCount=1, MaxCount=1 + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1 )[0] instance.create_image(Name="test-image") diff --git a/tests/test_ec2/test_ec2_cloudformation.py b/tests/test_ec2/test_ec2_cloudformation.py index 6fa27140b..5a7ac0d8f 100644 --- a/tests/test_ec2/test_ec2_cloudformation.py +++ b/tests/test_ec2/test_ec2_cloudformation.py @@ -1,5 +1,6 @@ from moto import mock_cloudformation_deprecated, mock_ec2_deprecated from moto import mock_cloudformation, mock_ec2 +from tests import EXAMPLE_AMI_ID from tests.test_cloudformation.fixtures import vpc_eni import boto import boto.ec2 @@ -46,7 +47,7 @@ def test_volume_size_through_cloudformation(): "testInstance": { "Type": "AWS::EC2::Instance", "Properties": { - "ImageId": "ami-d3adb33f", + "ImageId": EXAMPLE_AMI_ID, "KeyName": "dummy", "InstanceType": "t2.micro", "BlockDeviceMappings": [ diff --git a/tests/test_ec2/test_elastic_block_store.py b/tests/test_ec2/test_elastic_block_store.py index d0b1dee2d..7bf9f7c18 100644 --- a/tests/test_ec2/test_elastic_block_store.py +++ b/tests/test_ec2/test_elastic_block_store.py @@ -12,6 +12,7 @@ from moto import mock_ec2, mock_ec2_deprecated from moto.ec2 import ec2_backends from moto.ec2.models import OWNER_ID from moto.kms import mock_kms +from tests import EXAMPLE_AMI_ID @mock_ec2_deprecated @@ -54,7 +55,7 @@ def test_create_and_delete_volume(): @mock_ec2_deprecated def test_delete_attached_volume(): conn = boto.ec2.connect_to_region("us-east-1") - reservation = conn.run_instances("ami-1234abcd") + reservation = conn.run_instances(EXAMPLE_AMI_ID) # create an instance instance = reservation.instances[0] # create a volume @@ -143,7 +144,7 @@ def test_filter_volume_by_id(): def test_volume_filters(): conn = boto.ec2.connect_to_region("us-east-1") - reservation = conn.run_instances("ami-1234abcd") + reservation = conn.run_instances(EXAMPLE_AMI_ID) instance = reservation.instances[0] instance.update() @@ -250,7 +251,7 @@ def test_volume_filters(): @mock_ec2_deprecated def test_volume_attach_and_detach(): conn = boto.ec2.connect_to_region("us-east-1") - reservation = conn.run_instances("ami-1234abcd") + reservation = conn.run_instances(EXAMPLE_AMI_ID) instance = reservation.instances[0] volume = conn.create_volume(80, "us-east-1a") @@ -780,7 +781,7 @@ def test_modify_attribute_blockDeviceMapping(): """ conn = boto.ec2.connect_to_region("us-east-1") - reservation = conn.run_instances("ami-1234abcd") + reservation = conn.run_instances(EXAMPLE_AMI_ID) instance = reservation.instances[0] diff --git a/tests/test_ec2/test_elastic_ip_addresses.py b/tests/test_ec2/test_elastic_ip_addresses.py index ea60097ae..cb89c025c 100644 --- a/tests/test_ec2/test_elastic_ip_addresses.py +++ b/tests/test_ec2/test_elastic_ip_addresses.py @@ -11,6 +11,7 @@ import six import sure # noqa from moto import mock_ec2, mock_ec2_deprecated +from tests import EXAMPLE_AMI_ID import logging @@ -95,7 +96,7 @@ def test_eip_associate_classic(): """Associate/Disassociate EIP to classic instance""" conn = boto.connect_ec2("the_key", "the_secret") - reservation = conn.run_instances("ami-1234abcd") + reservation = conn.run_instances(EXAMPLE_AMI_ID) instance = reservation.instances[0] eip = conn.allocate_address() @@ -146,7 +147,7 @@ def test_eip_associate_vpc(): """Associate/Disassociate EIP to VPC instance""" conn = boto.connect_ec2("the_key", "the_secret") - reservation = conn.run_instances("ami-1234abcd") + reservation = conn.run_instances(EXAMPLE_AMI_ID) instance = reservation.instances[0] eip = conn.allocate_address(domain="vpc") @@ -194,7 +195,7 @@ def test_eip_boto3_vpc_association(): instance = service.create_instances( **{ "InstanceType": "t2.micro", - "ImageId": "ami-test", + "ImageId": EXAMPLE_AMI_ID, "MinCount": 1, "MaxCount": 1, "SubnetId": subnet_res["Subnet"]["SubnetId"], @@ -265,7 +266,7 @@ def test_eip_reassociate(): """reassociate EIP""" conn = boto.connect_ec2("the_key", "the_secret") - reservation = conn.run_instances("ami-1234abcd", min_count=2) + reservation = conn.run_instances(EXAMPLE_AMI_ID, min_count=2) instance1, instance2 = reservation.instances eip = conn.allocate_address() @@ -330,7 +331,7 @@ def test_eip_associate_invalid_args(): """Associate EIP, invalid args """ conn = boto.connect_ec2("the_key", "the_secret") - reservation = conn.run_instances("ami-1234abcd") + reservation = conn.run_instances(EXAMPLE_AMI_ID) instance = reservation.instances[0] eip = conn.allocate_address() @@ -457,7 +458,7 @@ def test_eip_filters(): instance = service.create_instances( **{ "InstanceType": "t2.micro", - "ImageId": "ami-test", + "ImageId": EXAMPLE_AMI_ID, "MinCount": 1, "MaxCount": 1, "SubnetId": subnet_res["Subnet"]["SubnetId"], diff --git a/tests/test_ec2/test_general.py b/tests/test_ec2/test_general.py index c2b578929..4d509e73b 100644 --- a/tests/test_ec2/test_general.py +++ b/tests/test_ec2/test_general.py @@ -9,12 +9,13 @@ from boto.exception import EC2ResponseError import sure # noqa from moto import mock_ec2_deprecated, mock_ec2 +from tests import EXAMPLE_AMI_ID @mock_ec2_deprecated def test_console_output(): conn = boto.connect_ec2("the_key", "the_secret") - reservation = conn.run_instances("ami-1234abcd") + reservation = conn.run_instances(EXAMPLE_AMI_ID) instance_id = reservation.instances[0].id output = conn.get_console_output(instance_id) output.output.should_not.equal(None) @@ -34,7 +35,7 @@ def test_console_output_without_instance(): @mock_ec2 def test_console_output_boto3(): conn = boto3.resource("ec2", "us-east-1") - instances = conn.create_instances(ImageId="ami-1234abcd", MinCount=1, MaxCount=1) + instances = conn.create_instances(ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1) output = instances[0].console_output() output.get("Output").should_not.equal(None) diff --git a/tests/test_ec2/test_iam_instance_profile_associations.py b/tests/test_ec2/test_iam_instance_profile_associations.py index 6a7dcad30..bf44deb6d 100644 --- a/tests/test_ec2/test_iam_instance_profile_associations.py +++ b/tests/test_ec2/test_iam_instance_profile_associations.py @@ -10,12 +10,14 @@ from botocore.exceptions import ClientError import sure # noqa from moto import mock_ec2, mock_iam, mock_cloudformation +from tests import EXAMPLE_AMI_ID def quick_instance_creation(): - image_id = "ami-1234abcd" conn_ec2 = boto3.resource("ec2", "us-east-1") - test_instance = conn_ec2.create_instances(ImageId=image_id, MinCount=1, MaxCount=1) + test_instance = conn_ec2.create_instances( + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1 + ) # We only need instance id for this tests return test_instance[0].id @@ -323,7 +325,7 @@ def test_cloudformation(): "Properties": { "IamInstanceProfile": {"Ref": "InstanceProfile"}, "KeyName": "mykey1", - "ImageId": "ami-7a11e213", + "ImageId": EXAMPLE_AMI_ID, }, }, }, diff --git a/tests/test_ec2/test_instances.py b/tests/test_ec2/test_instances.py index 146e3c696..f51da84b4 100644 --- a/tests/test_ec2/test_instances.py +++ b/tests/test_ec2/test_instances.py @@ -17,6 +17,7 @@ from freezegun import freeze_time import sure # noqa from moto import mock_ec2_deprecated, mock_ec2 +from tests import EXAMPLE_AMI_ID from tests.helpers import requires_boto_gte @@ -34,13 +35,13 @@ def add_servers(ami_id, count): @mock_ec2_deprecated def test_add_servers(): - add_servers("ami-1234abcd", 2) + add_servers(EXAMPLE_AMI_ID, 2) conn = boto.connect_ec2() reservations = conn.get_all_instances() assert len(reservations) == 2 instance1 = reservations[0].instances[0] - assert instance1.image_id == "ami-1234abcd" + assert instance1.image_id == EXAMPLE_AMI_ID ############################################ @@ -52,14 +53,14 @@ def test_instance_launch_and_terminate(): conn = boto.ec2.connect_to_region("us-east-1") with pytest.raises(EC2ResponseError) as ex: - reservation = conn.run_instances("ami-1234abcd", dry_run=True) + reservation = conn.run_instances(EXAMPLE_AMI_ID, dry_run=True) ex.value.error_code.should.equal("DryRunOperation") ex.value.status.should.equal(400) ex.value.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 = conn.run_instances(EXAMPLE_AMI_ID) reservation.should.be.a(Reservation) reservation.instances.should.have.length_of(1) instance = reservation.instances[0] @@ -107,7 +108,7 @@ def test_instance_terminate_discard_volumes(): ec2_resource = boto3.resource("ec2", "us-west-1") result = ec2_resource.create_instances( - ImageId="ami-d3adb33f", + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1, BlockDeviceMappings=[ @@ -135,7 +136,7 @@ def test_instance_terminate_keep_volumes_explicit(): ec2_resource = boto3.resource("ec2", "us-west-1") result = ec2_resource.create_instances( - ImageId="ami-d3adb33f", + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1, BlockDeviceMappings=[ @@ -162,7 +163,7 @@ def test_instance_terminate_keep_volumes_implicit(): ec2_resource = boto3.resource("ec2", "us-west-1") result = ec2_resource.create_instances( - ImageId="ami-d3adb33f", + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1, BlockDeviceMappings=[{"DeviceName": "/dev/sda1", "Ebs": {"VolumeSize": 50}}], @@ -185,7 +186,7 @@ def test_instance_terminate_keep_volumes_implicit(): def test_instance_terminate_detach_volumes(): ec2_resource = boto3.resource("ec2", "us-west-1") result = ec2_resource.create_instances( - ImageId="ami-d3adb33f", + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1, BlockDeviceMappings=[ @@ -208,7 +209,7 @@ def test_instance_terminate_detach_volumes(): def test_instance_detach_volume_wrong_path(): ec2_resource = boto3.resource("ec2", "us-west-1") result = ec2_resource.create_instances( - ImageId="ami-d3adb33f", + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1, BlockDeviceMappings=[{"DeviceName": "/dev/sda1", "Ebs": {"VolumeSize": 50}},], @@ -237,7 +238,7 @@ def test_terminate_empty_instances(): @mock_ec2_deprecated def test_instance_attach_volume(): conn = boto.connect_ec2("the_key", "the_secret") - reservation = conn.run_instances("ami-1234abcd") + reservation = conn.run_instances(EXAMPLE_AMI_ID) instance = reservation.instances[0] vol1 = conn.create_volume(size=36, zone=conn.region.name) @@ -270,7 +271,7 @@ def test_instance_attach_volume(): @mock_ec2_deprecated def test_get_instances_by_id(): conn = boto.connect_ec2() - reservation = conn.run_instances("ami-1234abcd", min_count=2) + reservation = conn.run_instances(EXAMPLE_AMI_ID, min_count=2) instance1, instance2 = reservation.instances reservations = conn.get_all_instances(instance_ids=[instance1.id]) @@ -296,11 +297,10 @@ def test_get_instances_by_id(): @mock_ec2 def test_get_paginated_instances(): - image_id = "ami-1234abcd" client = boto3.client("ec2", region_name="us-east-1") conn = boto3.resource("ec2", "us-east-1") for i in range(100): - conn.create_instances(ImageId=image_id, MinCount=1, MaxCount=1) + conn.create_instances(ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1) resp = client.describe_instances(MaxResults=50) reservations = resp["Reservations"] reservations.should.have.length_of(50) @@ -316,7 +316,7 @@ def test_get_paginated_instances(): def test_create_with_tags(): ec2 = boto3.client("ec2", region_name="us-west-2") instances = ec2.run_instances( - ImageId="ami-123", + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1, InstanceType="t2.micro", @@ -341,7 +341,7 @@ def test_create_with_tags(): @mock_ec2_deprecated def test_get_instances_filtering_by_state(): conn = boto.connect_ec2() - reservation = conn.run_instances("ami-1234abcd", min_count=3) + reservation = conn.run_instances(EXAMPLE_AMI_ID, min_count=3) instance1, instance2, instance3 = reservation.instances conn.terminate_instances([instance1.id]) @@ -377,7 +377,7 @@ def test_get_instances_filtering_by_state(): @mock_ec2_deprecated def test_get_instances_filtering_by_instance_id(): conn = boto.connect_ec2() - reservation = conn.run_instances("ami-1234abcd", min_count=3) + reservation = conn.run_instances(EXAMPLE_AMI_ID, min_count=3) instance1, instance2, instance3 = reservation.instances reservations = conn.get_all_instances(filters={"instance-id": instance1.id}) @@ -398,11 +398,11 @@ def test_get_instances_filtering_by_instance_id(): @mock_ec2_deprecated def test_get_instances_filtering_by_instance_type(): conn = boto.connect_ec2() - reservation1 = conn.run_instances("ami-1234abcd", instance_type="m1.small") + reservation1 = conn.run_instances(EXAMPLE_AMI_ID, instance_type="m1.small") instance1 = reservation1.instances[0] - reservation2 = conn.run_instances("ami-1234abcd", instance_type="m1.small") + reservation2 = conn.run_instances(EXAMPLE_AMI_ID, instance_type="m1.small") instance2 = reservation2.instances[0] - reservation3 = conn.run_instances("ami-1234abcd", instance_type="t1.micro") + reservation3 = conn.run_instances(EXAMPLE_AMI_ID, instance_type="t1.micro") instance3 = reservation3.instances[0] reservations = conn.get_all_instances(filters={"instance-type": "m1.small"}) @@ -441,7 +441,7 @@ def test_get_instances_filtering_by_instance_type(): @mock_ec2_deprecated def test_get_instances_filtering_by_reason_code(): conn = boto.connect_ec2() - reservation = conn.run_instances("ami-1234abcd", min_count=3) + reservation = conn.run_instances(EXAMPLE_AMI_ID, min_count=3) instance1, instance2, instance3 = reservation.instances instance1.stop() instance2.terminate() @@ -464,7 +464,7 @@ def test_get_instances_filtering_by_reason_code(): @mock_ec2_deprecated def test_get_instances_filtering_by_source_dest_check(): conn = boto.connect_ec2() - reservation = conn.run_instances("ami-1234abcd", min_count=2) + reservation = conn.run_instances(EXAMPLE_AMI_ID, min_count=2) instance1, instance2 = reservation.instances conn.modify_instance_attribute( instance1.id, attribute="sourceDestCheck", value=False @@ -489,12 +489,12 @@ 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(EXAMPLE_AMI_ID, 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(EXAMPLE_AMI_ID, min_count=1, subnet_id=subnet2.id) instance2 = reservation2.instances[0] reservations1 = conn.get_all_instances(filters={"vpc-id": vpc1.id}) @@ -515,7 +515,7 @@ def test_get_instances_filtering_by_vpc_id(): @mock_ec2_deprecated def test_get_instances_filtering_by_architecture(): conn = boto.connect_ec2() - reservation = conn.run_instances("ami-1234abcd", min_count=1) + reservation = conn.run_instances(EXAMPLE_AMI_ID, min_count=1) instance = reservation.instances reservations = conn.get_all_instances(filters={"architecture": "x86_64"}) @@ -525,23 +525,21 @@ def test_get_instances_filtering_by_architecture(): @mock_ec2 def test_get_instances_filtering_by_image_id(): - image_id = "ami-1234abcd" client = boto3.client("ec2", region_name="us-east-1") conn = boto3.resource("ec2", "us-east-1") - conn.create_instances(ImageId=image_id, MinCount=1, MaxCount=1) + conn.create_instances(ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1) reservations = client.describe_instances( - Filters=[{"Name": "image-id", "Values": [image_id]}] + Filters=[{"Name": "image-id", "Values": [EXAMPLE_AMI_ID]}] )["Reservations"] reservations[0]["Instances"].should.have.length_of(1) @mock_ec2 def test_get_instances_filtering_by_account_id(): - image_id = "ami-1234abcd" client = boto3.client("ec2", region_name="us-east-1") conn = boto3.resource("ec2", "us-east-1") - conn.create_instances(ImageId=image_id, MinCount=1, MaxCount=1) + conn.create_instances(ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1) reservations = client.describe_instances( Filters=[{"Name": "owner-id", "Values": ["123456789012"]}] @@ -552,11 +550,10 @@ def test_get_instances_filtering_by_account_id(): @mock_ec2 def test_get_instances_filtering_by_private_dns(): - image_id = "ami-1234abcd" client = boto3.client("ec2", region_name="us-east-1") conn = boto3.resource("ec2", "us-east-1") conn.create_instances( - ImageId=image_id, MinCount=1, MaxCount=1, PrivateIpAddress="10.0.0.1" + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1, PrivateIpAddress="10.0.0.1" ) reservations = client.describe_instances( Filters=[{"Name": "private-dns-name", "Values": ["ip-10-0-0-1.ec2.internal"]}] @@ -566,11 +563,10 @@ def test_get_instances_filtering_by_private_dns(): @mock_ec2 def test_get_instances_filtering_by_ni_private_dns(): - image_id = "ami-1234abcd" client = boto3.client("ec2", region_name="us-west-2") conn = boto3.resource("ec2", "us-west-2") conn.create_instances( - ImageId=image_id, MinCount=1, MaxCount=1, PrivateIpAddress="10.0.0.1" + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1, PrivateIpAddress="10.0.0.1" ) reservations = client.describe_instances( Filters=[ @@ -585,11 +581,10 @@ def test_get_instances_filtering_by_ni_private_dns(): @mock_ec2 def test_get_instances_filtering_by_instance_group_name(): - image_id = "ami-1234abcd" client = boto3.client("ec2", region_name="us-east-1") client.create_security_group(Description="test", GroupName="test_sg") client.run_instances( - ImageId=image_id, MinCount=1, MaxCount=1, SecurityGroups=["test_sg"] + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1, SecurityGroups=["test_sg"] ) reservations = client.describe_instances( Filters=[{"Name": "instance.group-name", "Values": ["test_sg"]}] @@ -599,12 +594,11 @@ def test_get_instances_filtering_by_instance_group_name(): @mock_ec2 def test_get_instances_filtering_by_instance_group_id(): - image_id = "ami-1234abcd" client = boto3.client("ec2", region_name="us-east-1") create_sg = client.create_security_group(Description="test", GroupName="test_sg") group_id = create_sg["GroupId"] client.run_instances( - ImageId=image_id, MinCount=1, MaxCount=1, SecurityGroups=["test_sg"] + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1, SecurityGroups=["test_sg"] ) reservations = client.describe_instances( Filters=[{"Name": "instance.group-id", "Values": [group_id]}] @@ -615,7 +609,7 @@ def test_get_instances_filtering_by_instance_group_id(): @mock_ec2_deprecated def test_get_instances_filtering_by_tag(): conn = boto.connect_ec2() - reservation = conn.run_instances("ami-1234abcd", min_count=3) + reservation = conn.run_instances(EXAMPLE_AMI_ID, min_count=3) instance1, instance2, instance3 = reservation.instances instance1.add_tag("tag1", "value1") instance1.add_tag("tag2", "value2") @@ -662,7 +656,7 @@ def test_get_instances_filtering_by_tag(): @mock_ec2_deprecated def test_get_instances_filtering_by_tag_value(): conn = boto.connect_ec2() - reservation = conn.run_instances("ami-1234abcd", min_count=3) + reservation = conn.run_instances(EXAMPLE_AMI_ID, min_count=3) instance1, instance2, instance3 = reservation.instances instance1.add_tag("tag1", "value1") instance1.add_tag("tag2", "value2") @@ -702,7 +696,7 @@ def test_get_instances_filtering_by_tag_value(): @mock_ec2_deprecated def test_get_instances_filtering_by_tag_name(): conn = boto.connect_ec2() - reservation = conn.run_instances("ami-1234abcd", min_count=3) + reservation = conn.run_instances(EXAMPLE_AMI_ID, min_count=3) instance1, instance2, instance3 = reservation.instances instance1.add_tag("tag1") instance1.add_tag("tag2") @@ -734,7 +728,7 @@ def test_get_instances_filtering_by_tag_name(): @mock_ec2_deprecated def test_instance_start_and_stop(): conn = boto.connect_ec2("the_key", "the_secret") - reservation = conn.run_instances("ami-1234abcd", min_count=2) + reservation = conn.run_instances(EXAMPLE_AMI_ID, min_count=2) instances = reservation.instances instances.should.have.length_of(2) @@ -768,7 +762,7 @@ def test_instance_start_and_stop(): @mock_ec2_deprecated def test_instance_reboot(): conn = boto.connect_ec2("the_key", "the_secret") - reservation = conn.run_instances("ami-1234abcd") + reservation = conn.run_instances(EXAMPLE_AMI_ID) instance = reservation.instances[0] with pytest.raises(EC2ResponseError) as ex: @@ -786,7 +780,7 @@ def test_instance_reboot(): @mock_ec2_deprecated def test_instance_attribute_instance_type(): conn = boto.connect_ec2("the_key", "the_secret") - reservation = conn.run_instances("ami-1234abcd") + reservation = conn.run_instances(EXAMPLE_AMI_ID) instance = reservation.instances[0] with pytest.raises(EC2ResponseError) as ex: @@ -807,7 +801,7 @@ def test_instance_attribute_instance_type(): @mock_ec2_deprecated def test_modify_instance_attribute_security_groups(): conn = boto.connect_ec2("the_key", "the_secret") - reservation = conn.run_instances("ami-1234abcd") + reservation = conn.run_instances(EXAMPLE_AMI_ID) instance = reservation.instances[0] sg_id = conn.create_security_group( @@ -837,7 +831,7 @@ def test_modify_instance_attribute_security_groups(): @mock_ec2_deprecated def test_instance_attribute_user_data(): conn = boto.connect_ec2("the_key", "the_secret") - reservation = conn.run_instances("ami-1234abcd") + reservation = conn.run_instances(EXAMPLE_AMI_ID) instance = reservation.instances[0] with pytest.raises(EC2ResponseError) as ex: @@ -858,7 +852,7 @@ def test_instance_attribute_user_data(): @mock_ec2_deprecated def test_instance_attribute_source_dest_check(): conn = boto.connect_ec2("the_key", "the_secret") - reservation = conn.run_instances("ami-1234abcd") + reservation = conn.run_instances(EXAMPLE_AMI_ID) instance = reservation.instances[0] # Default value is true @@ -902,7 +896,7 @@ def test_instance_attribute_source_dest_check(): def test_user_data_with_run_instance(): user_data = b"some user data" conn = boto.connect_ec2("the_key", "the_secret") - reservation = conn.run_instances("ami-1234abcd", user_data=user_data) + reservation = conn.run_instances(EXAMPLE_AMI_ID, user_data=user_data) instance = reservation.instances[0] instance_attribute = instance.get_attribute("userData") @@ -926,7 +920,7 @@ def test_run_instance_with_security_group_name(): group = conn.create_security_group("group1", "some description") - reservation = conn.run_instances("ami-1234abcd", security_groups=["group1"]) + reservation = conn.run_instances(EXAMPLE_AMI_ID, security_groups=["group1"]) instance = reservation.instances[0] instance.groups[0].id.should.equal(group.id) @@ -937,7 +931,7 @@ def test_run_instance_with_security_group_name(): def test_run_instance_with_security_group_id(): conn = boto.connect_ec2("the_key", "the_secret") group = conn.create_security_group("group1", "some description") - reservation = conn.run_instances("ami-1234abcd", security_group_ids=[group.id]) + reservation = conn.run_instances(EXAMPLE_AMI_ID, security_group_ids=[group.id]) instance = reservation.instances[0] instance.groups[0].id.should.equal(group.id) @@ -947,7 +941,7 @@ def test_run_instance_with_security_group_id(): @mock_ec2_deprecated def test_run_instance_with_instance_type(): conn = boto.connect_ec2("the_key", "the_secret") - reservation = conn.run_instances("ami-1234abcd", instance_type="t1.micro") + reservation = conn.run_instances(EXAMPLE_AMI_ID, instance_type="t1.micro") instance = reservation.instances[0] instance.instance_type.should.equal("t1.micro") @@ -956,7 +950,7 @@ def test_run_instance_with_instance_type(): @mock_ec2_deprecated def test_run_instance_with_default_placement(): conn = boto.ec2.connect_to_region("us-east-1") - reservation = conn.run_instances("ami-1234abcd") + reservation = conn.run_instances(EXAMPLE_AMI_ID) instance = reservation.instances[0] instance.placement.should.equal("us-east-1a") @@ -965,7 +959,7 @@ def test_run_instance_with_default_placement(): @mock_ec2_deprecated def test_run_instance_with_placement(): conn = boto.connect_ec2("the_key", "the_secret") - reservation = conn.run_instances("ami-1234abcd", placement="us-east-1b") + reservation = conn.run_instances(EXAMPLE_AMI_ID, placement="us-east-1b") instance = reservation.instances[0] instance.placement.should.equal("us-east-1b") @@ -997,7 +991,7 @@ def test_run_instance_with_subnet_boto3(): subnet_id = resp["Subnet"]["SubnetId"] resp = client.run_instances( - ImageId="ami-1234abcd", MaxCount=1, MinCount=1, SubnetId=subnet_id + ImageId=EXAMPLE_AMI_ID, MaxCount=1, MinCount=1, SubnetId=subnet_id ) instance = resp["Instances"][0] instance["SubnetId"].should.equal(subnet_id) @@ -1025,7 +1019,7 @@ def test_run_instance_with_specified_private_ipv4(): subnet_id = resp["Subnet"]["SubnetId"] resp = client.run_instances( - ImageId="ami-1234abcd", + ImageId=EXAMPLE_AMI_ID, MaxCount=1, MinCount=1, SubnetId=subnet_id, @@ -1058,7 +1052,7 @@ def test_run_instance_mapped_public_ipv4(): ) resp = client.run_instances( - ImageId="ami-1234abcd", MaxCount=1, MinCount=1, SubnetId=subnet_id + ImageId=EXAMPLE_AMI_ID, MaxCount=1, MinCount=1, SubnetId=subnet_id ) instance = resp["Instances"][0] instance.should.contain("PublicDnsName") @@ -1081,7 +1075,7 @@ def test_run_instance_with_nic_autocreated(): private_ip = "10.0.0.1" reservation = conn.run_instances( - "ami-1234abcd", + EXAMPLE_AMI_ID, subnet_id=subnet.id, security_groups=[security_group1.name], security_group_ids=[security_group2.id], @@ -1141,7 +1135,7 @@ def test_run_instance_with_nic_preexisting(): # end Boto objects reservation = conn.run_instances( - "ami-1234abcd", + EXAMPLE_AMI_ID, network_interfaces=interfaces, security_group_ids=[security_group2.id], ) @@ -1180,7 +1174,7 @@ def test_instance_with_nic_attach_detach(): ) reservation = conn.run_instances( - "ami-1234abcd", security_group_ids=[security_group1.id] + EXAMPLE_AMI_ID, security_group_ids=[security_group1.id] ) instance = reservation.instances[0] @@ -1249,7 +1243,7 @@ def test_instance_with_nic_attach_detach(): @mock_ec2_deprecated def test_ec2_classic_has_public_ip_address(): conn = boto.connect_ec2("the_key", "the_secret") - reservation = conn.run_instances("ami-1234abcd", key_name="keypair_name") + reservation = conn.run_instances(EXAMPLE_AMI_ID, key_name="keypair_name") instance = reservation.instances[0] instance.ip_address.should_not.equal(None) instance.public_dns_name.should.contain(instance.ip_address.replace(".", "-")) @@ -1262,7 +1256,7 @@ def test_ec2_classic_has_public_ip_address(): @mock_ec2_deprecated def test_run_instance_with_keypair(): conn = boto.connect_ec2("the_key", "the_secret") - reservation = conn.run_instances("ami-1234abcd", key_name="keypair_name") + reservation = conn.run_instances(EXAMPLE_AMI_ID, key_name="keypair_name") instance = reservation.instances[0] instance.key_name.should.equal("keypair_name") @@ -1275,7 +1269,7 @@ def test_run_instance_with_block_device_mappings(): kwargs = { "MinCount": 1, "MaxCount": 1, - "ImageId": "ami-d3adb33f", + "ImageId": EXAMPLE_AMI_ID, "KeyName": "the_key", "InstanceType": "t1.micro", "BlockDeviceMappings": [{"DeviceName": "/dev/sda2", "Ebs": {"VolumeSize": 50}}], @@ -1299,7 +1293,7 @@ def test_run_instance_with_block_device_mappings_missing_ebs(): kwargs = { "MinCount": 1, "MaxCount": 1, - "ImageId": "ami-d3adb33f", + "ImageId": EXAMPLE_AMI_ID, "KeyName": "the_key", "InstanceType": "t1.micro", "BlockDeviceMappings": [{"DeviceName": "/dev/sda2"}], @@ -1321,7 +1315,7 @@ def test_run_instance_with_block_device_mappings_missing_size(): kwargs = { "MinCount": 1, "MaxCount": 1, - "ImageId": "ami-d3adb33f", + "ImageId": EXAMPLE_AMI_ID, "KeyName": "the_key", "InstanceType": "t1.micro", "BlockDeviceMappings": [ @@ -1352,7 +1346,7 @@ def test_run_instance_with_block_device_mappings_from_snapshot(): kwargs = { "MinCount": 1, "MaxCount": 1, - "ImageId": "ami-d3adb33f", + "ImageId": EXAMPLE_AMI_ID, "KeyName": "the_key", "InstanceType": "t1.micro", "BlockDeviceMappings": [ @@ -1383,7 +1377,7 @@ def test_describe_instance_status_no_instances(): @mock_ec2_deprecated def test_describe_instance_status_with_instances(): conn = boto.connect_ec2("the_key", "the_secret") - conn.run_instances("ami-1234abcd", key_name="keypair_name") + conn.run_instances(EXAMPLE_AMI_ID, key_name="keypair_name") all_status = conn.get_all_instance_status() len(all_status).should.equal(1) @@ -1396,11 +1390,11 @@ def test_describe_instance_status_with_instance_filter_deprecated(): conn = boto.connect_ec2("the_key", "the_secret") # We want to filter based on this one - reservation = conn.run_instances("ami-1234abcd", key_name="keypair_name") + reservation = conn.run_instances(EXAMPLE_AMI_ID, key_name="keypair_name") instance = reservation.instances[0] # This is just to setup the test - conn.run_instances("ami-1234abcd", key_name="keypair_name") + conn.run_instances(EXAMPLE_AMI_ID, key_name="keypair_name") all_status = conn.get_all_instance_status(instance_ids=[instance.id]) len(all_status).should.equal(1) @@ -1419,7 +1413,7 @@ def test_describe_instance_credit_specifications(): conn = boto3.client("ec2", region_name="us-west-1") # We want to filter based on this one - reservation = conn.run_instances(ImageId="ami-1234abcd", MinCount=1, MaxCount=1) + reservation = conn.run_instances(ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1) result = conn.describe_instance_credit_specifications( InstanceIds=[reservation["Instances"][0]["InstanceId"]] ) @@ -1434,7 +1428,7 @@ def test_describe_instance_status_with_instance_filter(): conn = boto3.client("ec2", region_name="us-west-1") # We want to filter based on this one - reservation = conn.run_instances(ImageId="ami-1234abcd", MinCount=3, MaxCount=3) + reservation = conn.run_instances(ImageId=EXAMPLE_AMI_ID, MinCount=3, MaxCount=3) instance1 = reservation["Instances"][0] instance2 = reservation["Instances"][1] instance3 = reservation["Instances"][2] @@ -1502,7 +1496,7 @@ def test_describe_instance_status_with_instance_filter(): @mock_ec2_deprecated def test_describe_instance_status_with_non_running_instances(): conn = boto.connect_ec2("the_key", "the_secret") - reservation = conn.run_instances("ami-1234abcd", min_count=3) + reservation = conn.run_instances(EXAMPLE_AMI_ID, min_count=3) instance1, instance2, instance3 = reservation.instances instance1.stop() instance2.terminate() @@ -1529,7 +1523,7 @@ def test_describe_instance_status_with_non_running_instances(): def test_get_instance_by_security_group(): conn = boto.connect_ec2("the_key", "the_secret") - conn.run_instances("ami-1234abcd") + conn.run_instances(EXAMPLE_AMI_ID) instance = conn.get_only_instances()[0] security_group = conn.create_security_group("test", "test") @@ -1555,7 +1549,7 @@ def test_get_instance_by_security_group(): @mock_ec2 def test_modify_delete_on_termination(): ec2_client = boto3.resource("ec2", region_name="us-west-1") - result = ec2_client.create_instances(ImageId="ami-12345678", MinCount=1, MaxCount=1) + result = ec2_client.create_instances(ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1) instance = result[0] instance.load() instance.block_device_mappings[0]["Ebs"]["DeleteOnTermination"].should.be(True) @@ -1573,7 +1567,7 @@ def test_create_instance_ebs_optimized(): ec2_resource = boto3.resource("ec2", region_name="eu-west-1") instance = ec2_resource.create_instances( - ImageId="ami-12345678", MaxCount=1, MinCount=1, EbsOptimized=True + ImageId=EXAMPLE_AMI_ID, MaxCount=1, MinCount=1, EbsOptimized=True )[0] instance.load() instance.ebs_optimized.should.be(True) @@ -1583,7 +1577,7 @@ def test_create_instance_ebs_optimized(): instance.ebs_optimized.should.be(False) instance = ec2_resource.create_instances( - ImageId="ami-12345678", MaxCount=1, MinCount=1, + ImageId=EXAMPLE_AMI_ID, MaxCount=1, MinCount=1, )[0] instance.load() instance.ebs_optimized.should.be(False) @@ -1594,7 +1588,7 @@ def test_run_multiple_instances_in_same_command(): instance_count = 4 client = boto3.client("ec2", region_name="us-east-1") client.run_instances( - ImageId="ami-1234abcd", MinCount=instance_count, MaxCount=instance_count + ImageId=EXAMPLE_AMI_ID, MinCount=instance_count, MaxCount=instance_count ) reservations = client.describe_instances()["Reservations"] @@ -1612,7 +1606,7 @@ def test_describe_instance_attribute(): GroupName="test security group", Description="this is a test security group" )["GroupId"] client.run_instances( - ImageId="ami-1234abcd", + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1, SecurityGroupIds=[security_group_id], diff --git a/tests/test_ec2/test_regions.py b/tests/test_ec2/test_regions.py index 3504a2b5a..6571f1596 100644 --- a/tests/test_ec2/test_regions.py +++ b/tests/test_ec2/test_regions.py @@ -8,6 +8,7 @@ from boto3 import Session from moto import mock_ec2_deprecated, mock_autoscaling_deprecated, mock_elb_deprecated from moto.ec2 import ec2_backends +from tests import EXAMPLE_AMI_ID, EXAMPLE_AMI_ID2 def test_use_boto_regions(): @@ -32,24 +33,23 @@ def add_servers_to_region(ami_id, count, region): @mock_ec2_deprecated def test_add_servers_to_a_single_region(): region = "ap-northeast-1" - add_servers_to_region("ami-1234abcd", 1, region) - add_servers_to_region("ami-5678efgh", 1, region) + add_servers_to_region(EXAMPLE_AMI_ID, 1, region) + add_servers_to_region(EXAMPLE_AMI_ID2, 1, region) conn = boto.ec2.connect_to_region(region) reservations = conn.get_all_instances() len(reservations).should.equal(2) - reservations.sort(key=lambda x: x.instances[0].image_id) - reservations[0].instances[0].image_id.should.equal("ami-1234abcd") - reservations[1].instances[0].image_id.should.equal("ami-5678efgh") + image_ids = [r.instances[0].image_id for r in reservations] + image_ids.should.equal([EXAMPLE_AMI_ID, EXAMPLE_AMI_ID2]) @mock_ec2_deprecated def test_add_servers_to_multiple_regions(): region1 = "us-east-1" region2 = "ap-northeast-1" - add_servers_to_region("ami-1234abcd", 1, region1) - add_servers_to_region("ami-5678efgh", 1, region2) + add_servers_to_region(EXAMPLE_AMI_ID, 1, region1) + add_servers_to_region(EXAMPLE_AMI_ID2, 1, region2) us_conn = boto.ec2.connect_to_region(region1) ap_conn = boto.ec2.connect_to_region(region2) @@ -59,8 +59,8 @@ def test_add_servers_to_multiple_regions(): len(us_reservations).should.equal(1) len(ap_reservations).should.equal(1) - us_reservations[0].instances[0].image_id.should.equal("ami-1234abcd") - ap_reservations[0].instances[0].image_id.should.equal("ami-5678efgh") + us_reservations[0].instances[0].image_id.should.equal(EXAMPLE_AMI_ID) + ap_reservations[0].instances[0].image_id.should.equal(EXAMPLE_AMI_ID2) @mock_autoscaling_deprecated @@ -77,7 +77,7 @@ def test_create_autoscaling_group(): us_conn = boto.ec2.autoscale.connect_to_region("us-east-1") config = boto.ec2.autoscale.LaunchConfiguration( - name="us_tester", image_id="ami-abcd1234", instance_type="m1.small" + name="us_tester", image_id=EXAMPLE_AMI_ID, instance_type="m1.small" ) x = us_conn.create_launch_configuration(config) @@ -104,7 +104,7 @@ def test_create_autoscaling_group(): ap_conn = boto.ec2.autoscale.connect_to_region("ap-northeast-1") config = boto.ec2.autoscale.LaunchConfiguration( - name="ap_tester", image_id="ami-efgh5678", instance_type="m1.small" + name="ap_tester", image_id=EXAMPLE_AMI_ID, instance_type="m1.small" ) ap_conn.create_launch_configuration(config) diff --git a/tests/test_ec2/test_route_tables.py b/tests/test_ec2/test_route_tables.py index 889515962..62d330d1c 100644 --- a/tests/test_ec2/test_route_tables.py +++ b/tests/test_ec2/test_route_tables.py @@ -10,6 +10,7 @@ from botocore.exceptions import ClientError import sure # noqa from moto import mock_ec2, mock_ec2_deprecated +from tests import EXAMPLE_AMI_ID from tests.helpers import requires_boto_gte @@ -408,7 +409,7 @@ def test_routes_replace(): # Various route targets igw = conn.create_internet_gateway() - reservation = conn.run_instances("ami-1234abcd") + reservation = conn.run_instances(EXAMPLE_AMI_ID) instance = reservation.instances[0] # Create initial route diff --git a/tests/test_ec2/test_server.py b/tests/test_ec2/test_server.py index f09146b2a..490713c24 100644 --- a/tests/test_ec2/test_server.py +++ b/tests/test_ec2/test_server.py @@ -3,6 +3,7 @@ import re import sure # noqa import moto.server as server +from tests import EXAMPLE_AMI_ID """ Test the different server responses @@ -14,7 +15,7 @@ def test_ec2_server_get(): test_client = backend.test_client() res = test_client.get( - "/?Action=RunInstances&ImageId=ami-60a54009", + "/?Action=RunInstances&ImageId=" + EXAMPLE_AMI_ID, headers={"Host": "ec2.us-east-1.amazonaws.com"}, ) diff --git a/tests/test_ec2/test_spot_fleet.py b/tests/test_ec2/test_spot_fleet.py index 87b2f6291..d82aff89f 100644 --- a/tests/test_ec2/test_spot_fleet.py +++ b/tests/test_ec2/test_spot_fleet.py @@ -5,6 +5,7 @@ import sure # noqa from moto import mock_ec2 from moto.core import ACCOUNT_ID +from tests import EXAMPLE_AMI_ID def get_subnet_id(conn): @@ -24,7 +25,7 @@ def spot_config(subnet_id, allocation_strategy="lowestPrice"): "IamFleetRole": "arn:aws:iam::{}:role/fleet".format(ACCOUNT_ID), "LaunchSpecifications": [ { - "ImageId": "ami-123", + "ImageId": EXAMPLE_AMI_ID, "KeyName": "my-key", "SecurityGroups": [{"GroupId": "sg-123"}], "UserData": "some user data", @@ -54,7 +55,7 @@ def spot_config(subnet_id, allocation_strategy="lowestPrice"): "SpotPrice": "0.13", }, { - "ImageId": "ami-123", + "ImageId": EXAMPLE_AMI_ID, "KeyName": "my-key", "SecurityGroups": [{"GroupId": "sg-123"}], "UserData": "some user data", @@ -108,7 +109,7 @@ def test_create_spot_fleet_with_lowest_price(): launch_spec["IamInstanceProfile"].should.equal( {"Arn": "arn:aws:iam::{}:role/fleet".format(ACCOUNT_ID)} ) - launch_spec["ImageId"].should.equal("ami-123") + launch_spec["ImageId"].should.equal(EXAMPLE_AMI_ID) launch_spec["InstanceType"].should.equal("t2.small") launch_spec["KeyName"].should.equal("my-key") launch_spec["Monitoring"].should.equal({"Enabled": True}) diff --git a/tests/test_ec2/test_spot_instances.py b/tests/test_ec2/test_spot_instances.py index bb4ccac3b..0c226186b 100644 --- a/tests/test_ec2/test_spot_instances.py +++ b/tests/test_ec2/test_spot_instances.py @@ -12,6 +12,7 @@ import sure # noqa from moto import mock_ec2, mock_ec2_deprecated, settings from moto.ec2.models import ec2_backends from moto.core.utils import iso_8601_datetime_with_milliseconds +from tests import EXAMPLE_AMI_ID @mock_ec2 @@ -41,7 +42,7 @@ def test_request_spot_instances(): LaunchGroup="the-group", AvailabilityZoneGroup="my-group", LaunchSpecification={ - "ImageId": "ami-abcd1234", + "ImageId": EXAMPLE_AMI_ID, "KeyName": "test", "SecurityGroups": ["group1", "group2"], "UserData": "some test data", @@ -69,7 +70,7 @@ def test_request_spot_instances(): LaunchGroup="the-group", AvailabilityZoneGroup="my-group", LaunchSpecification={ - "ImageId": "ami-abcd1234", + "ImageId": EXAMPLE_AMI_ID, "KeyName": "test", "SecurityGroups": ["group1", "group2"], "UserData": "some test data", @@ -100,7 +101,7 @@ def test_request_spot_instances(): ] set(security_group_names).should.equal(set(["group1", "group2"])) - launch_spec["ImageId"].should.equal("ami-abcd1234") + launch_spec["ImageId"].should.equal(EXAMPLE_AMI_ID) launch_spec["KeyName"].should.equal("test") launch_spec["InstanceType"].should.equal("m1.small") launch_spec["KernelId"].should.equal("test-kernel") @@ -116,7 +117,7 @@ def test_request_spot_instances_default_arguments(): conn = boto3.client("ec2", "us-east-1") request = conn.request_spot_instances( - SpotPrice="0.5", LaunchSpecification={"ImageId": "ami-abcd1234"} + SpotPrice="0.5", LaunchSpecification={"ImageId": EXAMPLE_AMI_ID} ) requests = conn.describe_spot_instance_requests()["SpotInstanceRequests"] @@ -138,7 +139,7 @@ def test_request_spot_instances_default_arguments(): ] security_group_names.should.equal(["default"]) - launch_spec["ImageId"].should.equal("ami-abcd1234") + launch_spec["ImageId"].should.equal(EXAMPLE_AMI_ID) request.shouldnt.contain("KeyName") launch_spec["InstanceType"].should.equal("m1.small") request.shouldnt.contain("KernelId") @@ -150,7 +151,7 @@ def test_request_spot_instances_default_arguments(): def test_cancel_spot_instance_request(): conn = boto.connect_ec2() - conn.request_spot_instances(price=0.5, image_id="ami-abcd1234") + conn.request_spot_instances(price=0.5, image_id=EXAMPLE_AMI_ID) requests = conn.get_all_spot_instance_requests() requests.should.have.length_of(1) @@ -176,7 +177,7 @@ def test_request_spot_instances_fulfilled(): """ conn = boto.ec2.connect_to_region("us-east-1") - request = conn.request_spot_instances(price=0.5, image_id="ami-abcd1234") + request = conn.request_spot_instances(price=0.5, image_id=EXAMPLE_AMI_ID) requests = conn.get_all_spot_instance_requests() requests.should.have.length_of(1) @@ -201,7 +202,7 @@ def test_tag_spot_instance_request(): """ conn = boto.connect_ec2() - request = conn.request_spot_instances(price=0.5, image_id="ami-abcd1234") + request = conn.request_spot_instances(price=0.5, image_id=EXAMPLE_AMI_ID) request[0].add_tag("tag1", "value1") request[0].add_tag("tag2", "value2") @@ -220,9 +221,9 @@ def test_get_all_spot_instance_requests_filtering(): """ conn = boto.connect_ec2() - request1 = conn.request_spot_instances(price=0.5, image_id="ami-abcd1234") - request2 = conn.request_spot_instances(price=0.5, image_id="ami-abcd1234") - conn.request_spot_instances(price=0.5, image_id="ami-abcd1234") + request1 = conn.request_spot_instances(price=0.5, image_id=EXAMPLE_AMI_ID) + request2 = conn.request_spot_instances(price=0.5, image_id=EXAMPLE_AMI_ID) + conn.request_spot_instances(price=0.5, image_id=EXAMPLE_AMI_ID) request1[0].add_tag("tag1", "value1") request1[0].add_tag("tag2", "value2") request2[0].add_tag("tag1", "value1") @@ -246,7 +247,7 @@ def test_get_all_spot_instance_requests_filtering(): @mock_ec2_deprecated def test_request_spot_instances_setting_instance_id(): conn = boto.ec2.connect_to_region("us-east-1") - request = conn.request_spot_instances(price=0.5, image_id="ami-abcd1234") + request = conn.request_spot_instances(price=0.5, image_id=EXAMPLE_AMI_ID) if not settings.TEST_SERVER_MODE: req = ec2_backends["us-east-1"].spot_instance_requests[request[0].id] diff --git a/tests/test_ec2/test_subnets.py b/tests/test_ec2/test_subnets.py index 76e525990..a3d8620f6 100644 --- a/tests/test_ec2/test_subnets.py +++ b/tests/test_ec2/test_subnets.py @@ -12,6 +12,7 @@ import sure # noqa from boto.exception import EC2ResponseError from botocore.exceptions import ClientError, ParamValidationError from moto import mock_ec2, mock_ec2_deprecated +from tests import EXAMPLE_AMI_ID @mock_ec2_deprecated @@ -661,7 +662,9 @@ def test_run_instances_should_attach_to_default_subnet(): client = boto3.client("ec2", region_name="us-west-1") ec2.create_security_group(GroupName="sg01", Description="Test security group sg01") # run_instances - instances = client.run_instances(MinCount=1, MaxCount=1, SecurityGroups=["sg01"],) + instances = client.run_instances( + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1, SecurityGroups=["sg01"], + ) # Assert subnet is created appropriately subnets = client.describe_subnets()["Subnets"] default_subnet_id = subnets[0]["SubnetId"] diff --git a/tests/test_ec2/test_tags.py b/tests/test_ec2/test_tags.py index 82a23c91c..874d328e7 100644 --- a/tests/test_ec2/test_tags.py +++ b/tests/test_ec2/test_tags.py @@ -12,12 +12,13 @@ import sure # noqa from moto import mock_ec2_deprecated, mock_ec2 import pytest +from tests import EXAMPLE_AMI_ID @mock_ec2_deprecated def test_add_tag(): conn = boto.connect_ec2("the_key", "the_secret") - reservation = conn.run_instances("ami-1234abcd") + reservation = conn.run_instances(EXAMPLE_AMI_ID) instance = reservation.instances[0] with pytest.raises(EC2ResponseError) as ex: @@ -41,7 +42,7 @@ def test_add_tag(): @mock_ec2_deprecated def test_remove_tag(): conn = boto.connect_ec2("the_key", "the_secret") - reservation = conn.run_instances("ami-1234abcd") + reservation = conn.run_instances(EXAMPLE_AMI_ID) instance = reservation.instances[0] instance.add_tag("a key", "some value") @@ -70,7 +71,7 @@ def test_remove_tag(): @mock_ec2_deprecated def test_get_all_tags(): conn = boto.connect_ec2("the_key", "the_secret") - reservation = conn.run_instances("ami-1234abcd") + reservation = conn.run_instances(EXAMPLE_AMI_ID) instance = reservation.instances[0] instance.add_tag("a key", "some value") @@ -84,7 +85,7 @@ def test_get_all_tags(): @mock_ec2_deprecated def test_get_all_tags_with_special_characters(): conn = boto.connect_ec2("the_key", "the_secret") - reservation = conn.run_instances("ami-1234abcd") + reservation = conn.run_instances(EXAMPLE_AMI_ID) instance = reservation.instances[0] instance.add_tag("a key", "some<> value") @@ -98,7 +99,7 @@ def test_get_all_tags_with_special_characters(): @mock_ec2_deprecated def test_create_tags(): conn = boto.connect_ec2("the_key", "the_secret") - reservation = conn.run_instances("ami-1234abcd") + reservation = conn.run_instances(EXAMPLE_AMI_ID) instance = reservation.instances[0] tag_dict = { "a key": "some value", @@ -125,7 +126,7 @@ def test_create_tags(): @mock_ec2_deprecated def test_tag_limit_exceeded(): conn = boto.connect_ec2("the_key", "the_secret") - reservation = conn.run_instances("ami-1234abcd") + reservation = conn.run_instances(EXAMPLE_AMI_ID) instance = reservation.instances[0] tag_dict = {} for i in range(51): @@ -154,7 +155,7 @@ def test_tag_limit_exceeded(): @mock_ec2_deprecated def test_invalid_parameter_tag_null(): conn = boto.connect_ec2("the_key", "the_secret") - reservation = conn.run_instances("ami-1234abcd") + reservation = conn.run_instances(EXAMPLE_AMI_ID) instance = reservation.instances[0] with pytest.raises(EC2ResponseError) as cm: @@ -183,7 +184,7 @@ def test_invalid_id(): @mock_ec2_deprecated def test_get_all_tags_resource_id_filter(): conn = boto.connect_ec2("the_key", "the_secret") - reservation = conn.run_instances("ami-1234abcd") + reservation = conn.run_instances(EXAMPLE_AMI_ID) instance = reservation.instances[0] instance.add_tag("an instance key", "some value") image_id = conn.create_image(instance.id, "test-ami", "this is a test ami") @@ -210,7 +211,7 @@ def test_get_all_tags_resource_id_filter(): @mock_ec2_deprecated def test_get_all_tags_resource_type_filter(): conn = boto.connect_ec2("the_key", "the_secret") - reservation = conn.run_instances("ami-1234abcd") + reservation = conn.run_instances(EXAMPLE_AMI_ID) instance = reservation.instances[0] instance.add_tag("an instance key", "some value") image_id = conn.create_image(instance.id, "test-ami", "this is a test ami") @@ -237,7 +238,7 @@ def test_get_all_tags_resource_type_filter(): @mock_ec2_deprecated def test_get_all_tags_key_filter(): conn = boto.connect_ec2("the_key", "the_secret") - reservation = conn.run_instances("ami-1234abcd") + reservation = conn.run_instances(EXAMPLE_AMI_ID) instance = reservation.instances[0] instance.add_tag("an instance key", "some value") image_id = conn.create_image(instance.id, "test-ami", "this is a test ami") @@ -256,19 +257,19 @@ def test_get_all_tags_key_filter(): @mock_ec2_deprecated def test_get_all_tags_value_filter(): conn = boto.connect_ec2("the_key", "the_secret") - reservation = conn.run_instances("ami-1234abcd") + reservation = conn.run_instances(EXAMPLE_AMI_ID) instance = reservation.instances[0] instance.add_tag("an instance key", "some value") - reservation_b = conn.run_instances("ami-1234abcd") + reservation_b = conn.run_instances(EXAMPLE_AMI_ID) instance_b = reservation_b.instances[0] instance_b.add_tag("an instance key", "some other value") - reservation_c = conn.run_instances("ami-1234abcd") + reservation_c = conn.run_instances(EXAMPLE_AMI_ID) instance_c = reservation_c.instances[0] instance_c.add_tag("an instance key", "other value*") - reservation_d = conn.run_instances("ami-1234abcd") + reservation_d = conn.run_instances(EXAMPLE_AMI_ID) instance_d = reservation_d.instances[0] instance_d.add_tag("an instance key", "other value**") - reservation_e = conn.run_instances("ami-1234abcd") + reservation_e = conn.run_instances(EXAMPLE_AMI_ID) instance_e = reservation_e.instances[0] instance_e.add_tag("an instance key", "other value*?") image_id = conn.create_image(instance.id, "test-ami", "this is a test ami") @@ -304,7 +305,7 @@ def test_retrieved_instances_must_contain_their_tags(): tags_to_be_set = {tag_key: tag_value} conn = boto.connect_ec2("the_key", "the_secret") - reservation = conn.run_instances("ami-1234abcd") + reservation = conn.run_instances(EXAMPLE_AMI_ID) reservation.should.be.a(Reservation) reservation.instances.should.have.length_of(1) instance = reservation.instances[0] @@ -380,10 +381,10 @@ def test_filter_instances_by_wildcard_tags(): conn = boto.connect_ec2( aws_access_key_id="the_key", aws_secret_access_key="the_secret" ) - reservation = conn.run_instances("ami-1234abcd") + reservation = conn.run_instances(EXAMPLE_AMI_ID) instance_a = reservation.instances[0] instance_a.add_tag("Key1", "Value1") - reservation_b = conn.run_instances("ami-1234abcd") + reservation_b = conn.run_instances(EXAMPLE_AMI_ID) instance_b = reservation_b.instances[0] instance_b.add_tag("Key1", "Value2") @@ -473,7 +474,7 @@ def test_delete_tag_empty_resource(): @mock_ec2 def test_retrieve_resource_with_multiple_tags(): ec2 = boto3.resource("ec2", region_name="us-west-1") - blue, green = ec2.create_instances(ImageId="ANY_ID", MinCount=2, MaxCount=2) + blue, green = ec2.create_instances(ImageId=EXAMPLE_AMI_ID, MinCount=2, MaxCount=2) ec2.create_tags( Resources=[blue.instance_id], Tags=[ diff --git a/tests/test_ecs/test_ecs_boto3.py b/tests/test_ecs/test_ecs_boto3.py index 997023466..941664cc2 100644 --- a/tests/test_ecs/test_ecs_boto3.py +++ b/tests/test_ecs/test_ecs_boto3.py @@ -18,6 +18,7 @@ from moto.ecs.exceptions import ( RevisionNotFoundException, ) import pytest +from tests import EXAMPLE_AMI_ID @mock_ecs @@ -953,7 +954,7 @@ def test_register_container_instance(): _ = ecs_client.create_cluster(clusterName=test_cluster_name) test_instance = ec2.create_instances( - ImageId="ami-1234abcd", MinCount=1, MaxCount=1 + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1 )[0] instance_id_document = json.dumps( @@ -991,7 +992,7 @@ def test_deregister_container_instance(): _ = ecs_client.create_cluster(clusterName=test_cluster_name) test_instance = ec2.create_instances( - ImageId="ami-1234abcd", MinCount=1, MaxCount=1 + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1 )[0] instance_id_document = json.dumps( @@ -1068,7 +1069,7 @@ def test_list_container_instances(): test_instance_arns = [] for i in range(0, instance_to_create): test_instance = ec2.create_instances( - ImageId="ami-1234abcd", MinCount=1, MaxCount=1 + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1 )[0] instance_id_document = json.dumps( @@ -1101,7 +1102,7 @@ def test_describe_container_instances(): test_instance_arns = [] for i in range(0, instance_to_create): test_instance = ec2.create_instances( - ImageId="ami-1234abcd", MinCount=1, MaxCount=1 + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1 )[0] instance_id_document = json.dumps( @@ -1166,7 +1167,7 @@ def test_update_container_instances_state(): test_instance_arns = [] for i in range(0, instance_to_create): test_instance = ec2.create_instances( - ImageId="ami-1234abcd", MinCount=1, MaxCount=1 + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1 )[0] instance_id_document = json.dumps( @@ -1228,7 +1229,7 @@ def test_update_container_instances_state_by_arn(): test_instance_arns = [] for i in range(0, instance_to_create): test_instance = ec2.create_instances( - ImageId="ami-1234abcd", MinCount=1, MaxCount=1 + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1 )[0] instance_id_document = json.dumps( @@ -1289,7 +1290,7 @@ def test_run_task(): _ = client.create_cluster(clusterName=test_cluster_name) test_instance = ec2.create_instances( - ImageId="ami-1234abcd", MinCount=1, MaxCount=1 + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1 )[0] instance_id_document = json.dumps( @@ -1354,7 +1355,7 @@ def test_run_task_default_cluster(): _ = client.create_cluster(clusterName=test_cluster_name) test_instance = ec2.create_instances( - ImageId="ami-1234abcd", MinCount=1, MaxCount=1 + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1 )[0] instance_id_document = json.dumps( @@ -1439,7 +1440,7 @@ def test_start_task(): _ = client.create_cluster(clusterName=test_cluster_name) test_instance = ec2.create_instances( - ImageId="ami-1234abcd", MinCount=1, MaxCount=1 + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1 )[0] instance_id_document = json.dumps( @@ -1538,7 +1539,7 @@ def test_list_tasks(): _ = client.create_cluster() test_instance = ec2.create_instances( - ImageId="ami-1234abcd", MinCount=1, MaxCount=1 + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1 )[0] instance_id_document = json.dumps( @@ -1608,7 +1609,7 @@ def test_describe_tasks(): _ = client.create_cluster(clusterName=test_cluster_name) test_instance = ec2.create_instances( - ImageId="ami-1234abcd", MinCount=1, MaxCount=1 + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1 )[0] instance_id_document = json.dumps( @@ -1708,7 +1709,7 @@ def test_stop_task(): _ = client.create_cluster(clusterName=test_cluster_name) test_instance = ec2.create_instances( - ImageId="ami-1234abcd", MinCount=1, MaxCount=1 + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1 )[0] instance_id_document = json.dumps( @@ -1776,7 +1777,7 @@ def test_resource_reservation_and_release(): _ = client.create_cluster(clusterName=test_cluster_name) test_instance = ec2.create_instances( - ImageId="ami-1234abcd", MinCount=1, MaxCount=1 + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1 )[0] instance_id_document = json.dumps( @@ -1851,7 +1852,7 @@ def test_resource_reservation_and_release_memory_reservation(): _ = client.create_cluster(clusterName=test_cluster_name) test_instance = ec2.create_instances( - ImageId="ami-1234abcd", MinCount=1, MaxCount=1 + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1 )[0] instance_id_document = json.dumps( @@ -1924,7 +1925,7 @@ def test_task_definitions_unable_to_be_placed(): _ = client.create_cluster(clusterName=test_cluster_name) test_instance = ec2.create_instances( - ImageId="ami-1234abcd", MinCount=1, MaxCount=1 + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1 )[0] instance_id_document = json.dumps( @@ -1972,7 +1973,7 @@ def test_task_definitions_with_port_clash(): _ = client.create_cluster(clusterName=test_cluster_name) test_instance = ec2.create_instances( - ImageId="ami-1234abcd", MinCount=1, MaxCount=1 + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1 )[0] instance_id_document = json.dumps( @@ -2040,7 +2041,7 @@ def test_attributes(): instances = [] test_instance = ec2.create_instances( - ImageId="ami-1234abcd", MinCount=1, MaxCount=1 + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1 )[0] instances.append(test_instance) @@ -2056,7 +2057,7 @@ def test_attributes(): full_arn1 = response["containerInstance"]["containerInstanceArn"] test_instance = ec2.create_instances( - ImageId="ami-1234abcd", MinCount=1, MaxCount=1 + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1 )[0] instances.append(test_instance) @@ -2201,7 +2202,7 @@ def test_default_container_instance_attributes(): _ = ecs_client.create_cluster(clusterName=test_cluster_name) test_instance = ec2.create_instances( - ImageId="ami-1234abcd", MinCount=1, MaxCount=1 + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1 )[0] instance_id_document = json.dumps( @@ -2245,7 +2246,7 @@ def test_describe_container_instances_with_attributes(): _ = ecs_client.create_cluster(clusterName=test_cluster_name) test_instance = ec2.create_instances( - ImageId="ami-1234abcd", MinCount=1, MaxCount=1 + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1 )[0] instance_id_document = json.dumps( @@ -3066,7 +3067,7 @@ def test_list_tasks_with_filters(): _ = ecs.create_cluster(clusterName="test_cluster_2") test_instance = ec2.create_instances( - ImageId="ami-1234abcd", MinCount=1, MaxCount=1 + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1 )[0] instance_id_document = json.dumps( diff --git a/tests/test_resourcegroupstaggingapi/test_resourcegroupstaggingapi.py b/tests/test_resourcegroupstaggingapi/test_resourcegroupstaggingapi.py index f5a934b9b..65c167b00 100644 --- a/tests/test_resourcegroupstaggingapi/test_resourcegroupstaggingapi.py +++ b/tests/test_resourcegroupstaggingapi/test_resourcegroupstaggingapi.py @@ -7,6 +7,7 @@ from moto import mock_elbv2 from moto import mock_kms from moto import mock_resourcegroupstaggingapi from moto import mock_s3 +from tests import EXAMPLE_AMI_ID, EXAMPLE_AMI_ID2 @mock_ec2 @@ -15,7 +16,7 @@ def test_get_resources_ec2(): client = boto3.client("ec2", region_name="eu-central-1") instances = client.run_instances( - ImageId="ami-123", + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1, InstanceType="t2.micro", @@ -88,7 +89,7 @@ def test_get_tag_keys_ec2(): client = boto3.client("ec2", region_name="eu-central-1") client.run_instances( - ImageId="ami-123", + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1, InstanceType="t2.micro", @@ -123,7 +124,7 @@ def test_get_tag_values_ec2(): client = boto3.client("ec2", region_name="eu-central-1") client.run_instances( - ImageId="ami-123", + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1, InstanceType="t2.micro", @@ -142,7 +143,7 @@ def test_get_tag_values_ec2(): ], ) client.run_instances( - ImageId="ami-123", + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1, InstanceType="t2.micro", @@ -322,7 +323,7 @@ def test_multiple_tag_filters(): client = boto3.client("ec2", region_name="eu-central-1") resp = client.run_instances( - ImageId="ami-123", + ImageId=EXAMPLE_AMI_ID, MinCount=1, MaxCount=1, InstanceType="t2.micro", @@ -343,7 +344,7 @@ def test_multiple_tag_filters(): instance_1_id = resp["Instances"][0]["InstanceId"] resp = client.run_instances( - ImageId="ami-456", + ImageId=EXAMPLE_AMI_ID2, MinCount=1, MaxCount=1, InstanceType="t2.micro",