-
Notifications
You must be signed in to change notification settings - Fork 199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ansible_mitogen: Fix usage of connection_loader__get. #1215
base: master
Are you sure you want to change the base?
Conversation
9dfacc3
to
476754b
Compare
Thank you for looking at this. The PR needs work to fix one or more failing tests and to include a changelog entry.
|
I have an alternative approach that may eliminate the need for ansible_mitogen.loaders.connection_loader__get. I haven't had a chance to try it out/test it @@ -33,6 +33,7 @@ import os.path
import sys
from ansible.plugins.connection.ssh import (
+ Connection as _ansible_ssh_Connection,
DOCUMENTATION as _ansible_ssh_DOCUMENTATION,
)
@@ -55,18 +56,13 @@ except ImportError:
del base_dir
import ansible_mitogen.connection
-import ansible_mitogen.loaders
class Connection(ansible_mitogen.connection.Connection):
transport = 'ssh'
- vanilla_class = ansible_mitogen.loaders.connection_loader__get(
- 'ssh',
- class_only=True,
- )
@staticmethod
def _create_control_path(*args, **kwargs):
"""Forward _create_control_path() to the implementation in ssh.py."""
# https://github.com/dw/mitogen/issues/342
- return Connection.vanilla_class._create_control_path(*args, **kwargs)
+ return _ansible_ssh_Connection._create_control_path(*args, **kwargs) Does it work for you? |
That works, though I don't think it'd work as well for the kubectl connection plugin. That one checks for a valid return from |
476754b
to
9a01aef
Compare
I noticed another issue with how get_with_context is handled - Ansible's |
b03d18b
to
0f8575d
Compare
I'm currently working on tracking down the "Could not recover task_vars" issue - from what I've gathered thus far, it happens when the network_cli connection (which is not Mitogen) drops to the local connection (which is Mitogen) to run some raw commands. At that point, the action on the stack (gather_facts) has determined that it is not running under Mitogen and transmuted itself back to the non-mixin variant. However, we've not discovered the task vars yet, and we don't have a fallback to handle this like we do with I've tried forcing it through in various ways without any luck, and it all either boils down to the action on the stack not being a Mitogen action with a mixin while we're operating on the local Mitogen connection, or the python interpreter not having been discovered. Any input on that would be appreciated :) |
Notes to self
$ ag kubectl tests/ansible
tests/ansible/integration/transport/all.yml
2:- include_playbook: kubectl.yml
4: - kubectl
tests/ansible/integration/transport/kubectl.yml
45: ansible_connection: "kubectl"
50:- name: "Test kubectl connection (default strategy)"
73: ansible_kubectl_container: python3
94:- name: "Test kubectl connection (mitogen strategy)"
117: ansible_kubectl_container: python3
tests/ansible/integration/stub_connections/all.yml
1:- import_playbook: kubectl.yml
tests/ansible/integration/stub_connections/kubectl.yml
2:- name: integration/stub_connections/kubectl.yml
14: ansible_connection: kubectl
15: mitogen_kubectl_path: stub-kubectl.py
20: - out.env.THIS_IS_STUB_KUBECTL == '1'
24: - kubectl
tests/ansible/integration/stub_connections/README.md
5:tools (kubectl etc.) to verify arguments passed by Ansible to Mitogen and |
Agreed. I like
Good spot.
Looking, but no promises. We're in deep, at the intersection of many tight/accidental couplings. I've only recently got my head around this bit of the code. |
action_loader__get_with_context = action_loader.get_with_context | ||
connection_loader__get_with_context = connection_loader.get_with_context |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 changing the names. ...__get = ...get_with_context
has long bugged me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I saw that and thought like hell I'm leaving it like that hah
@@ -48,6 +48,8 @@ | |||
import ansible.template | |||
import ansible.utils.sentinel | |||
|
|||
from ansible.plugins.loader import get_with_context_result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personal preference, use absolute imports when possible. It makes it easier to distinguish what belongs to ansibler.*
and what belongs to ansible_mitogen.*
, or mitogen.*
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha - I had some issues getting an absolute import working in this file due to other imports masking things. Tried a few more ways just now but didn't get anywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried some variations in moreati@25da0f7. We could eliminate this import entirely by using
result = ansible_mitogen.loaders.action_loader__get_with_context(...)
...
return result._replace(object=adorned_klass)
It loses a little clarity. I'm in favour of the tradeoff, but ready to be convinced otherwise.
Which issue is this? Do you have a playbook or other way to reproduce it? |
Probably a reference to one or more of the issues (#766, #662, #342) that this PR (derived from #976 by @markafarrell) may solve. There are repro instructions in https://github.com/markafarrell/mitogen-issue-766-repro, mentioned in #976 (comment). |
This PR revives #976 and updates the proposed fix in both the SSH and kubectl connection methods.
As a short recap, get_with_context returns a named tuple as of Ansible 2.10, which necessitates a small change in how it's accessed in Mitogen.
The original PR states that this fixes #766, #662, and #342. I have verified that it resolves an issue with delegation of
set_facts
, but I haven't been able to get network_cli working yet.