Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Replicate most of the ansible style host matching logic#753

Open
Code0x58 wants to merge 5 commits intopytest-dev:mainfrom
Code0x58:rewrite-logic
Open

Replicate most of the ansible style host matching logic#753
Code0x58 wants to merge 5 commits intopytest-dev:mainfrom
Code0x58:rewrite-logic

Conversation

Copy link

Code0x58 commented Jan 21, 2024 *
edited
Loading

This expands on the ansible pattern matching so you can use multiple parts, intersection, negation, and regex patterns, on top of the already implemented globbing.

I'd like to backport this change into an 8.2 release if you'll take it.

Code0x58 commented Jan 24, 2024
Copy link
Author

Code0x58 left a comment

Choose a reason for hiding this comment

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

looks ok when used in testinfra_hosts on my setup. Should apply the change to easily reduce the minimum working python3 version (tested on 3.8)

Code0x58 commented May 15, 2024
else:
positive.update(expand_pattern(requirement, inventory))

result = positive
Copy link
Author

Code0x58 May 15, 2024

Choose a reason for hiding this comment

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

Comment about something that I don't see as worth changing right now as there hasn't been any response on this yet, and a significant improvement is much better than nothing.

I suspect a perfect copy of the logic from ansible would use something like this here:

Suggested change
result = positive
if positive:
result = positive
else:
result = expand_pattern('all')

Then you imitate behaviour like !right which is equivalent to all:!right, but this would also be best with additions to manual testing and adding of tests to this codebase for the confirmed functionality.

Given that adding all: to the start of a host pattern/query is equivalent, it's a fine enough workaround. If this change gets merged/released, I'll follow up with this change.

Code0x58 changed the title Draft: Replicate more of the ansible style host matching logic Replicate more of the ansible style host matching logic May 15, 2024
Code0x58 changed the title Replicate more of the ansible style host matching logic Replicate most of the ansible style host matching logic May 15, 2024
Copy link
Author

Code0x58 commented May 15, 2024

I'm happy with the improvements on here, so have un-drafted the PR

Code0x58 mentioned this pull request May 28, 2024
Copy link
Contributor

CarstenGrohmann commented Jun 3, 2024

What do you think about renaming test_ansible.py to test_ansible_inventory.py or similar? That would be more meaningful.

Code0x58 reacted with thumbs up emoji

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants