Skip to content

Commit

Permalink
Merge pull request #21 from serverscom/new_mitogen
Browse files Browse the repository at this point in the history
feat: add support for new mitogen
  • Loading branch information
amarao authored Oct 7, 2024
2 parents 6ffa2d8 + b22f719 commit 0561d0a
Show file tree
Hide file tree
Showing 7 changed files with 392 additions and 357 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@
This collection allows to use [Mitogen](https://github.com/mitogen-hq/mitogen)
strategy without the need to specify absolute path to the strategy file.

It also performs live patching for Mitogen restrictions in Ansible
versions, making it possible to use Mitogen with the current Ansible version.
It also performs live patching for oler versions of Mitogen (3.4), removing
Ansible version restrictions, making it possible to use Mitogen
on unsupported versions.

Tested versions of ansible-core:

* 2.14
* 2.15
* 2.16
* 2.17

It patches `ansible_mitogen` code and unpatches it
When needed, it patches `ansible_mitogen` code and unpatches it
back right after module import, so the original
files are kept intact.

If no patching needed, it just passes mitogen content as it is.

## Install
To use this collection, you need to install Mitogen:

Expand Down
2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
namespace: serverscom
name: mitogen
version: 1.3.6
version: 1.4.0
readme: README.md
authors:
- Sergey Putko <[email protected]>
Expand Down
13 changes: 11 additions & 2 deletions plugins/strategy/mitogen_free.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,17 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import importlib.metadata

from . import patching
try:
mitogen_version = importlib.metadata.version("mitogen")
except importlib.metadata.PackageNotFoundError:
raise ImportError("Unable to load mitogen module.")

with patching.patch_version():
if mitogen_version == "0.3.4":
from . import patching

with patching.patch_version():
from ansible_mitogen.plugins.strategy.mitogen_free import *
else:
from ansible_mitogen.plugins.strategy.mitogen_free import *
14 changes: 12 additions & 2 deletions plugins/strategy/mitogen_host_pinned.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@
short_description: Mitogen patching strategy
"""

from . import patching
import importlib.metadata

with patching.patch_version():
try:
mitogen_version = importlib.metadata.version("mitogen")
except importlib.metadata.PackageNotFoundError:
raise ImportError("Unable to load mitogen module.")

if mitogen_version == "0.3.4":
from . import patching

with patching.patch_version():
from ansible_mitogen.plugins.strategy.mitogen_host_pinned import *
else:
from ansible_mitogen.plugins.strategy.mitogen_host_pinned import *
14 changes: 12 additions & 2 deletions plugins/strategy/mitogen_linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@
short_description: Mitogen patching strategy
"""

from . import patching
import importlib.metadata

with patching.patch_version():
try:
mitogen_version = importlib.metadata.version("mitogen")
except importlib.metadata.PackageNotFoundError:
raise ImportError("Unable to load mitogen module.")

if mitogen_version == "0.3.4":
from . import patching

with patching.patch_version():
from ansible_mitogen.plugins.strategy.mitogen_linear import *
else:
from ansible_mitogen.plugins.strategy.mitogen_linear import *
690 changes: 346 additions & 344 deletions poetry.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ authors =["Sergey Putko <[email protected]>", "George Shuklin <geo
license = "BSD/MIT"

[tool.poetry.dependencies]
python = ">=3.9, <3.12"
ansible-core = ">=2.13, <2.17"
python = ">=3.10, <3.13"
ansible-core = ">=2.17, <2.18"
black = "^23.1.0"
mitogen = "0.3.4"
mitogen = "0.3.12"
molecule = ">=5.0.0"
yamllint = "^1.29.0"

Expand Down

0 comments on commit 0561d0a

Please sign in to comment.