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

Register scalable target prior to creating/deleting a scaling policy #35632

Merged
merged 15 commits into from Mar 22, 2018

Conversation

chenl87
Copy link
Contributor

@chenl87 chenl87 commented Feb 1, 2018

SUMMARY

Added essential step of creating scalable target registration before attempting to create (and delete)
a scaling policy.

up until now, this module has always failed with the following message (example message):
"An error occurred (ObjectNotFoundException) when calling the PutScalingPolicy operation: No scalable target registered for service namespace: ecs, resource ID: service/poc-pricing/test-as, scalable dimension: ecs:service:DesiredCount"

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

aws_application_scaling_policy


ADDITIONAL INFORMATION

From boto3 documentation:
"
Registers or updates a scalable target. A scalable target is a resource that Application Auto Scaling can scale out or scale in. After you have registered a scalable target, you can use this operation to update the minimum and maximum values for its scalable dimension.

After you register a scalable target, you can create and apply scaling policies using PutScalingPolicy
"

http://boto3.readthedocs.io/en/latest/reference/services/application-autoscaling.html#ApplicationAutoScaling.Client.register_scalable_target


@ansibot
Copy link
Contributor

ansibot commented Feb 1, 2018

@ansibot ansibot added aws bugfix_pull_request cloud community_review In order to be merged, this PR must follow the community review workflow. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. 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. 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 community_review In order to be merged, this PR must follow the community review workflow. labels Feb 1, 2018
@mkrizek mkrizek removed the needs_triage Needs a first human triage before being processed. label Feb 2, 2018
@ansibot ansibot removed the ci_verified Changes made in this PR are causing tests to fail. label Feb 4, 2018
@ansibot
Copy link
Contributor

ansibot commented Feb 4, 2018

The test ansible-test sanity --test ansible-doc --python 2.6 [?] failed with the following error:

lib/ansible/modules/cloud/amazon/aws_application_scaling_policy.py:0:0: has a documentation error formatting or is missing documentation.

The test ansible-test sanity --test ansible-doc --python 2.7 [?] failed with the following error:

lib/ansible/modules/cloud/amazon/aws_application_scaling_policy.py:0:0: has a documentation error formatting or is missing documentation.

The test ansible-test sanity --test ansible-doc --python 3.5 [?] failed with the following error:

lib/ansible/modules/cloud/amazon/aws_application_scaling_policy.py:0:0: has a documentation error formatting or is missing documentation.

The test ansible-test sanity --test ansible-doc --python 3.6 [?] failed with the following error:

lib/ansible/modules/cloud/amazon/aws_application_scaling_policy.py:0:0: has a documentation error formatting or is missing documentation.

The test ansible-test sanity --test ansible-doc --python 3.7 [?] failed with the following error:

lib/ansible/modules/cloud/amazon/aws_application_scaling_policy.py:0:0: has a documentation error formatting or is missing documentation.

click here for bot help

@ansibot ansibot added the ci_verified Changes made in this PR are causing tests to fail. label Feb 4, 2018
@ansibot ansibot added community_review In order to be merged, this PR must follow the community 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 Feb 4, 2018
@chenl87
Copy link
Contributor Author

chenl87 commented Feb 4, 2018

ready_for_review

@chenl87
Copy link
Contributor Author

chenl87 commented Feb 6, 2018

@gurumaia , Could you please take a look at the changes?
Thanks!

@ryansb ryansb self-requested a review February 7, 2018 18:31
@@ -170,7 +178,56 @@ def delete_scaling_policy(connection, module):
except Exception as e:
module.fail_json(msg=str(e), exception=traceback.format_exc())

module.exit_json(changed=changed)
result = {"changed": changed}
Copy link
Contributor

Choose a reason for hiding this comment

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

You could just return {'changed': changed}

def create_scalable_target(connection, module):
changed = False

