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

galaxy: Handle hidden git directories in role skeleton #72035

Merged
merged 2 commits into from
Feb 24, 2021

Conversation

manas-init
Copy link
Contributor

@manas-init manas-init commented Sep 30, 2020

ansible-galaxy role init --role-skeleton=ansible-role-skeleton example fails fix.
The issue was because 'dir' variable was changed to reference to a different list, but since it is a global variable so the update was causing issues.
Now updating 'dir' variable to change value of variable in local scope.

fixes #71977

SUMMARY
ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME
ADDITIONAL INFORMATION

@ansibot ansibot added affects_2.11 bug This issue/PR relates to a bug. core_review In order to be merged, this PR must follow the core review workflow. has_issue needs_triage Needs a first human triage before being processed. new_contributor This PR is the first contribution by a new community member. small_patch support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Sep 30, 2020
@bcoca bcoca removed the needs_triage Needs a first human triage before being processed. label Oct 1, 2020
bcoca
bcoca previously requested changes Oct 1, 2020
Copy link
Member

@bcoca bcoca left a comment

Choose a reason for hiding this comment

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

please add a test (so we don't revert again) and a changelog so we can backport this.

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed core_review In order to be merged, this PR must follow the core review workflow. labels Oct 1, 2020
@manas-init
Copy link
Contributor Author

please add a test (so we don't revert again) and a changelog so we can backport this.

Hi @bcoca I'm new to this. Could you please guide me on how to do the above mentioned.

@manas-init
Copy link
Contributor Author

@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. support:community This issue/PR relates to code supported by the Ansible community. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. small_patch core_review In order to be merged, this PR must follow the core review workflow. labels Oct 1, 2020
@manas-init manas-init requested a review from bcoca October 3, 2020 06:38
@ansibot ansibot added stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. stale_review Updates were made after the last review and the last review is more than 7 days old. labels Oct 11, 2020
Copy link
Contributor

@greg-hellings greg-hellings left a comment

Choose a reason for hiding this comment

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

This is a priority bug preventing downstream testing from working properly in many places.

@sivel
Copy link
Member

sivel commented Oct 27, 2020

Could you please guide me on how to do the above mentioned.

Typically speaking, you would use an integration test. We already have a directory at test/integration/targets/ansible-galaxy

You would effectively add a test that roughly replicates the issue originally reported. It should fail without the fix, and pass with the fix.

@ansibot ansibot added pre_azp This PR was last tested before migration to Azure Pipelines. and removed stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. stale_review Updates were made after the last review and the last review is more than 7 days old. labels Dec 6, 2020
@Akasurde
Copy link
Member

@manas-init Are you still working on this? Thanks.

ansible-galaxy role init --role-skeleton=ansible-role-skeleton example fails.

The issue was because 'dir' variable was changed to reference to a different list,
but since it is a global variable so the update was causing issues.
Now updating 'dir' variable to change value of variable in local scope.

Fixes: ansible#71977
@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. pre_azp This PR was last tested before migration to Azure Pipelines. core_review In order to be merged, this PR must follow the core review workflow. labels Jan 21, 2021
@Akasurde Akasurde changed the title Update galaxy.py galaxy: Handle hidden git directories in role skeleton Jan 21, 2021
@Akasurde
Copy link
Member

@bcoca I updated the test, could you please take a look?

@@ -912,7 +912,7 @@ def execute_init(self):
else:
in_templates_dir = rel_root_dir == 'templates'

dirs = [d for d in dirs if not any(r.match(d) for r in skeleton_ignore_re)]
dirs[:] = [d for d in dirs if not any(r.match(d) for r in skeleton_ignore_re)]
Copy link
Member

Choose a reason for hiding this comment

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

Could anybody explain why this works/necessary? I think it deserves a code comment. It looks to me like it exploits some side-effect of changing the list in-place instead of reassigning the object but I don't get why this fixes the bug.

Copy link
Member

Choose a reason for hiding this comment

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

I believe it is due to mutating the dirs created by os.walk, which impacts future iterations that include that same dirs reference.

I'm sure we could refactor the code, to not require it, but this is a known good change that works.

Copy link
Member

Choose a reason for hiding this comment

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

After looking at the PR description, it sounds like it'd be saner to use a different variable name. Also, it looks like this could be moved closer to the loop that iterates over these dirs.

Copy link
Member

Choose a reason for hiding this comment

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

I think that's the point, it needs to mutate the existing reference, or the code needs refactored in a larger scale.

@ansibot ansibot added stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. stale_review Updates were made after the last review and the last review is more than 7 days old. labels Jan 29, 2021
@pbpblush
Copy link

pbpblush commented Feb 2, 2021

Hi there, I found that this may also be fixed by updating ansible/config/base.yml

changing line 1414 to be:

default: ["^.git$", "^.git/.*$", "^.*/.git_keep$"]

this would be a smaller change

@s-hertel
Copy link
Contributor

@pbpblush This is a one-liner too 😄 Just has tests and changelog and a little baggage. Using the configuration setting is a good workaround, but I think we should fix it more generally like this. The setting matches files and directory names, so if "^.git$" matches a directory, the files inside of it should also be ignored. It doesn't look like the docs mention that the setting applies to directory names, but it looks intentional: c20beee.

Anyone ignoring a directory name could experience this bug. For example, ANSIBLE_GALAXY_ROLE_SKELETON_IGNORE='^ignored_dir$' would skip the directory still but try to add any files inside of it, which causes the traceback, whereas before os.walk wouldn't consider the contents of skipped directories at all because we mutated the list instead of reassigning it.

@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. stale_review Updates were made after the last review and the last review is more than 7 days old. core_review In order to be merged, this PR must follow the core review workflow. labels Feb 24, 2021
@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Feb 24, 2021
@s-hertel s-hertel merged commit eb72c36 into ansible:devel Feb 24, 2021
s-hertel pushed a commit to s-hertel/ansible that referenced this pull request Mar 5, 2021
* galaxy: restore left hand slicing in assignment

Fix 'ansible-galaxy role init --role-skeleton=role-skeleton' when the role skeleton
contains an ignored directory.

The issue was because the 'dirs' variable was changed to reference a different list,
but needs to be mutated instead to stop os.walk from traversing ignored directories.

Fixes: ansible#71977

Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com>
(cherry picked from commit eb72c36)
relrod pushed a commit that referenced this pull request Mar 8, 2021
)

* galaxy: restore left hand slicing in assignment

Fix 'ansible-galaxy role init --role-skeleton=role-skeleton' when the role skeleton
contains an ignored directory.

The issue was because the 'dirs' variable was changed to reference a different list,
but needs to be mutated instead to stop os.walk from traversing ignored directories.

Fixes: #71977

Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com>
(cherry picked from commit eb72c36)

Co-authored-by: manas-init <70483021+manas-init@users.noreply.github.com>
@ansible ansible locked and limited conversation to collaborators Mar 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.11 bug This issue/PR relates to a bug. core_review In order to be merged, this PR must follow the core review workflow. has_issue new_contributor This PR is the first contribution by a new community member. support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error "ansible-galaxy role init"
9 participants