mirror of
https://github.com/ansible/awx.git
synced 2026-03-18 17:37:30 -02:30
do not mark ujt None nodes dnr
* Leave workflow nodes with no related unified job template nodes do_not_run = False. If we mark it True, we can't differentiate between the actual want to not take that path vs. do not run this because I do not have a valid related unified job template.
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
|
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
from django.utils.encoding import smart_text
|
||||||
|
|
||||||
# Python
|
# Python
|
||||||
from awx.main.models import (
|
from awx.main.models import (
|
||||||
WorkflowJobTemplateNode,
|
WorkflowJobTemplateNode,
|
||||||
@@ -50,61 +53,37 @@ class WorkflowDAG(SimpleDAG):
|
|||||||
for edge in always_nodes:
|
for edge in always_nodes:
|
||||||
self.add_edge(wfn_by_id[edge[0]], wfn_by_id[edge[1]], 'always_nodes')
|
self.add_edge(wfn_by_id[edge[0]], wfn_by_id[edge[1]], 'always_nodes')
|
||||||
|
|
||||||
r'''
|
|
||||||
Determine if all, relevant, parents node are finished.
|
|
||||||
Relevant parents are parents that are marked do_not_run False.
|
|
||||||
|
|
||||||
:param node: a node entry from SimpleDag.nodes (i.e. a dict with property ['node_object']
|
|
||||||
|
|
||||||
Return a boolean
|
|
||||||
'''
|
|
||||||
def _are_relevant_parents_finished(self, node):
|
def _are_relevant_parents_finished(self, node):
|
||||||
obj = node['node_object']
|
obj = node['node_object']
|
||||||
parent_nodes = [p['node_object'] for p in self.get_dependents(obj)]
|
parent_nodes = [p['node_object'] for p in self.get_dependents(obj)]
|
||||||
for p in parent_nodes:
|
for p in parent_nodes:
|
||||||
if p.do_not_run is True:
|
if p.do_not_run is True:
|
||||||
continue
|
continue
|
||||||
|
elif p.unified_job_template is None:
|
||||||
# job template relationship deleted, don't run the node and take the failure path
|
continue
|
||||||
if p.do_not_run is False and not p.job and p.unified_job_template is None:
|
|
||||||
return True
|
|
||||||
|
|
||||||
# Node might run a job
|
# Node might run a job
|
||||||
if p.do_not_run is False and not p.job:
|
elif not p.job:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Node decidedly got a job; check if job is done
|
# Node decidedly got a job; check if job is done
|
||||||
if p.job and p.job.status not in ['successful', 'failed', 'error', 'canceled']:
|
elif p.job and p.job.status not in ['successful', 'failed', 'error', 'canceled']:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def bfs_nodes_to_run(self):
|
def bfs_nodes_to_run(self):
|
||||||
nodes = self.get_root_nodes()
|
|
||||||
nodes_found = []
|
nodes_found = []
|
||||||
node_ids_visited = set()
|
|
||||||
|
|
||||||
for index, n in enumerate(nodes):
|
for node in self.sort_nodes_topological():
|
||||||
obj = n['node_object']
|
obj = node['node_object']
|
||||||
if obj.id in node_ids_visited:
|
if obj.do_not_run is True:
|
||||||
continue
|
continue
|
||||||
node_ids_visited.add(obj.id)
|
elif obj.job:
|
||||||
|
|
||||||
if obj.do_not_run is True and obj.unified_job_template:
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if obj.job:
|
|
||||||
if obj.job.status in ['failed', 'error', 'canceled']:
|
|
||||||
nodes.extend(self.get_dependencies(obj, 'failure_nodes') +
|
|
||||||
self.get_dependencies(obj, 'always_nodes'))
|
|
||||||
elif obj.job.status == 'successful':
|
|
||||||
nodes.extend(self.get_dependencies(obj, 'success_nodes') +
|
|
||||||
self.get_dependencies(obj, 'always_nodes'))
|
|
||||||
elif obj.unified_job_template is None:
|
elif obj.unified_job_template is None:
|
||||||
nodes.extend(self.get_dependencies(obj, 'failure_nodes') +
|
continue
|
||||||
self.get_dependencies(obj, 'always_nodes'))
|
|
||||||
else:
|
if self._are_relevant_parents_finished(node):
|
||||||
if self._are_relevant_parents_finished(n):
|
nodes_found.append(node)
|
||||||
nodes_found.append(n)
|
|
||||||
return [n['node_object'] for n in nodes_found]
|
return [n['node_object'] for n in nodes_found]
|
||||||
|
|
||||||
def cancel_node_jobs(self):
|
def cancel_node_jobs(self):
|
||||||
@@ -123,7 +102,7 @@ class WorkflowDAG(SimpleDAG):
|
|||||||
def is_workflow_done(self):
|
def is_workflow_done(self):
|
||||||
for node in self.nodes:
|
for node in self.nodes:
|
||||||
obj = node['node_object']
|
obj = node['node_object']
|
||||||
if obj.do_not_run is False and not obj.job:
|
if obj.do_not_run is False and not obj.job and obj.unified_job_template:
|
||||||
return False
|
return False
|
||||||
elif obj.job and obj.job.status not in ['successful', 'failed', 'canceled', 'error']:
|
elif obj.job and obj.job.status not in ['successful', 'failed', 'canceled', 'error']:
|
||||||
return False
|
return False
|
||||||
@@ -131,20 +110,40 @@ class WorkflowDAG(SimpleDAG):
|
|||||||
|
|
||||||
def has_workflow_failed(self):
|
def has_workflow_failed(self):
|
||||||
failed_nodes = []
|
failed_nodes = []
|
||||||
|
res = False
|
||||||
|
failed_path_nodes_id_status = []
|
||||||
|
failed_unified_job_template_node_ids = []
|
||||||
|
|
||||||
for node in self.nodes:
|
for node in self.nodes:
|
||||||
obj = node['node_object']
|
obj = node['node_object']
|
||||||
if obj.job and obj.job.status in ['failed', 'canceled', 'error']:
|
if obj.do_not_run is False and obj.unified_job_template is None:
|
||||||
failed_nodes.append(node)
|
failed_nodes.append(node)
|
||||||
elif obj.do_not_run is True and obj.unified_job_template is None:
|
elif obj.job and obj.job.status in ['failed', 'canceled', 'error']:
|
||||||
failed_nodes.append(node)
|
failed_nodes.append(node)
|
||||||
|
|
||||||
for node in failed_nodes:
|
for node in failed_nodes:
|
||||||
obj = node['node_object']
|
obj = node['node_object']
|
||||||
if (len(self.get_dependencies(obj, 'failure_nodes')) +
|
if (len(self.get_dependencies(obj, 'failure_nodes')) +
|
||||||
len(self.get_dependencies(obj, 'always_nodes'))) == 0:
|
len(self.get_dependencies(obj, 'always_nodes'))) == 0:
|
||||||
if obj.unified_job_template is None:
|
if obj.unified_job_template is None:
|
||||||
return True, "Workflow job node {} related unified job template missing and is without an error handle path".format(obj.id)
|
res = True
|
||||||
|
failed_unified_job_template_node_ids.append(str(obj.id))
|
||||||
else:
|
else:
|
||||||
return True, "Workflow job node {} has a status of '{}' without an error handler path".format(obj.id, obj.job.status)
|
res = True
|
||||||
|
failed_path_nodes_id_status.append((str(obj.id), obj.job.status))
|
||||||
|
|
||||||
|
if res is True:
|
||||||
|
s = _("No error handle path for workflow job node(s) [{node_status}] workflow job "
|
||||||
|
"node(s) missing unified job template and error handle path [{no_ufjt}].")
|
||||||
|
parms = {
|
||||||
|
'node_status': '',
|
||||||
|
'no_ufjt': '',
|
||||||
|
}
|
||||||
|
if len(failed_path_nodes_id_status) > 0:
|
||||||
|
parms['node_status'] = ",".join(["({},{})".format(id, status) for id, status in failed_path_nodes_id_status])
|
||||||
|
if len(failed_unified_job_template_node_ids) > 0:
|
||||||
|
parms['no_ufjt'] = ",".join(failed_unified_job_template_node_ids)
|
||||||
|
return True, smart_text(s.format(**parms))
|
||||||
return False, None
|
return False, None
|
||||||
|
|
||||||
r'''
|
r'''
|
||||||
@@ -159,9 +158,7 @@ class WorkflowDAG(SimpleDAG):
|
|||||||
'''
|
'''
|
||||||
def _are_all_nodes_dnr_decided(self, workflow_nodes):
|
def _are_all_nodes_dnr_decided(self, workflow_nodes):
|
||||||
for n in workflow_nodes:
|
for n in workflow_nodes:
|
||||||
if n.unified_job_template is None and n.do_not_run is False:
|
if n.do_not_run is False and not n.job and n.unified_job_template:
|
||||||
return False
|
|
||||||
if n.do_not_run is False and not n.job:
|
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -177,7 +174,9 @@ class WorkflowDAG(SimpleDAG):
|
|||||||
'''
|
'''
|
||||||
def _should_mark_node_dnr(self, node, parent_nodes):
|
def _should_mark_node_dnr(self, node, parent_nodes):
|
||||||
for p in parent_nodes:
|
for p in parent_nodes:
|
||||||
if p.job:
|
if p.do_not_run is True:
|
||||||
|
pass
|
||||||
|
elif p.job:
|
||||||
if p.job.status == 'successful':
|
if p.job.status == 'successful':
|
||||||
if node in (self.get_dependencies(p, 'success_nodes') +
|
if node in (self.get_dependencies(p, 'success_nodes') +
|
||||||
self.get_dependencies(p, 'always_nodes')):
|
self.get_dependencies(p, 'always_nodes')):
|
||||||
@@ -188,12 +187,10 @@ class WorkflowDAG(SimpleDAG):
|
|||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
elif p.unified_job_template is None:
|
elif p.do_not_run is False and p.unified_job_template is None:
|
||||||
if node in (self.get_dependencies(p, 'failure_nodes') +
|
if node in (self.get_dependencies(p, 'failure_nodes') +
|
||||||
self.get_dependencies(p, 'always_nodes')):
|
self.get_dependencies(p, 'always_nodes')):
|
||||||
return False
|
return False
|
||||||
elif p.do_not_run is True:
|
|
||||||
pass
|
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
@@ -205,13 +202,10 @@ class WorkflowDAG(SimpleDAG):
|
|||||||
for node in self.sort_nodes_topological():
|
for node in self.sort_nodes_topological():
|
||||||
obj = node['node_object']
|
obj = node['node_object']
|
||||||
|
|
||||||
if obj.do_not_run is False and not obj.job:
|
if obj.do_not_run is False and not obj.job and node not in root_nodes:
|
||||||
parent_nodes = [p['node_object'] for p in self.get_dependents(obj)]
|
parent_nodes = [p['node_object'] for p in self.get_dependents(obj)]
|
||||||
if self._are_all_nodes_dnr_decided(parent_nodes):
|
if self._are_all_nodes_dnr_decided(parent_nodes):
|
||||||
if obj.unified_job_template is None:
|
if self._should_mark_node_dnr(node, parent_nodes):
|
||||||
obj.do_not_run = True
|
|
||||||
nodes_marked_do_not_run.append(node)
|
|
||||||
elif node not in root_nodes and self._should_mark_node_dnr(node, parent_nodes):
|
|
||||||
obj.do_not_run = True
|
obj.do_not_run = True
|
||||||
nodes_marked_do_not_run.append(node)
|
nodes_marked_do_not_run.append(node)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import pytest
|
import pytest
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
from django.utils.encoding import smart_text
|
||||||
|
|
||||||
from awx.main.scheduler.dag_workflow import WorkflowDAG
|
from awx.main.scheduler.dag_workflow import WorkflowDAG
|
||||||
|
|
||||||
|
|
||||||
@@ -22,7 +25,7 @@ def wf_node_generator(mocker):
|
|||||||
pytest.count = 0
|
pytest.count = 0
|
||||||
|
|
||||||
def fn(**kwargs):
|
def fn(**kwargs):
|
||||||
wfn = WorkflowNode(id=pytest.count, **kwargs)
|
wfn = WorkflowNode(id=pytest.count, unified_job_template=object(), **kwargs)
|
||||||
pytest.count += 1
|
pytest.count += 1
|
||||||
return wfn
|
return wfn
|
||||||
return fn
|
return fn
|
||||||
@@ -31,7 +34,7 @@ def wf_node_generator(mocker):
|
|||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def workflow_dag_1(wf_node_generator):
|
def workflow_dag_1(wf_node_generator):
|
||||||
g = WorkflowDAG()
|
g = WorkflowDAG()
|
||||||
nodes = [wf_node_generator(unified_job_template=object()) for i in range(4)]
|
nodes = [wf_node_generator() for i in range(4)]
|
||||||
map(lambda n: g.add_node(n), nodes)
|
map(lambda n: g.add_node(n), nodes)
|
||||||
|
|
||||||
r'''
|
r'''
|
||||||
@@ -85,8 +88,6 @@ class TestWorkflowDAG():
|
|||||||
class TestDNR():
|
class TestDNR():
|
||||||
def test_mark_dnr_nodes(self, workflow_dag_1):
|
def test_mark_dnr_nodes(self, workflow_dag_1):
|
||||||
(g, nodes) = workflow_dag_1
|
(g, nodes) = workflow_dag_1
|
||||||
for n in nodes:
|
|
||||||
n.unified_job_template = object()
|
|
||||||
|
|
||||||
r'''
|
r'''
|
||||||
S0
|
S0
|
||||||
@@ -132,8 +133,6 @@ class TestIsWorkflowDone():
|
|||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def workflow_dag_2(self, workflow_dag_1):
|
def workflow_dag_2(self, workflow_dag_1):
|
||||||
(g, nodes) = workflow_dag_1
|
(g, nodes) = workflow_dag_1
|
||||||
for n in nodes:
|
|
||||||
n.unified_job_template = uuid.uuid4()
|
|
||||||
r'''
|
r'''
|
||||||
S0
|
S0
|
||||||
/\
|
/\
|
||||||
@@ -184,7 +183,7 @@ class TestIsWorkflowDone():
|
|||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def workflow_dag_canceled(self, wf_node_generator):
|
def workflow_dag_canceled(self, wf_node_generator):
|
||||||
g = WorkflowDAG()
|
g = WorkflowDAG()
|
||||||
nodes = [wf_node_generator(unified_job_template=object()) for i in range(1)]
|
nodes = [wf_node_generator() for i in range(1)]
|
||||||
map(lambda n: g.add_node(n), nodes)
|
map(lambda n: g.add_node(n), nodes)
|
||||||
r'''
|
r'''
|
||||||
F0
|
F0
|
||||||
@@ -207,7 +206,9 @@ class TestIsWorkflowDone():
|
|||||||
(g, nodes) = workflow_dag_failed
|
(g, nodes) = workflow_dag_failed
|
||||||
|
|
||||||
assert g.is_workflow_done() is True
|
assert g.is_workflow_done() is True
|
||||||
assert g.has_workflow_failed() == (True, "Workflow job node {} has a status of 'failed' without an error handler path".format(nodes[2].id))
|
assert g.has_workflow_failed() == \
|
||||||
|
(True, smart_text(_("No error handle path for workflow job node(s) [({},{})] workflow job node(s)"
|
||||||
|
" missing unified job template and error handle path [].").format(nodes[2].id, nodes[2].job.status)))
|
||||||
|
|
||||||
def test_is_workflow_done_no_unified_job_tempalte_end(self, workflow_dag_failed):
|
def test_is_workflow_done_no_unified_job_tempalte_end(self, workflow_dag_failed):
|
||||||
(g, nodes) = workflow_dag_failed
|
(g, nodes) = workflow_dag_failed
|
||||||
@@ -216,8 +217,8 @@ class TestIsWorkflowDone():
|
|||||||
|
|
||||||
assert g.is_workflow_done() is True
|
assert g.is_workflow_done() is True
|
||||||
assert g.has_workflow_failed() == \
|
assert g.has_workflow_failed() == \
|
||||||
(True, "Workflow job node {} related unified job template missing"
|
(True, smart_text(_("No error handle path for workflow job node(s) [] workflow job node(s) missing"
|
||||||
" and is without an error handle path".format(nodes[2].id))
|
" unified job template and error handle path [{}].").format(nodes[2].id)))
|
||||||
|
|
||||||
def test_is_workflow_done_no_unified_job_tempalte_begin(self, workflow_dag_1):
|
def test_is_workflow_done_no_unified_job_tempalte_begin(self, workflow_dag_1):
|
||||||
(g, nodes) = workflow_dag_1
|
(g, nodes) = workflow_dag_1
|
||||||
@@ -227,25 +228,29 @@ class TestIsWorkflowDone():
|
|||||||
|
|
||||||
assert g.is_workflow_done() is True
|
assert g.is_workflow_done() is True
|
||||||
assert g.has_workflow_failed() == \
|
assert g.has_workflow_failed() == \
|
||||||
(True, "Workflow job node {} related unified job template missing"
|
(True, smart_text(_("No error handle path for workflow job node(s) [] workflow job node(s) missing"
|
||||||
" and is without an error handle path".format(nodes[0].id))
|
" unified job template and error handle path [{}].").format(nodes[0].id)))
|
||||||
|
|
||||||
def test_canceled_should_fail(self, workflow_dag_canceled):
|
def test_canceled_should_fail(self, workflow_dag_canceled):
|
||||||
(g, nodes) = workflow_dag_canceled
|
(g, nodes) = workflow_dag_canceled
|
||||||
|
|
||||||
assert g.has_workflow_failed() == (True, "Workflow job node {} has a status of 'canceled' without an error handler path".format(nodes[0].id))
|
assert g.has_workflow_failed() == \
|
||||||
|
(True, smart_text(_("No error handle path for workflow job node(s) [({},{})] workflow job node(s)"
|
||||||
|
" missing unified job template and error handle path [].").format(nodes[0].id, nodes[0].job.status)))
|
||||||
|
|
||||||
def test_failure_should_fail(self, workflow_dag_failure):
|
def test_failure_should_fail(self, workflow_dag_failure):
|
||||||
(g, nodes) = workflow_dag_failure
|
(g, nodes) = workflow_dag_failure
|
||||||
|
|
||||||
assert g.has_workflow_failed() == (True, "Workflow job node {} has a status of 'failed' without an error handler path".format(nodes[0].id))
|
assert g.has_workflow_failed() == \
|
||||||
|
(True, smart_text(_("No error handle path for workflow job node(s) [({},{})] workflow job node(s)"
|
||||||
|
" missing unified job template and error handle path [].").format(nodes[0].id, nodes[0].job.status)))
|
||||||
|
|
||||||
|
|
||||||
class TestBFSNodesToRun():
|
class TestBFSNodesToRun():
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def workflow_dag_canceled(self, wf_node_generator):
|
def workflow_dag_canceled(self, wf_node_generator):
|
||||||
g = WorkflowDAG()
|
g = WorkflowDAG()
|
||||||
nodes = [wf_node_generator(unified_job_template=object()) for i in range(4)]
|
nodes = [wf_node_generator() for i in range(4)]
|
||||||
map(lambda n: g.add_node(n), nodes)
|
map(lambda n: g.add_node(n), nodes)
|
||||||
r'''
|
r'''
|
||||||
C0
|
C0
|
||||||
@@ -262,5 +267,6 @@ class TestBFSNodesToRun():
|
|||||||
|
|
||||||
def test_cancel_still_runs_children(self, workflow_dag_canceled):
|
def test_cancel_still_runs_children(self, workflow_dag_canceled):
|
||||||
(g, nodes) = workflow_dag_canceled
|
(g, nodes) = workflow_dag_canceled
|
||||||
|
g.mark_dnr_nodes()
|
||||||
|
|
||||||
assert set([nodes[1], nodes[2]]) == set(g.bfs_nodes_to_run())
|
assert set([nodes[1], nodes[2]]) == set(g.bfs_nodes_to_run())
|
||||||
|
|||||||
Reference in New Issue
Block a user