Insert missing events during build of staged graph
In case if reaction was inserted in changes graph, we missed all possible successors of that reaction Closes-Bug #1552275 Change-Id: Iba21e20d1d31086bf76d64b906b52bc85fcd7693
This commit is contained in:
parent
170aa1827e
commit
8fcd41bbd6
@ -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
|
||||
|
@ -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):
|
||||
|
@ -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')
|
||||
|
Loading…
x
Reference in New Issue
Block a user