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

portage: drop usage of gentoolkit, add knobs for --with-bdeps, --backtrack #5349

Merged
merged 4 commits into from
Oct 14, 2022

Conversation

ajakk
Copy link
Contributor

@ajakk ajakk commented Oct 12, 2022

SUMMARY

This solves the issue brought up in #3870. The Portage Ansible module depends on an external shell command, when it could simply use the Portage module on every system that uses Portage.

Additionally, this adds support for handling the --with-bdeps and --backtrack emerge command line options.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

Portage

ADDITIONAL INFORMATION

Similar to the other PR, this fixes the following kind of issue when running on a system that doesn't have the requisite external shell command:

host | FAILED! => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python3.9"
    },
    "changed": false,
    "msg": "Failed to find required executable \"equery\" in paths: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin"
}

@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added bug This issue/PR relates to a bug module module new_contributor Help guide this first time contributor os packaging plugins plugin (any type) labels Oct 12, 2022
@ansibullbot

This comment was marked as outdated.

@ansibullbot ansibullbot added ci_verified Push fixes to PR branch to re-run CI needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR labels Oct 12, 2022
@ajakk
Copy link
Contributor Author

ajakk commented Oct 12, 2022

Not sure how to handle the failing tests. Running ansible with a different Python than the system python on Gentoo is nonsensical - /usr/bin/python shouldn't ever be a Python implementation that the Portage module isn't installed for.

@github-actions
Copy link

github-actions bot commented Oct 12, 2022

Docs Build 📝

Thank you for contribution!✨

This PR has been merged and your docs changes will be incorporated when they are next published.

@felixfontein
Copy link
Collaborator

Check out https://docs.ansible.com/ansible-core/devel/dev_guide/testing/sanity/import.html, it shows how to properly import Python modules that are not part of the standard library.

@felixfontein felixfontein added check-before-release PR will be looked at again shortly before release and merged if possible. backport-5 labels Oct 12, 2022
Copy link
Collaborator

@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution! Please add a changelog fragment.

Since it is possible that the module is run with another Python interpreter (could also simply be inside a venv), you need to use respawning to make sure that the module can fall back to the correct Python interpreter that has access to the required Python module. See https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/yum.py#L1693 and https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/dnf.py#L579 for how to do this (they both use https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/common/respawn.py, which is available since ansible-core 2.11, which since community.general 5.0.0 is the minimum supported version of ansible-core).

plugins/modules/packaging/os/portage.py Outdated Show resolved Hide resolved
plugins/modules/packaging/os/portage.py Show resolved Hide resolved
plugins/modules/packaging/os/portage.py Outdated Show resolved Hide resolved
plugins/modules/packaging/os/portage.py Show resolved Hide resolved
@@ -229,6 +239,8 @@
import os
import re

from portage.dbapi import vartree
from portage.exception import InvalidAtom
Copy link
Collaborator

Choose a reason for hiding this comment

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

These imports need to be guarded, see https://docs.ansible.com/ansible/devel/dev_guide/testing/sanity/import.html for details.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I've addressed this and the respawn issue, and I've tested at runtime but I haven't tried terribly hard to break it.

Forgot to do the changelog before pushing just now, looking into that now.

@felixfontein felixfontein added feature This issue/PR relates to a feature request and removed bug This issue/PR relates to a bug labels Oct 12, 2022
@ansibullbot ansibullbot removed the ci_verified Push fixes to PR branch to re-run CI label Oct 13, 2022
@ansibullbot

This comment was marked as outdated.

@ansibullbot ansibullbot added the ci_verified Push fixes to PR branch to re-run CI label Oct 13, 2022
ajakk added a commit to ajakk/community.general that referenced this pull request Oct 13, 2022
Signed-off-by: John Helmert III <ajak@gentoo.org>
ajakk added a commit to ajakk/community.general that referenced this pull request Oct 13, 2022
Signed-off-by: John Helmert III <ajak@gentoo.org>
@ajakk
Copy link
Contributor Author

ajakk commented Oct 13, 2022

To fix the PORTAGE_IMPORT_ERROR used-before-assignment issue, what's best? Should I assign it to None before the portage import try/catch?

@ansibullbot ansibullbot removed the ci_verified Push fixes to PR branch to re-run CI label Oct 13, 2022
@ansibullbot

This comment was marked as outdated.

@ansibullbot ansibullbot added the ci_verified Push fixes to PR branch to re-run CI label Oct 13, 2022
This was referenced Nov 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This issue/PR relates to a feature request module module new_contributor Help guide this first time contributor os packaging plugins plugin (any type)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants