def _validate(G): ''' Validates dependency graph to ensure it has no missing or cyclic dependencies ''' for name in G.nodes(): if 'value' not in G.node[name] and 'template' not in G.node[name]: msg = 'Dependency unsatisfied in variable "%s"' % name raise ParamException(msg) if not nx.is_directed_acyclic_graph(G): graph_cycles = nx.simple_cycles(G) variable_names = [] for cycle in graph_cycles: try: variable_name = cycle[0] except IndexError: continue variable_names.append(variable_name) variable_names = ', '.join(sorted(variable_names)) msg = ( 'Cyclic dependency found in the following variables: %s. Likely the variable is ' 'referencing itself' % (variable_names)) raise ParamException(msg)
def _validate(G): ''' Validates dependency graph to ensure it has no missing or cyclic dependencies ''' for name in G.nodes(): if 'value' not in G.node[name] and 'template' not in G.node[name]: msg = 'Dependecy unsatisfied in %s' % name raise ParamException(msg) if not nx.is_directed_acyclic_graph(G): msg = 'Cyclic dependecy found' raise ParamException(msg)
def _resolve_dependencies(G): ''' Traverse the dependency graph starting from resolved nodes ''' context = {} for name in nx.topological_sort(G): node = G.node[name] try: template = node.get('template', None) # Special case for non simple types which contains Jinja notation (lists, dicts) if 'template' in node and isinstance(template, (list, dict)): if isinstance(template, list): rendered_list = list() for template in G.node[name]['template']: rendered_list.append( _render(dict(template=template), context)) context[name] = rendered_list elif isinstance(template, dict): rendered_dict = dict() for key, value in G.node[name]['template'].items(): value = _render(dict(template=value), context) rendered_dict[key] = value context[name] = rendered_dict else: context[name] = _render(node, context) except Exception as e: LOG.debug('Failed to render %s: %s', name, e, exc_info=True) msg = 'Failed to render parameter "%s": %s' % (name, str(e)) raise ParamException(msg) return context
def __init__(self, *args, **kwargs): super(TokenController, self).__init__(*args, **kwargs) try: self.handler = HANDLER_MAPPINGS[cfg.CONF.auth.mode]() except KeyError: raise ParamException("%s is not a valid auth mode" % cfg.CONF.auth.mode)
def _resolve_dependencies(G): ''' Traverse the dependency graph starting from resolved nodes ''' context = {} for name in nx.topological_sort(G): node = G.node[name] try: context[name] = _render(node, context) except Exception as e: LOG.debug('Failed to render %s: %s', name, e, exc_info=True) msg = 'Failed to render parameter "%s": %s' % (name, str(e)) raise ParamException(msg) return context
def _resolve_dependencies(G): ''' Traverse the dependency graph starting from resolved nodes ''' context = {} for name in nx.topological_sort(G): node = G.node[name] try: if 'template' in node and isinstance(node.get('template', None), list): rendered_list = list() for template in G.node[name]['template']: rendered_list.append( _render(dict(template=template), context)) context[name] = rendered_list else: context[name] = _render(node, context) except Exception as e: LOG.debug('Failed to render %s: %s', name, e, exc_info=True) msg = 'Failed to render parameter "%s": %s' % (name, str(e)) raise ParamException(msg) return context
def __init__(self): try: self.handler = HANDLER_MAPPINGS[cfg.CONF.auth.mode]() except KeyError: raise ParamException("%s is not a valid auth mode" % cfg.CONF.auth.mode)