Fixed new subnets associated with a network ACL from a different VPC.
This commit is contained in:
		
							parent
							
								
									850496f29a
								
							
						
					
					
						commit
						3c5ce6c09e
					
				| @ -2464,7 +2464,7 @@ class SubnetBackend(object): | |||||||
|                         default_for_az, map_public_ip_on_launch) |                         default_for_az, map_public_ip_on_launch) | ||||||
| 
 | 
 | ||||||
|         # AWS associates a new subnet with the default Network ACL |         # AWS associates a new subnet with the default Network ACL | ||||||
|         self.associate_default_network_acl_with_subnet(subnet_id) |         self.associate_default_network_acl_with_subnet(subnet_id, vpc_id) | ||||||
|         self.subnets[availability_zone][subnet_id] = subnet |         self.subnets[availability_zone][subnet_id] = subnet | ||||||
|         return subnet |         return subnet | ||||||
| 
 | 
 | ||||||
| @ -3636,9 +3636,9 @@ class NetworkAclBackend(object): | |||||||
|         new_acl.associations[new_assoc_id] = association |         new_acl.associations[new_assoc_id] = association | ||||||
|         return association |         return association | ||||||
| 
 | 
 | ||||||
|     def associate_default_network_acl_with_subnet(self, subnet_id): |     def associate_default_network_acl_with_subnet(self, subnet_id, vpc_id): | ||||||
|         association_id = random_network_acl_subnet_association_id() |         association_id = random_network_acl_subnet_association_id() | ||||||
|         acl = next(acl for acl in self.network_acls.values() if acl.default) |         acl = next(acl for acl in self.network_acls.values() if acl.default and acl.vpc_id == vpc_id) | ||||||
|         acl.associations[association_id] = NetworkAclAssociation(self, association_id, |         acl.associations[association_id] = NetworkAclAssociation(self, association_id, | ||||||
|                                                                  subnet_id, acl.id) |                                                                  subnet_id, acl.id) | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,8 +1,9 @@ | |||||||
| from __future__ import unicode_literals | from __future__ import unicode_literals | ||||||
| import boto | import boto | ||||||
|  | import boto3 | ||||||
| import sure  # noqa | import sure  # noqa | ||||||
| 
 | 
 | ||||||
| from moto import mock_ec2_deprecated | from moto import mock_ec2_deprecated, mock_ec2 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @mock_ec2_deprecated | @mock_ec2_deprecated | ||||||
| @ -173,3 +174,19 @@ def test_network_acl_tagging(): | |||||||
|                             if na.id == network_acl.id) |                             if na.id == network_acl.id) | ||||||
|     test_network_acl.tags.should.have.length_of(1) |     test_network_acl.tags.should.have.length_of(1) | ||||||
|     test_network_acl.tags["a key"].should.equal("some value") |     test_network_acl.tags["a key"].should.equal("some value") | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | @mock_ec2 | ||||||
|  | def test_new_subnet_in_new_vpc_associates_with_default_network_acl(): | ||||||
|  |     ec2 = boto3.resource('ec2', region_name='us-west-1') | ||||||
|  |     new_vpc = ec2.create_vpc(CidrBlock='10.0.0.0/16') | ||||||
|  |     new_vpc.reload() | ||||||
|  | 
 | ||||||
|  |     subnet = ec2.create_subnet(VpcId=new_vpc.id, CidrBlock='10.0.0.0/24') | ||||||
|  |     subnet.reload() | ||||||
|  | 
 | ||||||
|  |     new_vpcs_default_network_acl = next(iter(new_vpc.network_acls.all()), None) | ||||||
|  |     new_vpcs_default_network_acl.reload() | ||||||
|  |     new_vpcs_default_network_acl.vpc_id.should.equal(new_vpc.id) | ||||||
|  |     new_vpcs_default_network_acl.associations.should.have.length_of(1) | ||||||
|  |     new_vpcs_default_network_acl.associations[0]['SubnetId'].should.equal(subnet.id) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user