| 
									
										
										
										
											2021-09-22 18:05:28 +00:00
										 |  |  | import base64 | 
					
						
							| 
									
										
										
										
											2017-05-10 21:58:42 -04:00
										 |  |  | import boto3 | 
					
						
							| 
									
										
										
										
											2021-02-14 03:38:03 -08:00
										 |  |  | from botocore.exceptions import ClientError | 
					
						
							| 
									
										
										
										
											2013-07-27 16:24:38 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-14 03:38:03 -08:00
										 |  |  | import pytest | 
					
						
							| 
									
										
										
										
											2021-10-18 19:44:29 +00:00
										 |  |  | import sure  # noqa # pylint: disable=unused-import | 
					
						
							| 
									
										
										
										
											2013-07-27 16:24:38 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-21 14:19:36 +00:00
										 |  |  | from moto import mock_autoscaling, mock_ec2 | 
					
						
							| 
									
										
										
										
											2022-08-13 09:49:43 +00:00
										 |  |  | from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID | 
					
						
							| 
									
										
										
										
											2021-01-27 11:49:33 -08:00
										 |  |  | from tests import EXAMPLE_AMI_ID | 
					
						
							| 
									
										
										
										
											2013-07-27 16:24:38 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-22 18:05:28 +00:00
										 |  |  | @mock_autoscaling | 
					
						
							| 
									
										
										
										
											2022-03-29 21:46:06 +00:00
										 |  |  | def test_create_launch_configuration(): | 
					
						
							| 
									
										
										
										
											2021-09-22 18:05:28 +00:00
										 |  |  |     client = boto3.client("autoscaling", region_name="us-east-1") | 
					
						
							|  |  |  |     client.create_launch_configuration( | 
					
						
							|  |  |  |         LaunchConfigurationName="tester", | 
					
						
							|  |  |  |         ImageId=EXAMPLE_AMI_ID, | 
					
						
							|  |  |  |         InstanceType="t1.micro", | 
					
						
							|  |  |  |         KeyName="the_keys", | 
					
						
							|  |  |  |         SecurityGroups=["default", "default2"], | 
					
						
							|  |  |  |         UserData="This is some user_data", | 
					
						
							|  |  |  |         InstanceMonitoring={"Enabled": True}, | 
					
						
							| 
									
										
										
										
											2022-11-17 21:41:08 -01:00
										 |  |  |         IamInstanceProfile=f"arn:aws:iam::{ACCOUNT_ID}:instance-profile/testing", | 
					
						
							| 
									
										
										
										
											2021-09-22 18:05:28 +00:00
										 |  |  |         SpotPrice="0.1", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     launch_config = client.describe_launch_configurations()["LaunchConfigurations"][0] | 
					
						
							|  |  |  |     launch_config["LaunchConfigurationName"].should.equal("tester") | 
					
						
							|  |  |  |     launch_config.should.have.key("LaunchConfigurationARN") | 
					
						
							|  |  |  |     launch_config["ImageId"].should.equal(EXAMPLE_AMI_ID) | 
					
						
							|  |  |  |     launch_config["InstanceType"].should.equal("t1.micro") | 
					
						
							|  |  |  |     launch_config["KeyName"].should.equal("the_keys") | 
					
						
							|  |  |  |     set(launch_config["SecurityGroups"]).should.equal(set(["default", "default2"])) | 
					
						
							|  |  |  |     userdata = launch_config["UserData"] | 
					
						
							|  |  |  |     userdata = base64.b64decode(userdata) | 
					
						
							|  |  |  |     userdata.should.equal(b"This is some user_data") | 
					
						
							|  |  |  |     launch_config["InstanceMonitoring"].should.equal({"Enabled": True}) | 
					
						
							|  |  |  |     launch_config["IamInstanceProfile"].should.equal( | 
					
						
							| 
									
										
										
										
											2022-11-17 21:41:08 -01:00
										 |  |  |         f"arn:aws:iam::{ACCOUNT_ID}:instance-profile/testing" | 
					
						
							| 
									
										
										
										
											2021-09-22 18:05:28 +00:00
										 |  |  |     ) | 
					
						
							|  |  |  |     launch_config["SpotPrice"].should.equal("0.1") | 
					
						
							|  |  |  |     launch_config["BlockDeviceMappings"].should.equal([]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_autoscaling | 
					
						
							| 
									
										
										
										
											2022-03-29 21:46:06 +00:00
										 |  |  | def test_create_launch_configuration_with_block_device_mappings(): | 
					
						
							| 
									
										
										
										
											2021-09-22 18:05:28 +00:00
										 |  |  |     client = boto3.client("autoscaling", region_name="us-east-1") | 
					
						
							|  |  |  |     client.create_launch_configuration( | 
					
						
							|  |  |  |         LaunchConfigurationName="tester", | 
					
						
							|  |  |  |         ImageId=EXAMPLE_AMI_ID, | 
					
						
							|  |  |  |         InstanceType="t1.micro", | 
					
						
							|  |  |  |         KeyName="the_keys", | 
					
						
							|  |  |  |         SecurityGroups=["default", "default2"], | 
					
						
							|  |  |  |         UserData="This is some user_data", | 
					
						
							|  |  |  |         InstanceMonitoring={"Enabled": True}, | 
					
						
							| 
									
										
										
										
											2022-11-17 21:41:08 -01:00
										 |  |  |         IamInstanceProfile=f"arn:aws:iam::{ACCOUNT_ID}:instance-profile/testing", | 
					
						
							| 
									
										
										
										
											2021-09-22 18:05:28 +00:00
										 |  |  |         SpotPrice="0.1", | 
					
						
							|  |  |  |         BlockDeviceMappings=[ | 
					
						
							|  |  |  |             {"DeviceName": "/dev/xvdb", "VirtualName": "ephemeral0"}, | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 "DeviceName": "/dev/xvdp", | 
					
						
							|  |  |  |                 "Ebs": {"SnapshotId": "snap-1234abcd", "VolumeType": "standard"}, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 "DeviceName": "/dev/xvdh", | 
					
						
							|  |  |  |                 "Ebs": { | 
					
						
							|  |  |  |                     "VolumeType": "io1", | 
					
						
							|  |  |  |                     "VolumeSize": 100, | 
					
						
							|  |  |  |                     "Iops": 1000, | 
					
						
							|  |  |  |                     "DeleteOnTermination": False, | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     launch_config = client.describe_launch_configurations()["LaunchConfigurations"][0] | 
					
						
							|  |  |  |     launch_config["LaunchConfigurationName"].should.equal("tester") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     mappings = launch_config["BlockDeviceMappings"] | 
					
						
							|  |  |  |     mappings.should.have.length_of(3) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     xvdh = [m for m in mappings if m["DeviceName"] == "/dev/xvdh"][0] | 
					
						
							|  |  |  |     xvdp = [m for m in mappings if m["DeviceName"] == "/dev/xvdp"][0] | 
					
						
							|  |  |  |     xvdb = [m for m in mappings if m["DeviceName"] == "/dev/xvdb"][0] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     xvdh.shouldnt.have.key("VirtualName") | 
					
						
							|  |  |  |     xvdh.should.have.key("Ebs") | 
					
						
							|  |  |  |     xvdh["Ebs"]["VolumeSize"].should.equal(100) | 
					
						
							|  |  |  |     xvdh["Ebs"]["VolumeType"].should.equal("io1") | 
					
						
							|  |  |  |     xvdh["Ebs"]["DeleteOnTermination"].should.equal(False) | 
					
						
							|  |  |  |     xvdh["Ebs"]["Iops"].should.equal(1000) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     xvdp.shouldnt.have.key("VirtualName") | 
					
						
							|  |  |  |     xvdp.should.have.key("Ebs") | 
					
						
							|  |  |  |     xvdp["Ebs"]["SnapshotId"].should.equal("snap-1234abcd") | 
					
						
							|  |  |  |     xvdp["Ebs"]["VolumeType"].should.equal("standard") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     xvdb["VirtualName"].should.equal("ephemeral0") | 
					
						
							|  |  |  |     xvdb.shouldnt.have.key("Ebs") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_autoscaling | 
					
						
							|  |  |  | def test_create_launch_configuration_additional_parameters(): | 
					
						
							|  |  |  |     client = boto3.client("autoscaling", region_name="us-east-1") | 
					
						
							|  |  |  |     client.create_launch_configuration( | 
					
						
							| 
									
										
										
										
											2022-04-22 15:40:30 +00:00
										 |  |  |         ClassicLinkVPCId="vpc_id", | 
					
						
							|  |  |  |         ClassicLinkVPCSecurityGroups=["classic_sg1"], | 
					
						
							| 
									
										
										
										
											2021-09-22 18:05:28 +00:00
										 |  |  |         LaunchConfigurationName="tester", | 
					
						
							|  |  |  |         ImageId=EXAMPLE_AMI_ID, | 
					
						
							|  |  |  |         InstanceType="t1.micro", | 
					
						
							|  |  |  |         EbsOptimized=True, | 
					
						
							|  |  |  |         AssociatePublicIpAddress=True, | 
					
						
							| 
									
										
										
										
											2022-04-22 15:40:30 +00:00
										 |  |  |         MetadataOptions={ | 
					
						
							|  |  |  |             "HttpTokens": "optional", | 
					
						
							|  |  |  |             "HttpPutResponseHopLimit": 123, | 
					
						
							|  |  |  |             "HttpEndpoint": "disabled", | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2021-09-22 18:05:28 +00:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     launch_config = client.describe_launch_configurations()["LaunchConfigurations"][0] | 
					
						
							| 
									
										
										
										
											2022-04-22 15:40:30 +00:00
										 |  |  |     launch_config["ClassicLinkVPCId"].should.equal("vpc_id") | 
					
						
							|  |  |  |     launch_config["ClassicLinkVPCSecurityGroups"].should.equal(["classic_sg1"]) | 
					
						
							| 
									
										
										
										
											2021-09-22 18:05:28 +00:00
										 |  |  |     launch_config["EbsOptimized"].should.equal(True) | 
					
						
							|  |  |  |     launch_config["AssociatePublicIpAddress"].should.equal(True) | 
					
						
							| 
									
										
										
										
											2022-04-22 15:40:30 +00:00
										 |  |  |     launch_config["MetadataOptions"].should.equal( | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             "HttpTokens": "optional", | 
					
						
							|  |  |  |             "HttpPutResponseHopLimit": 123, | 
					
						
							|  |  |  |             "HttpEndpoint": "disabled", | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2021-09-22 18:05:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-26 17:23:26 +00:00
										 |  |  | @mock_autoscaling | 
					
						
							|  |  |  | @mock_ec2 | 
					
						
							|  |  |  | def test_create_launch_configuration_without_public_ip(): | 
					
						
							|  |  |  |     ec2 = boto3.resource("ec2", "us-east-1") | 
					
						
							|  |  |  |     vpc = ec2.create_vpc(CidrBlock="10.0.0.0/16") | 
					
						
							|  |  |  |     subnet = ec2.create_subnet(VpcId=vpc.id, CidrBlock="10.0.0.0/27") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ec2_client = boto3.client("ec2", region_name="us-east-1") | 
					
						
							|  |  |  |     random_image_id = ec2_client.describe_images()["Images"][0]["ImageId"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     client = boto3.client("autoscaling", region_name="us-east-1") | 
					
						
							|  |  |  |     client.create_launch_configuration( | 
					
						
							|  |  |  |         LaunchConfigurationName="tester", | 
					
						
							|  |  |  |         ImageId=EXAMPLE_AMI_ID, | 
					
						
							|  |  |  |         InstanceType="t1.micro", | 
					
						
							|  |  |  |         AssociatePublicIpAddress=False, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     launch_config = client.describe_launch_configurations()["LaunchConfigurations"][0] | 
					
						
							|  |  |  |     launch_config["AssociatePublicIpAddress"].should.equal(False) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     asg_name = f"asg-{random_image_id}" | 
					
						
							|  |  |  |     client.create_auto_scaling_group( | 
					
						
							|  |  |  |         AutoScalingGroupName=asg_name, | 
					
						
							|  |  |  |         LaunchConfigurationName=launch_config["LaunchConfigurationName"], | 
					
						
							|  |  |  |         MinSize=1, | 
					
						
							|  |  |  |         MaxSize=1, | 
					
						
							|  |  |  |         DesiredCapacity=1, | 
					
						
							|  |  |  |         VPCZoneIdentifier=subnet.id, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     instances = client.describe_auto_scaling_instances()["AutoScalingInstances"] | 
					
						
							|  |  |  |     instance_id = instances[0]["InstanceId"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     instance = ec2_client.describe_instances(InstanceIds=[instance_id])["Reservations"][ | 
					
						
							|  |  |  |         0 | 
					
						
							|  |  |  |     ]["Instances"][0] | 
					
						
							|  |  |  |     instance.shouldnt.have.key("PublicIpAddress") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-22 18:05:28 +00:00
										 |  |  | @mock_autoscaling | 
					
						
							|  |  |  | def test_create_launch_configuration_additional_params_default_to_false(): | 
					
						
							|  |  |  |     client = boto3.client("autoscaling", region_name="us-east-1") | 
					
						
							|  |  |  |     client.create_launch_configuration( | 
					
						
							|  |  |  |         LaunchConfigurationName="tester", | 
					
						
							|  |  |  |         ImageId=EXAMPLE_AMI_ID, | 
					
						
							|  |  |  |         InstanceType="t1.micro", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     launch_config = client.describe_launch_configurations()["LaunchConfigurations"][0] | 
					
						
							|  |  |  |     launch_config["EbsOptimized"].should.equal(False) | 
					
						
							|  |  |  |     launch_config["AssociatePublicIpAddress"].should.equal(False) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_autoscaling | 
					
						
							| 
									
										
										
										
											2022-03-29 21:46:06 +00:00
										 |  |  | def test_create_launch_configuration_defaults(): | 
					
						
							| 
									
										
										
										
											2021-09-22 18:05:28 +00:00
										 |  |  |     """Test with the minimum inputs and check that all of the proper defaults
 | 
					
						
							|  |  |  |     are assigned for the other attributes"""
 | 
					
						
							|  |  |  |     client = boto3.client("autoscaling", region_name="us-east-1") | 
					
						
							|  |  |  |     client.create_launch_configuration( | 
					
						
							|  |  |  |         LaunchConfigurationName="tester", | 
					
						
							|  |  |  |         ImageId=EXAMPLE_AMI_ID, | 
					
						
							|  |  |  |         InstanceType="m1.small", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     launch_config = client.describe_launch_configurations()["LaunchConfigurations"][0] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Defaults | 
					
						
							|  |  |  |     launch_config["KeyName"].should.equal("") | 
					
						
							|  |  |  |     launch_config["SecurityGroups"].should.equal([]) | 
					
						
							|  |  |  |     launch_config["UserData"].should.equal("") | 
					
						
							|  |  |  |     launch_config["InstanceMonitoring"].should.equal({"Enabled": False}) | 
					
						
							|  |  |  |     launch_config.shouldnt.have.key("IamInstanceProfile") | 
					
						
							|  |  |  |     launch_config.shouldnt.have.key("SpotPrice") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_autoscaling | 
					
						
							| 
									
										
										
										
											2022-03-29 21:46:06 +00:00
										 |  |  | def test_launch_configuration_describe_filter(): | 
					
						
							| 
									
										
										
										
											2021-09-22 18:05:28 +00:00
										 |  |  |     client = boto3.client("autoscaling", region_name="us-east-1") | 
					
						
							|  |  |  |     for name in ["tester", "tester2", "tester3"]: | 
					
						
							|  |  |  |         client.create_launch_configuration( | 
					
						
							|  |  |  |             LaunchConfigurationName=name, | 
					
						
							|  |  |  |             ImageId=EXAMPLE_AMI_ID, | 
					
						
							|  |  |  |             InstanceType="m1.small", | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     configs = client.describe_launch_configurations( | 
					
						
							|  |  |  |         LaunchConfigurationNames=["tester", "tester2"] | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     configs["LaunchConfigurations"].should.have.length_of(2) | 
					
						
							|  |  |  |     client.describe_launch_configurations()[ | 
					
						
							|  |  |  |         "LaunchConfigurations" | 
					
						
							|  |  |  |     ].should.have.length_of(3) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-10 21:58:42 -04:00
										 |  |  | @mock_autoscaling | 
					
						
							|  |  |  | def test_launch_configuration_describe_paginated(): | 
					
						
							|  |  |  |     conn = boto3.client("autoscaling", region_name="us-east-1") | 
					
						
							|  |  |  |     for i in range(51): | 
					
						
							| 
									
										
										
										
											2021-01-27 11:49:33 -08:00
										 |  |  |         conn.create_launch_configuration( | 
					
						
							| 
									
										
										
										
											2022-11-17 21:41:08 -01:00
										 |  |  |             LaunchConfigurationName=f"TestLC{i}", | 
					
						
							| 
									
										
										
										
											2021-01-27 11:49:33 -08:00
										 |  |  |             ImageId=EXAMPLE_AMI_ID, | 
					
						
							|  |  |  |             InstanceType="t2.medium", | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2017-05-10 21:58:42 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     response = conn.describe_launch_configurations() | 
					
						
							|  |  |  |     lcs = response["LaunchConfigurations"] | 
					
						
							|  |  |  |     marker = response["NextToken"] | 
					
						
							|  |  |  |     lcs.should.have.length_of(50) | 
					
						
							|  |  |  |     marker.should.equal(lcs[-1]["LaunchConfigurationName"]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response2 = conn.describe_launch_configurations(NextToken=marker) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     lcs.extend(response2["LaunchConfigurations"]) | 
					
						
							|  |  |  |     lcs.should.have.length_of(51) | 
					
						
							|  |  |  |     assert "NextToken" not in response2.keys() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-22 18:05:28 +00:00
										 |  |  | @mock_autoscaling | 
					
						
							| 
									
										
										
										
											2022-03-29 21:46:06 +00:00
										 |  |  | def test_launch_configuration_delete(): | 
					
						
							| 
									
										
										
										
											2021-09-22 18:05:28 +00:00
										 |  |  |     client = boto3.client("autoscaling", region_name="us-east-1") | 
					
						
							|  |  |  |     client.create_launch_configuration( | 
					
						
							|  |  |  |         LaunchConfigurationName="tester", | 
					
						
							|  |  |  |         ImageId=EXAMPLE_AMI_ID, | 
					
						
							|  |  |  |         InstanceType="m1.small", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     client.describe_launch_configurations()[ | 
					
						
							|  |  |  |         "LaunchConfigurations" | 
					
						
							|  |  |  |     ].should.have.length_of(1) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     client.delete_launch_configuration(LaunchConfigurationName="tester") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     client.describe_launch_configurations()[ | 
					
						
							|  |  |  |         "LaunchConfigurations" | 
					
						
							|  |  |  |     ].should.have.length_of(0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-14 03:38:03 -08:00
										 |  |  | @pytest.mark.parametrize( | 
					
						
							|  |  |  |     "request_params", | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         pytest.param( | 
					
						
							|  |  |  |             {"LaunchConfigurationName": "test"}, | 
					
						
							|  |  |  |             id="No InstanceId, ImageId, or InstanceType parameters", | 
					
						
							|  |  |  |         ), | 
					
						
							|  |  |  |         pytest.param( | 
					
						
							|  |  |  |             {"LaunchConfigurationName": "test", "ImageId": "ami-test"}, | 
					
						
							|  |  |  |             id="ImageId without InstanceType parameter", | 
					
						
							|  |  |  |         ), | 
					
						
							|  |  |  |         pytest.param( | 
					
						
							|  |  |  |             {"LaunchConfigurationName": "test", "InstanceType": "t2.medium"}, | 
					
						
							|  |  |  |             id="InstanceType without ImageId parameter", | 
					
						
							|  |  |  |         ), | 
					
						
							|  |  |  |     ], | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | @mock_autoscaling | 
					
						
							|  |  |  | def test_invalid_launch_configuration_request_raises_error(request_params): | 
					
						
							|  |  |  |     client = boto3.client("autoscaling", region_name="us-east-1") | 
					
						
							|  |  |  |     with pytest.raises(ClientError) as ex: | 
					
						
							|  |  |  |         client.create_launch_configuration(**request_params) | 
					
						
							|  |  |  |     ex.value.response["Error"]["Code"].should.equal("ValidationError") | 
					
						
							|  |  |  |     ex.value.response["Error"]["Message"].should.match( | 
					
						
							|  |  |  |         r"^Valid requests must contain.*" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2022-04-21 14:19:36 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_autoscaling | 
					
						
							|  |  |  | @mock_ec2 | 
					
						
							|  |  |  | def test_launch_config_with_block_device_mappings__volumes_are_created(): | 
					
						
							|  |  |  |     as_client = boto3.client("autoscaling", "us-east-2") | 
					
						
							|  |  |  |     ec2_client = boto3.client("ec2", "us-east-2") | 
					
						
							|  |  |  |     random_image_id = ec2_client.describe_images()["Images"][0]["ImageId"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     as_client.create_launch_configuration( | 
					
						
							|  |  |  |         LaunchConfigurationName=f"lc-{random_image_id}", | 
					
						
							|  |  |  |         ImageId=random_image_id, | 
					
						
							|  |  |  |         InstanceType="t2.nano", | 
					
						
							|  |  |  |         BlockDeviceMappings=[ | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 "DeviceName": "/dev/sdf", | 
					
						
							|  |  |  |                 "Ebs": { | 
					
						
							|  |  |  |                     "VolumeSize": 10, | 
					
						
							|  |  |  |                     "VolumeType": "standard", | 
					
						
							|  |  |  |                     "Encrypted": False, | 
					
						
							|  |  |  |                     "DeleteOnTermination": True, | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     asg_name = f"asg-{random_image_id}" | 
					
						
							|  |  |  |     as_client.create_auto_scaling_group( | 
					
						
							|  |  |  |         AutoScalingGroupName=asg_name, | 
					
						
							|  |  |  |         LaunchConfigurationName=f"lc-{random_image_id}", | 
					
						
							|  |  |  |         MinSize=1, | 
					
						
							|  |  |  |         MaxSize=1, | 
					
						
							|  |  |  |         DesiredCapacity=1, | 
					
						
							|  |  |  |         AvailabilityZones=["us-east-2b"], | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     instances = as_client.describe_auto_scaling_instances()["AutoScalingInstances"] | 
					
						
							|  |  |  |     instance_id = instances[0]["InstanceId"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     volumes = ec2_client.describe_volumes( | 
					
						
							|  |  |  |         Filters=[{"Name": "attachment.instance-id", "Values": [instance_id]}] | 
					
						
							|  |  |  |     )["Volumes"] | 
					
						
							| 
									
										
										
										
											2022-04-22 15:40:30 +00:00
										 |  |  |     volumes.should.have.length_of(2) | 
					
						
							|  |  |  |     volumes[0].should.have.key("Size").equals(8) | 
					
						
							| 
									
										
										
										
											2022-04-21 14:19:36 +00:00
										 |  |  |     volumes[0].should.have.key("Encrypted").equals(False) | 
					
						
							| 
									
										
										
										
											2022-04-22 15:40:30 +00:00
										 |  |  |     volumes[0].should.have.key("VolumeType").equals("gp2") | 
					
						
							|  |  |  |     volumes[1].should.have.key("Size").equals(10) | 
					
						
							|  |  |  |     volumes[1].should.have.key("Encrypted").equals(False) | 
					
						
							|  |  |  |     volumes[1].should.have.key("VolumeType").equals("standard") |