def modify_conf(cfgfile, service_name, outfn):
    """Modify config file neutron and keystone to include enabler options."""

    if not cfgfile or not outfn:
        print('ERROR: There is no config file.')
        sys.exit(0)

    options = service_options[service_name]
    with open(cfgfile, 'r') as cf:
        lines = cf.readlines()

    for opt in options:
        op = opt.get('option')
        res = [line for line in lines if line.startswith(op)]
        if len(res) > 1:
            print('ERROR: There are more than one %s option.' % res)
            sys.exit(0)
        if res:
            (op, sep, val) = (res[0].strip('\n').replace(' ', '').
                              partition('='))
            new_val = None
            if opt.get('is_list'):
                # Value for this option can contain list of values.
                # Append the value if it does not exist.
                if not any(opt.get('value') == value for value in
                           val.split(',')):
                    new_val = ','.join((val, opt.get('value')))
            else:
                if val != opt.get('value'):
                    new_val = opt.get('value')
            if new_val:
                opt_idx = lines.index(res[0])
                # The setting is different, replace it with new one.
                lines.pop(opt_idx)
                lines.insert(opt_idx, '='.join((opt.get('option'),
                             new_val + '\n')))
        else:
            # Option does not exist. Add the option.
            try:
                sec_idx = lines.index('[' + opt.get('section') + ']\n')
                lines.insert(sec_idx + 1, '='.join(
                    (opt.get('option'), opt.get('value') + '\n')))
            except __HOLE__:
                print('Invalid %s section name.' % opt.get('section'))
                sys.exit(0)

    with open(outfn, 'w') as fwp:
        all_lines = ''
        for line in lines:
            all_lines += line

        fwp.write(all_lines)
dataset/ETHPy150Open openstack/networking-cisco/tools/saf_prepare_setup.py/modify_conf