scalable_targets = connection.describe_scalable_targets(
Copy link
Contributor

Choose a reason for hiding this comment

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

This call needs exception handling.

MinCapacity=module.params.get('minimum_tasks'),
MaxCapacity=module.params.get('maximum_tasks')
)
except Exception as e:
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like the rest of the module is using except Exception so you've probably done this for consistency, but it would be better to catch only the specific exceptions, which would be the botocore.exceptions ClientError and BotoCoreError. Same for the one below. At some point the other 'except Exception's need to be removed.
Guidelines on exception handling: https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/cloud/amazon/GUIDELINES.md#using-fail_json-and-avoiding-ansiblemodule_utilsawscore

else:
snaked_response = {}

result = {"changed": changed, "response": snaked_response}
Copy link
Contributor

Choose a reason for hiding this comment

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

You could just return this dict, same below.

@@ -284,11 +344,19 @@ def main():
except botocore.exceptions.ProfileNotFound as e:
module.fail_json(msg=str(e))

# A scalable target must be registered prior to creating a scaling policy
scalable_target_result = create_scalable_target(connection, module)
Copy link
Contributor

Choose a reason for hiding this comment

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

For backwards compatibility should there be a way to turn this on or off?


# return the scalable target result only if it has changed and there were no policy changes
if scalable_target_result['changed'] is True and policy_result['changed'] is False:
module.exit_json(**scalable_target_result)
Copy link
Contributor

Choose a reason for hiding this comment

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

The contents of this needs to be added to the RETURN doc.

@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 Feb 15, 2018
@ansibot ansibot added community_review In order to be merged, this PR must follow the community 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 Feb 20, 2018
@chenl87
Copy link
Contributor Author

chenl87 commented Feb 20, 2018

ready_for_review

@chenl87
Copy link
Contributor Author

chenl87 commented Feb 21, 2018

@s-hertel , thanks for the review and the comments. I've pushed the necessary fixes and some other enhancements. I'd really appreciate if you could give it another look.

@ansibot ansibot added bug This issue/PR relates to a bug. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. and removed bugfix_pull_request labels Mar 1, 2018
@chenl87
Copy link
Contributor Author

chenl87 commented Mar 5, 2018

@s-hertel @ryansb , any chance you guys can review it anytime soon?
I'm already running with this in our production environment and I would really prefer to run with an Ansible devel installation instead of my fork.

Thanks!

Copy link
Contributor

@s-hertel s-hertel left a comment

Choose a reason for hiding this comment

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

This looks great @chenl87, thanks for the patience. Feel free to add yourself as an author, and then you'll get updates and be able to use the power of "shipit" to help get community contributions merged.

))

module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True)

if not HAS_BOTO3:
Copy link
Contributor

Choose a reason for hiding this comment

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

AnsibleAWSModule checks this for you so you can remove this and the import.


if not HAS_BOTO3:
module.fail_json(msg='boto3 is required.')
module.fail_json_aws(msg='boto3 is required.')

try:
region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module, boto3=True)
if not region:
Copy link
Contributor

Choose a reason for hiding this comment

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

boto3_conn handles this for you. You can remove this, as well as the try/except around boto3_conn. It handles ProfileNotFound. Since you're using AnsibleAWSModule you can replace this entire try/except with: connection = module.client('application-autoscaling').

@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 Mar 21, 2018
@ansibot
Copy link
Contributor

ansibot commented Mar 21, 2018

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

lib/ansible/modules/cloud/amazon/aws_application_scaling_policy.py:472:0: trailing-whitespace Trailing whitespace

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

lib/ansible/modules/cloud/amazon/aws_application_scaling_policy.py:472:1: W293 blank line contains whitespace

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 community_review In order to be merged, this PR must follow the community review workflow. labels Mar 21, 2018
@ansibot ansibot added community_review In order to be merged, this PR must follow the community 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 Mar 21, 2018
@ansible ansible deleted a comment from ansibot Mar 22, 2018
@ansible ansible deleted a comment from chenl87 Mar 22, 2018
@ansible ansible deleted a comment from ansibot Mar 22, 2018
@ryansb ryansb merged commit e501134 into ansible:devel Mar 22, 2018
@ansible ansible locked and limited conversation to collaborators Apr 27, 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 community_review In order to be merged, this PR must follow the community review workflow. module This issue/PR relates to a module. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants