Merge pull request #332 from dshulyak/graph_tests
Fixing graph tests + test for load by tags
This commit is contained in:
commit
65a63cc907
@ -48,13 +48,6 @@ def create(plan):
|
|||||||
click.echo(uid)
|
click.echo(uid)
|
||||||
|
|
||||||
|
|
||||||
@orchestration.command()
|
|
||||||
@click.argument('uid', type=SOLARUID)
|
|
||||||
@click.argument('plan')
|
|
||||||
def update(uid, plan):
|
|
||||||
graph.update_plan(uid, plan)
|
|
||||||
|
|
||||||
|
|
||||||
def wait_report(uid, timeout, interval=3):
|
def wait_report(uid, timeout, interval=3):
|
||||||
try:
|
try:
|
||||||
if timeout:
|
if timeout:
|
||||||
|
@ -152,6 +152,5 @@ def build_edges(changes_graph, events):
|
|||||||
for parent, child, data in events_graph.edges(event_name, data=True):
|
for parent, child, data in events_graph.edges(event_name, data=True):
|
||||||
succ_ev = data['event']
|
succ_ev = data['event']
|
||||||
succ_ev.insert(stack, changes_graph)
|
succ_ev.insert(stack, changes_graph)
|
||||||
|
|
||||||
visited.add(event_name)
|
visited.add(event_name)
|
||||||
return changes_graph
|
return changes_graph
|
||||||
|
@ -118,9 +118,11 @@ class StateChange(Event):
|
|||||||
etype = 'state_change'
|
etype = 'state_change'
|
||||||
|
|
||||||
def insert(self, changed_resources, changes_graph):
|
def insert(self, changed_resources, changes_graph):
|
||||||
changed_resources.append(self.parent)
|
changed_resources.append(self.parent_node)
|
||||||
|
try:
|
||||||
location_id = Resource.get(self.parent).inputs['location_id']
|
location_id = Resource.get(self.parent).inputs['location_id']
|
||||||
|
except DBLayerNotFound:
|
||||||
|
location_id = None
|
||||||
changes_graph.add_node(
|
changes_graph.add_node(
|
||||||
self.parent_node, status='PENDING',
|
self.parent_node, status='PENDING',
|
||||||
target=location_id,
|
target=location_id,
|
||||||
|
@ -24,6 +24,7 @@ from solar import errors
|
|||||||
from collections import Counter
|
from collections import Counter
|
||||||
|
|
||||||
from solar.dblayer.solar_models import Task
|
from solar.dblayer.solar_models import Task
|
||||||
|
from solar.dblayer.model import clear_cache
|
||||||
|
|
||||||
|
|
||||||
def save_graph(graph):
|
def save_graph(graph):
|
||||||
@ -128,24 +129,6 @@ def create_plan(plan_path, save=True):
|
|||||||
return create_plan_from_graph(dg, save=save)
|
return create_plan_from_graph(dg, save=save)
|
||||||
|
|
||||||
|
|
||||||
def update_plan(uid, plan_path):
|
|
||||||
"""update preserves old status of tasks if they werent removed
|
|
||||||
"""
|
|
||||||
|
|
||||||
new = parse_plan(plan_path)
|
|
||||||
old = get_graph(uid)
|
|
||||||
return update_plan_from_graph(new, old).graph['uid']
|
|
||||||
|
|
||||||
|
|
||||||
def update_plan_from_graph(new, old):
|
|
||||||
new.graph = old.graph
|
|
||||||
for n in new:
|
|
||||||
if n in old:
|
|
||||||
new.node[n]['status'] = old.node[n]['status']
|
|
||||||
|
|
||||||
save_graph(new)
|
|
||||||
return new
|
|
||||||
|
|
||||||
|
|
||||||
def reset_by_uid(uid, state_list=None):
|
def reset_by_uid(uid, state_list=None):
|
||||||
dg = get_graph(uid)
|
dg = get_graph(uid)
|
||||||
@ -187,6 +170,8 @@ def wait_finish(uid, timeout):
|
|||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
|
|
||||||
while start_time + timeout >= time.time():
|
while start_time + timeout >= time.time():
|
||||||
|
# need to clear cache before fetching updated status
|
||||||
|
clear_cache()
|
||||||
dg = get_graph(uid)
|
dg = get_graph(uid)
|
||||||
summary = Counter()
|
summary = Counter()
|
||||||
summary.update({s.name: 0 for s in states})
|
summary.update({s.name: 0 for s in states})
|
||||||
@ -194,6 +179,7 @@ def wait_finish(uid, timeout):
|
|||||||
yield summary
|
yield summary
|
||||||
if summary[states.PENDING.name] + summary[states.INPROGRESS.name] == 0:
|
if summary[states.PENDING.name] + summary[states.INPROGRESS.name] == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise errors.ExecutionTimeout(
|
raise errors.ExecutionTimeout(
|
||||||
'Run %s wasnt able to finish' % uid)
|
'Run %s wasnt able to finish' % uid)
|
||||||
|
@ -13,12 +13,12 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from copy import deepcopy
|
|
||||||
|
|
||||||
from pytest import fixture
|
from pytest import fixture
|
||||||
|
|
||||||
from solar.orchestration import graph
|
from solar.orchestration import graph
|
||||||
from solar.orchestration.traversal import states
|
from solar.orchestration.traversal import states
|
||||||
|
from solar.dblayer.model import ModelMeta
|
||||||
|
|
||||||
|
|
||||||
@fixture
|
@fixture
|
||||||
@ -34,28 +34,6 @@ def test_simple_plan_created_and_loaded(simple):
|
|||||||
plan = graph.get_plan(simple.graph['uid'])
|
plan = graph.get_plan(simple.graph['uid'])
|
||||||
assert set(plan.nodes()) == {'just_fail', 'echo_stuff'}
|
assert set(plan.nodes()) == {'just_fail', 'echo_stuff'}
|
||||||
|
|
||||||
|
|
||||||
def test_update_plan_with_new_node(simple):
|
|
||||||
new = deepcopy(simple)
|
|
||||||
new.add_node('one_more', {})
|
|
||||||
graph.update_plan_from_graph(new, simple)
|
|
||||||
updated = graph.get_plan(new.graph['uid'])
|
|
||||||
assert set(updated.nodes()) == {'one_more', 'just_fail', 'echo_stuff'}
|
|
||||||
|
|
||||||
|
|
||||||
def test_status_preserved_on_update(simple):
|
|
||||||
new = deepcopy(simple)
|
|
||||||
task_under_test = 'echo_stuff'
|
|
||||||
|
|
||||||
assert new.node[task_under_test]['status'] == states.PENDING.name
|
|
||||||
|
|
||||||
simple.node[task_under_test]['status'] = states.SUCCESS.name
|
|
||||||
graph.update_plan_from_graph(new, simple)
|
|
||||||
|
|
||||||
updated = graph.get_plan(new.graph['uid'])
|
|
||||||
assert new.node[task_under_test]['status'] == states.SUCCESS.name
|
|
||||||
|
|
||||||
|
|
||||||
def test_reset_all_states(simple):
|
def test_reset_all_states(simple):
|
||||||
for n in simple:
|
for n in simple:
|
||||||
simple.node[n]['status'] == states.ERROR.name
|
simple.node[n]['status'] == states.ERROR.name
|
||||||
@ -78,18 +56,17 @@ def test_reset_only_provided(simple):
|
|||||||
def test_wait_finish(simple):
|
def test_wait_finish(simple):
|
||||||
for n in simple:
|
for n in simple:
|
||||||
simple.node[n]['status'] = states.SUCCESS.name
|
simple.node[n]['status'] = states.SUCCESS.name
|
||||||
graph.save_graph(simple)
|
graph.update_graph(simple)
|
||||||
|
|
||||||
assert next(graph.wait_finish(simple.graph['uid'], 10)) == {'SKIPPED': 0, 'SUCCESS': 2, 'NOOP': 0, 'ERROR': 0, 'INPROGRESS': 0, 'PENDING': 0}
|
assert next(graph.wait_finish(simple.graph['uid'], 10)) == {'SKIPPED': 0, 'SUCCESS': 2, 'NOOP': 0, 'ERROR': 0, 'INPROGRESS': 0, 'PENDING': 0}
|
||||||
|
|
||||||
|
|
||||||
def test_several_updates(simple):
|
def test_several_updates(simple):
|
||||||
simple.node['just_fail']['status'] = states.ERROR.name
|
simple.node['just_fail']['status'] = states.ERROR.name
|
||||||
graph.save_graph(simple)
|
graph.update_graph(simple)
|
||||||
|
|
||||||
assert next(graph.wait_finish(simple.graph['uid'], 10)) == {'SKIPPED': 0, 'SUCCESS': 0, 'NOOP': 0, 'ERROR': 1, 'INPROGRESS': 0, 'PENDING': 1}
|
assert next(graph.wait_finish(simple.graph['uid'], 10)) == {'SKIPPED': 0, 'SUCCESS': 0, 'NOOP': 0, 'ERROR': 1, 'INPROGRESS': 0, 'PENDING': 1}
|
||||||
|
|
||||||
simple.node['echo_stuff']['status'] = states.ERROR.name
|
simple.node['echo_stuff']['status'] = states.ERROR.name
|
||||||
graph.save_graph(simple)
|
graph.update_graph(simple)
|
||||||
|
|
||||||
assert next(graph.wait_finish(simple.graph['uid'], 10)) == {'SKIPPED': 0, 'SUCCESS': 0, 'NOOP': 0, 'ERROR': 2, 'INPROGRESS': 0, 'PENDING': 0}
|
assert next(graph.wait_finish(simple.graph['uid'], 10)) == {'SKIPPED': 0, 'SUCCESS': 0, 'NOOP': 0, 'ERROR': 2, 'INPROGRESS': 0, 'PENDING': 0}
|
||||||
|
@ -15,20 +15,31 @@
|
|||||||
from pytest import fixture
|
from pytest import fixture
|
||||||
|
|
||||||
from solar.core import resource
|
from solar.core import resource
|
||||||
|
from solar.dblayer.solar_models import Resource
|
||||||
|
from solar.dblayer.model import ModelMeta
|
||||||
|
|
||||||
|
|
||||||
@fixture
|
@fixture
|
||||||
def tagged_resources(resources):
|
def tagged_resources():
|
||||||
assert len(resources) == 3
|
tags = ['n1', 'n2', 'n3']
|
||||||
for res in resources.values():
|
t1 = Resource.from_dict('t1',
|
||||||
res.add_tags('n1', 'n2', 'n3')
|
{'name': 't1', 'tags': tags, 'base_path': 'x'})
|
||||||
return resources
|
t1.save_lazy()
|
||||||
|
t2 = Resource.from_dict('t2',
|
||||||
|
{'name': 't2', 'tags': tags, 'base_path': 'x'})
|
||||||
|
t2.save_lazy()
|
||||||
|
t3 = Resource.from_dict('t3',
|
||||||
|
{'name': 't3', 'tags': tags, 'base_path': 'x'})
|
||||||
|
t3.save_lazy()
|
||||||
|
ModelMeta.save_all_lazy()
|
||||||
|
return [t1, t2, t3]
|
||||||
|
|
||||||
|
|
||||||
def test_add_remove_tags(tagged_resources):
|
def test_add_remove_tags(tagged_resources):
|
||||||
assert len(resource.load_by_tags({'n1', 'n2'})) == 3
|
loaded = resource.load_by_tags({'n1', 'n2'})
|
||||||
|
assert len(loaded) == 3
|
||||||
|
|
||||||
for res in tagged_resources.values():
|
for res in loaded:
|
||||||
res.remove_tags('n1')
|
res.remove_tags('n1')
|
||||||
|
|
||||||
assert len(resource.load_by_tags(set(['n1']))) == 0
|
assert len(resource.load_by_tags(set(['n1']))) == 0
|
||||||
|
Loading…
Reference in New Issue
Block a user