def validate_model(model):
    """
    Validate a single data model parameter or a full data model block by
    recursively calling the 'validate' method on each node working from
    the leaf nodes up the tree.

    :param model: part of data model to validate
    :type model:  :graphit:GraphAxis

    :return:      overall successful validation
    :rtype:       :py:bool
    """

    allnodes = model.nodes.keys()
    leaves = model.leaves(return_nids=True)
    done = []

    def _walk_ancestors(nodes, success=True):
        parents = []
        for node in nodes:
            node = model.getnodes(node)

            # Continue only if the node was found and it has a 'validate' method
            if not node.empty() and hasattr(node, 'validate'):
                val = node.validate()
                done.append(node.nid)
                if not val:
                    return False

                pnid = node.parent().nid
                if pnid not in done and pnid in allnodes:
                    parents.append(pnid)

        if parents:
            return _walk_ancestors(set(parents), success=success)
        return success

    # Recursively walk the tree from leaves up to root.
    return _walk_ancestors(leaves)