PlayIterator - remove deprecated states (#77444)

pull/77516/head
Martin Krizek 3 years ago committed by GitHub
parent 477c55b0d2
commit 94eff70030
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
removed_features:
- PlayIterator - remove deprecated ``PlayIterator.ITERATING_*`` and ``PlayIterator.FAILED_*``

@ -125,52 +125,7 @@ class HostState:
return new_state
def _redirect_to_enum(name):
if name.startswith('ITERATING_'):
rv = getattr(IteratingStates, name.replace('ITERATING_', ''))
display.deprecated(
f"PlayIterator.{name} is deprecated, use ansible.play_iterator.IteratingStates.{name} instead.",
version=2.14
)
return rv
elif name.startswith('FAILED_'):
rv = getattr(FailedStates, name.replace('FAILED_', ''))
display.deprecated(
f"PlayIterator.{name} is deprecated, use ansible.play_iterator.FailedStates.{name} instead.",
version=2.14
)
return rv
raise AttributeError(name)
class MetaPlayIterator(type):
"""Meta class to intercept calls to old *class* attributes
like PlayIterator.ITERATING_TASKS and use new enums instead.
This is for backwards compatibility as 3rd party strategies might
use those attributes. Deprecation warning is printed when old attr
is redirected to new enum.
"""
def __getattribute__(cls, name):
try:
rv = _redirect_to_enum(name)
except AttributeError:
return super().__getattribute__(name)
return rv
class PlayIterator(metaclass=MetaPlayIterator):
def __getattr__(self, name):
"""Same as MetaPlayIterator.__getattribute__ but for instance attributes,
because our code used iterator_object.ITERATING_TASKS so it's safe to assume
that 3rd party code could use that too.
__getattr__ is called when the default attribute access fails so this
should not impact existing attributes lookup.
"""
return _redirect_to_enum(name)
class PlayIterator:
def __init__(self, inventory, play, play_context, variable_manager, all_vars, start_at_done=False):
self._play = play

@ -460,33 +460,3 @@ class TestPlayIterator(unittest.TestCase):
# test a regular insertion
s_copy = s.copy()
res_state = itr._insert_tasks_into_state(s_copy, task_list=[MagicMock()])
def test_iterating_states_deprecation_class_attr(self):
assert PlayIterator.ITERATING_SETUP == IteratingStates.SETUP
assert PlayIterator.ITERATING_TASKS == IteratingStates.TASKS
assert PlayIterator.ITERATING_RESCUE == IteratingStates.RESCUE
assert PlayIterator.ITERATING_ALWAYS == IteratingStates.ALWAYS
assert PlayIterator.ITERATING_COMPLETE == IteratingStates.COMPLETE
def test_failed_states_deprecation_class_attr(self):
assert PlayIterator.FAILED_NONE == FailedStates.NONE
assert PlayIterator.FAILED_SETUP == FailedStates.SETUP
assert PlayIterator.FAILED_TASKS == FailedStates.TASKS
assert PlayIterator.FAILED_RESCUE == FailedStates.RESCUE
assert PlayIterator.FAILED_ALWAYS == FailedStates.ALWAYS
def test_iterating_states_deprecation_instance_attr(self):
iterator = PlayIterator(MagicMock(), MagicMock(), MagicMock(), MagicMock(), MagicMock())
assert iterator.ITERATING_SETUP == IteratingStates.SETUP
assert iterator.ITERATING_TASKS == IteratingStates.TASKS
assert iterator.ITERATING_RESCUE == IteratingStates.RESCUE
assert iterator.ITERATING_ALWAYS == IteratingStates.ALWAYS
assert iterator.ITERATING_COMPLETE == IteratingStates.COMPLETE
def test_failed_states_deprecation_instance_attr(self):
iterator = PlayIterator(MagicMock(), MagicMock(), MagicMock(), MagicMock(), MagicMock())
assert iterator.FAILED_NONE == FailedStates.NONE
assert iterator.FAILED_SETUP == FailedStates.SETUP
assert iterator.FAILED_TASKS == FailedStates.TASKS
assert iterator.FAILED_RESCUE == FailedStates.RESCUE
assert iterator.FAILED_ALWAYS == FailedStates.ALWAYS

Loading…
Cancel
Save