Ejemplo n.º 1
0
def _cross_validate_final_config(objtree, evict_on_error=True):
    """
    Run validation checks that require correlating values from different sections.
    """
    # take a copy of cluster config as we might be modifying it
    for name, cluster in list(objtree['cluster'].items()):
        valid = True
        # ensure all cluster node kinds are defined in the `setup/*` section
        setup_sect = cluster['setup']
        for groupname, properties in cluster['nodes'].items():
            if (groupname + '_groups') not in setup_sect:
                log.error(
                    "Cluster `%s` requires nodes of kind `%s`,"
                    " but no such group is defined"
                    " in the referenced setup section.", name, groupname)
                valid = False
                break

        # ensure `ssh_to` has a valid value
        if 'ssh_to' in cluster:
            ssh_to = cluster['ssh_to']
            try:
                # extract node kind if this is a node name (e.g., `master001` => `master`)
                parts = NodeNamingPolicy.parse(ssh_to)
                ssh_to = parts['kind']
            except ValueError:
                pass
            if ssh_to not in cluster['nodes']:
                log.error(
                    "Cluster `%s` is configured to SSH into nodes of kind `%s`,"
                    " but no such kind is defined.", name, ssh_to)
                valid = False

        # EC2-specific checks
        if cluster['cloud']['provider'] == 'ec2_boto':
            cluster_uses_vpc = ('vpc' in cluster['cloud'])
            for groupname, properties in cluster['nodes'].items():
                if cluster_uses_vpc and 'network_ids' not in properties:
                    log.error(
                        "Node group `%s/%s` is being used in a VPC,"
                        " so it must specify ``network_ids``.", cluster,
                        groupname)
                    if evict_on_error:
                        valid = False
                        break
                if not cluster_uses_vpc and 'network_ids' in properties:
                    log.error(
                        "Cluster `%s` must specify a VPC"
                        " to place `%s` instances in network `%s`", cluster,
                        groupname, properties['network_ids'])
                    if evict_on_error:
                        valid = False
                        break
        if not valid:
            log.error("Dropping cluster `%s` because of the above errors",
                      name)
            del objtree['cluster'][name]
    return objtree
Ejemplo n.º 2
0
def _cross_validate_final_config(objtree, evict_on_error=True):
    """
    Run validation checks that require correlating values from different sections.
    """
    # take a copy of cluster config as we might be modifying it
    for name, cluster in list(objtree['cluster'].items()):
        valid = True
        # ensure all cluster node kinds are defined in the `setup/*` section
        setup_sect = cluster['setup']
        for groupname, properties in cluster['nodes'].items():
            if (groupname + '_groups') not in setup_sect:
                log.error("Cluster `%s` requires nodes of kind `%s`,"
                          " but no such group is defined"
                          " in the referenced setup section.",
                          name, groupname)
                valid = False
                break

        # ensure `ssh_to` has a valid value
        if 'ssh_to' in cluster:
            ssh_to = cluster['ssh_to']
            try:
                # extract node kind if this is a node name (e.g., `master001` => `master`)
                parts = NodeNamingPolicy.parse(ssh_to)
                ssh_to = parts['kind']
            except ValueError:
                pass
            if ssh_to not in cluster['nodes']:
                log.error("Cluster `%s` is configured to SSH into nodes of kind `%s`,"
                          " but no such kind is defined.", name, ssh_to)
                valid = False

        # EC2-specific checks
        if cluster['cloud']['provider'] == 'ec2_boto':
            cluster_uses_vpc = ('vpc' in cluster['cloud'])
            for groupname, properties in cluster['nodes'].items():
                if cluster_uses_vpc and 'network_ids' not in properties:
                    log.error(
                        "Node group `%s/%s` is being used in a VPC,"
                        " so it must specify ``network_ids``.",
                        cluster, groupname)
                    if evict_on_error:
                        valid = False
                        break
                if not cluster_uses_vpc and 'network_ids' in properties:
                    log.error(
                        "Cluster `%s` must specify a VPC"
                        " to place `%s` instances in network `%s`",
                        cluster, groupname, properties['network_ids'])
                    if evict_on_error:
                        valid = False
                        break
        if not valid:
            log.error("Dropping cluster `%s` because of the above errors", name)
            del objtree['cluster'][name]
    return objtree