

@mock_ec2
def test_eip_associate_vpc():
    'Associate/Disassociate EIP to VPC instance'
    conn = boto.connect_ec2('the_key', 'the_secret')
    reservation = conn.run_instances('ami-1234abcd')
    instance = reservation.instances[0]
    eip = conn.allocate_address(domain='vpc')
    eip.instance_id.should.be.none
    with assert_raises(EC2ResponseError) as cm:
        conn.associate_address(allocation_id=eip.allocation_id)
    cm.exception.code.should.equal('MissingParameter')
    reservation.exception.status.should.equal(400)
    cm.exception.request_id.should_not.be.none
    conn.associate_address(instance_id=instance.id, allocation_id=eip.allocation_id)
    eip = conn.get_all_addresses(addresses=[eip.public_ip])[0]
    eip.instance_id.should.be.equal(instance.id)
    conn.disassociate_address(association_id=eip.association_id)
    eip = conn.get_all_addresses(addresses=[eip.public_ip])[0]
    eip.instance_id.should.be.equal('')
    eip.association_id.should.be.none
    eip.release()
    eip = None
    instance.terminate()

dataset/ETHPy150Open spulec/moto/tests/test_ec2/test_elastic_ip_addresses.py test_eip_associate_vpc/VarMisuse@99/156 `cm`->`reservation`