Skip to content
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

Replace ansible.module_utils._text by ansible.module_utils.common.text.converters #2877

Merged
merged 2 commits into from
Jun 26, 2021

Conversation

felixfontein
Copy link
Collaborator

SUMMARY

While the private API ansible.module_utils._text was the default place to get to_text, to_bytes and to_native for a long time, at least since Ansible 2.9 there's a non-private alternative: ansible.module_utils.common.text.converters. So let's use it :)

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

various plugins

@ansibullbot
Copy link
Collaborator

@felixfontein This PR was evaluated as a potentially problematic PR for the following reasons:

  • More than 50 changed files.

Such PR can only be merged by human. Contact a Core team member to review this PR on IRC: #ansible-devel on irc.freenode.net

click here for bot help

@ansibullbot ansibullbot added affects_2.10 community_review feature This issue/PR relates to a feature request needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR needs_triage labels Jun 26, 2021
Copy link
Contributor

@tadeboro tadeboro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look OK, but a quick grep through source code revealed some potential misses:

$ git grep "module_utils._text"
tests/unit/mock/loader.py:12:from ansible.module_utils._text import to_bytes, to_text
tests/unit/mock/procenv.py:16:from ansible.module_utils._text import to_bytes
tests/unit/mock/vault_helper.py:6:from ansible.module_utils._text import to_bytes
tests/unit/plugins/module_utils/conftest.py:15:from ansible.module_utils._text import to_bytes
tests/unit/plugins/modules/conftest.py:12:from ansible.module_utils._text import to_bytes
tests/unit/plugins/modules/monitoring/test_circonus_annotation.py:14:from ansible.module_utils._text import to_bytes
tests/unit/plugins/modules/net_tools/test_nmcli.py:11:from ansible.module_utils._text import to_text
tests/unit/plugins/modules/packaging/os/test_rhn_register.py:11:from ansible.module_utils._text import to_native
tests/unit/plugins/modules/remote_management/lenovoxcc/test_xcc_redfish_command.py:11:from ansible.module_utils._text import to_bytes
tests/unit/plugins/modules/system/test_ufw.py:9:from ansible.module_utils._text import to_bytes
tests/unit/plugins/modules/utils.py:11:from ansible.module_utils._text import to_bytes
tests/unit/plugins/modules/web_infrastructure/test_jenkins_build.py:9:from ansible.module_utils._text import to_bytes

Were those left out of this changeset on purpose?

@felixfontein
Copy link
Collaborator Author

@tadeboro no they weren't... I only grepped in plugins/... :)

@gundalow
Copy link
Contributor

Thank you for this. Makes me wonder if we should have CI detect is people are using private methods

@tadeboro
Copy link
Contributor

Thank you for this. Makes me wonder if we should have CI detect is people are using private methods

Not all private methods are private in ansible/ansible, so I think this is not possible yet.

@felixfontein felixfontein merged commit fafabed into ansible-collections:main Jun 26, 2021
@felixfontein felixfontein deleted the text-conv branch June 26, 2021 21:59
@patchback
Copy link

patchback bot commented Jun 26, 2021

Backport to stable-3: 💔 cherry-picking failed — conflicts found

❌ Failed to cleanly apply fafabed on top of patchback/backports/stable-3/fafabed9e6acc6bd49ce6e9bf266ee27f686aebe/pr-2877

Backporting merged PR #2877 into main

  1. Ensure you have a local repo clone of your fork. Unless you cloned it
    from the upstream, this would be your origin remote.
  2. Make sure you have an upstream repo added as a remote too. In these
    instructions you'll refer to it by the name upstream. If you don't
    have it, here's how you can add it:
    $ git add remote upstream https://github.com/ansible-collections/community.general.git
  3. Ensure you have the latest copy of upstream and prepare a branch
    that will hold the backported code:
    $ git fetch upstream
    $ git checkout -b patchback/backports/stable-3/fafabed9e6acc6bd49ce6e9bf266ee27f686aebe/pr-2877 upstream/stable-3
  4. Now, cherry-pick PR Replace ansible.module_utils._text by ansible.module_utils.common.text.converters #2877 contents into that branch:
    $ git cherry-pick -x fafabed9e6acc6bd49ce6e9bf266ee27f686aebe
    If it'll yell at you with something like fatal: Commit fafabed9e6acc6bd49ce6e9bf266ee27f686aebe is a merge but no -m option was given., add -m 1 as follows intead:
    $ git cherry-pick -m1 -x fafabed9e6acc6bd49ce6e9bf266ee27f686aebe
  5. At this point, you'll probably encounter some merge conflicts. You must
    resolve them in to preserve the patch from PR Replace ansible.module_utils._text by ansible.module_utils.common.text.converters #2877 as close to the
    original as possible.
  6. Push this branch to your fork on GitHub:
    $ git push origin patchback/backports/stable-3/fafabed9e6acc6bd49ce6e9bf266ee27f686aebe/pr-2877
  7. Create a PR, ensure that the CI is green. If it's not — update it so that
    the tests and any other checks pass. This is it!
    Now relax and wait for the maintainers to process your pull request
    when they have some cycles to do reviews. Don't worry — they'll tell you if
    any improvements are necessary when the time comes!

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

@felixfontein
Copy link
Collaborator Author

@tadeboro @gundalow thanks for reviewing!

felixfontein added a commit to felixfontein/community.general that referenced this pull request Jun 26, 2021
…t.converters (ansible-collections#2877)

* Replace ansible.module_utils._text by ansible.module_utils.common.text.converters.

* Also adjust tests.

(cherry picked from commit fafabed)
@felixfontein
Copy link
Collaborator Author

Manual backport to stable-3 in #2882. There was a conflict in plugins/modules/cloud/scaleway/scaleway_security_group_rule.py due to removal of the vendored ipadress copy in the main branch (for community.general 4.0.0).

felixfontein added a commit that referenced this pull request Jun 27, 2021
…t.converters (#2877) (#2882)

* Replace ansible.module_utils._text by ansible.module_utils.common.text.converters.

* Also adjust tests.

(cherry picked from commit fafabed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community_review feature This issue/PR relates to a feature request needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR needs_triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants