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_vol: boto3 migration (migrating ansible/ansible#45500 to amazon.aws) #53

Merged
merged 2 commits into from
Nov 16, 2020

Conversation

falcon78921
Copy link
Contributor

@falcon78921 falcon78921 commented May 14, 2020

SUMMARY

In order to keep the boto3 migration work in ansible/ansible#45500 alive, I attempted to add
the changes that were reviewed previously into a new PR.

ansible/ansible#45500 and some of the changes made in this PR were courtesy of @zeenlym.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

plugins/modules/ec2_vol.py

@falcon78921 falcon78921 changed the title plugins/modules: migrating ansible/ansible#45500 to amazon.aws [WIP] plugins/modules: migrating ansible/ansible#45500 to amazon.aws May 14, 2020
@falcon78921 falcon78921 marked this pull request as draft May 15, 2020 20:49
Copy link
Contributor

@tremble tremble 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 porting this over and getting this boto3-update moving again. A couple of minor niggles while you're still working on this

plugins/modules/ec2_vol.py Outdated Show resolved Hide resolved
plugins/modules/ec2_vol.py Outdated Show resolved Hide resolved
@falcon78921
Copy link
Contributor Author

Just wanted to say I'm still working on this PR.

@falcon78921
Copy link
Contributor Author

@tremble I've been working on integrating the paginator for get_volume() and get_volumes(), per the previous PR's review.

I'm able to gather results using something like this:

def getVolume():
    vols = []
    paginator = ec2_conn.get_paginator('describe_volumes')
    vols_response = paginator.paginate(Filters=[{'Name':'volume-id', 'Values':["{}".format(vol_id)]}])
    for p in vols_response:
        vols.append(p['Volumes'])
    return vols[0]
def getVolumes():
    vols = []
    paginator = ec2_conn.get_paginator('describe_volumes')
    vols_response = paginator.paginate(Filters=[{'Name':'attachment.instance-id', 'Values':["{}".format(instance)]}])
    for p in vols_response:
        vols.append(p['Volumes'])
    return vols

I'm just a little lost on how to integrate the preceding back into ec2_vol.py. The Paginator object returns an iterator, but I'm not sure if this may change behaviors in other functions.

@falcon78921 falcon78921 force-pushed the move-to-boto3 branch 5 times, most recently from 603ba40 to 694958d Compare June 10, 2020 21:48
@falcon78921
Copy link
Contributor Author

@tremble Ok, I think I have the paginator working now. I tested the changes against my EC2 instance and the playbook appeared to work.

Other than implementing the paginator and some minor formatting fixes, there were three things left:

ansible/ansible#45500 (comment)
ansible/ansible#45500 (comment)
ansible/ansible#45500 (comment)

I'll keep moving forward with the requested changes.

@jillr jillr changed the base branch from master to main July 2, 2020 19:22
@falcon78921 falcon78921 changed the title [WIP] plugins/modules: migrating ansible/ansible#45500 to amazon.aws plugins/modules: migrating ansible/ansible#45500 to amazon.aws Jul 2, 2020
@falcon78921 falcon78921 force-pushed the move-to-boto3 branch 6 times, most recently from a6e4f6f to 14294ac Compare July 13, 2020 17:52
@falcon78921 falcon78921 changed the title plugins/modules: migrating ansible/ansible#45500 to amazon.aws [WIP] plugins/modules: migrating ansible/ansible#45500 to amazon.aws Jul 13, 2020
@falcon78921 falcon78921 marked this pull request as ready for review July 13, 2020 19:12
@falcon78921
Copy link
Contributor Author

@s-hertel Regarding ansible/ansible#45500 (comment), do you mean removing changed = True and just letting ec2_conn.delete_volume() run? If it fails, botocore can return why.

@ansibullbot
Copy link

@falcon78921
Copy link
Contributor Author

In my AWS environment, ec2_vol seems to work when running through tests in main/tests/integration/targets/ec2_vol/tasks/main.yml.

@tremble
Copy link
Contributor

tremble commented Oct 22, 2020

In my AWS environment, ec2_vol seems to work when running through tests in main/tests/integration/targets/ec2_vol/tasks/main.yml.

Interesting, they're working for me. I wonder if there's something going on due to the way CI works...

@falcon78921
Copy link
Contributor Author

@tremble 🤔

@tremble
Copy link
Contributor

tremble commented Oct 22, 2020

I've done some digging and it looks like the ec2 instance isn't reporting the new volume in its description. This is after the waiter's done its thing.

By the time I run ec2_instance_info after the failed test it's showing up. I suspect that this is a very subtle race condition in the AWS APIs.

@tremble
Copy link
Contributor

tremble commented Oct 22, 2020

So... I've got something that seems to work: de6a699

Looks like this is a race condition of some variety: Basically the waiter which looks at the volume returns with "I'm attached to something" before the instance description includes the new volume.

plugins/modules/ec2_vol.py Outdated Show resolved Hide resolved
@falcon78921
Copy link
Contributor Author

@tremble Thanks for investigating the testing oddity. I applied your diff.

@tremble
Copy link
Contributor

tremble commented Oct 27, 2020

Thanks for working on getting this boto3 migration in :)

@falcon78921
Copy link
Contributor Author

@tremble Looks like there's still one test failing, but the rest are passing! 🎉

Copy link
Contributor

@tremble tremble left a comment

Choose a reason for hiding this comment

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

2 last minor changes and then I think we're ready to get this merged.

In theory we could also make more use of AWSRetry, but I'd rather see this merged and I'll CC you on the relevant change so you could see how it would work.

changelogs/fragments/53-ec2_vol-boto3-port.yml Outdated Show resolved Hide resolved
plugins/modules/ec2_vol.py Outdated Show resolved Hide resolved
@falcon78921
Copy link
Contributor Author

@tremble 👍

@tremble tremble merged commit 0c13bdb into ansible-collections:main Nov 16, 2020
@tremble
Copy link
Contributor

tremble commented Nov 16, 2020

Thanks for seeing this through. Scratch one more module off the boto v2 list.

@falcon78921 falcon78921 deleted the move-to-boto3 branch November 16, 2020 16:55
abikouo pushed a commit to abikouo/amazon.aws that referenced this pull request Sep 18, 2023
…s#53)

* Adds module aws_direct_connect_confirm_connection

DirectConnect connections that are created by a Hosted provider
require approval by users.  This module simply finds the
DirectConnect connection and confirms it if it's in the
'ordering' state.

* Adding unit tests

* Correcting test cases

* Correct linting issue

* Switch to AWSRetry decorator to correct test cases
abikouo pushed a commit to abikouo/amazon.aws that referenced this pull request Sep 18, 2023
…s#53)

* Adds module aws_direct_connect_confirm_connection

DirectConnect connections that are created by a Hosted provider
require approval by users.  This module simply finds the
DirectConnect connection and confirms it if it's in the
'ordering' state.

* Adding unit tests

* Correcting test cases

* Correct linting issue

* Switch to AWSRetry decorator to correct test cases
abikouo pushed a commit to abikouo/amazon.aws that referenced this pull request Oct 24, 2023
…s#53)

* Adds module aws_direct_connect_confirm_connection

DirectConnect connections that are created by a Hosted provider
require approval by users.  This module simply finds the
DirectConnect connection and confirms it if it's in the
'ordering' state.

* Adding unit tests

* Correcting test cases

* Correct linting issue

* Switch to AWSRetry decorator to correct test cases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects_2.10 bug This issue/PR relates to a bug has_issue integration tests/integration module module needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR new_contributor Help guide this first time contributor plugins plugin (any type) tests tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants