From 4b80fcec814ceac02baf95e1e53b1e25492cf6e7 Mon Sep 17 00:00:00 2001 From: Maciej Kwiek Date: Wed, 2 Mar 2016 09:53:04 +0100 Subject: [PATCH] Change PENDING_RETRY to ERROR_RETRY in soft_stop * Added test for soft_stop * Replaced simple fixture with simple_plan fixture in tests Change-Id: I2375c586f2e733f1ff3de3455b19a39d3baff7be Closes-bug: 1549312 --- solar/orchestration/workers/scheduler.py | 2 +- solar/test/orchestration/test_scheduler.py | 14 +++++ solar/test/test_graph_api.py | 62 +++++++++------------- 3 files changed, 41 insertions(+), 37 deletions(-) diff --git a/solar/orchestration/workers/scheduler.py b/solar/orchestration/workers/scheduler.py index 1cc31e65..b75f4507 100644 --- a/solar/orchestration/workers/scheduler.py +++ b/solar/orchestration/workers/scheduler.py @@ -71,7 +71,7 @@ class Scheduler(base.Worker): plan = graph.get_graph(plan_uid) for n in plan: if plan.node[n]['status'] in ( - states.PENDING.name, states.PENDING_RETRY.name): + states.PENDING.name, states.ERROR_RETRY.name): plan.node[n]['status'] = states.SKIPPED.name graph.update_graph(plan) diff --git a/solar/test/orchestration/test_scheduler.py b/solar/test/orchestration/test_scheduler.py index 4924749a..a5fc5cec 100644 --- a/solar/test/orchestration/test_scheduler.py +++ b/solar/test/orchestration/test_scheduler.py @@ -14,6 +14,8 @@ import pytest +from solar.orchestration import graph +from solar.orchestration.traversal import states from solar.orchestration.workers.scheduler import Scheduler @@ -21,3 +23,15 @@ def test_scheduler_next_fails_with_empty_plan(): scheduler = Scheduler(None) with pytest.raises(ValueError): scheduler.next({}, 'nonexistent_uid') + + +def test_soft_stop(simple_plan): + # graph.save_graph(simple_plan) + uid = simple_plan.graph['uid'] + + scheduler = Scheduler(None) + scheduler.soft_stop({}, uid) + + plan = graph.get_graph(uid) + for n in plan: + assert plan.node[n]['status'] == states.SKIPPED.name diff --git a/solar/test/test_graph_api.py b/solar/test/test_graph_api.py index cc95d1cc..c5bacca3 100644 --- a/solar/test/test_graph_api.py +++ b/solar/test/test_graph_api.py @@ -12,8 +12,6 @@ # License for the specific language governing permissions and limitations # under the License. -import os - import networkx as nx from pytest import fixture @@ -21,43 +19,35 @@ from solar.orchestration import graph from solar.orchestration.traversal import states -@fixture -def simple(): - simple_path = os.path.join( - os.path.dirname(os.path.realpath(__file__)), 'orch_fixtures', - 'simple.yaml') - return graph.create_plan(simple_path) - - -def test_simple_plan_created_and_loaded(simple): - plan = graph.get_plan(simple.graph['uid']) +def test_simple_plan_plan_created_and_loaded(simple_plan): + plan = graph.get_plan(simple_plan.graph['uid']) assert set(plan.nodes()) == {'just_fail', 'echo_stuff'} -def test_reset_all_states(simple): - for n in simple: - simple.node[n]['status'] == states.ERROR.name - graph.reset(simple) +def test_reset_all_states(simple_plan): + for n in simple_plan: + simple_plan.node[n]['status'] == states.ERROR.name + graph.reset(simple_plan) - for n in simple: - assert simple.node[n]['status'] == states.PENDING.name + for n in simple_plan: + assert simple_plan.node[n]['status'] == states.PENDING.name -def test_reset_only_provided(simple): - simple.node['just_fail']['status'] = states.ERROR.name - simple.node['echo_stuff']['status'] = states.SUCCESS.name +def test_reset_only_provided(simple_plan): + simple_plan.node['just_fail']['status'] = states.ERROR.name + simple_plan.node['echo_stuff']['status'] = states.SUCCESS.name - graph.reset(simple, [states.ERROR.name]) + graph.reset(simple_plan, [states.ERROR.name]) - assert simple.node['just_fail']['status'] == states.PENDING.name - assert simple.node['echo_stuff']['status'] == states.SUCCESS.name + assert simple_plan.node['just_fail']['status'] == states.PENDING.name + assert simple_plan.node['echo_stuff']['status'] == states.SUCCESS.name -def test_wait_finish(simple): - for n in simple: - simple.node[n]['status'] = states.SUCCESS.name - graph.update_graph(simple) - assert next(graph.wait_finish(simple.graph['uid'], 10)) == { +def test_wait_finish(simple_plan): + for n in simple_plan: + simple_plan.node[n]['status'] = states.SUCCESS.name + graph.update_graph(simple_plan) + assert next(graph.wait_finish(simple_plan.graph['uid'], 10)) == { 'SKIPPED': 0, 'SUCCESS': 2, 'NOOP': 0, @@ -68,11 +58,11 @@ def test_wait_finish(simple): } -def test_several_updates(simple): - simple.node['just_fail']['status'] = states.ERROR.name - graph.update_graph(simple) +def test_several_updates(simple_plan): + simple_plan.node['just_fail']['status'] = states.ERROR.name + graph.update_graph(simple_plan) - assert next(graph.wait_finish(simple.graph['uid'], 10)) == { + assert next(graph.wait_finish(simple_plan.graph['uid'], 10)) == { 'SKIPPED': 0, 'SUCCESS': 0, 'NOOP': 0, @@ -82,10 +72,10 @@ def test_several_updates(simple): 'ERROR_RETRY': 0, } - simple.node['echo_stuff']['status'] = states.ERROR.name - graph.update_graph(simple) + simple_plan.node['echo_stuff']['status'] = states.ERROR.name + graph.update_graph(simple_plan) - assert next(graph.wait_finish(simple.graph['uid'], 10)) == { + assert next(graph.wait_finish(simple_plan.graph['uid'], 10)) == { 'SKIPPED': 0, 'SUCCESS': 0, 'NOOP': 0,