Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for instance public ip not being cleared on eip disassociation #1149

Merged
merged 1 commit into from
Sep 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions moto/ec2/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,10 +590,6 @@ def prep_nics(self, nic_spec, subnet_id=None, private_ip=None, associate_public_

self.attach_eni(use_nic, device_index)

def set_ip(self, ip_address):
# Should we be creating a new ENI?
self.nics[0].public_ip = ip_address

def attach_eni(self, eni, device_index):
device_index = int(device_index)
self.nics[device_index] = eni
Expand Down Expand Up @@ -3047,8 +3043,6 @@ def associate_address(self, instance=None, eni=None, address=None, allocation_id
eip.eni.public_ip = eip.public_ip
if eip.domain == "vpc":
eip.association_id = random_eip_association_id()
if instance:
instance.set_ip(eip.public_ip)

return eip

Expand Down Expand Up @@ -3082,10 +3076,9 @@ def disassociate_address(self, address=None, association_id=None):
eip = eips[0]

if eip.eni:
eip.eni.public_ip = None
if eip.eni.instance and eip.eni.instance._state.name == "running":
eip.eni.check_auto_public_ip()
else:
eip.eni.public_ip = None
eip.eni = None

eip.instance = None
Expand Down
18 changes: 18 additions & 0 deletions tests/test_ec2/test_elastic_ip_addresses.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,31 @@ def test_eip_boto3_vpc_association():
'SubnetId': subnet_res['Subnet']['SubnetId']
})[0]
allocation_id = client.allocate_address(Domain='vpc')['AllocationId']
address = service.VpcAddress(allocation_id)
address.load()
address.association_id.should.be.none
address.instance_id.should.be.empty
address.network_interface_id.should.be.empty
association_id = client.associate_address(
InstanceId=instance.id,
AllocationId=allocation_id,
AllowReassociation=False)
instance.load()
address.reload()
address.association_id.should_not.be.none
instance.public_ip_address.should_not.be.none
instance.public_dns_name.should_not.be.none
address.network_interface_id.should.equal(instance.network_interfaces_attribute[0].get('NetworkInterfaceId'))
address.public_ip.should.equal(instance.public_ip_address)
address.instance_id.should.equal(instance.id)

client.disassociate_address(AssociationId=address.association_id)
instance.reload()
address.reload()
instance.public_ip_address.should.be.none
address.network_interface_id.should.be.empty
address.association_id.should.be.none
address.instance_id.should.be.empty


@mock_ec2_deprecated
Expand Down