Exemple #1
0
def validate_config(user_arguments):
    user_arguments = gen.stringify_configuration(user_arguments)
    messages = gen.internals.resolve_configuration([source], [get_target()], user_arguments).status_dict
    if messages['status'] == 'ok':
        return {}

    # Re-format to the expected format
    # TODO(cmaloney): Make the unnecessary
    final_errors = dict()
    for name, message_blob in messages['errors'].items():
        final_errors[name] = message_blob['message']
    return final_errors
Exemple #2
0
def validate_onprem_dcos_config_contents(onprem_dcos_config_contents, num_masters, prevalidate_onprem_config):
    # TODO DCOS-14033: [gen.internals] Source validate functions are global only
    if prevalidate_onprem_config != 'true':
        return
    user_config = yaml.load(onprem_dcos_config_contents)
    # Use the default config in the installer
    config = yaml.load(dcos_installer.config.config_sample)
    config.update(user_config)
    # This field is required and auto-added by installer, so add a dummy here
    if 'bootstrap_id' not in config:
        config['bootstrap_id'] = 'deadbeef'

    # dummy master list to pass validation
    config['master_list'] = [('10.0.0.' + str(i)) for i in range(int(num_masters))]

    # Use the default config in the installer
    sources, targets, templates = gen.get_dcosconfig_source_target_and_templates(
        gen.stringify_configuration(config), list(), [ssh.validate.source, gen.build_deploy.bash.onprem_source])

    # Copy the gen target from dcos_installer/config.py, but instead remove
    # 'ssh_key_path' from the target because the validate fn in ssh_source is
    # too strict I.E. we cannot validate a key if we are going to generate
    # Furthermore, we cannot use the target ssh_key_path as it will automatically
    # invoked the validate fn from ssh/validate.py Luckily, we can instead use
    # the more idiomatic 'ssh_private_key_filename'
    targets.append(Target({
        'ssh_user',
        'ssh_port',
        'master_list',
        'agent_list',
        'public_agent_list',
        'ssh_parallelism',
        'process_timeout'}))

    resolver = resolve_configuration(sources, targets)
    status = resolver.status_dict
    if status['status'] == 'errors':
        raise AssertionError(pretty_print_validate_error(status['errors'], status['unset']))
Exemple #3
0
 def as_gen_format(self):
     return gen.stringify_configuration(self._config)
Exemple #4
0
 def as_gen_format(self):
     config = copy.copy(self._config)
     config.update({'provider': 'onprem'})
     return gen.stringify_configuration(config)
Exemple #5
0
def gen_format_config(config: dict, config_dir: str) -> dict:
    """ path-expands, yaml-flattens, and stringifies user-provided config-dict
    """
    return gen.stringify_configuration(
        yaml_flatten(expand_filenames(config, config_dir)))
Exemple #6
0
 def as_gen_format(self):
     return gen.stringify_configuration(self._config)
Exemple #7
0
def gen_format_config(config: dict, config_dir: str) -> dict:
    """ path-expands, yaml-flattens, and stringifies user-provided config-dict
    """
    return gen.stringify_configuration(yaml_flatten(expand_filenames(config, config_dir)))