Merge "Insert missing events during build of staged graph"

This commit is contained in:
Jenkins 2016-03-03 10:32:06 +00:00 committed by Gerrit Code Review
commit 65f4898f98
3 changed files with 29 additions and 21 deletions

View File

@ -143,17 +143,20 @@ def build_edges(changes_graph, events):
visited = set()
while stack:
event_name = stack.pop(0)
if event_name in events_graph:
log.debug('Next events after %s are %s', event_name,
events_graph.successors(event_name))
else:
log.debug('No outgoing events based on %s', event_name)
if event_name not in visited:
for parent, child, data in events_graph.edges(event_name,
data=True):
succ_ev = data['event']
succ_ev.insert(stack, changes_graph)
# FIXME(dshulyak) interface of events should be changed
if succ_ev.insert(stack, changes_graph):
new_events = all_events(succ_ev.child)
for ev in new_events:
events_graph.add_edge(
ev.parent_node, ev.child_node, event=ev)
visited.add(event_name)
return changes_graph

View File

@ -115,6 +115,7 @@ class React(Event):
changes_graph.add_edge(
self.parent_node, self.child_node, state=self.state)
changed_resources.append(self.child_node)
return True
class StateChange(Event):

View File

@ -56,30 +56,29 @@ def test_single_event(events_example):
@fixture
def nova_deps():
rst = [
evapi.Dep('nova', 'run', 'success', 'nova_api', 'run'),
evapi.Dep('nova', 'update', 'success', 'nova_api', 'update'),
evapi.React('nova', 'update', 'success', 'nova_api', 'update')
]
return {'nova': rst}
for name in ['nova', 'nova_api', 'nova_sch']:
r = Resource.from_dict(dict(key=name, name=name))
r.inputs.add_new('location_id', '1')
r.save()
nova = [
evapi.Dep('nova', 'run', 'success', 'nova_sch', 'run'),
evapi.React('nova', 'run', 'success', 'nova_api', 'update')]
nova_api = [
evapi.React('nova_api', 'update', 'success', 'nova', 'reboot')]
evapi.add_events('nova', nova)
evapi.add_events('nova_api', nova_api)
return {'nova': nova}
def test_nova_api_run_after_nova(nova_deps):
def test_nova_api(nova_deps):
changes_graph = nx.DiGraph()
changes_graph.add_node('nova.run')
changes_graph.add_node('nova_api.run')
changes_graph.add_node('nova_sch.run')
evapi.build_edges(changes_graph, nova_deps)
assert changes_graph.successors('nova.run') == ['nova_api.run']
def test_nova_api_react_on_update(nova_deps):
"""Test that nova_api:update will be called even if there is no changes in nova_api""" # NOQA
changes_graph = nx.DiGraph()
changes_graph.add_node('nova.update')
evapi.build_edges(changes_graph, nova_deps)
assert changes_graph.successors('nova.update') == ['nova_api.update']
assert set(changes_graph.successors('nova.run')) == {
'nova_sch.run', 'nova_api.update'}
assert changes_graph.successors('nova_api.update') == ['nova.reboot']
@fixture
@ -142,6 +141,11 @@ def test_riak():
'commit')
],
}
for name in events:
res = Resource.from_dict({'key': name, 'name': name})
res.save()
res.inputs.add_new('location_id', '1')
evapi.add_events(name, events[name])
changes_graph = nx.MultiDiGraph()
changes_graph.add_node('riak_service1.run')