2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								from  __future__  import  unicode_literals  
						 
					
						
							
								
									
										
										
										
											2018-04-11 18:16:56 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  json  
						 
					
						
							
								
									
										
										
										
											2017-10-29 16:06:03 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  os  
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								import  boto3  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  botocore  
						 
					
						
							
								
									
										
										
										
											2019-09-12 12:29:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								from  botocore . exceptions  import  ClientError ,  ParamValidationError  
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								from  nose . tools  import  assert_raises  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  sure   # noqa  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-04-11 18:16:56 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								from  moto  import  mock_elbv2 ,  mock_ec2 ,  mock_acm ,  mock_cloudformation  
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								from  moto . elbv2  import  elbv2_backends  
						 
					
						
							
								
									
										
										
										
											2019-12-16 21:05:29 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								from  moto . core  import  ACCOUNT_ID  
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_elbv2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_ec2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								def  test_create_load_balancer ( ) :  
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    conn  =  boto3 . client ( " elbv2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ec2  =  boto3 . resource ( " ec2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    security_group  =  ec2 . create_security_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        GroupName = " a-security-group " ,  Description = " First One " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    vpc  =  ec2 . create_vpc ( CidrBlock = " 172.28.7.0/24 " ,  InstanceTenancy = " default " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet1  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.192/26 " ,  AvailabilityZone = " us-east-1a " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet2  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.0/26 " ,  AvailabilityZone = " us-east-1b " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . create_load_balancer ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Name = " my-lb " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        Subnets = [ subnet1 . id ,  subnet2 . id ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        SecurityGroups = [ security_group . id ] , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Scheme = " internal " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Tags = [ { " Key " :  " key_name " ,  " Value " :  " a_value " } ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    lb  =  response . get ( " LoadBalancers " ) [ 0 ] 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    lb . get ( " DNSName " ) . should . equal ( " my-lb-1.us-east-1.elb.amazonaws.com " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    lb . get ( " LoadBalancerArn " ) . should . equal ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " arn:aws:elasticloadbalancing:us-east-1:1:loadbalancer/my-lb/50dc6c495c0c9188 " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    lb . get ( " SecurityGroups " ) . should . equal ( [ security_group . id ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    lb . get ( " AvailabilityZones " ) . should . equal ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            { " SubnetId " :  subnet1 . id ,  " ZoneName " :  " us-east-1a " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            { " SubnetId " :  subnet2 . id ,  " ZoneName " :  " us-east-1b " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # Ensure the tags persisted 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    response  =  conn . describe_tags ( ResourceArns = [ lb . get ( " LoadBalancerArn " ) ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    tags  =  { d [ " Key " ] :  d [ " Value " ]  for  d  in  response [ " TagDescriptions " ] [ 0 ] [ " Tags " ] } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    tags . should . equal ( { " key_name " :  " a_value " } ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_elbv2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_ec2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								def  test_describe_load_balancers ( ) :  
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    conn  =  boto3 . client ( " elbv2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ec2  =  boto3 . resource ( " ec2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    security_group  =  ec2 . create_security_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        GroupName = " a-security-group " ,  Description = " First One " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    vpc  =  ec2 . create_vpc ( CidrBlock = " 172.28.7.0/24 " ,  InstanceTenancy = " default " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet1  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.192/26 " ,  AvailabilityZone = " us-east-1a " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet2  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.0/26 " ,  AvailabilityZone = " us-east-1b " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    conn . create_load_balancer ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Name = " my-lb " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        Subnets = [ subnet1 . id ,  subnet2 . id ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        SecurityGroups = [ security_group . id ] , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Scheme = " internal " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Tags = [ { " Key " :  " key_name " ,  " Value " :  " a_value " } ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . describe_load_balancers ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    response . get ( " LoadBalancers " ) . should . have . length_of ( 1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    lb  =  response . get ( " LoadBalancers " ) [ 0 ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    lb . get ( " LoadBalancerName " ) . should . equal ( " my-lb " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    response  =  conn . describe_load_balancers ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        LoadBalancerArns = [ lb . get ( " LoadBalancerArn " ) ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response . get ( " LoadBalancers " ) [ 0 ] . get ( " LoadBalancerName " ) . should . equal ( " my-lb " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    response  =  conn . describe_load_balancers ( Names = [ " my-lb " ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response . get ( " LoadBalancers " ) [ 0 ] . get ( " LoadBalancerName " ) . should . equal ( " my-lb " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    with  assert_raises ( ClientError ) : 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        conn . describe_load_balancers ( LoadBalancerArns = [ " not-a/real/arn " ] ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    with  assert_raises ( ClientError ) : 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        conn . describe_load_balancers ( Names = [ " nope " ] ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_elbv2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_ec2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								def  test_add_remove_tags ( ) :  
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    conn  =  boto3 . client ( " elbv2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ec2  =  boto3 . resource ( " ec2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    security_group  =  ec2 . create_security_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        GroupName = " a-security-group " ,  Description = " First One " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    vpc  =  ec2 . create_vpc ( CidrBlock = " 172.28.7.0/24 " ,  InstanceTenancy = " default " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet1  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.0/26 " ,  AvailabilityZone = " us-east-1a " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet2  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.192/26 " ,  AvailabilityZone = " us-east-1b " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    conn . create_load_balancer ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Name = " my-lb " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        Subnets = [ subnet1 . id ,  subnet2 . id ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        SecurityGroups = [ security_group . id ] , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Scheme = " internal " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Tags = [ { " Key " :  " key_name " ,  " Value " :  " a_value " } ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    lbs  =  conn . describe_load_balancers ( ) [ " LoadBalancers " ] 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    lbs . should . have . length_of ( 1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    lb  =  lbs [ 0 ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    with  assert_raises ( ClientError ) : 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        conn . add_tags ( ResourceArns = [ " missing-arn " ] ,  Tags = [ { " Key " :  " a " ,  " Value " :  " b " } ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    conn . add_tags ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ResourceArns = [ lb . get ( " LoadBalancerArn " ) ] ,  Tags = [ { " Key " :  " a " ,  " Value " :  " b " } ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    tags  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        d [ " Key " ] :  d [ " Value " ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        for  d  in  conn . describe_tags ( ResourceArns = [ lb . get ( " LoadBalancerArn " ) ] ) [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " TagDescriptions " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ] [ 0 ] [ " Tags " ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    tags . should . have . key ( " a " ) . which . should . equal ( " b " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    conn . add_tags ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ResourceArns = [ lb . get ( " LoadBalancerArn " ) ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Tags = [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            { " Key " :  " a " ,  " Value " :  " b " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            { " Key " :  " b " ,  " Value " :  " b " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            { " Key " :  " c " ,  " Value " :  " b " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            { " Key " :  " d " ,  " Value " :  " b " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            { " Key " :  " e " ,  " Value " :  " b " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            { " Key " :  " f " ,  " Value " :  " b " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            { " Key " :  " g " ,  " Value " :  " b " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            { " Key " :  " h " ,  " Value " :  " b " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            { " Key " :  " j " ,  " Value " :  " b " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    conn . add_tags . when . called_with ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ResourceArns = [ lb . get ( " LoadBalancerArn " ) ] ,  Tags = [ { " Key " :  " k " ,  " Value " :  " b " } ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) . should . throw ( botocore . exceptions . ClientError ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    conn . add_tags ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ResourceArns = [ lb . get ( " LoadBalancerArn " ) ] ,  Tags = [ { " Key " :  " j " ,  " Value " :  " c " } ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    tags  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        d [ " Key " ] :  d [ " Value " ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        for  d  in  conn . describe_tags ( ResourceArns = [ lb . get ( " LoadBalancerArn " ) ] ) [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " TagDescriptions " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ] [ 0 ] [ " Tags " ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    tags . should . have . key ( " a " ) . which . should . equal ( " b " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    tags . should . have . key ( " b " ) . which . should . equal ( " b " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    tags . should . have . key ( " c " ) . which . should . equal ( " b " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    tags . should . have . key ( " d " ) . which . should . equal ( " b " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    tags . should . have . key ( " e " ) . which . should . equal ( " b " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    tags . should . have . key ( " f " ) . which . should . equal ( " b " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    tags . should . have . key ( " g " ) . which . should . equal ( " b " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    tags . should . have . key ( " h " ) . which . should . equal ( " b " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    tags . should . have . key ( " j " ) . which . should . equal ( " c " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    tags . shouldnt . have . key ( " k " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    conn . remove_tags ( ResourceArns = [ lb . get ( " LoadBalancerArn " ) ] ,  TagKeys = [ " a " ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    tags  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        d [ " Key " ] :  d [ " Value " ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        for  d  in  conn . describe_tags ( ResourceArns = [ lb . get ( " LoadBalancerArn " ) ] ) [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " TagDescriptions " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ] [ 0 ] [ " Tags " ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    tags . shouldnt . have . key ( " a " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    tags . should . have . key ( " b " ) . which . should . equal ( " b " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    tags . should . have . key ( " c " ) . which . should . equal ( " b " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    tags . should . have . key ( " d " ) . which . should . equal ( " b " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    tags . should . have . key ( " e " ) . which . should . equal ( " b " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    tags . should . have . key ( " f " ) . which . should . equal ( " b " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    tags . should . have . key ( " g " ) . which . should . equal ( " b " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    tags . should . have . key ( " h " ) . which . should . equal ( " b " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    tags . should . have . key ( " j " ) . which . should . equal ( " c " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_elbv2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_ec2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								def  test_create_elb_in_multiple_region ( ) :  
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    for  region  in  [ " us-west-1 " ,  " us-west-2 " ] : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        conn  =  boto3 . client ( " elbv2 " ,  region_name = region ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ec2  =  boto3 . resource ( " ec2 " ,  region_name = region ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        security_group  =  ec2 . create_security_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            GroupName = " a-security-group " ,  Description = " First One " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        vpc  =  ec2 . create_vpc ( CidrBlock = " 172.28.7.0/24 " ,  InstanceTenancy = " default " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        subnet1  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            VpcId = vpc . id ,  CidrBlock = " 172.28.7.0/26 " ,  AvailabilityZone = region  +  " a " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        subnet2  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            VpcId = vpc . id ,  CidrBlock = " 172.28.7.192/26 " ,  AvailabilityZone = region  +  " b " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        conn . create_load_balancer ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            Name = " my-lb " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            Subnets = [ subnet1 . id ,  subnet2 . id ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            SecurityGroups = [ security_group . id ] , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            Scheme = " internal " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            Tags = [ { " Key " :  " key_name " ,  " Value " :  " a_value " } ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    list ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        boto3 . client ( " elbv2 " ,  region_name = " us-west-1 " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        . describe_load_balancers ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        . get ( " LoadBalancers " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    ) . should . have . length_of ( 1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    list ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        boto3 . client ( " elbv2 " ,  region_name = " us-west-2 " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        . describe_load_balancers ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        . get ( " LoadBalancers " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    ) . should . have . length_of ( 1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_elbv2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_ec2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								def  test_create_target_group_and_listeners ( ) :  
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    conn  =  boto3 . client ( " elbv2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ec2  =  boto3 . resource ( " ec2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    security_group  =  ec2 . create_security_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        GroupName = " a-security-group " ,  Description = " First One " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    vpc  =  ec2 . create_vpc ( CidrBlock = " 172.28.7.0/24 " ,  InstanceTenancy = " default " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet1  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.192/26 " ,  AvailabilityZone = " us-east-1a " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet2  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.0/26 " ,  AvailabilityZone = " us-east-1b " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . create_load_balancer ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Name = " my-lb " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        Subnets = [ subnet1 . id ,  subnet2 . id ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        SecurityGroups = [ security_group . id ] , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Scheme = " internal " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Tags = [ { " Key " :  " key_name " ,  " Value " :  " a_value " } ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    load_balancer_arn  =  response . get ( " LoadBalancers " ) [ 0 ] . get ( " LoadBalancerArn " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-27 03:16:06 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    # Can't create a target group with an invalid protocol 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    with  assert_raises ( ClientError ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        conn . create_target_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            Name = " a-target " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            Protocol = " HTTP " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-27 03:16:06 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            Port = 8080 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            VpcId = vpc . id , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            HealthCheckProtocol = " /HTTP " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            HealthCheckPort = " 8080 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            HealthCheckPath = " / " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-27 03:16:06 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            HealthCheckIntervalSeconds = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            HealthCheckTimeoutSeconds = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            HealthyThresholdCount = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            UnhealthyThresholdCount = 2 , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            Matcher = { " HttpCode " :  " 200 " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    response  =  conn . create_target_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Name = " a-target " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Protocol = " HTTP " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        Port = 8080 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        VpcId = vpc . id , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        HealthCheckProtocol = " HTTP " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthCheckPort = " 8080 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthCheckPath = " / " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        HealthCheckIntervalSeconds = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthCheckTimeoutSeconds = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthyThresholdCount = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        UnhealthyThresholdCount = 2 , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Matcher = { " HttpCode " :  " 200 " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    target_group  =  response . get ( " TargetGroups " ) [ 0 ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    target_group_arn  =  target_group [ " TargetGroupArn " ] 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-16 19:53:09 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # Add tags to the target group 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    conn . add_tags ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ResourceArns = [ target_group_arn ] ,  Tags = [ { " Key " :  " target " ,  " Value " :  " group " } ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    conn . describe_tags ( ResourceArns = [ target_group_arn ] ) [ " TagDescriptions " ] [ 0 ] [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " Tags " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ] . should . equal ( [ { " Key " :  " target " ,  " Value " :  " group " } ] ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # Check it's in the describe_target_groups response 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . describe_target_groups ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    response . get ( " TargetGroups " ) . should . have . length_of ( 1 ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # Plain HTTP listener 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . create_listener ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        LoadBalancerArn = load_balancer_arn , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Protocol = " HTTP " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        Port = 80 , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        DefaultActions = [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            { " Type " :  " forward " ,  " TargetGroupArn " :  target_group . get ( " TargetGroupArn " ) } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    listener  =  response . get ( " Listeners " ) [ 0 ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    listener . get ( " Port " ) . should . equal ( 80 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    listener . get ( " Protocol " ) . should . equal ( " HTTP " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    listener . get ( " DefaultActions " ) . should . equal ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        [ { " TargetGroupArn " :  target_group . get ( " TargetGroupArn " ) ,  " Type " :  " forward " } ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    http_listener_arn  =  listener . get ( " ListenerArn " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . describe_target_groups ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        LoadBalancerArn = load_balancer_arn ,  Names = [ " a-target " ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response . get ( " TargetGroups " ) . should . have . length_of ( 1 ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-03-06 16:56:15 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    # And another with SSL 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . create_listener ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        LoadBalancerArn = load_balancer_arn , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Protocol = " HTTPS " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        Port = 443 , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Certificates = [ 
							 
						 
					
						
							
								
									
										
										
										
											2019-12-16 21:25:20 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " CertificateArn " :  " arn:aws:iam: {} :server-certificate/test-cert " . format ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    ACCOUNT_ID 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        DefaultActions = [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            { " Type " :  " forward " ,  " TargetGroupArn " :  target_group . get ( " TargetGroupArn " ) } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    listener  =  response . get ( " Listeners " ) [ 0 ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    listener . get ( " Port " ) . should . equal ( 443 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    listener . get ( " Protocol " ) . should . equal ( " HTTPS " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    listener . get ( " Certificates " ) . should . equal ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-12-16 21:25:20 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " CertificateArn " :  " arn:aws:iam: {} :server-certificate/test-cert " . format ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    ACCOUNT_ID 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ] 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    listener . get ( " DefaultActions " ) . should . equal ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        [ { " TargetGroupArn " :  target_group . get ( " TargetGroupArn " ) ,  " Type " :  " forward " } ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    https_listener_arn  =  listener . get ( " ListenerArn " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . describe_listeners ( LoadBalancerArn = load_balancer_arn ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    response . get ( " Listeners " ) . should . have . length_of ( 2 ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    response  =  conn . describe_listeners ( ListenerArns = [ https_listener_arn ] ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    response . get ( " Listeners " ) . should . have . length_of ( 1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    listener  =  response . get ( " Listeners " ) [ 0 ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    listener . get ( " Port " ) . should . equal ( 443 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    listener . get ( " Protocol " ) . should . equal ( " HTTPS " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    response  =  conn . describe_listeners ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        ListenerArns = [ http_listener_arn ,  https_listener_arn ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response . get ( " Listeners " ) . should . have . length_of ( 2 ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:35:52 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    # Try to delete the target group and it fails because there's a 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # listener referencing it 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    with  assert_raises ( ClientError )  as  e : 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        conn . delete_target_group ( TargetGroupArn = target_group . get ( " TargetGroupArn " ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    e . exception . operation_name . should . equal ( " DeleteTargetGroup " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    e . exception . args . should . equal ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " An error occurred (ResourceInUse) when calling the DeleteTargetGroup operation: The target group  ' arn:aws:elasticloadbalancing:us-east-1:1:targetgroup/a-target/50dc6c495c0c9188 '  is currently in use by a listener or a rule " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    )   # NOQA 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:35:52 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    # Delete one listener 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . describe_listeners ( LoadBalancerArn = load_balancer_arn ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    response . get ( " Listeners " ) . should . have . length_of ( 2 ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    conn . delete_listener ( ListenerArn = http_listener_arn ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . describe_listeners ( LoadBalancerArn = load_balancer_arn ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    response . get ( " Listeners " ) . should . have . length_of ( 1 ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # Then delete the load balancer 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    conn . delete_load_balancer ( LoadBalancerArn = load_balancer_arn ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # It's gone 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . describe_load_balancers ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    response . get ( " LoadBalancers " ) . should . have . length_of ( 0 ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # And it deleted the remaining listener 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    response  =  conn . describe_listeners ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        ListenerArns = [ http_listener_arn ,  https_listener_arn ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response . get ( " Listeners " ) . should . have . length_of ( 0 ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # But not the target groups 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . describe_target_groups ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    response . get ( " TargetGroups " ) . should . have . length_of ( 1 ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # Which we'll now delete 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    conn . delete_target_group ( TargetGroupArn = target_group . get ( " TargetGroupArn " ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    response  =  conn . describe_target_groups ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    response . get ( " TargetGroups " ) . should . have . length_of ( 0 ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-04-11 18:16:56 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-11-20 20:18:21 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								@mock_elbv2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_ec2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								def  test_create_target_group_without_non_required_parameters ( ) :  
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    conn  =  boto3 . client ( " elbv2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ec2  =  boto3 . resource ( " ec2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-11-20 20:18:21 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    security_group  =  ec2 . create_security_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        GroupName = " a-security-group " ,  Description = " First One " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    vpc  =  ec2 . create_vpc ( CidrBlock = " 172.28.7.0/24 " ,  InstanceTenancy = " default " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-11-20 20:18:21 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet1  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.192/26 " ,  AvailabilityZone = " us-east-1a " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-11-20 20:18:21 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet2  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.0/26 " ,  AvailabilityZone = " us-east-1b " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-11-20 20:18:21 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . create_load_balancer ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Name = " my-lb " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-11-20 20:18:21 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Subnets = [ subnet1 . id ,  subnet2 . id ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        SecurityGroups = [ security_group . id ] , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Scheme = " internal " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Tags = [ { " Key " :  " key_name " ,  " Value " :  " a_value " } ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-11-20 20:18:21 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # request without HealthCheckIntervalSeconds parameter 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # which is default to 30 seconds 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . create_target_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Name = " a-target " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Protocol = " HTTP " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-11-20 20:18:21 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Port = 8080 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        VpcId = vpc . id , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        HealthCheckProtocol = " HTTP " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthCheckPort = " 8080 " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-11-20 20:18:21 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    target_group  =  response . get ( " TargetGroups " ) [ 0 ] 
							 
						 
					
						
							
								
									
										
										
										
											2017-11-20 20:18:21 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    target_group . should_not . be . none 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-04-11 18:16:56 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-08-19 00:16:11 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								@mock_elbv2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_ec2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								def  test_create_invalid_target_group ( ) :  
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    conn  =  boto3 . client ( " elbv2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ec2  =  boto3 . resource ( " ec2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-19 00:16:11 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    vpc  =  ec2 . create_vpc ( CidrBlock = " 172.28.7.0/24 " ,  InstanceTenancy = " default " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-19 00:16:11 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-08-18 23:54:28 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    # Fail to create target group with name which length is 33 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    long_name  =  " A "  *  33 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-18 23:54:28 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    with  assert_raises ( ClientError ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        conn . create_target_group ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            Name = long_name , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            Protocol = " HTTP " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-18 23:54:28 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            Port = 8080 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            VpcId = vpc . id , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            HealthCheckProtocol = " HTTP " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            HealthCheckPort = " 8080 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            HealthCheckPath = " / " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-18 23:54:28 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            HealthCheckIntervalSeconds = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            HealthCheckTimeoutSeconds = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            HealthyThresholdCount = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            UnhealthyThresholdCount = 2 , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            Matcher = { " HttpCode " :  " 200 " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    invalid_names  =  [ " -name " ,  " name- " ,  " -name- " ,  " example.com " ,  " test@test " ,  " Na--me " ] 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-19 00:16:11 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    for  name  in  invalid_names : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        with  assert_raises ( ClientError ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            conn . create_target_group ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                Name = name , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                Protocol = " HTTP " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-19 00:16:11 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                Port = 8080 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                VpcId = vpc . id , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                HealthCheckProtocol = " HTTP " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                HealthCheckPort = " 8080 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                HealthCheckPath = " / " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-19 00:16:11 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                HealthCheckIntervalSeconds = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                HealthCheckTimeoutSeconds = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                HealthyThresholdCount = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                UnhealthyThresholdCount = 2 , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                Matcher = { " HttpCode " :  " 200 " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-19 00:16:11 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    valid_names  =  [ " name " ,  " Name " ,  " 000 " ] 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-19 00:16:11 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    for  name  in  valid_names : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        conn . create_target_group ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            Name = name , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            Protocol = " HTTP " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-19 00:16:11 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            Port = 8080 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            VpcId = vpc . id , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            HealthCheckProtocol = " HTTP " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            HealthCheckPort = " 8080 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            HealthCheckPath = " / " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-19 00:16:11 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            HealthCheckIntervalSeconds = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            HealthCheckTimeoutSeconds = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            HealthyThresholdCount = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            UnhealthyThresholdCount = 2 , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            Matcher = { " HttpCode " :  " 200 " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-19 00:16:11 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_elbv2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_ec2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								def  test_describe_paginated_balancers ( ) :  
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    conn  =  boto3 . client ( " elbv2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ec2  =  boto3 . resource ( " ec2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    security_group  =  ec2 . create_security_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        GroupName = " a-security-group " ,  Description = " First One " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    vpc  =  ec2 . create_vpc ( CidrBlock = " 172.28.7.0/24 " ,  InstanceTenancy = " default " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet1  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.192/26 " ,  AvailabilityZone = " us-east-1a " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet2  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.0/26 " ,  AvailabilityZone = " us-east-1b " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    for  i  in  range ( 51 ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        conn . create_load_balancer ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            Name = " my-lb %d "  %  i , 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            Subnets = [ subnet1 . id ,  subnet2 . id ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            SecurityGroups = [ security_group . id ] , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            Scheme = " internal " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            Tags = [ { " Key " :  " key_name " ,  " Value " :  " a_value " } ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    resp  =  conn . describe_load_balancers ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    resp [ " LoadBalancers " ] . should . have . length_of ( 50 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    resp [ " NextMarker " ] . should . equal ( resp [ " LoadBalancers " ] [ - 1 ] [ " LoadBalancerName " ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    resp2  =  conn . describe_load_balancers ( Marker = resp [ " NextMarker " ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    resp2 [ " LoadBalancers " ] . should . have . length_of ( 1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    assert  " NextToken "  not  in  resp2 . keys ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_elbv2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_ec2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								def  test_delete_load_balancer ( ) :  
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    conn  =  boto3 . client ( " elbv2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ec2  =  boto3 . resource ( " ec2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    security_group  =  ec2 . create_security_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        GroupName = " a-security-group " ,  Description = " First One " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    vpc  =  ec2 . create_vpc ( CidrBlock = " 172.28.7.0/24 " ,  InstanceTenancy = " default " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet1  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.192/26 " ,  AvailabilityZone = " us-east-1a " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet2  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.0/26 " ,  AvailabilityZone = " us-east-1b " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . create_load_balancer ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Name = " my-lb " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        Subnets = [ subnet1 . id ,  subnet2 . id ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        SecurityGroups = [ security_group . id ] , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Scheme = " internal " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Tags = [ { " Key " :  " key_name " ,  " Value " :  " a_value " } ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    response . get ( " LoadBalancers " ) . should . have . length_of ( 1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    lb  =  response . get ( " LoadBalancers " ) [ 0 ] 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    conn . delete_load_balancer ( LoadBalancerArn = lb . get ( " LoadBalancerArn " ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    balancers  =  conn . describe_load_balancers ( ) . get ( " LoadBalancers " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    balancers . should . have . length_of ( 0 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_ec2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_elbv2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								def  test_register_targets ( ) :  
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    conn  =  boto3 . client ( " elbv2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ec2  =  boto3 . resource ( " ec2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    security_group  =  ec2 . create_security_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        GroupName = " a-security-group " ,  Description = " First One " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    vpc  =  ec2 . create_vpc ( CidrBlock = " 172.28.7.0/24 " ,  InstanceTenancy = " default " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet1  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.192/26 " ,  AvailabilityZone = " us-east-1a " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet2  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.0/26 " ,  AvailabilityZone = " us-east-1b " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    conn . create_load_balancer ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Name = " my-lb " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        Subnets = [ subnet1 . id ,  subnet2 . id ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        SecurityGroups = [ security_group . id ] , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Scheme = " internal " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Tags = [ { " Key " :  " key_name " ,  " Value " :  " a_value " } ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . create_target_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Name = " a-target " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Protocol = " HTTP " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        Port = 8080 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        VpcId = vpc . id , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        HealthCheckProtocol = " HTTP " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthCheckPort = " 8080 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthCheckPath = " / " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        HealthCheckIntervalSeconds = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthCheckTimeoutSeconds = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthyThresholdCount = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        UnhealthyThresholdCount = 2 , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Matcher = { " HttpCode " :  " 200 " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    target_group  =  response . get ( " TargetGroups " ) [ 0 ] 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # No targets registered yet 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    response  =  conn . describe_target_health ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        TargetGroupArn = target_group . get ( " TargetGroupArn " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response . get ( " TargetHealthDescriptions " ) . should . have . length_of ( 0 ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    response  =  ec2 . create_instances ( ImageId = " ami-1234abcd " ,  MinCount = 2 ,  MaxCount = 2 ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    instance_id1  =  response [ 0 ] . id 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    instance_id2  =  response [ 1 ] . id 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . register_targets ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        TargetGroupArn = target_group . get ( " TargetGroupArn " ) , 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        Targets = [ 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            { " Id " :  instance_id1 ,  " Port " :  5060 } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            { " Id " :  instance_id2 ,  " Port " :  4030 } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    response  =  conn . describe_target_health ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        TargetGroupArn = target_group . get ( " TargetGroupArn " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response . get ( " TargetHealthDescriptions " ) . should . have . length_of ( 2 ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . deregister_targets ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        TargetGroupArn = target_group . get ( " TargetGroupArn " ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Targets = [ { " Id " :  instance_id2 } ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-07-20 15:00:30 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    response  =  conn . describe_target_health ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        TargetGroupArn = target_group . get ( " TargetGroupArn " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response . get ( " TargetHealthDescriptions " ) . should . have . length_of ( 1 ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-02 15:57:15 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-07-18 16:25:41 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								@mock_ec2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_elbv2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								def  test_stopped_instance_target ( ) :  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    target_group_port  =  8080 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    conn  =  boto3 . client ( " elbv2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ec2  =  boto3 . resource ( " ec2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-07-18 16:25:41 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    security_group  =  ec2 . create_security_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        GroupName = " a-security-group " ,  Description = " First One " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    vpc  =  ec2 . create_vpc ( CidrBlock = " 172.28.7.0/24 " ,  InstanceTenancy = " default " ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-07-18 16:25:41 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet1  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.192/26 " ,  AvailabilityZone = " us-east-1a " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-07-18 16:25:41 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet2  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.0/26 " ,  AvailabilityZone = " us-east-1b " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-07-18 16:25:41 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    conn . create_load_balancer ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Name = " my-lb " , 
							 
						 
					
						
							
								
									
										
										
										
											2019-07-18 16:25:41 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Subnets = [ subnet1 . id ,  subnet2 . id ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        SecurityGroups = [ security_group . id ] , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Scheme = " internal " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Tags = [ { " Key " :  " key_name " ,  " Value " :  " a_value " } ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-07-18 16:25:41 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . create_target_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Name = " a-target " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Protocol = " HTTP " , 
							 
						 
					
						
							
								
									
										
										
										
											2019-07-18 16:25:41 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Port = target_group_port , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        VpcId = vpc . id , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        HealthCheckProtocol = " HTTP " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthCheckPath = " / " , 
							 
						 
					
						
							
								
									
										
										
										
											2019-07-18 16:25:41 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        HealthCheckIntervalSeconds = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthCheckTimeoutSeconds = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthyThresholdCount = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        UnhealthyThresholdCount = 2 , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Matcher = { " HttpCode " :  " 200 " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    target_group  =  response . get ( " TargetGroups " ) [ 0 ] 
							 
						 
					
						
							
								
									
										
										
										
											2019-07-18 16:25:41 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # No targets registered yet 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . describe_target_health ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        TargetGroupArn = target_group . get ( " TargetGroupArn " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response . get ( " TargetHealthDescriptions " ) . should . have . length_of ( 0 ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-07-18 16:25:41 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    response  =  ec2 . create_instances ( ImageId = " ami-1234abcd " ,  MinCount = 1 ,  MaxCount = 1 ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-07-18 16:25:41 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    instance  =  response [ 0 ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    target_dict  =  { " Id " :  instance . id ,  " Port " :  500 } 
							 
						 
					
						
							
								
									
										
										
										
											2019-07-18 16:25:41 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . register_targets ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        TargetGroupArn = target_group . get ( " TargetGroupArn " ) ,  Targets = [ target_dict ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-07-18 16:25:41 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . describe_target_health ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        TargetGroupArn = target_group . get ( " TargetGroupArn " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response . get ( " TargetHealthDescriptions " ) . should . have . length_of ( 1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    target_health_description  =  response . get ( " TargetHealthDescriptions " ) [ 0 ] 
							 
						 
					
						
							
								
									
										
										
										
											2019-07-18 16:25:41 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    target_health_description [ " Target " ] . should . equal ( target_dict ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    target_health_description [ " HealthCheckPort " ] . should . equal ( str ( target_group_port ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    target_health_description [ " TargetHealth " ] . should . equal ( { " State " :  " healthy " } ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-07-18 16:25:41 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    instance . stop ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . describe_target_health ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        TargetGroupArn = target_group . get ( " TargetGroupArn " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response . get ( " TargetHealthDescriptions " ) . should . have . length_of ( 1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    target_health_description  =  response . get ( " TargetHealthDescriptions " ) [ 0 ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    target_health_description [ " Target " ] . should . equal ( target_dict ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    target_health_description [ " HealthCheckPort " ] . should . equal ( str ( target_group_port ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    target_health_description [ " TargetHealth " ] . should . equal ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " State " :  " unused " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " Reason " :  " Target.InvalidState " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " Description " :  " Target is in the stopped state " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-07-18 16:25:41 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-08-30 18:21:11 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								@mock_ec2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_elbv2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								def  test_terminated_instance_target ( ) :  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    target_group_port  =  8080 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    conn  =  boto3 . client ( " elbv2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ec2  =  boto3 . resource ( " ec2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-30 18:21:11 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    security_group  =  ec2 . create_security_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        GroupName = " a-security-group " ,  Description = " First One " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    vpc  =  ec2 . create_vpc ( CidrBlock = " 172.28.7.0/24 " ,  InstanceTenancy = " default " ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-30 18:21:11 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet1  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.192/26 " ,  AvailabilityZone = " us-east-1a " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-30 18:21:11 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet2  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.0/26 " ,  AvailabilityZone = " us-east-1b " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-30 18:21:11 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    conn . create_load_balancer ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Name = " my-lb " , 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-30 18:21:11 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Subnets = [ subnet1 . id ,  subnet2 . id ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        SecurityGroups = [ security_group . id ] , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Scheme = " internal " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Tags = [ { " Key " :  " key_name " ,  " Value " :  " a_value " } ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-30 18:21:11 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . create_target_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Name = " a-target " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Protocol = " HTTP " , 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-30 18:21:11 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Port = target_group_port , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        VpcId = vpc . id , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        HealthCheckProtocol = " HTTP " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthCheckPath = " / " , 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-30 18:21:11 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        HealthCheckIntervalSeconds = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthCheckTimeoutSeconds = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthyThresholdCount = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        UnhealthyThresholdCount = 2 , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Matcher = { " HttpCode " :  " 200 " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    target_group  =  response . get ( " TargetGroups " ) [ 0 ] 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-30 18:21:11 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # No targets registered yet 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . describe_target_health ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        TargetGroupArn = target_group . get ( " TargetGroupArn " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response . get ( " TargetHealthDescriptions " ) . should . have . length_of ( 0 ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-30 18:21:11 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    response  =  ec2 . create_instances ( ImageId = " ami-1234abcd " ,  MinCount = 1 ,  MaxCount = 1 ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-30 18:21:11 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    instance  =  response [ 0 ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    target_dict  =  { " Id " :  instance . id ,  " Port " :  500 } 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-30 18:21:11 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . register_targets ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        TargetGroupArn = target_group . get ( " TargetGroupArn " ) ,  Targets = [ target_dict ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-30 18:21:11 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . describe_target_health ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        TargetGroupArn = target_group . get ( " TargetGroupArn " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response . get ( " TargetHealthDescriptions " ) . should . have . length_of ( 1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    target_health_description  =  response . get ( " TargetHealthDescriptions " ) [ 0 ] 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-30 18:21:11 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    target_health_description [ " Target " ] . should . equal ( target_dict ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    target_health_description [ " HealthCheckPort " ] . should . equal ( str ( target_group_port ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    target_health_description [ " TargetHealth " ] . should . equal ( { " State " :  " healthy " } ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-30 18:21:11 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    instance . terminate ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . describe_target_health ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        TargetGroupArn = target_group . get ( " TargetGroupArn " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response . get ( " TargetHealthDescriptions " ) . should . have . length_of ( 0 ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-30 18:21:11 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-08-02 15:57:15 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								@mock_ec2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_elbv2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								def  test_target_group_attributes ( ) :  
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    conn  =  boto3 . client ( " elbv2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ec2  =  boto3 . resource ( " ec2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-02 15:57:15 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    security_group  =  ec2 . create_security_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        GroupName = " a-security-group " ,  Description = " First One " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    vpc  =  ec2 . create_vpc ( CidrBlock = " 172.28.7.0/24 " ,  InstanceTenancy = " default " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet1  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.192/26 " ,  AvailabilityZone = " us-east-1a " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet2  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.0/26 " ,  AvailabilityZone = " us-east-1b " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-02 15:57:15 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . create_load_balancer ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Name = " my-lb " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-02 15:57:15 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Subnets = [ subnet1 . id ,  subnet2 . id ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        SecurityGroups = [ security_group . id ] , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Scheme = " internal " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Tags = [ { " Key " :  " key_name " ,  " Value " :  " a_value " } ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-02 15:57:15 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . create_target_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Name = " a-target " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Protocol = " HTTP " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-02 15:57:15 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Port = 8080 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        VpcId = vpc . id , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        HealthCheckProtocol = " HTTP " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthCheckPort = " 8080 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthCheckPath = " / " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-02 15:57:15 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        HealthCheckIntervalSeconds = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthCheckTimeoutSeconds = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthyThresholdCount = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        UnhealthyThresholdCount = 2 , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Matcher = { " HttpCode " :  " 200 " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    target_group  =  response . get ( " TargetGroups " ) [ 0 ] 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-02 15:57:15 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # Check it's in the describe_target_groups response 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . describe_target_groups ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    response . get ( " TargetGroups " ) . should . have . length_of ( 1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    target_group_arn  =  target_group [ " TargetGroupArn " ] 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-02 15:57:15 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-08-18 15:56:53 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    # check if Names filter works 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . describe_target_groups ( Names = [ ] ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    response  =  conn . describe_target_groups ( Names = [ " a-target " ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response . get ( " TargetGroups " ) . should . have . length_of ( 1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    target_group_arn  =  target_group [ " TargetGroupArn " ] 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-18 15:56:53 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-08-02 15:57:15 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    # The attributes should start with the two defaults 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    response  =  conn . describe_target_group_attributes ( TargetGroupArn = target_group_arn ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response [ " Attributes " ] . should . have . length_of ( 2 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    attributes  =  { attr [ " Key " ] :  attr [ " Value " ]  for  attr  in  response [ " Attributes " ] } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    attributes [ " deregistration_delay.timeout_seconds " ] . should . equal ( " 300 " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    attributes [ " stickiness.enabled " ] . should . equal ( " false " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-02 15:57:15 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-08-02 15:58:32 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    # Add cookie stickiness 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-02 15:57:15 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    response  =  conn . modify_target_group_attributes ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        TargetGroupArn = target_group_arn , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Attributes = [ 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            { " Key " :  " stickiness.enabled " ,  " Value " :  " true " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            { " Key " :  " stickiness.type " ,  " Value " :  " lb_cookie " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-02 15:57:15 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-08-02 15:58:32 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    # The response should have only the keys updated 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    response [ " Attributes " ] . should . have . length_of ( 2 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    attributes  =  { attr [ " Key " ] :  attr [ " Value " ]  for  attr  in  response [ " Attributes " ] } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    attributes [ " stickiness.type " ] . should . equal ( " lb_cookie " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    attributes [ " stickiness.enabled " ] . should . equal ( " true " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-02 15:57:15 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # These new values should be in the full attribute list 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    response  =  conn . describe_target_group_attributes ( TargetGroupArn = target_group_arn ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response [ " Attributes " ] . should . have . length_of ( 3 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    attributes  =  { attr [ " Key " ] :  attr [ " Value " ]  for  attr  in  response [ " Attributes " ] } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    attributes [ " stickiness.type " ] . should . equal ( " lb_cookie " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    attributes [ " stickiness.enabled " ] . should . equal ( " true " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 21:09:14 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_elbv2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_ec2  
						 
					
						
							
								
									
										
										
										
											2017-08-17 04:28:32 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								def  test_handle_listener_rules ( ) :  
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    conn  =  boto3 . client ( " elbv2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ec2  =  boto3 . resource ( " ec2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 21:09:14 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    security_group  =  ec2 . create_security_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        GroupName = " a-security-group " ,  Description = " First One " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    vpc  =  ec2 . create_vpc ( CidrBlock = " 172.28.7.0/24 " ,  InstanceTenancy = " default " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet1  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.192/26 " ,  AvailabilityZone = " us-east-1a " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet2  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.0/26 " ,  AvailabilityZone = " us-east-1b " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 21:09:14 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . create_load_balancer ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Name = " my-lb " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 21:09:14 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Subnets = [ subnet1 . id ,  subnet2 . id ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        SecurityGroups = [ security_group . id ] , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Scheme = " internal " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Tags = [ { " Key " :  " key_name " ,  " Value " :  " a_value " } ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 21:09:14 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    load_balancer_arn  =  response . get ( " LoadBalancers " ) [ 0 ] . get ( " LoadBalancerArn " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 21:09:14 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-27 03:16:06 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    # Can't create a target group with an invalid protocol 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    with  assert_raises ( ClientError ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        conn . create_target_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            Name = " a-target " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            Protocol = " HTTP " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-27 03:16:06 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            Port = 8080 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            VpcId = vpc . id , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            HealthCheckProtocol = " /HTTP " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            HealthCheckPort = " 8080 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            HealthCheckPath = " / " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-27 03:16:06 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            HealthCheckIntervalSeconds = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            HealthCheckTimeoutSeconds = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            HealthyThresholdCount = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            UnhealthyThresholdCount = 2 , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            Matcher = { " HttpCode " :  " 200 " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 21:09:14 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    response  =  conn . create_target_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Name = " a-target " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Protocol = " HTTP " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 21:09:14 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Port = 8080 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        VpcId = vpc . id , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        HealthCheckProtocol = " HTTP " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthCheckPort = " 8080 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthCheckPath = " / " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 21:09:14 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        HealthCheckIntervalSeconds = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthCheckTimeoutSeconds = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthyThresholdCount = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        UnhealthyThresholdCount = 2 , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Matcher = { " HttpCode " :  " 200 " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    target_group  =  response . get ( " TargetGroups " ) [ 0 ] 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 21:09:14 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # Plain HTTP listener 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . create_listener ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        LoadBalancerArn = load_balancer_arn , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Protocol = " HTTP " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 21:09:14 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Port = 80 , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        DefaultActions = [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            { " Type " :  " forward " ,  " TargetGroupArn " :  target_group . get ( " TargetGroupArn " ) } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    listener  =  response . get ( " Listeners " ) [ 0 ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    listener . get ( " Port " ) . should . equal ( 80 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    listener . get ( " Protocol " ) . should . equal ( " HTTP " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    listener . get ( " DefaultActions " ) . should . equal ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        [ { " TargetGroupArn " :  target_group . get ( " TargetGroupArn " ) ,  " Type " :  " forward " } ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    http_listener_arn  =  listener . get ( " ListenerArn " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 21:09:14 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # create first rule 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    priority  =  100 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    host  =  " xxx.example.com " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    path_pattern  =  " foobar " 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-17 02:29:49 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    created_rule  =  conn . create_rule ( 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 21:09:14 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        ListenerArn = http_listener_arn , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Priority = priority , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Conditions = [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            { " Field " :  " host-header " ,  " Values " :  [ host ] } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            { " Field " :  " path-pattern " ,  " Values " :  [ path_pattern ] } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Actions = [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            { " TargetGroupArn " :  target_group . get ( " TargetGroupArn " ) ,  " Type " :  " forward " } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) [ " Rules " ] [ 0 ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    created_rule [ " Priority " ] . should . equal ( " 100 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 21:09:14 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # check if rules is sorted by priority 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    priority  =  50 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    host  =  " yyy.example.com " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    path_pattern  =  " foobar " 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 21:09:14 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    rules  =  conn . create_rule ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ListenerArn = http_listener_arn , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Priority = priority , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Conditions = [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            { " Field " :  " host-header " ,  " Values " :  [ host ] } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            { " Field " :  " path-pattern " ,  " Values " :  [ path_pattern ] } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Actions = [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            { " TargetGroupArn " :  target_group . get ( " TargetGroupArn " ) ,  " Type " :  " forward " } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ] , 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 21:09:14 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-08-17 03:10:26 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    # test for PriorityInUse 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    with  assert_raises ( ClientError ) : 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:38:36 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        conn . create_rule ( 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-17 03:10:26 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            ListenerArn = http_listener_arn , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            Priority = priority , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            Conditions = [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                { " Field " :  " host-header " ,  " Values " :  [ host ] } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                { " Field " :  " path-pattern " ,  " Values " :  [ path_pattern ] } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            Actions = [ 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                { 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    " TargetGroupArn " :  target_group . get ( " TargetGroupArn " ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " Type " :  " forward " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ] , 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-17 03:10:26 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-08-17 01:57:02 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    # test for describe listeners 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    obtained_rules  =  conn . describe_rules ( ListenerArn = http_listener_arn ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    len ( obtained_rules [ " Rules " ] ) . should . equal ( 3 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    priorities  =  [ rule [ " Priority " ]  for  rule  in  obtained_rules [ " Rules " ] ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    priorities . should . equal ( [ " 50 " ,  " 100 " ,  " default " ] ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-17 01:57:02 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    first_rule  =  obtained_rules [ " Rules " ] [ 0 ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    second_rule  =  obtained_rules [ " Rules " ] [ 1 ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    obtained_rules  =  conn . describe_rules ( RuleArns = [ first_rule [ " RuleArn " ] ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    obtained_rules [ " Rules " ] . should . equal ( [ first_rule ] ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-17 01:57:02 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # test for pagination 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    obtained_rules  =  conn . describe_rules ( ListenerArn = http_listener_arn ,  PageSize = 1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    len ( obtained_rules [ " Rules " ] ) . should . equal ( 1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    obtained_rules . should . have . key ( " NextMarker " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    next_marker  =  obtained_rules [ " NextMarker " ] 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-17 04:37:42 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    following_rules  =  conn . describe_rules ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        ListenerArn = http_listener_arn ,  PageSize = 1 ,  Marker = next_marker 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    len ( following_rules [ " Rules " ] ) . should . equal ( 1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    following_rules . should . have . key ( " NextMarker " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    following_rules [ " Rules " ] [ 0 ] [ " RuleArn " ] . should_not . equal ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        obtained_rules [ " Rules " ] [ 0 ] [ " RuleArn " ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-17 01:57:02 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # test for invalid describe rule request 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    with  assert_raises ( ClientError ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        conn . describe_rules ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    with  assert_raises ( ClientError ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        conn . describe_rules ( RuleArns = [ ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    with  assert_raises ( ClientError ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        conn . describe_rules ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            ListenerArn = http_listener_arn ,  RuleArns = [ first_rule [ " RuleArn " ] ] 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-17 01:57:02 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-08-22 04:28:58 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    # modify rule partially 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    new_host  =  " new.example.com " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    new_path_pattern  =  " new_path " 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-17 02:25:39 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    modified_rule  =  conn . modify_rule ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        RuleArn = first_rule [ " RuleArn " ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Conditions = [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            { " Field " :  " host-header " ,  " Values " :  [ new_host ] } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            { " Field " :  " path-pattern " ,  " Values " :  [ new_path_pattern ] } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) [ " Rules " ] [ 0 ] 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-22 04:28:58 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-08-17 02:25:39 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    rules  =  conn . describe_rules ( ListenerArn = http_listener_arn ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    obtained_rule  =  rules [ " Rules " ] [ 0 ] 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-22 04:28:58 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    modified_rule . should . equal ( obtained_rule ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    obtained_rule [ " Conditions " ] [ 0 ] [ " Values " ] [ 0 ] . should . equal ( new_host ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    obtained_rule [ " Conditions " ] [ 1 ] [ " Values " ] [ 0 ] . should . equal ( new_path_pattern ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    obtained_rule [ " Actions " ] [ 0 ] [ " TargetGroupArn " ] . should . equal ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        target_group . get ( " TargetGroupArn " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-17 02:25:39 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-08-17 03:10:26 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    # modify priority 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    conn . set_rule_priorities ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        RulePriorities = [ 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " RuleArn " :  first_rule [ " RuleArn " ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Priority " :  int ( first_rule [ " Priority " ] )  -  1 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-17 03:10:26 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    with  assert_raises ( ClientError ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        conn . set_rule_priorities ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            RulePriorities = [ 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                { " RuleArn " :  first_rule [ " RuleArn " ] ,  " Priority " :  999 } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                { " RuleArn " :  second_rule [ " RuleArn " ] ,  " Priority " :  999 } , 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-17 03:10:26 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-08-17 01:57:02 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    # delete 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    arn  =  first_rule [ " RuleArn " ] 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-17 00:35:45 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    conn . delete_rule ( RuleArn = arn ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    rules  =  conn . describe_rules ( ListenerArn = http_listener_arn ) [ " Rules " ] 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-22 04:30:03 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    len ( rules ) . should . equal ( 2 ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-17 00:35:45 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 21:09:14 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    # test for invalid action type 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    safe_priority  =  2 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    with  assert_raises ( ClientError ) : 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:38:36 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        conn . create_rule ( 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 21:09:14 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            ListenerArn = http_listener_arn , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            Priority = safe_priority , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            Conditions = [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                { " Field " :  " host-header " ,  " Values " :  [ host ] } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                { " Field " :  " path-pattern " ,  " Values " :  [ path_pattern ] } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            Actions = [ 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                { 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    " TargetGroupArn " :  target_group . get ( " TargetGroupArn " ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " Type " :  " forward2 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ] , 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 21:09:14 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # test for invalid action type 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    safe_priority  =  2 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    invalid_target_group_arn  =  target_group . get ( " TargetGroupArn " )  +  " x " 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 21:09:14 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    with  assert_raises ( ClientError ) : 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:38:36 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        conn . create_rule ( 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 21:09:14 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            ListenerArn = http_listener_arn , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            Priority = safe_priority , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            Conditions = [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                { " Field " :  " host-header " ,  " Values " :  [ host ] } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                { " Field " :  " path-pattern " ,  " Values " :  [ path_pattern ] } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            Actions = [ { " TargetGroupArn " :  invalid_target_group_arn ,  " Type " :  " forward " } ] , 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 21:09:14 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # test for invalid condition field_name 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    safe_priority  =  2 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    with  assert_raises ( ClientError ) : 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:38:36 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        conn . create_rule ( 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 21:09:14 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            ListenerArn = http_listener_arn , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            Priority = safe_priority , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            Conditions = [ { " Field " :  " xxxxxxx " ,  " Values " :  [ host ] } ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            Actions = [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " TargetGroupArn " :  target_group . get ( " TargetGroupArn " ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " Type " :  " forward " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ] , 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 21:09:14 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # test for emptry condition value 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    safe_priority  =  2 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    with  assert_raises ( ClientError ) : 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:38:36 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        conn . create_rule ( 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 21:09:14 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            ListenerArn = http_listener_arn , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            Priority = safe_priority , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            Conditions = [ { " Field " :  " host-header " ,  " Values " :  [ ] } ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            Actions = [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " TargetGroupArn " :  target_group . get ( " TargetGroupArn " ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " Type " :  " forward " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ] , 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 21:09:14 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # test for multiple condition value 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    safe_priority  =  2 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    with  assert_raises ( ClientError ) : 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:38:36 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        conn . create_rule ( 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 21:09:14 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            ListenerArn = http_listener_arn , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            Priority = safe_priority , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            Conditions = [ { " Field " :  " host-header " ,  " Values " :  [ host ,  host ] } ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            Actions = [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " TargetGroupArn " :  target_group . get ( " TargetGroupArn " ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " Type " :  " forward " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ] , 
							 
						 
					
						
							
								
									
										
										
										
											2017-08-16 21:09:14 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-08 03:25:59 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_elbv2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_ec2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								def  test_describe_invalid_target_group ( ) :  
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    conn  =  boto3 . client ( " elbv2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ec2  =  boto3 . resource ( " ec2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-08 03:25:59 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    security_group  =  ec2 . create_security_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        GroupName = " a-security-group " ,  Description = " First One " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    vpc  =  ec2 . create_vpc ( CidrBlock = " 172.28.7.0/24 " ,  InstanceTenancy = " default " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet1  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.192/26 " ,  AvailabilityZone = " us-east-1a " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-02 12:36:47 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet2  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.0/26 " ,  AvailabilityZone = " us-east-1b " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-08 03:25:59 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . create_load_balancer ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Name = " my-lb " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-08 03:25:59 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Subnets = [ subnet1 . id ,  subnet2 . id ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        SecurityGroups = [ security_group . id ] , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Scheme = " internal " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Tags = [ { " Key " :  " key_name " ,  " Value " :  " a_value " } ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-08 03:25:59 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    response . get ( " LoadBalancers " ) [ 0 ] . get ( " LoadBalancerArn " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-08 03:25:59 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . create_target_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Name = " a-target " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Protocol = " HTTP " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-08 03:25:59 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Port = 8080 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        VpcId = vpc . id , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        HealthCheckProtocol = " HTTP " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthCheckPort = " 8080 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthCheckPath = " / " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-08 03:25:59 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        HealthCheckIntervalSeconds = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthCheckTimeoutSeconds = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthyThresholdCount = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        UnhealthyThresholdCount = 2 , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Matcher = { " HttpCode " :  " 200 " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-09-08 03:25:59 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # Check error raises correctly 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    with  assert_raises ( ClientError ) : 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        conn . describe_target_groups ( Names = [ " invalid " ] ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-04-11 18:16:56 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								@mock_elbv2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_ec2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								def  test_describe_target_groups_no_arguments ( ) :  
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    conn  =  boto3 . client ( " elbv2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ec2  =  boto3 . resource ( " ec2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-11 18:16:56 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    security_group  =  ec2 . create_security_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        GroupName = " a-security-group " ,  Description = " First One " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    vpc  =  ec2 . create_vpc ( CidrBlock = " 172.28.7.0/24 " ,  InstanceTenancy = " default " ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-11 18:16:56 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet1  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.192/26 " ,  AvailabilityZone = " us-east-1a " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-11 18:16:56 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet2  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.0/26 " ,  AvailabilityZone = " us-east-1b " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-11 18:16:56 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . create_load_balancer ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Name = " my-lb " , 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-11 18:16:56 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Subnets = [ subnet1 . id ,  subnet2 . id ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        SecurityGroups = [ security_group . id ] , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Scheme = " internal " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Tags = [ { " Key " :  " key_name " ,  " Value " :  " a_value " } ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-11 18:16:56 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    response . get ( " LoadBalancers " ) [ 0 ] . get ( " LoadBalancerArn " ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-11 18:16:56 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    conn . create_target_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Name = " a-target " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Protocol = " HTTP " , 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-11 18:16:56 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Port = 8080 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        VpcId = vpc . id , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        HealthCheckProtocol = " HTTP " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthCheckPort = " 8080 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthCheckPath = " / " , 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-11 18:16:56 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        HealthCheckIntervalSeconds = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthCheckTimeoutSeconds = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthyThresholdCount = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        UnhealthyThresholdCount = 2 , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Matcher = { " HttpCode " :  " 200 " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-11 18:16:56 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    assert  len ( conn . describe_target_groups ( ) [ " TargetGroups " ] )  ==  1 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-11 18:16:56 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								@mock_elbv2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								def  test_describe_account_limits ( ) :  
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    client  =  boto3 . client ( " elbv2 " ,  region_name = " eu-central-1 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    resp  =  client . describe_account_limits ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    resp [ " Limits " ] [ 0 ] . should . contain ( " Name " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    resp [ " Limits " ] [ 0 ] . should . contain ( " Max " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_elbv2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								def  test_describe_ssl_policies ( ) :  
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    client  =  boto3 . client ( " elbv2 " ,  region_name = " eu-central-1 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    resp  =  client . describe_ssl_policies ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    len ( resp [ " SslPolicies " ] ) . should . equal ( 5 ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    resp  =  client . describe_ssl_policies ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Names = [ " ELBSecurityPolicy-TLS-1-2-2017-01 " ,  " ELBSecurityPolicy-2016-08 " ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    len ( resp [ " SslPolicies " ] ) . should . equal ( 2 ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_elbv2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_ec2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								def  test_set_ip_address_type ( ) :  
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    client  =  boto3 . client ( " elbv2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ec2  =  boto3 . resource ( " ec2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    security_group  =  ec2 . create_security_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        GroupName = " a-security-group " ,  Description = " First One " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    vpc  =  ec2 . create_vpc ( CidrBlock = " 172.28.7.0/24 " ,  InstanceTenancy = " default " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet1  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.192/26 " ,  AvailabilityZone = " us-east-1a " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet2  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.0/26 " ,  AvailabilityZone = " us-east-1b " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  client . create_load_balancer ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Name = " my-lb " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Subnets = [ subnet1 . id ,  subnet2 . id ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        SecurityGroups = [ security_group . id ] , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Scheme = " internal " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Tags = [ { " Key " :  " key_name " ,  " Value " :  " a_value " } ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    arn  =  response [ " LoadBalancers " ] [ 0 ] [ " LoadBalancerArn " ] 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # Internal LBs cant be dualstack yet 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    with  assert_raises ( ClientError ) : 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        client . set_ip_address_type ( LoadBalancerArn = arn ,  IpAddressType = " dualstack " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # Create internet facing one 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  client . create_load_balancer ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Name = " my-lb2 " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Subnets = [ subnet1 . id ,  subnet2 . id ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        SecurityGroups = [ security_group . id ] , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Scheme = " internet-facing " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Tags = [ { " Key " :  " key_name " ,  " Value " :  " a_value " } ] , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    arn  =  response [ " LoadBalancers " ] [ 0 ] [ " LoadBalancerArn " ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    client . set_ip_address_type ( LoadBalancerArn = arn ,  IpAddressType = " dualstack " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_elbv2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_ec2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								def  test_set_security_groups ( ) :  
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    client  =  boto3 . client ( " elbv2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ec2  =  boto3 . resource ( " ec2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    security_group  =  ec2 . create_security_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        GroupName = " a-security-group " ,  Description = " First One " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    security_group2  =  ec2 . create_security_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        GroupName = " b-security-group " ,  Description = " Second One " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    vpc  =  ec2 . create_vpc ( CidrBlock = " 172.28.7.0/24 " ,  InstanceTenancy = " default " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet1  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.192/26 " ,  AvailabilityZone = " us-east-1a " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet2  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.0/26 " ,  AvailabilityZone = " us-east-1b " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  client . create_load_balancer ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Name = " my-lb " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Subnets = [ subnet1 . id ,  subnet2 . id ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        SecurityGroups = [ security_group . id ] , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Scheme = " internal " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Tags = [ { " Key " :  " key_name " ,  " Value " :  " a_value " } ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    arn  =  response [ " LoadBalancers " ] [ 0 ] [ " LoadBalancerArn " ] 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    client . set_security_groups ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        LoadBalancerArn = arn ,  SecurityGroups = [ security_group . id ,  security_group2 . id ] 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    resp  =  client . describe_load_balancers ( LoadBalancerArns = [ arn ] ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    len ( resp [ " LoadBalancers " ] [ 0 ] [ " SecurityGroups " ] ) . should . equal ( 2 ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    with  assert_raises ( ClientError ) : 
							 
						 
					
						
							
								
									
										
										
										
											2020-01-20 15:21:11 -08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        client . set_security_groups ( LoadBalancerArn = arn ,  SecurityGroups = [ " non_existent " ] ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_elbv2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_ec2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								def  test_set_subnets ( ) :  
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    client  =  boto3 . client ( " elbv2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ec2  =  boto3 . resource ( " ec2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    security_group  =  ec2 . create_security_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        GroupName = " a-security-group " ,  Description = " First One " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    vpc  =  ec2 . create_vpc ( CidrBlock = " 172.28.7.0/24 " ,  InstanceTenancy = " default " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet1  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.0/26 " ,  AvailabilityZone = " us-east-1a " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet2  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.64/26 " ,  AvailabilityZone = " us-east-1b " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet3  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.192/26 " ,  AvailabilityZone = " us-east-1c " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  client . create_load_balancer ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Name = " my-lb " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Subnets = [ subnet1 . id ,  subnet2 . id ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        SecurityGroups = [ security_group . id ] , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Scheme = " internal " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Tags = [ { " Key " :  " key_name " ,  " Value " :  " a_value " } ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    arn  =  response [ " LoadBalancers " ] [ 0 ] [ " LoadBalancerArn " ] 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    client . set_subnets ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        LoadBalancerArn = arn ,  Subnets = [ subnet1 . id ,  subnet2 . id ,  subnet3 . id ] 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    resp  =  client . describe_load_balancers ( LoadBalancerArns = [ arn ] ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    len ( resp [ " LoadBalancers " ] [ 0 ] [ " AvailabilityZones " ] ) . should . equal ( 3 ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # Only 1 AZ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    with  assert_raises ( ClientError ) : 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        client . set_subnets ( LoadBalancerArn = arn ,  Subnets = [ subnet1 . id ] ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # Multiple subnets in same AZ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    with  assert_raises ( ClientError ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        client . set_subnets ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            LoadBalancerArn = arn ,  Subnets = [ subnet1 . id ,  subnet2 . id ,  subnet2 . id ] 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_elbv2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_ec2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								def  test_set_subnets ( ) :  
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    client  =  boto3 . client ( " elbv2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ec2  =  boto3 . resource ( " ec2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    security_group  =  ec2 . create_security_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        GroupName = " a-security-group " ,  Description = " First One " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    vpc  =  ec2 . create_vpc ( CidrBlock = " 172.28.7.0/24 " ,  InstanceTenancy = " default " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet1  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.192/26 " ,  AvailabilityZone = " us-east-1a " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet2  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.0/26 " ,  AvailabilityZone = " us-east-1b " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  client . create_load_balancer ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Name = " my-lb " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Subnets = [ subnet1 . id ,  subnet2 . id ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        SecurityGroups = [ security_group . id ] , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Scheme = " internal " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Tags = [ { " Key " :  " key_name " ,  " Value " :  " a_value " } ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    arn  =  response [ " LoadBalancers " ] [ 0 ] [ " LoadBalancerArn " ] 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    client . modify_load_balancer_attributes ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        LoadBalancerArn = arn , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Attributes = [ { " Key " :  " idle_timeout.timeout_seconds " ,  " Value " :  " 600 " } ] , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # Check its 600 not 60 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    response  =  client . describe_load_balancer_attributes ( LoadBalancerArn = arn ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    idle_timeout  =  list ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        filter ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            lambda  item :  item [ " Key " ]  ==  " idle_timeout.timeout_seconds " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            response [ " Attributes " ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) [ 0 ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    idle_timeout [ " Value " ] . should . equal ( " 600 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_elbv2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_ec2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								def  test_modify_target_group ( ) :  
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    client  =  boto3 . client ( " elbv2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ec2  =  boto3 . resource ( " ec2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    vpc  =  ec2 . create_vpc ( CidrBlock = " 172.28.7.0/24 " ,  InstanceTenancy = " default " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  client . create_target_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Name = " a-target " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Protocol = " HTTP " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Port = 8080 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        VpcId = vpc . id , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        HealthCheckProtocol = " HTTP " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthCheckPort = " 8080 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthCheckPath = " / " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        HealthCheckIntervalSeconds = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthCheckTimeoutSeconds = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthyThresholdCount = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        UnhealthyThresholdCount = 2 , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Matcher = { " HttpCode " :  " 200 " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    arn  =  response . get ( " TargetGroups " ) [ 0 ] [ " TargetGroupArn " ] 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    client . modify_target_group ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        TargetGroupArn = arn , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        HealthCheckProtocol = " HTTPS " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthCheckPort = " 8081 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthCheckPath = " /status " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        HealthCheckIntervalSeconds = 10 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthCheckTimeoutSeconds = 10 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthyThresholdCount = 10 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        UnhealthyThresholdCount = 4 , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Matcher = { " HttpCode " :  " 200-399 " } , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    response  =  client . describe_target_groups ( TargetGroupArns = [ arn ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response [ " TargetGroups " ] [ 0 ] [ " Matcher " ] [ " HttpCode " ] . should . equal ( " 200-399 " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response [ " TargetGroups " ] [ 0 ] [ " HealthCheckIntervalSeconds " ] . should . equal ( 10 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response [ " TargetGroups " ] [ 0 ] [ " HealthCheckPath " ] . should . equal ( " /status " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response [ " TargetGroups " ] [ 0 ] [ " HealthCheckPort " ] . should . equal ( " 8081 " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response [ " TargetGroups " ] [ 0 ] [ " HealthCheckProtocol " ] . should . equal ( " HTTPS " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response [ " TargetGroups " ] [ 0 ] [ " HealthCheckTimeoutSeconds " ] . should . equal ( 10 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response [ " TargetGroups " ] [ 0 ] [ " HealthyThresholdCount " ] . should . equal ( 10 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response [ " TargetGroups " ] [ 0 ] [ " UnhealthyThresholdCount " ] . should . equal ( 4 ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_elbv2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_ec2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_acm  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								def  test_modify_listener_http_to_https ( ) :  
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    client  =  boto3 . client ( " elbv2 " ,  region_name = " eu-central-1 " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    acm  =  boto3 . client ( " acm " ,  region_name = " eu-central-1 " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ec2  =  boto3 . resource ( " ec2 " ,  region_name = " eu-central-1 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    security_group  =  ec2 . create_security_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        GroupName = " a-security-group " ,  Description = " First One " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    vpc  =  ec2 . create_vpc ( CidrBlock = " 172.28.7.0/24 " ,  InstanceTenancy = " default " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet1  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.192/26 " ,  AvailabilityZone = " eu-central-1a " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet2  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.0/26 " ,  AvailabilityZone = " eu-central-1b " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  client . create_load_balancer ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Name = " my-lb " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Subnets = [ subnet1 . id ,  subnet2 . id ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        SecurityGroups = [ security_group . id ] , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Scheme = " internal " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Tags = [ { " Key " :  " key_name " ,  " Value " :  " a_value " } ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    load_balancer_arn  =  response . get ( " LoadBalancers " ) [ 0 ] . get ( " LoadBalancerArn " ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  client . create_target_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Name = " a-target " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Protocol = " HTTP " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Port = 8080 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        VpcId = vpc . id , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        HealthCheckProtocol = " HTTP " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthCheckPort = " 8080 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthCheckPath = " / " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        HealthCheckIntervalSeconds = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthCheckTimeoutSeconds = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        HealthyThresholdCount = 5 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        UnhealthyThresholdCount = 2 , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Matcher = { " HttpCode " :  " 200 " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    target_group  =  response . get ( " TargetGroups " ) [ 0 ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    target_group_arn  =  target_group [ " TargetGroupArn " ] 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # Plain HTTP listener 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  client . create_listener ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        LoadBalancerArn = load_balancer_arn , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Protocol = " HTTP " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Port = 80 , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        DefaultActions = [ { " Type " :  " forward " ,  " TargetGroupArn " :  target_group_arn } ] , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    listener_arn  =  response [ " Listeners " ] [ 0 ] [ " ListenerArn " ] 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  acm . request_certificate ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        DomainName = " google.com " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        SubjectAlternativeNames = [ " google.com " ,  " www.google.com " ,  " mail.google.com " ] , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    google_arn  =  response [ " CertificateArn " ] 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    response  =  acm . request_certificate ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        DomainName = " yahoo.com " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        SubjectAlternativeNames = [ " yahoo.com " ,  " www.yahoo.com " ,  " mail.yahoo.com " ] , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    yahoo_arn  =  response [ " CertificateArn " ] 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  client . modify_listener ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ListenerArn = listener_arn , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Port = 443 , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Protocol = " HTTPS " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        SslPolicy = " ELBSecurityPolicy-TLS-1-2-2017-01 " , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Certificates = [ 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            { " CertificateArn " :  google_arn ,  " IsDefault " :  False } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            { " CertificateArn " :  yahoo_arn ,  " IsDefault " :  True } , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        ] , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        DefaultActions = [ { " Type " :  " forward " ,  " TargetGroupArn " :  target_group_arn } ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response [ " Listeners " ] [ 0 ] [ " Port " ] . should . equal ( 443 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response [ " Listeners " ] [ 0 ] [ " Protocol " ] . should . equal ( " HTTPS " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response [ " Listeners " ] [ 0 ] [ " SslPolicy " ] . should . equal ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " ELBSecurityPolicy-TLS-1-2-2017-01 " 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    len ( response [ " Listeners " ] [ 0 ] [ " Certificates " ] ) . should . equal ( 2 ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 16:06:03 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    # Check default cert, can't do this in server mode 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    if  os . environ . get ( " TEST_SERVER_MODE " ,  " false " ) . lower ( )  ==  " false " : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        listener  =  ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            elbv2_backends [ " eu-central-1 " ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            . load_balancers [ load_balancer_arn ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            . listeners [ listener_arn ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 16:06:03 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        listener . certificate . should . equal ( yahoo_arn ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # No default cert 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    with  assert_raises ( ClientError ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        client . modify_listener ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ListenerArn = listener_arn , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            Port = 443 , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            Protocol = " HTTPS " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            SslPolicy = " ELBSecurityPolicy-TLS-1-2-2017-01 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            Certificates = [ { " CertificateArn " :  google_arn ,  " IsDefault " :  False } ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            DefaultActions = [ { " Type " :  " forward " ,  " TargetGroupArn " :  target_group_arn } ] , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # Bad cert 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    with  assert_raises ( ClientError ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        client . modify_listener ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ListenerArn = listener_arn , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            Port = 443 , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            Protocol = " HTTPS " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            SslPolicy = " ELBSecurityPolicy-TLS-1-2-2017-01 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            Certificates = [ { " CertificateArn " :  " lalala " ,  " IsDefault " :  True } ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            DefaultActions = [ { " Type " :  " forward " ,  " TargetGroupArn " :  target_group_arn } ] , 
							 
						 
					
						
							
								
									
										
										
										
											2017-10-29 14:14:17 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-11 18:16:56 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_ec2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_elbv2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_cloudformation  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								def  test_create_target_groups_through_cloudformation ( ) :  
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    cfn_conn  =  boto3 . client ( " cloudformation " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    elbv2_client  =  boto3 . client ( " elbv2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-11 18:16:56 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # test that setting a name manually as well as letting cloudformation create a name both work 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # this is a special case because test groups have a name length limit of 22 characters, and must be unique 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-elasticloadbalancingv2-targetgroup.html#cfn-elasticloadbalancingv2-targetgroup-name 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    template  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " AWSTemplateFormatVersion " :  " 2010-09-09 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " Description " :  " ECS Cluster Test CloudFormation " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " Resources " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " testVPC " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Type " :  " AWS::EC2::VPC " , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                " Properties " :  { " CidrBlock " :  " 10.0.0.0/16 " } , 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-11 18:16:56 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " testGroup1 " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Type " :  " AWS::ElasticLoadBalancingV2::TargetGroup " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Properties " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " Port " :  80 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " Protocol " :  " HTTP " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " VpcId " :  { " Ref " :  " testVPC " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " testGroup2 " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Type " :  " AWS::ElasticLoadBalancingV2::TargetGroup " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Properties " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " Port " :  90 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " Protocol " :  " HTTP " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " VpcId " :  { " Ref " :  " testVPC " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " testGroup3 " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Type " :  " AWS::ElasticLoadBalancingV2::TargetGroup " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Properties " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " Name " :  " MyTargetGroup " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " Port " :  70 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " Protocol " :  " HTTPS " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " VpcId " :  { " Ref " :  " testVPC " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        } , 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-11 18:16:56 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    template_json  =  json . dumps ( template ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    cfn_conn . create_stack ( StackName = " test-stack " ,  TemplateBody = template_json ) 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-11 18:16:56 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    describe_target_groups_response  =  elbv2_client . describe_target_groups ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    target_group_dicts  =  describe_target_groups_response [ " TargetGroups " ] 
							 
						 
					
						
							
								
									
										
										
										
											2018-04-11 18:16:56 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    assert  len ( target_group_dicts )  ==  3 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # there should be 2 target groups with the same prefix of 10 characters (since the random suffix is 12) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    # and one named MyTargetGroup 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    assert  ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        len ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                tg 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                for  tg  in  target_group_dicts 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  tg [ " TargetGroupName " ]  ==  " MyTargetGroup " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ==  1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    assert  ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        len ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                tg 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                for  tg  in  target_group_dicts 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  tg [ " TargetGroupName " ] . startswith ( " test-stack " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ==  2 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-25 06:18:39 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_elbv2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_ec2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								def  test_redirect_action_listener_rule ( ) :  
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    conn  =  boto3 . client ( " elbv2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ec2  =  boto3 . resource ( " ec2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-25 06:18:39 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    security_group  =  ec2 . create_security_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        GroupName = " a-security-group " ,  Description = " First One " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    vpc  =  ec2 . create_vpc ( CidrBlock = " 172.28.7.0/24 " ,  InstanceTenancy = " default " ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-25 06:18:39 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet1  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.192/26 " ,  AvailabilityZone = " us-east-1a " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-25 06:18:39 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet2  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.128/26 " ,  AvailabilityZone = " us-east-1b " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-25 06:18:39 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . create_load_balancer ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Name = " my-lb " , 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-25 06:18:39 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Subnets = [ subnet1 . id ,  subnet2 . id ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        SecurityGroups = [ security_group . id ] , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Scheme = " internal " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Tags = [ { " Key " :  " key_name " ,  " Value " :  " a_value " } ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    load_balancer_arn  =  response . get ( " LoadBalancers " ) [ 0 ] . get ( " LoadBalancerArn " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . create_listener ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        LoadBalancerArn = load_balancer_arn , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Protocol = " HTTP " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Port = 80 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        DefaultActions = [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Type " :  " redirect " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " RedirectConfig " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " Protocol " :  " HTTPS " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " Port " :  " 443 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " StatusCode " :  " HTTP_301 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    listener  =  response . get ( " Listeners " ) [ 0 ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    expected_default_actions  =  [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " Type " :  " redirect " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " RedirectConfig " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Protocol " :  " HTTPS " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Port " :  " 443 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " StatusCode " :  " HTTP_301 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } , 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-25 06:18:39 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    listener . get ( " DefaultActions " ) . should . equal ( expected_default_actions ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    listener_arn  =  listener . get ( " ListenerArn " ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-25 06:18:39 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    describe_rules_response  =  conn . describe_rules ( ListenerArn = listener_arn ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    describe_rules_response [ " Rules " ] [ 0 ] [ " Actions " ] . should . equal ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        expected_default_actions 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-25 06:18:39 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    describe_listener_response  =  conn . describe_listeners ( ListenerArns = [ listener_arn ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    describe_listener_actions  =  describe_listener_response [ " Listeners " ] [ 0 ] [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " DefaultActions " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ] 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-25 06:18:39 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    describe_listener_actions . should . equal ( expected_default_actions ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    modify_listener_response  =  conn . modify_listener ( ListenerArn = listener_arn ,  Port = 81 ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    modify_listener_actions  =  modify_listener_response [ " Listeners " ] [ 0 ] [ " DefaultActions " ] 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-25 06:18:39 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    modify_listener_actions . should . equal ( expected_default_actions ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_elbv2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_cloudformation  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								def  test_redirect_action_listener_rule_cloudformation ( ) :  
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    cnf_conn  =  boto3 . client ( " cloudformation " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    elbv2_client  =  boto3 . client ( " elbv2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-25 06:18:39 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    template  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " AWSTemplateFormatVersion " :  " 2010-09-09 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " Description " :  " ECS Cluster Test CloudFormation " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " Resources " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " testVPC " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Type " :  " AWS::EC2::VPC " , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                " Properties " :  { " CidrBlock " :  " 10.0.0.0/16 " } , 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-25 06:18:39 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " subnet1 " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Type " :  " AWS::EC2::Subnet " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Properties " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " CidrBlock " :  " 10.0.0.0/24 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " VpcId " :  { " Ref " :  " testVPC " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " AvalabilityZone " :  " us-east-1b " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " subnet2 " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Type " :  " AWS::EC2::Subnet " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Properties " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " CidrBlock " :  " 10.0.1.0/24 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " VpcId " :  { " Ref " :  " testVPC " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " AvalabilityZone " :  " us-east-1b " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " testLb " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Type " :  " AWS::ElasticLoadBalancingV2::LoadBalancer " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Properties " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " Name " :  " my-lb " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " Subnets " :  [ { " Ref " :  " subnet1 " } ,  { " Ref " :  " subnet2 " } ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " Type " :  " application " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " SecurityGroups " :  [ ] , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                } , 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-25 06:18:39 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " testListener " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Type " :  " AWS::ElasticLoadBalancingV2::Listener " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Properties " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " LoadBalancerArn " :  { " Ref " :  " testLb " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " Port " :  80 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " Protocol " :  " HTTP " , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    " DefaultActions " :  [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            " Type " :  " redirect " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            " RedirectConfig " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                " Port " :  " 443 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                " Protocol " :  " HTTPS " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                " StatusCode " :  " HTTP_301 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            } , 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-25 06:18:39 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                        } 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } , 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-25 06:18:39 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    template_json  =  json . dumps ( template ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    cnf_conn . create_stack ( StackName = " test-stack " ,  TemplateBody = template_json ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    describe_load_balancers_response  =  elbv2_client . describe_load_balancers ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Names = [ " my-lb " ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    describe_load_balancers_response [ " LoadBalancers " ] . should . have . length_of ( 1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    load_balancer_arn  =  describe_load_balancers_response [ " LoadBalancers " ] [ 0 ] [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " LoadBalancerArn " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ] 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-25 06:18:39 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    describe_listeners_response  =  elbv2_client . describe_listeners ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        LoadBalancerArn = load_balancer_arn 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-05-25 06:18:39 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    describe_listeners_response [ " Listeners " ] . should . have . length_of ( 1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    describe_listeners_response [ " Listeners " ] [ 0 ] [ " DefaultActions " ] . should . equal ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Type " :  " redirect " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " RedirectConfig " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " Port " :  " 443 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " Protocol " :  " HTTPS " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " StatusCode " :  " HTTP_301 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-09 23:34:52 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_elbv2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_ec2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								def  test_cognito_action_listener_rule ( ) :  
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    conn  =  boto3 . client ( " elbv2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ec2  =  boto3 . resource ( " ec2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-09 23:34:52 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    security_group  =  ec2 . create_security_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        GroupName = " a-security-group " ,  Description = " First One " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    vpc  =  ec2 . create_vpc ( CidrBlock = " 172.28.7.0/24 " ,  InstanceTenancy = " default " ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-09 23:34:52 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet1  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.192/26 " ,  AvailabilityZone = " us-east-1a " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-09 23:34:52 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet2  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.128/26 " ,  AvailabilityZone = " us-east-1b " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-09 23:34:52 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . create_load_balancer ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Name = " my-lb " , 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-09 23:34:52 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Subnets = [ subnet1 . id ,  subnet2 . id ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        SecurityGroups = [ security_group . id ] , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Scheme = " internal " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Tags = [ { " Key " :  " key_name " ,  " Value " :  " a_value " } ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    load_balancer_arn  =  response . get ( " LoadBalancers " ) [ 0 ] . get ( " LoadBalancerArn " ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-09 23:34:52 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    action  =  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        " Type " :  " authenticate-cognito " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " AuthenticateCognitoConfig " :  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-12-16 21:25:20 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            " UserPoolArn " :  " arn:aws:cognito-idp:us-east-1: {} :userpool/us-east-1_ABCD1234 " . format ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                ACCOUNT_ID 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ) , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            " UserPoolClientId " :  " abcd1234abcd " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " UserPoolDomain " :  " testpool " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } , 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-09 23:34:52 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    response  =  conn . create_listener ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        LoadBalancerArn = load_balancer_arn , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Protocol = " HTTP " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Port = 80 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        DefaultActions = [ action ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-09 23:34:52 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    listener  =  response . get ( " Listeners " ) [ 0 ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    listener . get ( " DefaultActions " ) [ 0 ] . should . equal ( action ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    listener_arn  =  listener . get ( " ListenerArn " ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-09 23:34:52 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    describe_rules_response  =  conn . describe_rules ( ListenerArn = listener_arn ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    describe_rules_response [ " Rules " ] [ 0 ] [ " Actions " ] [ 0 ] . should . equal ( action ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-09 23:34:52 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    describe_listener_response  =  conn . describe_listeners ( ListenerArns = [ listener_arn ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    describe_listener_actions  =  describe_listener_response [ " Listeners " ] [ 0 ] [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " DefaultActions " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ] [ 0 ] 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-09 23:34:52 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    describe_listener_actions . should . equal ( action ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_elbv2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_cloudformation  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								def  test_cognito_action_listener_rule_cloudformation ( ) :  
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    cnf_conn  =  boto3 . client ( " cloudformation " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    elbv2_client  =  boto3 . client ( " elbv2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-09 23:34:52 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    template  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " AWSTemplateFormatVersion " :  " 2010-09-09 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " Description " :  " ECS Cluster Test CloudFormation " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " Resources " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " testVPC " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Type " :  " AWS::EC2::VPC " , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                " Properties " :  { " CidrBlock " :  " 10.0.0.0/16 " } , 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-09 23:34:52 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " subnet1 " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Type " :  " AWS::EC2::Subnet " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Properties " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " CidrBlock " :  " 10.0.0.0/24 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " VpcId " :  { " Ref " :  " testVPC " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " AvalabilityZone " :  " us-east-1b " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " subnet2 " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Type " :  " AWS::EC2::Subnet " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Properties " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " CidrBlock " :  " 10.0.1.0/24 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " VpcId " :  { " Ref " :  " testVPC " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " AvalabilityZone " :  " us-east-1b " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " testLb " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Type " :  " AWS::ElasticLoadBalancingV2::LoadBalancer " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Properties " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " Name " :  " my-lb " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " Subnets " :  [ { " Ref " :  " subnet1 " } ,  { " Ref " :  " subnet2 " } ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " Type " :  " application " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " SecurityGroups " :  [ ] , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                } , 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-09 23:34:52 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " testListener " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Type " :  " AWS::ElasticLoadBalancingV2::Listener " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Properties " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " LoadBalancerArn " :  { " Ref " :  " testLb " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " Port " :  80 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " Protocol " :  " HTTP " , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    " DefaultActions " :  [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            " Type " :  " authenticate-cognito " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            " AuthenticateCognitoConfig " :  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-12-16 21:25:20 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                                " UserPoolArn " :  " arn:aws:cognito-idp:us-east-1: {} :userpool/us-east-1_ABCD1234 " . format ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                    ACCOUNT_ID 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                ) , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                                " UserPoolClientId " :  " abcd1234abcd " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                " UserPoolDomain " :  " testpool " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            } , 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-09 23:34:52 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                        } 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } , 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-09 23:34:52 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    template_json  =  json . dumps ( template ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    cnf_conn . create_stack ( StackName = " test-stack " ,  TemplateBody = template_json ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    describe_load_balancers_response  =  elbv2_client . describe_load_balancers ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Names = [ " my-lb " ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    load_balancer_arn  =  describe_load_balancers_response [ " LoadBalancers " ] [ 0 ] [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " LoadBalancerArn " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    describe_listeners_response  =  elbv2_client . describe_listeners ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        LoadBalancerArn = load_balancer_arn 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-08-09 23:34:52 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    describe_listeners_response [ " Listeners " ] . should . have . length_of ( 1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    describe_listeners_response [ " Listeners " ] [ 0 ] [ " DefaultActions " ] . should . equal ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Type " :  " authenticate-cognito " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " AuthenticateCognitoConfig " :  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-12-16 21:25:20 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    " UserPoolArn " :  " arn:aws:cognito-idp:us-east-1: {} :userpool/us-east-1_ABCD1234 " . format ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        ACCOUNT_ID 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    ) , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    " UserPoolClientId " :  " abcd1234abcd " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " UserPoolDomain " :  " testpool " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 11:24:47 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_elbv2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_ec2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								def  test_fixed_response_action_listener_rule ( ) :  
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    conn  =  boto3 . client ( " elbv2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ec2  =  boto3 . resource ( " ec2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 11:24:47 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    security_group  =  ec2 . create_security_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        GroupName = " a-security-group " ,  Description = " First One " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    vpc  =  ec2 . create_vpc ( CidrBlock = " 172.28.7.0/24 " ,  InstanceTenancy = " default " ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 11:24:47 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet1  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.192/26 " ,  AvailabilityZone = " us-east-1a " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 11:24:47 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet2  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.128/26 " ,  AvailabilityZone = " us-east-1b " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 11:24:47 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . create_load_balancer ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Name = " my-lb " , 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 11:24:47 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Subnets = [ subnet1 . id ,  subnet2 . id ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        SecurityGroups = [ security_group . id ] , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Scheme = " internal " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Tags = [ { " Key " :  " key_name " ,  " Value " :  " a_value " } ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    load_balancer_arn  =  response . get ( " LoadBalancers " ) [ 0 ] . get ( " LoadBalancerArn " ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 11:24:47 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    action  =  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        " Type " :  " fixed-response " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " FixedResponseConfig " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " ContentType " :  " text/plain " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " MessageBody " :  " This page does not exist " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " StatusCode " :  " 404 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } , 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 11:24:47 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    response  =  conn . create_listener ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        LoadBalancerArn = load_balancer_arn , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Protocol = " HTTP " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Port = 80 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        DefaultActions = [ action ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 11:24:47 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    listener  =  response . get ( " Listeners " ) [ 0 ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    listener . get ( " DefaultActions " ) [ 0 ] . should . equal ( action ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    listener_arn  =  listener . get ( " ListenerArn " ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 11:24:47 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    describe_rules_response  =  conn . describe_rules ( ListenerArn = listener_arn ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    describe_rules_response [ " Rules " ] [ 0 ] [ " Actions " ] [ 0 ] . should . equal ( action ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 11:24:47 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    describe_listener_response  =  conn . describe_listeners ( ListenerArns = [ listener_arn ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    describe_listener_actions  =  describe_listener_response [ " Listeners " ] [ 0 ] [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " DefaultActions " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ] [ 0 ] 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 11:24:47 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    describe_listener_actions . should . equal ( action ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_elbv2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_cloudformation  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								def  test_fixed_response_action_listener_rule_cloudformation ( ) :  
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    cnf_conn  =  boto3 . client ( " cloudformation " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    elbv2_client  =  boto3 . client ( " elbv2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 11:24:47 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    template  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " AWSTemplateFormatVersion " :  " 2010-09-09 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " Description " :  " ECS Cluster Test CloudFormation " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " Resources " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " testVPC " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Type " :  " AWS::EC2::VPC " , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                " Properties " :  { " CidrBlock " :  " 10.0.0.0/16 " } , 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 11:24:47 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " subnet1 " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Type " :  " AWS::EC2::Subnet " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Properties " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " CidrBlock " :  " 10.0.0.0/24 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " VpcId " :  { " Ref " :  " testVPC " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " AvalabilityZone " :  " us-east-1b " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " subnet2 " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Type " :  " AWS::EC2::Subnet " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Properties " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " CidrBlock " :  " 10.0.1.0/24 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " VpcId " :  { " Ref " :  " testVPC " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " AvalabilityZone " :  " us-east-1b " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " testLb " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Type " :  " AWS::ElasticLoadBalancingV2::LoadBalancer " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Properties " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " Name " :  " my-lb " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " Subnets " :  [ { " Ref " :  " subnet1 " } ,  { " Ref " :  " subnet2 " } ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " Type " :  " application " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " SecurityGroups " :  [ ] , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                } , 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 11:24:47 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " testListener " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Type " :  " AWS::ElasticLoadBalancingV2::Listener " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Properties " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " LoadBalancerArn " :  { " Ref " :  " testLb " } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " Port " :  80 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " Protocol " :  " HTTP " , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    " DefaultActions " :  [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            " Type " :  " fixed-response " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            " FixedResponseConfig " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                " ContentType " :  " text/plain " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                " MessageBody " :  " This page does not exist " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                " StatusCode " :  " 404 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            } , 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 11:24:47 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                        } 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } , 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 11:24:47 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    template_json  =  json . dumps ( template ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    cnf_conn . create_stack ( StackName = " test-stack " ,  TemplateBody = template_json ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    describe_load_balancers_response  =  elbv2_client . describe_load_balancers ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Names = [ " my-lb " ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    load_balancer_arn  =  describe_load_balancers_response [ " LoadBalancers " ] [ 0 ] [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " LoadBalancerArn " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    describe_listeners_response  =  elbv2_client . describe_listeners ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        LoadBalancerArn = load_balancer_arn 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 11:24:47 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    describe_listeners_response [ " Listeners " ] . should . have . length_of ( 1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    describe_listeners_response [ " Listeners " ] [ 0 ] [ " DefaultActions " ] . should . equal ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " Type " :  " fixed-response " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " FixedResponseConfig " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " ContentType " :  " text/plain " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " MessageBody " :  " This page does not exist " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    " StatusCode " :  " 404 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 12:29:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_elbv2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_ec2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								def  test_fixed_response_action_listener_rule_validates_status_code ( ) :  
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    conn  =  boto3 . client ( " elbv2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ec2  =  boto3 . resource ( " ec2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 12:29:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    security_group  =  ec2 . create_security_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        GroupName = " a-security-group " ,  Description = " First One " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    vpc  =  ec2 . create_vpc ( CidrBlock = " 172.28.7.0/24 " ,  InstanceTenancy = " default " ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 12:29:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet1  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.192/26 " ,  AvailabilityZone = " us-east-1a " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 12:29:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet2  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.128/26 " ,  AvailabilityZone = " us-east-1b " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 12:29:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . create_load_balancer ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Name = " my-lb " , 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 12:29:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Subnets = [ subnet1 . id ,  subnet2 . id ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        SecurityGroups = [ security_group . id ] , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Scheme = " internal " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Tags = [ { " Key " :  " key_name " ,  " Value " :  " a_value " } ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    load_balancer_arn  =  response . get ( " LoadBalancers " ) [ 0 ] . get ( " LoadBalancerArn " ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 12:29:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    missing_status_code_action  =  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        " Type " :  " fixed-response " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " FixedResponseConfig " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " ContentType " :  " text/plain " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " MessageBody " :  " This page does not exist " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } , 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 12:29:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    with  assert_raises ( ParamValidationError ) : 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        conn . create_listener ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            LoadBalancerArn = load_balancer_arn , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            Protocol = " HTTP " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            Port = 80 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            DefaultActions = [ missing_status_code_action ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 12:29:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    invalid_status_code_action  =  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        " Type " :  " fixed-response " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " FixedResponseConfig " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " ContentType " :  " text/plain " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " MessageBody " :  " This page does not exist " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " StatusCode " :  " 100 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } , 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 12:29:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    @mock_elbv2 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    @mock_ec2 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    def  test_fixed_response_action_listener_rule_validates_status_code ( ) : 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        conn  =  boto3 . client ( " elbv2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ec2  =  boto3 . resource ( " ec2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 12:29:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        security_group  =  ec2 . create_security_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            GroupName = " a-security-group " ,  Description = " First One " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        vpc  =  ec2 . create_vpc ( CidrBlock = " 172.28.7.0/24 " ,  InstanceTenancy = " default " ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 12:29:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        subnet1  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            VpcId = vpc . id ,  CidrBlock = " 172.28.7.192/26 " ,  AvailabilityZone = " us-east-1a " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 12:29:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        subnet2  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            VpcId = vpc . id ,  CidrBlock = " 172.28.7.128/26 " ,  AvailabilityZone = " us-east-1b " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 12:29:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        response  =  conn . create_load_balancer ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            Name = " my-lb " , 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 12:29:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            Subnets = [ subnet1 . id ,  subnet2 . id ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            SecurityGroups = [ security_group . id ] , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            Scheme = " internal " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            Tags = [ { " Key " :  " key_name " ,  " Value " :  " a_value " } ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        load_balancer_arn  =  response . get ( " LoadBalancers " ) [ 0 ] . get ( " LoadBalancerArn " ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 12:29:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        missing_status_code_action  =  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            " Type " :  " fixed-response " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " FixedResponseConfig " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " ContentType " :  " text/plain " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " MessageBody " :  " This page does not exist " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } , 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 12:29:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        with  assert_raises ( ParamValidationError ) : 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            conn . create_listener ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                LoadBalancerArn = load_balancer_arn , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                Protocol = " HTTP " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                Port = 80 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                DefaultActions = [ missing_status_code_action ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 12:29:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        invalid_status_code_action  =  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            " Type " :  " fixed-response " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " FixedResponseConfig " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " ContentType " :  " text/plain " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " MessageBody " :  " This page does not exist " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                " StatusCode " :  " 100 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } , 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 12:29:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        with  assert_raises ( ClientError )  as  invalid_status_code_exception : 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            conn . create_listener ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                LoadBalancerArn = load_balancer_arn , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                Protocol = " HTTP " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                Port = 80 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                DefaultActions = [ invalid_status_code_action ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        invalid_status_code_exception . exception . response [ " Error " ] [ " Code " ] . should . equal ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " ValidationError " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 12:29:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_elbv2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								@mock_ec2  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								def  test_fixed_response_action_listener_rule_validates_content_type ( ) :  
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    conn  =  boto3 . client ( " elbv2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ec2  =  boto3 . resource ( " ec2 " ,  region_name = " us-east-1 " ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 12:29:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    security_group  =  ec2 . create_security_group ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        GroupName = " a-security-group " ,  Description = " First One " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    vpc  =  ec2 . create_vpc ( CidrBlock = " 172.28.7.0/24 " ,  InstanceTenancy = " default " ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 12:29:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet1  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.192/26 " ,  AvailabilityZone = " us-east-1a " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 12:29:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    subnet2  =  ec2 . create_subnet ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        VpcId = vpc . id ,  CidrBlock = " 172.28.7.128/26 " ,  AvailabilityZone = " us-east-1b " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 12:29:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    response  =  conn . create_load_balancer ( 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Name = " my-lb " , 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 12:29:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Subnets = [ subnet1 . id ,  subnet2 . id ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        SecurityGroups = [ security_group . id ] , 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        Scheme = " internal " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        Tags = [ { " Key " :  " key_name " ,  " Value " :  " a_value " } ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    load_balancer_arn  =  response . get ( " LoadBalancers " ) [ 0 ] . get ( " LoadBalancerArn " ) 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 12:29:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    invalid_content_type_action  =  { 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        " Type " :  " fixed-response " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " FixedResponseConfig " :  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " ContentType " :  " Fake content type " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " MessageBody " :  " This page does not exist " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            " StatusCode " :  " 200 " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } , 
							 
						 
					
						
							
								
									
										
										
										
											2019-09-12 12:29:03 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    with  assert_raises ( ClientError )  as  invalid_content_type_exception : 
							 
						 
					
						
							
								
									
										
										
										
											2019-10-31 08:44:26 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        conn . create_listener ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            LoadBalancerArn = load_balancer_arn , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            Protocol = " HTTP " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            Port = 80 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            DefaultActions = [ invalid_content_type_action ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    invalid_content_type_exception . exception . response [ " Error " ] [ " Code " ] . should . equal ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        " InvalidLoadBalancerAction " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    )