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

ec2_vpc_route_table: Update matching_count parsing on find_subnets fu… #38707

Merged
merged 2 commits into from
May 3, 2018

Conversation

ZuZuD
Copy link
Contributor

@ZuZuD ZuZuD commented Apr 13, 2018

…nction. Fix #38570

SUMMARY

Fix #38570. Tags for the list of subnets are now parsed properly. I was able to reproduce the initial issue and this PR fixed it.

I don't understand how this could have worked initially if someone can shed some light on this I would appreciate.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

ec2_vpc_route_table

ANSIBLE VERSION
ansible --version
ansible 2.6.0
ADDITIONAL INFORMATION

Also fixed a typo in the function comment.

@ansibot
Copy link
Contributor

ansibot commented Apr 13, 2018

@ansibot ansibot added aws bug This issue/PR relates to a bug. cloud committer_review In order to be merged, this PR must follow the certified review workflow. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. support:certified This issue/PR relates to certified code. labels Apr 13, 2018
@ansibot
Copy link
Contributor

ansibot commented Apr 13, 2018

The test ansible-test sanity --test pep8 [explain] failed with 1 error:

lib/ansible/modules/cloud/amazon/ec2_vpc_route_table.py:297:90: E221 multiple spaces before operator

click here for bot help

@ansibot ansibot added ci_verified Changes made in this PR are causing tests to fail. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed committer_review In order to be merged, this PR must follow the certified review workflow. labels Apr 13, 2018
@mkrizek mkrizek removed the needs_triage Needs a first human triage before being processed. label Apr 13, 2018
@ansibot ansibot added committer_review In order to be merged, this PR must follow the certified review workflow. and removed ci_verified Changes made in this PR are causing tests to fail. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Apr 13, 2018
@@ -294,7 +294,7 @@ def find_subnets(connection, module, vpc_id, identified_subnets):
module.fail_json_aws(e, msg="Couldn't find subnet with names %s" % subnet_names)

for name in subnet_names:
matching_count = len([1 for s in subnets_by_name if s.tags.get('Name') == name])
matching_count = len([1 for s in subnets_by_name if s['Tags'][0].get('Value') == name])
Copy link
Contributor

Choose a reason for hiding this comment

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

How could this happen? I clearly stuffed this bit up in the boto3 conversion and no-one noticed.

I don't think this improvement will work unless the first tag is always the Name tag, which seems unlikely.

This should probably be

matching_count = len([1 for s in subnets_by_name for t in s.get('Tags', []) if t['Name'] == 'Name' and t['Value'] == name])

Could you add a test for this situation into test/integration/targets/ec2_vpc_route_table/tasks/main.yml (tests would hopefully have caught both the original error and the flaw in this solution)

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed committer_review In order to be merged, this PR must follow the certified review workflow. labels Apr 16, 2018
@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Apr 24, 2018
@ansibot ansibot removed the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Apr 25, 2018
@ZuZuD
Copy link
Contributor Author

ZuZuD commented Apr 25, 2018

Indeed I missed something @willthames! I added the tests and corrected a bug with the ternary operator used to give an appropriate subnet name:

        {
            "assign_ipv6_address_on_creation": false,
            "availability_zone": "us-east-1b",
            "available_ip_address_count": 251,
            "cidr_block": "10.228.231.0/24",
            "default_for_az": false,
            "id": "subnet-b92fce97",
            "ipv6_cidr_block_association_set": [],
            "map_public_ip_on_launch": false,
            "state": "available",
            "subnet_id": "subnet-b92fce97",
            "tags": {
                "Name": "public-b",
                "Public": "False"
            },
            "vpc_id": "vpc-45a0ec3e"
        },

@ansibot ansibot added the test This PR relates to tests. label Apr 25, 2018
@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label May 3, 2018
@ansibot ansibot added the stale_review Updates were made after the last review and the last review is more than 7 days old. label May 3, 2018
@s-hertel
Copy link
Contributor

s-hertel commented May 3, 2018

Hm. The ternary operator without explicit bool is working exactly the same as with the bool for me. Looks good though. This should be backported to 2.5 as well.

@ryansb ryansb merged commit 1905a6e into ansible:devel May 3, 2018
ZuZuD added a commit to ZuZuD/ansible that referenced this pull request May 10, 2018
ansible#38707)

* ec2_vpc_route_table: Update matching_count parsing on find_subnets function and tests

* ec2_vpc_route_table: Update matching_count parsing on find_subnets function

(cherry picked from commit 1905a6e)
oolongbrothers pushed a commit to oolongbrothers/ansible that referenced this pull request May 12, 2018
ansible#38707)

* ec2_vpc_route_table: Update matching_count parsing on find_subnets function and tests

* ec2_vpc_route_table: Update matching_count parsing on find_subnets function
oolongbrothers pushed a commit to oolongbrothers/ansible that referenced this pull request May 14, 2018
ansible#38707)

* ec2_vpc_route_table: Update matching_count parsing on find_subnets function and tests

* ec2_vpc_route_table: Update matching_count parsing on find_subnets function
oolongbrothers pushed a commit to oolongbrothers/ansible that referenced this pull request May 14, 2018
ansible#38707)

* ec2_vpc_route_table: Update matching_count parsing on find_subnets function and tests

* ec2_vpc_route_table: Update matching_count parsing on find_subnets function
tonal pushed a commit to tonal/ansible that referenced this pull request May 15, 2018
ansible#38707)

* ec2_vpc_route_table: Update matching_count parsing on find_subnets function and tests

* ec2_vpc_route_table: Update matching_count parsing on find_subnets function
oolongbrothers pushed a commit to oolongbrothers/ansible that referenced this pull request May 15, 2018
ansible#38707)

* ec2_vpc_route_table: Update matching_count parsing on find_subnets function and tests

* ec2_vpc_route_table: Update matching_count parsing on find_subnets function
oolongbrothers pushed a commit to oolongbrothers/ansible that referenced this pull request May 15, 2018
ansible#38707)

* ec2_vpc_route_table: Update matching_count parsing on find_subnets function and tests

* ec2_vpc_route_table: Update matching_count parsing on find_subnets function
nitzmahone pushed a commit that referenced this pull request May 17, 2018
#38707) (#39899)

* ec2_vpc_route_table: Update matching_count parsing on find_subnets function and tests

* ec2_vpc_route_table: Update matching_count parsing on find_subnets function

(cherry picked from commit 1905a6e)
ilicmilan pushed a commit to ilicmilan/ansible that referenced this pull request Nov 7, 2018
ansible#38707)

* ec2_vpc_route_table: Update matching_count parsing on find_subnets function and tests

* ec2_vpc_route_table: Update matching_count parsing on find_subnets function
@ansible ansible locked and limited conversation to collaborators May 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
aws bug This issue/PR relates to a bug. cloud module This issue/PR relates to a module. 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. support:certified This issue/PR relates to certified code. test This PR relates to tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ec2_vpc_route_table fails with "AttributeError: 'dict' object has no attribute 'tags'" on route table creation
6 participants