示例#1
0
def setup_farmrole_params(
        role_options=None,
        alias=None,
        behaviors=None,
        setup_bundled_role=False):

    platform = CONF.feature.platform
    dist = CONF.feature.dist
    behaviors = behaviors or []
    role_options = role_options or []
    role_params = farmrole.FarmRoleParams(platform, alias=alias)

    if isinstance(behaviors, types.StringTypes):
        behaviors = [behaviors]

    if not (setup_bundled_role and len('{}-{}'.format(world.farm.name, alias)) < 63):
        Defaults.set_hostname(role_params)

    for opt in role_options:
        LOG.info('Inspect role option: %s' % opt)
        if opt in ('branch_latest', 'branch_stable'):
            role_params.advanced.agent_update_repository = opt.split('_')[1]
        elif 'redis processes' in opt:
            redis_count = re.findall(r'(\d+) redis processes', opt)[0].strip()
            LOG.info('Setup %s redis processes' % redis_count)
            role_params.database.redis_processes = int(redis_count)
        elif 'chef-solo' in opt:
            Defaults.set_chef_solo(role_params, opt)
        else:
            Defaults.apply_option(role_params, opt)

    if not setup_bundled_role:
        if dist.is_windows:
            role_params.advanced.reboot_after_hostinit = True
        elif dist.id == 'scientific-6-x' or \
                (dist.id in ['centos-6-x', 'centos-7-x'] and platform.is_ec2):
            role_params.advanced.disable_iptables_mgmt = False

        if platform.is_ec2:
            role_params.global_variables.variables.append(
                role_params.global_variables,
                farmrole.Variable(
                    name='REVIZOR_TEST_ID',
                    value=getattr(world, 'test_id')
                )
            )
        if 'rabbitmq' in behaviors:
            role_params.network.hostname_template = ''

    if any(b in DATABASE_BEHAVIORS for b in behaviors):
        LOG.debug('Setup default db storages')
        Defaults.set_db_storage(role_params)
        if 'redis' in behaviors:
            LOG.info('Insert redis settings')
            snapshotting_type = CONF.feature.redis_snapshotting
            role_params.database.redis_persistence_type = snapshotting_type
            role_params.database.redis_use_password = True
    return role_params