Exceptions cleanup
Most TaskFlow exception don't have 'Exception' suffix in their names, so we drop it from the few that have it, for sake of consistency and more concise and expressive code. MissingDependencies parent object is changed from InvalidState to InvariantViolation, which is more appropriate. Unused ClosedException is dropped. Breaking change: any client code that used renamed exceptions, ClosedException or relied on catching MissingDependencies as InvariantViolationException is affected. Change-Id: I649b7760d382ccb6df333bdffd667ba6b67a431e
This commit is contained in:
@@ -45,24 +45,19 @@ class AlreadyExists(TaskFlowException):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ClosedException(TaskFlowException):
|
class InvalidState(TaskFlowException):
|
||||||
"""Raised when an access on a closed object occurs."""
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class InvalidStateException(TaskFlowException):
|
|
||||||
"""Raised when a task/job/workflow is in an invalid state when an
|
"""Raised when a task/job/workflow is in an invalid state when an
|
||||||
operation is attempting to apply to said task/job/workflow.
|
operation is attempting to apply to said task/job/workflow.
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class InvariantViolationException(TaskFlowException):
|
class InvariantViolation(TaskFlowException):
|
||||||
"""Raised when flow invariant violation is attempted."""
|
"""Raised when flow invariant violation is attempted."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class UnclaimableJobException(TaskFlowException):
|
class UnclaimableJob(TaskFlowException):
|
||||||
"""Raised when a job can not be claimed."""
|
"""Raised when a job can not be claimed."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -72,7 +67,7 @@ class JobNotFound(TaskFlowException):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class MissingDependencies(InvalidStateException):
|
class MissingDependencies(InvariantViolation):
|
||||||
"""Raised when a entity has dependencies that can not be satisfied."""
|
"""Raised when a entity has dependencies that can not be satisfied."""
|
||||||
message = ("%(who)s requires %(requirements)s but no other entity produces"
|
message = ("%(who)s requires %(requirements)s but no other entity produces"
|
||||||
" said requirements")
|
" said requirements")
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ class Flow(flow.Flow):
|
|||||||
requires |= item.requires
|
requires |= item.requires
|
||||||
out_of_order = requires & item.provides
|
out_of_order = requires & item.provides
|
||||||
if out_of_order:
|
if out_of_order:
|
||||||
raise exceptions.InvariantViolationException(
|
raise exceptions.InvariantViolation(
|
||||||
"%(item)s provides %(oo)s that are required "
|
"%(item)s provides %(oo)s that are required "
|
||||||
"by previous item(s) of linear flow %(flow)s"
|
"by previous item(s) of linear flow %(flow)s"
|
||||||
% dict(item=item.name, flow=self.name,
|
% dict(item=item.name, flow=self.name,
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ class Flow(flow.Flow):
|
|||||||
item_provides = item.provides
|
item_provides = item.provides
|
||||||
bad_provs = item_provides & old_requires
|
bad_provs = item_provides & old_requires
|
||||||
if bad_provs:
|
if bad_provs:
|
||||||
raise exceptions.InvariantViolationException(
|
raise exceptions.InvariantViolation(
|
||||||
"%(item)s provides %(oo)s that are required "
|
"%(item)s provides %(oo)s that are required "
|
||||||
"by other item(s) of unordered flow %(flow)s"
|
"by other item(s) of unordered flow %(flow)s"
|
||||||
% dict(item=item.name, flow=self.name,
|
% dict(item=item.name, flow=self.name,
|
||||||
@@ -65,7 +65,7 @@ class Flow(flow.Flow):
|
|||||||
for item in items:
|
for item in items:
|
||||||
bad_reqs = provides & item.requires
|
bad_reqs = provides & item.requires
|
||||||
if bad_reqs:
|
if bad_reqs:
|
||||||
raise exceptions.InvariantViolationException(
|
raise exceptions.InvariantViolation(
|
||||||
"%(item)s requires %(oo)s that are provided "
|
"%(item)s requires %(oo)s that are provided "
|
||||||
"by other item(s) of unordered flow %(flow)s"
|
"by other item(s) of unordered flow %(flow)s"
|
||||||
% dict(item=item.name, flow=self.name,
|
% dict(item=item.name, flow=self.name,
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ def check_flow_transition(old_state, new_state):
|
|||||||
|
|
||||||
If transition can be performed, it returns True. If transition
|
If transition can be performed, it returns True. If transition
|
||||||
should be ignored, it returns False. If transition is not
|
should be ignored, it returns False. If transition is not
|
||||||
valid, it raises InvalidStateException.
|
valid, it raises InvalidState exception.
|
||||||
"""
|
"""
|
||||||
if old_state == new_state:
|
if old_state == new_state:
|
||||||
return False
|
return False
|
||||||
@@ -121,8 +121,8 @@ def check_flow_transition(old_state, new_state):
|
|||||||
return True
|
return True
|
||||||
if pair in _IGNORED_FLOW_TRANSITIONS:
|
if pair in _IGNORED_FLOW_TRANSITIONS:
|
||||||
return False
|
return False
|
||||||
raise exc.InvalidStateException(
|
raise exc.InvalidState("Flow transition from %s to %s is not allowed"
|
||||||
"Flow transition from %s to %s is not allowed" % pair)
|
% pair)
|
||||||
|
|
||||||
|
|
||||||
## Task state transitions
|
## Task state transitions
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ class CheckFlowTransitionTest(test.TestCase):
|
|||||||
states.check_flow_transition(states.RUNNING, states.RESUMING))
|
states.check_flow_transition(states.RUNNING, states.RESUMING))
|
||||||
|
|
||||||
def test_bad_transition_raises(self):
|
def test_bad_transition_raises(self):
|
||||||
self.assertRaisesRegexp(exc.InvalidStateException,
|
self.assertRaisesRegexp(exc.InvalidState,
|
||||||
'^Flow transition.*not allowed',
|
'^Flow transition.*not allowed',
|
||||||
states.check_flow_transition,
|
states.check_flow_transition,
|
||||||
states.FAILURE, states.SUCCESS)
|
states.FAILURE, states.SUCCESS)
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ class FlattenTest(test.TestCase):
|
|||||||
t_utils.DummyTask(name="a"),
|
t_utils.DummyTask(name="a"),
|
||||||
t_utils.DummyTask(name="a")
|
t_utils.DummyTask(name="a")
|
||||||
)
|
)
|
||||||
self.assertRaisesRegexp(exc.InvariantViolationException,
|
self.assertRaisesRegexp(exc.InvariantViolation,
|
||||||
'^Tasks with duplicate names',
|
'^Tasks with duplicate names',
|
||||||
f_utils.flatten, flo)
|
f_utils.flatten, flo)
|
||||||
|
|
||||||
@@ -182,6 +182,6 @@ class FlattenTest(test.TestCase):
|
|||||||
flo = gf.Flow("test").add(
|
flo = gf.Flow("test").add(
|
||||||
gf.Flow("int1").add(t_utils.DummyTask(name="a")),
|
gf.Flow("int1").add(t_utils.DummyTask(name="a")),
|
||||||
gf.Flow("int2").add(t_utils.DummyTask(name="a")))
|
gf.Flow("int2").add(t_utils.DummyTask(name="a")))
|
||||||
self.assertRaisesRegexp(exc.InvariantViolationException,
|
self.assertRaisesRegexp(exc.InvariantViolation,
|
||||||
'^Tasks with duplicate names',
|
'^Tasks with duplicate names',
|
||||||
f_utils.flatten, flo)
|
f_utils.flatten, flo)
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ class FlowDependenciesTest(test.TestCase):
|
|||||||
|
|
||||||
def test_linear_flow_provides_out_of_order(self):
|
def test_linear_flow_provides_out_of_order(self):
|
||||||
flow = lf.Flow('lf')
|
flow = lf.Flow('lf')
|
||||||
self.assertRaises(exceptions.InvariantViolationException,
|
self.assertRaises(exceptions.InvariantViolation,
|
||||||
flow.add,
|
flow.add,
|
||||||
utils.TaskOneArg('task2'),
|
utils.TaskOneArg('task2'),
|
||||||
utils.TaskOneReturn('task1', provides='x'))
|
utils.TaskOneReturn('task1', provides='x'))
|
||||||
@@ -111,7 +111,7 @@ class FlowDependenciesTest(test.TestCase):
|
|||||||
|
|
||||||
def test_linear_flow_self_requires(self):
|
def test_linear_flow_self_requires(self):
|
||||||
flow = lf.Flow('lf')
|
flow = lf.Flow('lf')
|
||||||
self.assertRaises(exceptions.InvariantViolationException,
|
self.assertRaises(exceptions.InvariantViolation,
|
||||||
flow.add,
|
flow.add,
|
||||||
utils.TaskNoRequiresNoReturns(rebind=['x'],
|
utils.TaskNoRequiresNoReturns(rebind=['x'],
|
||||||
provides='x'))
|
provides='x'))
|
||||||
@@ -138,7 +138,7 @@ class FlowDependenciesTest(test.TestCase):
|
|||||||
|
|
||||||
def test_unordered_flow_self_requires(self):
|
def test_unordered_flow_self_requires(self):
|
||||||
flow = uf.Flow('uf')
|
flow = uf.Flow('uf')
|
||||||
self.assertRaises(exceptions.InvariantViolationException,
|
self.assertRaises(exceptions.InvariantViolation,
|
||||||
flow.add,
|
flow.add,
|
||||||
utils.TaskNoRequiresNoReturns(rebind=['x'],
|
utils.TaskNoRequiresNoReturns(rebind=['x'],
|
||||||
provides='x'))
|
provides='x'))
|
||||||
@@ -166,7 +166,7 @@ class FlowDependenciesTest(test.TestCase):
|
|||||||
|
|
||||||
def test_unordered_flow_provides_required_values(self):
|
def test_unordered_flow_provides_required_values(self):
|
||||||
flow = uf.Flow('uf')
|
flow = uf.Flow('uf')
|
||||||
self.assertRaises(exceptions.InvariantViolationException,
|
self.assertRaises(exceptions.InvariantViolation,
|
||||||
flow.add,
|
flow.add,
|
||||||
utils.TaskOneReturn('task1', provides='x'),
|
utils.TaskOneReturn('task1', provides='x'),
|
||||||
utils.TaskOneArg('task2'))
|
utils.TaskOneArg('task2'))
|
||||||
@@ -174,14 +174,14 @@ class FlowDependenciesTest(test.TestCase):
|
|||||||
def test_unordered_flow_requires_provided_value_other_call(self):
|
def test_unordered_flow_requires_provided_value_other_call(self):
|
||||||
flow = uf.Flow('uf')
|
flow = uf.Flow('uf')
|
||||||
flow.add(utils.TaskOneReturn('task1', provides='x'))
|
flow.add(utils.TaskOneReturn('task1', provides='x'))
|
||||||
self.assertRaises(exceptions.InvariantViolationException,
|
self.assertRaises(exceptions.InvariantViolation,
|
||||||
flow.add,
|
flow.add,
|
||||||
utils.TaskOneArg('task2'))
|
utils.TaskOneArg('task2'))
|
||||||
|
|
||||||
def test_unordered_flow_provides_required_value_other_call(self):
|
def test_unordered_flow_provides_required_value_other_call(self):
|
||||||
flow = uf.Flow('uf')
|
flow = uf.Flow('uf')
|
||||||
flow.add(utils.TaskOneArg('task2'))
|
flow.add(utils.TaskOneArg('task2'))
|
||||||
self.assertRaises(exceptions.InvariantViolationException,
|
self.assertRaises(exceptions.InvariantViolation,
|
||||||
flow.add,
|
flow.add,
|
||||||
utils.TaskOneReturn('task1', provides='x'))
|
utils.TaskOneReturn('task1', provides='x'))
|
||||||
|
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ def _post_flatten(graph):
|
|||||||
dup_names = misc.get_duplicate_keys(graph.nodes_iter(),
|
dup_names = misc.get_duplicate_keys(graph.nodes_iter(),
|
||||||
key=lambda node: node.name)
|
key=lambda node: node.name)
|
||||||
if dup_names:
|
if dup_names:
|
||||||
raise exceptions.InvariantViolationException(
|
raise exceptions.InvariantViolation(
|
||||||
"Tasks with duplicate names found: %s"
|
"Tasks with duplicate names found: %s"
|
||||||
% ', '.join(sorted(dup_names)))
|
% ', '.join(sorted(dup_names)))
|
||||||
return graph
|
return graph
|
||||||
|
|||||||
Reference in New Issue
Block a user