remove obsolete set_play on play_context (#47934)

* remove redundant assignments from play

 - fix unit tests
This commit is contained in:
Brian Coca 2019-03-11 18:25:48 -04:00 committed by GitHub
parent b03b951789
commit f73e03632f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 27 deletions

View file

@ -171,21 +171,7 @@ class PlayContext(Base):
setattr(self, flag, self.connection.get_option(flag))
def set_attributes_from_play(self, play):
# From ansible.playbook.Become
self.become = play.become
self.become_method = play.become_method
self.become_user = play.become_user
# From ansible.playbook.Base
self.check_mode = play.check_mode
self.diff = play.diff
self.connection = play.connection
self.remote_user = play.remote_user
# from ansible.playbook.Play
self.force_handlers = play.force_handlers
self.only_tags = play.only_tags
self.skip_tags = play.skip_tags
def set_attributes_from_cli(self):
'''
@ -359,6 +345,13 @@ class PlayContext(Base):
def set_become_plugin(self, plugin):
self._become_plugin = plugin
def _get_attr_force_handlers(self):
display.deprecated(
"PlayContext.force_handlers should not be used, the calling code should be using play itself instead",
version="2.19"
)
return self._attributes.get('force_handlers', None)
def make_become_cmd(self, cmd, executable=None):
""" helper function to create privilege escalation commands """
display.deprecated(

View file

@ -51,21 +51,19 @@ def test_play_context(mocker, parser, reset_cli_args):
play = Play.load({})
play_context = PlayContext(play=play)
# Note: **Must** test the value from _attributes here because play_context.connection will end
# up calling PlayContext._get_attr_connection() which changes the 'smart' connection type into
# the best guessed type (and since C.DEFAULT_TRANSPORT starts off as smart, we would then never
# match)
assert play_context._attributes['connection'] == C.DEFAULT_TRANSPORT
assert play_context.remote_addr is None
assert play_context.remote_user is None
assert play_context.password == ''
assert play_context.port is None
assert play_context.private_key_file == C.DEFAULT_PRIVATE_KEY_FILE
assert play_context.timeout == C.DEFAULT_TIMEOUT
assert play_context.shell is None
assert play_context.verbosity == 2
assert play_context.check_mode is True
assert play_context.no_log is None
mock_play = mocker.MagicMock()
mock_play.force_handlers = True
play_context = PlayContext(play=mock_play)
assert play_context.force_handlers is True
mock_task = mocker.MagicMock()
mock_task.connection = 'mocktask'
@ -91,12 +89,7 @@ def test_play_context(mocker, parser, reset_cli_args):
assert play_context.connection == 'mock_inventory'
assert play_context.remote_user == 'mocktask'
assert play_context.port == 4321
assert play_context.no_log is True
assert play_context.become is True
assert play_context.become_method == "mocktask"
assert play_context.become_user == "mocktaskroot"
assert play_context.become_pass == "mocktaskpass"
mock_task.no_log = False
play_context = play_context.set_task_and_variable_override(task=mock_task, variables=all_vars, templar=mock_templar)