issue #370: add 'disconnect resets connection' test
parent
c510e58f9b
commit
89852db163
@ -1,6 +1,7 @@
|
||||
---
|
||||
|
||||
- import_playbook: disconnect_during_module.yml
|
||||
- import_playbook: disconnect_resets_connection.yml
|
||||
- import_playbook: exec_command.yml
|
||||
- import_playbook: put_large_file.yml
|
||||
- import_playbook: put_small_file.yml
|
||||
|
@ -0,0 +1,44 @@
|
||||
# issue 370: Connection should reset to 'disconnected' state when disconnect
|
||||
# detected
|
||||
#
|
||||
# Previously the 'Mitogen was disconnected' error would fail the first task,
|
||||
# but the Connection instance would still think it still had a valid
|
||||
# connection.
|
||||
#
|
||||
# See also disconnect_during_module.yml
|
||||
|
||||
---
|
||||
|
||||
- name: integration/connection/disconnect_resets_connection.yml
|
||||
hosts: test-targets
|
||||
gather_facts: no
|
||||
any_errors_fatal: true
|
||||
tasks:
|
||||
- mitogen_action_script:
|
||||
script: |
|
||||
import sys
|
||||
from ansible.errors import AnsibleConnectionFailure
|
||||
|
||||
assert not self._connection.connected, \
|
||||
"Connection was not initially disconnected."
|
||||
|
||||
self._low_level_execute_command('echo')
|
||||
assert self._connection.connected, \
|
||||
"Connection was not connected after good command."
|
||||
|
||||
try:
|
||||
self._low_level_execute_command('kill -9 $PPID')
|
||||
assert 0, 'AnsibleConnectionFailure was not raised'
|
||||
except AnsibleConnectionFailure:
|
||||
e = sys.exc_info()[1]
|
||||
assert str(e).startswith('Mitogen was disconnected')
|
||||
|
||||
assert not self._connection.connected, \
|
||||
"Connection did not reset."
|
||||
|
||||
try:
|
||||
self._low_level_execute_command('kill -9 $PPID')
|
||||
assert 0, 'AnsibleConnectionFailure was not raised'
|
||||
except AnsibleConnectionFailure:
|
||||
e = sys.exc_info()[1]
|
||||
assert str(e).startswith('Mitogen was disconnected')
|
@ -0,0 +1,28 @@
|
||||
# I am an Ansible action plug-in. I run the script provided in the parameter in
|
||||
# the context of the action.
|
||||
|
||||
import sys
|
||||
|
||||
from ansible.plugins.action import ActionBase
|
||||
|
||||
|
||||
def execute(s, gbls, lcls):
|
||||
if sys.version_info > (3,):
|
||||
exec(s, gbls, lcls)
|
||||
else:
|
||||
exec('exec s in gbls, lcls')
|
||||
|
||||
|
||||
class ActionModule(ActionBase):
|
||||
def run(self, tmp=None, task_vars=None):
|
||||
super(ActionModule, self).run(tmp=tmp, task_vars=task_vars)
|
||||
lcls = {
|
||||
'self': self,
|
||||
'result': {}
|
||||
}
|
||||
execute(self._task.args['script'], globals(), lcls)
|
||||
return lcls['result']
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in New Issue