Ejemplo n.º 1
0
def validate_jobs(config, config_context):
    """Validate jobs"""
    valid_jobs = build_dict_name_validator(valid_job, allow_empty=True)
    validation = [('jobs', valid_jobs)]

    for config_name, valid in validation:
        child_context = config_context.build_child_context(config_name)
        config[config_name] = valid(config.get(config_name, []), child_context)

    fmt_string = 'Job names must be unique %s'
    config_utils.unique_names(fmt_string, config['jobs'])
Ejemplo n.º 2
0
def validate_jobs_and_services(config, config_context):
    """Validate jobs and services."""
    valid_jobs      = build_dict_name_validator(valid_job, allow_empty=True)
    valid_services  = build_dict_name_validator(valid_service, allow_empty=True)
    validation      = [('jobs', valid_jobs), ('services', valid_services)]

    for config_name, valid in validation:
        child_context = config_context.build_child_context(config_name)
        config[config_name] = valid(config.get(config_name, []), child_context)

    fmt_string = 'Job and Service names must be unique %s'
    config_utils.unique_names(fmt_string, config['jobs'], config['services'])
Ejemplo n.º 3
0
def validate_jobs_and_services(config, config_context):
    """Validate jobs and services."""
    if 'command_context' in config:
        sorted_context = [(key,config['command_context'][key]) for key in \
            sorted(config['command_context'], key=len, reverse=True)]
        for job in config['jobs']:
            tron_cmd = 'enable' if ('enabled' not in job or job['enabled']) \
                else 'disable'
            #namespace_job = '%s.%s' % (config_context.namespace,
            #    job['name'].replace(" ", "_"))
            #disable_pr = subprocess.Popen(['tronctl', tron_cmd,
            #    namespace_job], stdout=subprocess.PIPE,
            #    stderr=subprocess.PIPE)
            #disable_pr.communicate()
            if tron_cmd == 'disable':
                print '%s %sd' % (job['name'], tron_cmd)
            if 'report' in job:
                if job['report'] is True:
                    job['email'] = 'report-%s' % job['email']
                del job['report']
            if 'node' not in job:
                job['node'] = 'be-master'
            if 'actions' not in job:
                job['actions'] = [{}]
                job['actions'][0]['command'] = job['command']
                job['actions'][0]['name'] = job['email'] \
                    if 'email' in job else 'none'
            for var, repl_var in sorted_context:
                old_cmd = job['actions'][0]['command']
                if var in old_cmd:
                    job['actions'][0]['command'] = old_cmd.replace(
                        var, repl_var)
                    continue
    valid_jobs = build_dict_name_validator(valid_job, allow_empty=True)
    valid_services = build_dict_name_validator(valid_service, allow_empty=True)
    validation = [('jobs', valid_jobs), ('services', valid_services)]

    for config_name, valid in validation:
        child_context = config_context.build_child_context(config_name)
        config[config_name] = valid(config.get(config_name, []), child_context)

    fmt_string = 'Job and Service names must be unique %s'
    config_utils.unique_names(fmt_string, config['jobs'], config['services'])
Ejemplo n.º 4
0
def validate_jobs_and_services(config, config_context):
    """Validate jobs and services."""
    if 'command_context' in config:
        sorted_context = [(key,config['command_context'][key]) for key in \
            sorted(config['command_context'], key=len, reverse=True)]
        for job in config['jobs']:
            tron_cmd = 'enable' if ('enabled' not in job or job['enabled']) \
                else 'disable'
            #namespace_job = '%s.%s' % (config_context.namespace,
            #    job['name'].replace(" ", "_"))
            #disable_pr = subprocess.Popen(['tronctl', tron_cmd,
            #    namespace_job], stdout=subprocess.PIPE,
            #    stderr=subprocess.PIPE)
            #disable_pr.communicate()
            if tron_cmd == 'disable':
                print '%s %sd' % (job['name'], tron_cmd)
            if 'report' in job:
                if job['report'] is True:
                    job['email'] = 'report-%s' % job['email']
                del job['report']
            if 'node' not in job:
                job['node'] = 'be-master'
            if 'actions' not in job:
                job['actions'] = [{}]
                job['actions'][0]['command'] = job['command']
                job['actions'][0]['name'] = job['email'] \
                    if 'email' in job else 'none'
            for var, repl_var in sorted_context:
                old_cmd = job['actions'][0]['command']
                if var in old_cmd:
                    job['actions'][0]['command'] = old_cmd.replace(var, repl_var)
                    continue
    valid_jobs      = build_dict_name_validator(valid_job, allow_empty=True)
    valid_services  = build_dict_name_validator(valid_service, allow_empty=True)
    validation      = [('jobs', valid_jobs), ('services', valid_services)]

    for config_name, valid in validation:
        child_context = config_context.build_child_context(config_name)
        config[config_name] = valid(config.get(config_name, []), child_context)

    fmt_string = 'Job and Service names must be unique %s'
    config_utils.unique_names(fmt_string, config['jobs'], config['services'])
Ejemplo n.º 5
0
    def post_validation(self, config, _):
        """Validate a non-named config."""
        node_names = config_utils.unique_names(
            "Node and NodePool names must be unique %s", config["nodes"], config.get("node_pools", [])
        )

        if config.get("node_pools"):
            self.validate_node_pool_nodes(config)

        config_context = ConfigContext("config", node_names, config.get("command_context"), MASTER_NAMESPACE)
        validate_jobs_and_services(config, config_context)
Ejemplo n.º 6
0
    def post_validation(self, config, _):
        """Validate a non-named config."""
        node_names = config_utils.unique_names(
            'Node and NodePool names must be unique %s',
            config['nodes'], config.get('node_pools', []))

        if config.get('node_pools'):
            self.validate_node_pool_nodes(config)

        config_context = ConfigContext('config', node_names,
            config.get('command_context'), MASTER_NAMESPACE)
        validate_jobs_and_services(config, config_context)
Ejemplo n.º 7
0
    def post_validation(self, config, _):
        """Validate a non-named config."""
        node_names = config_utils.unique_names(
            'Node and NodePool names must be unique %s',
            config['nodes'], config.get('node_pools', []))

        if config.get('node_pools'):
            self.validate_node_pool_nodes(config)

        config_context = ConfigContext('config', node_names,
            config.get('command_context'), MASTER_NAMESPACE)
        validate_jobs_and_services(config, config_context)