

@mock_ec2
def test_eip_associate_network_interface():
    'Associate/Disassociate EIP to NIC'
    conn = boto.connect_vpc('the_key', 'the_secret')
    vpc = conn.create_vpc('10.0.0.0/16')
    subnet = conn.create_subnet(vpc.id, '10.0.0.0/18')
    eni = conn.create_network_interface(subnet.id)
    eip = conn.allocate_address(domain='vpc')
    eip.network_interface_id.should.be.none
    with assert_raises(EC2ResponseError) as cm:
        conn.associate_address(network_interface_id=eni.id)
    cm.exception.code.should.equal('MissingParameter')
    cm.exception.status.should.equal(400)
    cm.exception.request_id.should_not.be.none
    conn.associate_address(network_interface_id=eni.id, allocation_id=eip.allocation_id)
    eip = conn.get_all_addresses(addresses=[eip.public_ip])[0]
    eip.network_interface_id.should.be.equal(eni.id)
    conn.disassociate_address(association_id=eip.association_id)
    eip = conn.get_all_addresses(addresses=[eip.public_ip])[0]
    eip.network_interface_id.should.be.equal('')
    eip.association_id.should.be.none
    eip.release()
    eip = None

dataset/ETHPy150Open spulec/moto/tests/test_ec2/test_elastic_ip_addresses.py test_eip_associate_network_interface/original