예제 #1
0
def test_assigned_weights_simple_sequence():
    dg = nx.DiGraph()
    t1 = Mock(name='t1', weight=0)
    t2 = Mock(name='t2', weight=0)
    t3 = Mock(name='t3', weight=0)
    dg.add_nodes_from([t1, t2, t3])
    dg.add_path([t1, t2, t3])
    graph.assign_weights_nested(dg)
    assert t1.weight == 2
    assert t2.weight == 1
    assert t3.weight == 0
예제 #2
0
def test_weights_multi_path():
    dg = nx.DiGraph()
    tasks = [Mock(name='t%s' % i, weight=0) for i in range(11)]
    first = tasks[0]
    half = (len(tasks) / 2) + 1
    dg.add_nodes_from(tasks)
    dg.add_path([first] + tasks[1:half])
    dg.add_path([first] + tasks[half:])
    graph.assign_weights_nested(dg)
    assert first.weight == len(tasks) - 1
    # two subtree are equal
    for s1, s2 in zip(tasks[1:half], tasks[half:]):
        assert s1.weight == s2.weight
예제 #3
0
def test_weights_strictly_decreasing():
    dg = nx.DiGraph()
    tasks = [Mock(name='t%s' % i, weight=0) for i in range(10)]
    dg.add_nodes_from(tasks)
    for i in range(10):
        first, rest = tasks[i], tasks[i + 1:]
        dg.add_edges_from([(first, n) for n in rest])
    graph.assign_weights_nested(dg)
    weights = iter(t.weight for t in tasks)
    previous = next(weights)
    for item in weights:
        assert previous > item
        previous = item
예제 #4
0
파일: change.py 프로젝트: openstack/solar
def send_to_orchestration(tags=None):
    dg = nx.MultiDiGraph()
    events = {}
    changed_nodes = []

    if tags:
        staged_log = LogItem.log_items_by_tags(tags)
    else:
        staged_log = data.SL()
    for logitem in staged_log:
        events[logitem.resource] = evapi.all_events(logitem.resource)
        changed_nodes.append(logitem.resource)

        state_change = StateChange(logitem.resource, logitem.action)
        state_change.insert(changed_nodes, dg)

    evapi.build_edges(dg, events)
    # what `name` should be?
    dg.graph['name'] = 'system_log'
    built_graph = graph.create_plan_from_graph(dg)
    graph.assign_weights_nested(built_graph)
    return built_graph