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_instance should allow setting and changing PlacementGroup and PartitionNumber #1264

Closed
wants to merge 4 commits into from

Conversation

daniel-trnk
Copy link

SUMMARY

I needed the ability to set PlacementGroup and PartitionNumber for the Placement of a new instance as well as changing them for a stopped existing instance. This is an attempt to implement that for your review.

Fixes #1263

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

ec2_instance

ADDITIONAL INFORMATION

@ansibullbot
Copy link

@daniel-trnk this PR contains the following merge commits:

Please rebase your branch to remove these commits.

click here for bot help

@ansibullbot ansibullbot added feature This issue/PR relates to a feature request merge_commit This PR contains at least one merge commit. Please resolve! module module needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_triage new_contributor Help guide this first time contributor labels Nov 13, 2022
@softwarefactory-project-zuul
Copy link
Contributor

Build failed.

✔️ ansible-galaxy-importer SUCCESS in 6m 19s
✔️ build-ansible-collection SUCCESS in 6m 34s
ansible-test-sanity-aws-ansible-python38 FAILURE in 12m 12s (non-voting)
ansible-test-sanity-aws-ansible-2.12-python38 FAILURE in 14m 27s
ansible-test-sanity-aws-ansible-2.13-python38 FAILURE in 15m 16s
ansible-test-sanity-aws-ansible-2.14 FAILURE in 15m 14s
✔️ ansible-test-units-amazon-aws-python36 SUCCESS in 11m 45s
✔️ ansible-test-units-amazon-aws-python38 SUCCESS in 10m 40s
✔️ ansible-test-units-amazon-aws-python39 SUCCESS in 12m 32s
✔️ cloud-tox-py3 SUCCESS in 3m 39s
ansible-test-changelog FAILURE in 2m 38s
✔️ ansible-test-splitter SUCCESS in 3m 10s
✔️ integration-amazon.aws-1 SUCCESS in 44m 42s
✔️ integration-amazon.aws-2 SUCCESS in 43m 47s
✔️ integration-amazon.aws-3 SUCCESS in 36m 49s
⚠️ integration-amazon.aws-4 SKIPPED
⚠️ integration-amazon.aws-5 SKIPPED
⚠️ integration-amazon.aws-6 SKIPPED
⚠️ integration-amazon.aws-7 SKIPPED
⚠️ integration-amazon.aws-8 SKIPPED
⚠️ integration-amazon.aws-9 SKIPPED
⚠️ integration-amazon.aws-10 SKIPPED
⚠️ integration-amazon.aws-11 SKIPPED
⚠️ integration-amazon.aws-12 SKIPPED
⚠️ integration-amazon.aws-13 SKIPPED
⚠️ integration-amazon.aws-14 SKIPPED
⚠️ integration-amazon.aws-15 SKIPPED
⚠️ integration-amazon.aws-16 SKIPPED
⚠️ integration-amazon.aws-17 SKIPPED
⚠️ integration-amazon.aws-18 SKIPPED
⚠️ integration-amazon.aws-19 SKIPPED
⚠️ integration-amazon.aws-20 SKIPPED
⚠️ integration-amazon.aws-21 SKIPPED
⚠️ integration-amazon.aws-22 SKIPPED
⚠️ integration-community.aws-1 SKIPPED
⚠️ integration-community.aws-2 SKIPPED
⚠️ integration-community.aws-3 SKIPPED
⚠️ integration-community.aws-4 SKIPPED
⚠️ integration-community.aws-5 SKIPPED
⚠️ integration-community.aws-6 SKIPPED
⚠️ integration-community.aws-7 SKIPPED
⚠️ integration-community.aws-8 SKIPPED
⚠️ integration-community.aws-9 SKIPPED
⚠️ integration-community.aws-10 SKIPPED
⚠️ integration-community.aws-11 SKIPPED
⚠️ integration-community.aws-12 SKIPPED
⚠️ integration-community.aws-13 SKIPPED
⚠️ integration-community.aws-14 SKIPPED
⚠️ integration-community.aws-15 SKIPPED
⚠️ integration-community.aws-16 SKIPPED
⚠️ integration-community.aws-17 SKIPPED
⚠️ integration-community.aws-18 SKIPPED
⚠️ integration-community.aws-19 SKIPPED
⚠️ integration-community.aws-20 SKIPPED
⚠️ integration-community.aws-21 SKIPPED
⚠️ integration-community.aws-22 SKIPPED

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 taking the time to submit this PR. Some comments inline.

It looks like our tests threw out a few errors and can be found in the logs (click on the link for each test, that'll take you to the build, from there you can click on the logs tab). Please address these.

Additionally:

@@ -2016,6 +2049,7 @@ def main():
)),
tenancy=dict(type='str', choices=['dedicated', 'default']),
placement_group=dict(type='str'),
partition_number=dict(type='int', choices=[1,2,3,4,5,6,7]),
Copy link
Contributor

Choose a reason for hiding this comment

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

