def rommon_prompt_handler(spawn, session, context):
    """ handles connection refused scenarios
    """
    image = context.get('image')
    cmd = 'boot ' + image[0] if image else 'boot'
    if not session.get('please_reset_seen'):
        if not session.get('rommon_count'):
            spawn.sendline(cmd)
            session['rommon_count'] = 1
        else:
            raise Exception(
                'Rommon prompt encountered unexpectedly, Maybe golden image does not exist for  % '
                , str(spawn))
    elif session.get('rommon_count'):
        if session['rommon_count'] == 1:
            spawn.send('reset\r\r')
            session['rommon_count'] += 1
        elif session['rommon_count'] == 2:
            spawn.send('confreg 0x1\r')
            session['rommon_count'] += 1
        elif session['rommon_count'] == 3:
            spawn.sendline(cmd)
            session['rommon_count'] += 1
        else:
            raise Exception(
                'Rommon prompt encountered unexpectedly, Maybe golden image does not exist for  % '
                , str(spawn))
    else:
        spawn.send('confreg 0x0\r')
        session['rommon_count'] = 1