While there's currently a limit of 7 partitions per placement group, I'd recommend against hardcoding this limit using choices. With a hard coded limit, should Amazon increase the limit we need a new release to support the new partitions.

Comment on lines +325 to +327
partition_number:
description:
- The number of the partition within the placement group - only valid with partition typle placement groups.
Copy link
Contributor

@tremble tremble Nov 14, 2022

Choose a reason for hiding this comment

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

Suggested change
partition_number:
description:
- The number of the partition within the placement group - only valid with partition typle placement groups.
partition_number:
description:
- The number of the partition within the placement group - only valid with partition typle placement groups.
type: int
version_added: 5.3.0

Comment on lines +1516 to +1517
if (( desired_placement['GroupName'] != current_placement['GroupName']) or
( 'PartitionNumber' in desired_placement and ( desired_placement['PartitionNumber'] != current_placement['PartitionNumber']))):
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is going to throw a KeyError exception if someone tries to assign a partition number while using a cluster placement group. While the API would still return an error, the API error message is cleanly caught and likely has a helpful error message.

Comment on lines +1526 to +1527
module.fail_json_aws(e, msg="Could not change placement instance {0} to {1}".format(instance['InstanceId'],
desired_placement_group,desired_partition_number))
Copy link
Contributor

Choose a reason for hiding this comment

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

There are 3 args passed and only 2 used in the format...

@@ -1497,6 +1502,33 @@ def change_network_attachments(instance, params):
return False


def change_placement(instance, params):
Copy link
Contributor

Choose a reason for hiding this comment

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

This will currently result in the placement being updated while running in "check" mode.

What I'd suggest is something like the following.

def change_placement(instance, params):
    current_placement = instance.get("Placement", {}) 
    current_group = current_placement.get("GroupName")
    current_partition = current_placement.get("PartitionNumber")
    desired_group = params.get("placement_group")
    desired_partition = params.get("partition_number")

    changed = False

    if desired_group is not None and current_group != desired_group:
        changed = True
    if desired_partition is not None and current_partition != desired_partition:
        changed = True

    if module.check_mode or changed is False:
        return changed

    desired_placement = {"GroupName": desired_group or current_group}
    if desired_partition:
        desired_placement["PartitionNumber"] = desired_partition

    try:
        client.modify_instance_placement(
            aws_retry=True, InstanceId=instance["InstanceId"], **desired_placement
        )   
    except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e:
        module.fail_json_aws(
            e,  
            msg="Could not change placement of instance {0} to {1}".format(
                instance["InstanceId"], desired_placement
            ),  
        )   

    return True

By simply returning early if we're in check mode or don't have a change to make we can avoid the extra level of nesting.

By pulling the desired/current state out into temporary variables, it's much easier to follow (and debug) the "has something changed" logic.

@@ -2016,6 +2049,7 @@ def main():
)),
tenancy=dict(type='str', choices=['dedicated', 'default']),
placement_group=dict(type='str'),
partition_number=dict(type='int', choices=[1,2,3,4,5,6,7]),
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to require that the placement group is set if someone sets the partition number?
This would cause things to fail early with an obvious error message if someone tried to set the partition number when still using the default placement, rather than potentially performing half an update.

This could be achieved using "required_by" to the module creation (we already have things like mutually_exclusive)
https://docs.ansible.com/ansible/latest/dev_guide/developing_program_flow_modules.html#argument-spec-dependencies

…y resolution? Error was: Provided candidate <amazon.aws:6.0.0-dev0 ... <amazon.aws:>=4.0.0 ,,,
@softwarefactory-project-zuul
Copy link
Contributor

Build failed.

✔️ ansible-galaxy-importer SUCCESS in 4m 17s
✔️ build-ansible-collection SUCCESS in 5m 19s
ansible-test-sanity-aws-ansible-python38 FAILURE in 9m 11s (non-voting)
ansible-test-sanity-aws-ansible-2.12-python38 FAILURE in 9m 57s
ansible-test-sanity-aws-ansible-2.13-python38 FAILURE in 8m 35s
ansible-test-sanity-aws-ansible-2.14 FAILURE in 9m 47s
✔️ ansible-test-units-amazon-aws-python36 SUCCESS in 9m 22s
✔️ ansible-test-units-amazon-aws-python38 SUCCESS in 8m 45s
✔️ ansible-test-units-amazon-aws-python39 SUCCESS in 10m 07s
✔️ cloud-tox-py3 SUCCESS in 6m 02s
ansible-test-changelog FAILURE in 2m 13s
✔️ ansible-test-splitter SUCCESS in 2m 32s
✔️ integration-amazon.aws-1 SUCCESS in 45m 18s
integration-amazon.aws-2 FAILURE in 40m 16s
✔️ integration-amazon.aws-3 SUCCESS in 41m 01s
⚠️ integration-amazon.aws-4 SKIPPED
⚠️ integration-amazon.aws-5 SKIPPED
⚠️ integration-amazon.aws-6 SKIPPED
⚠️ integration-amazon.aws-7 SKIPPED
⚠️ integration-amazon.aws-8 SKIPPED
⚠️ integration-amazon.aws-9 SKIPPED
⚠️ integration-amazon.aws-10 SKIPPED
⚠️ integration-amazon.aws-11 SKIPPED
⚠️ integration-amazon.aws-12 SKIPPED
⚠️ integration-amazon.aws-13 SKIPPED
⚠️ integration-amazon.aws-14 SKIPPED
⚠️ integration-amazon.aws-15 SKIPPED
⚠️ integration-amazon.aws-16 SKIPPED
⚠️ integration-amazon.aws-17 SKIPPED
⚠️ integration-amazon.aws-18 SKIPPED
⚠️ integration-amazon.aws-19 SKIPPED
⚠️ integration-amazon.aws-20 SKIPPED
⚠️ integration-amazon.aws-21 SKIPPED
⚠️ integration-amazon.aws-22 SKIPPED
⚠️ integration-community.aws-1 SKIPPED
⚠️ integration-community.aws-2 SKIPPED
⚠️ integration-community.aws-3 SKIPPED
⚠️ integration-community.aws-4 SKIPPED
⚠️ integration-community.aws-5 SKIPPED
⚠️ integration-community.aws-6 SKIPPED
⚠️ integration-community.aws-7 SKIPPED
⚠️ integration-community.aws-8 SKIPPED
⚠️ integration-community.aws-9 SKIPPED
⚠️ integration-community.aws-10 SKIPPED
⚠️ integration-community.aws-11 SKIPPED
⚠️ integration-community.aws-12 SKIPPED
⚠️ integration-community.aws-13 SKIPPED
⚠️ integration-community.aws-14 SKIPPED
⚠️ integration-community.aws-15 SKIPPED
⚠️ integration-community.aws-16 SKIPPED
⚠️ integration-community.aws-17 SKIPPED
⚠️ integration-community.aws-18 SKIPPED
⚠️ integration-community.aws-19 SKIPPED
⚠️ integration-community.aws-20 SKIPPED
⚠️ integration-community.aws-21 SKIPPED
⚠️ integration-community.aws-22 SKIPPED

abikouo pushed a commit to abikouo/amazon.aws that referenced this pull request Sep 18, 2023
Rename SES modules

SUMMARY
In line with what I understood to be the consensus on ansible-collections#881 and ansible-collections#610
Rename ses modules to remove the aws_ prefix.
ISSUE TYPE

Feature Pull Request

COMPONENT NAME
plugins/modules/aws_ses_identity.py
plugins/modules/aws_ses_identity_policy.py
plugins/modules/aws_ses_rule_set.py
plugins/modules/ses_identity.py
plugins/modules/ses_identity_policy.py
plugins/modules/ses_rule_set.py
ADDITIONAL INFORMATION

Reviewed-by: Alina Buzachis <None>
abikouo pushed a commit to abikouo/amazon.aws that referenced this pull request Sep 18, 2023
Rename SES modules

SUMMARY
In line with what I understood to be the consensus on ansible-collections#881 and ansible-collections#610
Rename ses modules to remove the aws_ prefix.
ISSUE TYPE

Feature Pull Request

COMPONENT NAME
plugins/modules/aws_ses_identity.py
plugins/modules/aws_ses_identity_policy.py
plugins/modules/aws_ses_rule_set.py
plugins/modules/ses_identity.py
plugins/modules/ses_identity_policy.py
plugins/modules/ses_rule_set.py
ADDITIONAL INFORMATION

Reviewed-by: Alina Buzachis <None>
abikouo pushed a commit to abikouo/amazon.aws that referenced this pull request Oct 24, 2023
Rename SES modules

SUMMARY
In line with what I understood to be the consensus on ansible-collections#881 and ansible-collections#610
Rename ses modules to remove the aws_ prefix.
ISSUE TYPE

Feature Pull Request

COMPONENT NAME
plugins/modules/aws_ses_identity.py
plugins/modules/aws_ses_identity_policy.py
plugins/modules/aws_ses_rule_set.py
plugins/modules/ses_identity.py
plugins/modules/ses_identity_policy.py
plugins/modules/ses_rule_set.py
ADDITIONAL INFORMATION

Reviewed-by: Alina Buzachis <None>
@mfortin
Copy link
Contributor

mfortin commented Oct 28, 2023

#1825 handles placement group name and partition id

@tremble
Copy link
Contributor

tremble commented Oct 30, 2023

Thanks for taking the time to open this PR.

Unfortunately this PR has now bit rotted and as mentioned by @mfortin there's an alternative PR which is being actively worked on.. As such I'm going to close this PR. Please feel free to submit PRs in future.

@tremble tremble closed this Oct 30, 2023
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 merge_commit This PR contains at least one merge commit. Please resolve! module module needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html new_contributor Help guide this first time contributor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ec2_instance should allow setting and changing PlacementGroup and PartitionNumber
6 participants